DeclCXX.h revision 7ae282fde0a12635893931ebf31b35b0d5d5cab3
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
1813  /// \brief Get the initializer. This is 0 if this is an in-class initializer
1814  /// for a non-static data member which has not yet been parsed.
1815  Expr *getInit() const {
1816    if (!Init)
1817      return getAnyMember()->getInClassInitializer();
1818
1819    return static_cast<Expr*>(Init);
1820  }
1821};
1822
1823/// CXXConstructorDecl - Represents a C++ constructor within a
1824/// class. For example:
1825///
1826/// @code
1827/// class X {
1828/// public:
1829///   explicit X(int); // represented by a CXXConstructorDecl.
1830/// };
1831/// @endcode
1832class CXXConstructorDecl : public CXXMethodDecl {
1833  virtual void anchor();
1834  /// IsExplicitSpecified - Whether this constructor declaration has the
1835  /// 'explicit' keyword specified.
1836  bool IsExplicitSpecified : 1;
1837
1838  /// ImplicitlyDefined - Whether this constructor was implicitly
1839  /// defined by the compiler. When false, the constructor was defined
1840  /// by the user. In C++03, this flag will have the same value as
1841  /// Implicit. In C++0x, however, a constructor that is
1842  /// explicitly defaulted (i.e., defined with " = default") will have
1843  /// @c !Implicit && ImplicitlyDefined.
1844  bool ImplicitlyDefined : 1;
1845
1846  /// Support for base and member initializers.
1847  /// CtorInitializers - The arguments used to initialize the base
1848  /// or member.
1849  CXXCtorInitializer **CtorInitializers;
1850  unsigned NumCtorInitializers;
1851
1852  CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
1853                     const DeclarationNameInfo &NameInfo,
1854                     QualType T, TypeSourceInfo *TInfo,
1855                     bool isExplicitSpecified, bool isInline,
1856                     bool isImplicitlyDeclared, bool isConstexpr)
1857    : CXXMethodDecl(CXXConstructor, RD, StartLoc, NameInfo, T, TInfo, false,
1858                    SC_None, isInline, isConstexpr, SourceLocation()),
1859      IsExplicitSpecified(isExplicitSpecified), ImplicitlyDefined(false),
1860      CtorInitializers(0), NumCtorInitializers(0) {
1861    setImplicit(isImplicitlyDeclared);
1862  }
1863
1864public:
1865  static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1866  static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1867                                    SourceLocation StartLoc,
1868                                    const DeclarationNameInfo &NameInfo,
1869                                    QualType T, TypeSourceInfo *TInfo,
1870                                    bool isExplicit,
1871                                    bool isInline, bool isImplicitlyDeclared,
1872                                    bool isConstexpr);
1873
1874  /// isExplicitSpecified - Whether this constructor declaration has the
1875  /// 'explicit' keyword specified.
1876  bool isExplicitSpecified() const { return IsExplicitSpecified; }
1877
1878  /// isExplicit - Whether this constructor was marked "explicit" or not.
1879  bool isExplicit() const {
1880    return cast<CXXConstructorDecl>(getFirstDeclaration())
1881      ->isExplicitSpecified();
1882  }
1883
1884  /// isImplicitlyDefined - Whether this constructor was implicitly
1885  /// defined. If false, then this constructor was defined by the
1886  /// user. This operation can only be invoked if the constructor has
1887  /// already been defined.
1888  bool isImplicitlyDefined() const {
1889    assert(isThisDeclarationADefinition() &&
1890           "Can only get the implicit-definition flag once the "
1891           "constructor has been defined");
1892    return ImplicitlyDefined;
1893  }
1894
1895  /// setImplicitlyDefined - Set whether this constructor was
1896  /// implicitly defined or not.
1897  void setImplicitlyDefined(bool ID) {
1898    assert(isThisDeclarationADefinition() &&
1899           "Can only set the implicit-definition flag once the constructor "
1900           "has been defined");
1901    ImplicitlyDefined = ID;
1902  }
1903
1904  /// init_iterator - Iterates through the member/base initializer list.
1905  typedef CXXCtorInitializer **init_iterator;
1906
1907  /// init_const_iterator - Iterates through the memberbase initializer list.
1908  typedef CXXCtorInitializer * const * init_const_iterator;
1909
1910  /// init_begin() - Retrieve an iterator to the first initializer.
1911  init_iterator       init_begin()       { return CtorInitializers; }
1912  /// begin() - Retrieve an iterator to the first initializer.
1913  init_const_iterator init_begin() const { return CtorInitializers; }
1914
1915  /// init_end() - Retrieve an iterator past the last initializer.
1916  init_iterator       init_end()       {
1917    return CtorInitializers + NumCtorInitializers;
1918  }
1919  /// end() - Retrieve an iterator past the last initializer.
1920  init_const_iterator init_end() const {
1921    return CtorInitializers + NumCtorInitializers;
1922  }
1923
1924  typedef std::reverse_iterator<init_iterator> init_reverse_iterator;
1925  typedef std::reverse_iterator<init_const_iterator>
1926          init_const_reverse_iterator;
1927
1928  init_reverse_iterator init_rbegin() {
1929    return init_reverse_iterator(init_end());
1930  }
1931  init_const_reverse_iterator init_rbegin() const {
1932    return init_const_reverse_iterator(init_end());
1933  }
1934
1935  init_reverse_iterator init_rend() {
1936    return init_reverse_iterator(init_begin());
1937  }
1938  init_const_reverse_iterator init_rend() const {
1939    return init_const_reverse_iterator(init_begin());
1940  }
1941
1942  /// getNumArgs - Determine the number of arguments used to
1943  /// initialize the member or base.
1944  unsigned getNumCtorInitializers() const {
1945      return NumCtorInitializers;
1946  }
1947
1948  void setNumCtorInitializers(unsigned numCtorInitializers) {
1949    NumCtorInitializers = numCtorInitializers;
1950  }
1951
1952  void setCtorInitializers(CXXCtorInitializer ** initializers) {
1953    CtorInitializers = initializers;
1954  }
1955
1956  /// isDelegatingConstructor - Whether this constructor is a
1957  /// delegating constructor
1958  bool isDelegatingConstructor() const {
1959    return (getNumCtorInitializers() == 1) &&
1960      CtorInitializers[0]->isDelegatingInitializer();
1961  }
1962
1963  /// getTargetConstructor - When this constructor delegates to
1964  /// another, retrieve the target
1965  CXXConstructorDecl *getTargetConstructor() const;
1966
1967  /// isDefaultConstructor - Whether this constructor is a default
1968  /// constructor (C++ [class.ctor]p5), which can be used to
1969  /// default-initialize a class of this type.
1970  bool isDefaultConstructor() const;
1971
1972  /// isCopyConstructor - Whether this constructor is a copy
1973  /// constructor (C++ [class.copy]p2, which can be used to copy the
1974  /// class. @p TypeQuals will be set to the qualifiers on the
1975  /// argument type. For example, @p TypeQuals would be set to @c
1976  /// QualType::Const for the following copy constructor:
1977  ///
1978  /// @code
1979  /// class X {
1980  /// public:
1981  ///   X(const X&);
1982  /// };
1983  /// @endcode
1984  bool isCopyConstructor(unsigned &TypeQuals) const;
1985
1986  /// isCopyConstructor - Whether this constructor is a copy
1987  /// constructor (C++ [class.copy]p2, which can be used to copy the
1988  /// class.
1989  bool isCopyConstructor() const {
1990    unsigned TypeQuals = 0;
1991    return isCopyConstructor(TypeQuals);
1992  }
1993
1994  /// \brief Determine whether this constructor is a move constructor
1995  /// (C++0x [class.copy]p3), which can be used to move values of the class.
1996  ///
1997  /// \param TypeQuals If this constructor is a move constructor, will be set
1998  /// to the type qualifiers on the referent of the first parameter's type.
1999  bool isMoveConstructor(unsigned &TypeQuals) const;
2000
2001  /// \brief Determine whether this constructor is a move constructor
2002  /// (C++0x [class.copy]p3), which can be used to move values of the class.
2003  bool isMoveConstructor() const {
2004    unsigned TypeQuals = 0;
2005    return isMoveConstructor(TypeQuals);
2006  }
2007
2008  /// \brief Determine whether this is a copy or move constructor.
2009  ///
2010  /// \param TypeQuals Will be set to the type qualifiers on the reference
2011  /// parameter, if in fact this is a copy or move constructor.
2012  bool isCopyOrMoveConstructor(unsigned &TypeQuals) const;
2013
2014  /// \brief Determine whether this a copy or move constructor.
2015  bool isCopyOrMoveConstructor() const {
2016    unsigned Quals;
2017    return isCopyOrMoveConstructor(Quals);
2018  }
2019
2020  /// isConvertingConstructor - Whether this constructor is a
2021  /// converting constructor (C++ [class.conv.ctor]), which can be
2022  /// used for user-defined conversions.
2023  bool isConvertingConstructor(bool AllowExplicit) const;
2024
2025  /// \brief Determine whether this is a member template specialization that
2026  /// would copy the object to itself. Such constructors are never used to copy
2027  /// an object.
2028  bool isSpecializationCopyingObject() const;
2029
2030  /// \brief Get the constructor that this inheriting constructor is based on.
2031  const CXXConstructorDecl *getInheritedConstructor() const;
2032
2033  /// \brief Set the constructor that this inheriting constructor is based on.
2034  void setInheritedConstructor(const CXXConstructorDecl *BaseCtor);
2035
2036  const CXXConstructorDecl *getCanonicalDecl() const {
2037    return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
2038  }
2039  CXXConstructorDecl *getCanonicalDecl() {
2040    return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
2041  }
2042
2043  // Implement isa/cast/dyncast/etc.
2044  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2045  static bool classof(const CXXConstructorDecl *D) { return true; }
2046  static bool classofKind(Kind K) { return K == CXXConstructor; }
2047
2048  friend class ASTDeclReader;
2049  friend class ASTDeclWriter;
2050};
2051
2052/// CXXDestructorDecl - Represents a C++ destructor within a
2053/// class. For example:
2054///
2055/// @code
2056/// class X {
2057/// public:
2058///   ~X(); // represented by a CXXDestructorDecl.
2059/// };
2060/// @endcode
2061class CXXDestructorDecl : public CXXMethodDecl {
2062  virtual void anchor();
2063  /// ImplicitlyDefined - Whether this destructor was implicitly
2064  /// defined by the compiler. When false, the destructor was defined
2065  /// by the user. In C++03, this flag will have the same value as
2066  /// Implicit. In C++0x, however, a destructor that is
2067  /// explicitly defaulted (i.e., defined with " = default") will have
2068  /// @c !Implicit && ImplicitlyDefined.
2069  bool ImplicitlyDefined : 1;
2070
2071  FunctionDecl *OperatorDelete;
2072
2073  CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
2074                    const DeclarationNameInfo &NameInfo,
2075                    QualType T, TypeSourceInfo *TInfo,
2076                    bool isInline, bool isImplicitlyDeclared)
2077    : CXXMethodDecl(CXXDestructor, RD, StartLoc, NameInfo, T, TInfo, false,
2078                    SC_None, isInline, /*isConstexpr=*/false, SourceLocation()),
2079      ImplicitlyDefined(false), OperatorDelete(0) {
2080    setImplicit(isImplicitlyDeclared);
2081  }
2082
2083public:
2084  static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2085                                   SourceLocation StartLoc,
2086                                   const DeclarationNameInfo &NameInfo,
2087                                   QualType T, TypeSourceInfo* TInfo,
2088                                   bool isInline,
2089                                   bool isImplicitlyDeclared);
2090  static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID);
2091
2092  /// isImplicitlyDefined - Whether this destructor was implicitly
2093  /// defined. If false, then this destructor was defined by the
2094  /// user. This operation can only be invoked if the destructor has
2095  /// already been defined.
2096  bool isImplicitlyDefined() const {
2097    assert(isThisDeclarationADefinition() &&
2098           "Can only get the implicit-definition flag once the destructor has "
2099           "been defined");
2100    return ImplicitlyDefined;
2101  }
2102
2103  /// setImplicitlyDefined - Set whether this destructor was
2104  /// implicitly defined or not.
2105  void setImplicitlyDefined(bool ID) {
2106    assert(isThisDeclarationADefinition() &&
2107           "Can only set the implicit-definition flag once the destructor has "
2108           "been defined");
2109    ImplicitlyDefined = ID;
2110  }
2111
2112  void setOperatorDelete(FunctionDecl *OD) { OperatorDelete = OD; }
2113  const FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
2114
2115  // Implement isa/cast/dyncast/etc.
2116  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2117  static bool classof(const CXXDestructorDecl *D) { return true; }
2118  static bool classofKind(Kind K) { return K == CXXDestructor; }
2119
2120  friend class ASTDeclReader;
2121  friend class ASTDeclWriter;
2122};
2123
2124/// CXXConversionDecl - Represents a C++ conversion function within a
2125/// class. For example:
2126///
2127/// @code
2128/// class X {
2129/// public:
2130///   operator bool();
2131/// };
2132/// @endcode
2133class CXXConversionDecl : public CXXMethodDecl {
2134  virtual void anchor();
2135  /// IsExplicitSpecified - Whether this conversion function declaration is
2136  /// marked "explicit", meaning that it can only be applied when the user
2137  /// explicitly wrote a cast. This is a C++0x feature.
2138  bool IsExplicitSpecified : 1;
2139
2140  CXXConversionDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
2141                    const DeclarationNameInfo &NameInfo,
2142                    QualType T, TypeSourceInfo *TInfo,
2143                    bool isInline, bool isExplicitSpecified,
2144                    bool isConstexpr, SourceLocation EndLocation)
2145    : CXXMethodDecl(CXXConversion, RD, StartLoc, NameInfo, T, TInfo, false,
2146                    SC_None, isInline, isConstexpr, EndLocation),
2147      IsExplicitSpecified(isExplicitSpecified) { }
2148
2149public:
2150  static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2151                                   SourceLocation StartLoc,
2152                                   const DeclarationNameInfo &NameInfo,
2153                                   QualType T, TypeSourceInfo *TInfo,
2154                                   bool isInline, bool isExplicit,
2155                                   bool isConstexpr,
2156                                   SourceLocation EndLocation);
2157  static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2158
2159  /// IsExplicitSpecified - Whether this conversion function declaration is
2160  /// marked "explicit", meaning that it can only be applied when the user
2161  /// explicitly wrote a cast. This is a C++0x feature.
2162  bool isExplicitSpecified() const { return IsExplicitSpecified; }
2163
2164  /// isExplicit - Whether this is an explicit conversion operator
2165  /// (C++0x only). Explicit conversion operators are only considered
2166  /// when the user has explicitly written a cast.
2167  bool isExplicit() const {
2168    return cast<CXXConversionDecl>(getFirstDeclaration())
2169      ->isExplicitSpecified();
2170  }
2171
2172  /// getConversionType - Returns the type that this conversion
2173  /// function is converting to.
2174  QualType getConversionType() const {
2175    return getType()->getAs<FunctionType>()->getResultType();
2176  }
2177
2178  // Implement isa/cast/dyncast/etc.
2179  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2180  static bool classof(const CXXConversionDecl *D) { return true; }
2181  static bool classofKind(Kind K) { return K == CXXConversion; }
2182
2183  friend class ASTDeclReader;
2184  friend class ASTDeclWriter;
2185};
2186
2187/// LinkageSpecDecl - This represents a linkage specification.  For example:
2188///   extern "C" void foo();
2189///
2190class LinkageSpecDecl : public Decl, public DeclContext {
2191  virtual void anchor();
2192public:
2193  /// LanguageIDs - Used to represent the language in a linkage
2194  /// specification.  The values are part of the serialization abi for
2195  /// ASTs and cannot be changed without altering that abi.  To help
2196  /// ensure a stable abi for this, we choose the DW_LANG_ encodings
2197  /// from the dwarf standard.
2198  enum LanguageIDs {
2199    lang_c = /* DW_LANG_C */ 0x0002,
2200    lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004
2201  };
2202private:
2203  /// Language - The language for this linkage specification.
2204  LanguageIDs Language;
2205  /// ExternLoc - The source location for the extern keyword.
2206  SourceLocation ExternLoc;
2207  /// RBraceLoc - The source location for the right brace (if valid).
2208  SourceLocation RBraceLoc;
2209
2210  LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
2211                  SourceLocation LangLoc, LanguageIDs lang,
2212                  SourceLocation RBLoc)
2213    : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec),
2214      Language(lang), ExternLoc(ExternLoc), RBraceLoc(RBLoc) { }
2215
2216public:
2217  static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
2218                                 SourceLocation ExternLoc,
2219                                 SourceLocation LangLoc, LanguageIDs Lang,
2220                                 SourceLocation RBraceLoc = SourceLocation());
2221  static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2222
2223  /// \brief Return the language specified by this linkage specification.
2224  LanguageIDs getLanguage() const { return Language; }
2225  /// \brief Set the language specified by this linkage specification.
2226  void setLanguage(LanguageIDs L) { Language = L; }
2227
2228  /// \brief Determines whether this linkage specification had braces in
2229  /// its syntactic form.
2230  bool hasBraces() const { return RBraceLoc.isValid(); }
2231
2232  SourceLocation getExternLoc() const { return ExternLoc; }
2233  SourceLocation getRBraceLoc() const { return RBraceLoc; }
2234  void setExternLoc(SourceLocation L) { ExternLoc = L; }
2235  void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
2236
2237  SourceLocation getLocEnd() const {
2238    if (hasBraces())
2239      return getRBraceLoc();
2240    // No braces: get the end location of the (only) declaration in context
2241    // (if present).
2242    return decls_empty() ? getLocation() : decls_begin()->getLocEnd();
2243  }
2244
2245  SourceRange getSourceRange() const {
2246    return SourceRange(ExternLoc, getLocEnd());
2247  }
2248
2249  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2250  static bool classof(const LinkageSpecDecl *D) { return true; }
2251  static bool classofKind(Kind K) { return K == LinkageSpec; }
2252  static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
2253    return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
2254  }
2255  static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
2256    return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
2257  }
2258};
2259
2260/// UsingDirectiveDecl - Represents C++ using-directive. For example:
2261///
2262///    using namespace std;
2263///
2264// NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide
2265// artificial names for all using-directives in order to store
2266// them in DeclContext effectively.
2267class UsingDirectiveDecl : public NamedDecl {
2268  virtual void anchor();
2269  /// \brief The location of the "using" keyword.
2270  SourceLocation UsingLoc;
2271
2272  /// SourceLocation - Location of 'namespace' token.
2273  SourceLocation NamespaceLoc;
2274
2275  /// \brief The nested-name-specifier that precedes the namespace.
2276  NestedNameSpecifierLoc QualifierLoc;
2277
2278  /// NominatedNamespace - Namespace nominated by using-directive.
2279  NamedDecl *NominatedNamespace;
2280
2281  /// Enclosing context containing both using-directive and nominated
2282  /// namespace.
2283  DeclContext *CommonAncestor;
2284
2285  /// getUsingDirectiveName - Returns special DeclarationName used by
2286  /// using-directives. This is only used by DeclContext for storing
2287  /// UsingDirectiveDecls in its lookup structure.
2288  static DeclarationName getName() {
2289    return DeclarationName::getUsingDirectiveName();
2290  }
2291
2292  UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc,
2293                     SourceLocation NamespcLoc,
2294                     NestedNameSpecifierLoc QualifierLoc,
2295                     SourceLocation IdentLoc,
2296                     NamedDecl *Nominated,
2297                     DeclContext *CommonAncestor)
2298    : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc),
2299      NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc),
2300      NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) { }
2301
2302public:
2303  /// \brief Retrieve the nested-name-specifier that qualifies the
2304  /// name of the namespace, with source-location information.
2305  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2306
2307  /// \brief Retrieve the nested-name-specifier that qualifies the
2308  /// name of the namespace.
2309  NestedNameSpecifier *getQualifier() const {
2310    return QualifierLoc.getNestedNameSpecifier();
2311  }
2312
2313  NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
2314  const NamedDecl *getNominatedNamespaceAsWritten() const {
2315    return NominatedNamespace;
2316  }
2317
2318  /// getNominatedNamespace - Returns namespace nominated by using-directive.
2319  NamespaceDecl *getNominatedNamespace();
2320
2321  const NamespaceDecl *getNominatedNamespace() const {
2322    return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
2323  }
2324
2325  /// \brief Returns the common ancestor context of this using-directive and
2326  /// its nominated namespace.
2327  DeclContext *getCommonAncestor() { return CommonAncestor; }
2328  const DeclContext *getCommonAncestor() const { return CommonAncestor; }
2329
2330  /// \brief Return the location of the "using" keyword.
2331  SourceLocation getUsingLoc() const { return UsingLoc; }
2332
2333  // FIXME: Could omit 'Key' in name.
2334  /// getNamespaceKeyLocation - Returns location of namespace keyword.
2335  SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
2336
2337  /// getIdentLocation - Returns location of identifier.
2338  SourceLocation getIdentLocation() const { return getLocation(); }
2339
2340  static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
2341                                    SourceLocation UsingLoc,
2342                                    SourceLocation NamespaceLoc,
2343                                    NestedNameSpecifierLoc QualifierLoc,
2344                                    SourceLocation IdentLoc,
2345                                    NamedDecl *Nominated,
2346                                    DeclContext *CommonAncestor);
2347  static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2348
2349  SourceRange getSourceRange() const {
2350    return SourceRange(UsingLoc, getLocation());
2351  }
2352
2353  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2354  static bool classof(const UsingDirectiveDecl *D) { return true; }
2355  static bool classofKind(Kind K) { return K == UsingDirective; }
2356
2357  // Friend for getUsingDirectiveName.
2358  friend class DeclContext;
2359
2360  friend class ASTDeclReader;
2361};
2362
2363/// NamespaceAliasDecl - Represents a C++ namespace alias. For example:
2364///
2365/// @code
2366/// namespace Foo = Bar;
2367/// @endcode
2368class NamespaceAliasDecl : public NamedDecl {
2369  virtual void anchor();
2370
2371  /// \brief The location of the "namespace" keyword.
2372  SourceLocation NamespaceLoc;
2373
2374  /// IdentLoc - Location of namespace identifier. Accessed by TargetNameLoc.
2375  SourceLocation IdentLoc;
2376
2377  /// \brief The nested-name-specifier that precedes the namespace.
2378  NestedNameSpecifierLoc QualifierLoc;
2379
2380  /// Namespace - The Decl that this alias points to. Can either be a
2381  /// NamespaceDecl or a NamespaceAliasDecl.
2382  NamedDecl *Namespace;
2383
2384  NamespaceAliasDecl(DeclContext *DC, SourceLocation NamespaceLoc,
2385                     SourceLocation AliasLoc, IdentifierInfo *Alias,
2386                     NestedNameSpecifierLoc QualifierLoc,
2387                     SourceLocation IdentLoc, NamedDecl *Namespace)
2388    : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias),
2389      NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc),
2390      QualifierLoc(QualifierLoc), Namespace(Namespace) { }
2391
2392  friend class ASTDeclReader;
2393
2394public:
2395  /// \brief Retrieve the nested-name-specifier that qualifies the
2396  /// name of the namespace, with source-location information.
2397  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2398
2399  /// \brief Retrieve the nested-name-specifier that qualifies the
2400  /// name of the namespace.
2401  NestedNameSpecifier *getQualifier() const {
2402    return QualifierLoc.getNestedNameSpecifier();
2403  }
2404
2405  /// \brief Retrieve the namespace declaration aliased by this directive.
2406  NamespaceDecl *getNamespace() {
2407    if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
2408      return AD->getNamespace();
2409
2410    return cast<NamespaceDecl>(Namespace);
2411  }
2412
2413  const NamespaceDecl *getNamespace() const {
2414    return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
2415  }
2416
2417  /// Returns the location of the alias name, i.e. 'foo' in
2418  /// "namespace foo = ns::bar;".
2419  SourceLocation getAliasLoc() const { return getLocation(); }
2420
2421  /// Returns the location of the 'namespace' keyword.
2422  SourceLocation getNamespaceLoc() const { return NamespaceLoc; }
2423
2424  /// Returns the location of the identifier in the named namespace.
2425  SourceLocation getTargetNameLoc() const { return IdentLoc; }
2426
2427  /// \brief Retrieve the namespace that this alias refers to, which
2428  /// may either be a NamespaceDecl or a NamespaceAliasDecl.
2429  NamedDecl *getAliasedNamespace() const { return Namespace; }
2430
2431  static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
2432                                    SourceLocation NamespaceLoc,
2433                                    SourceLocation AliasLoc,
2434                                    IdentifierInfo *Alias,
2435                                    NestedNameSpecifierLoc QualifierLoc,
2436                                    SourceLocation IdentLoc,
2437                                    NamedDecl *Namespace);
2438
2439  static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2440
2441  virtual SourceRange getSourceRange() const {
2442    return SourceRange(NamespaceLoc, IdentLoc);
2443  }
2444
2445  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2446  static bool classof(const NamespaceAliasDecl *D) { return true; }
2447  static bool classofKind(Kind K) { return K == NamespaceAlias; }
2448};
2449
2450/// UsingShadowDecl - Represents a shadow declaration introduced into
2451/// a scope by a (resolved) using declaration.  For example,
2452///
2453/// namespace A {
2454///   void foo();
2455/// }
2456/// namespace B {
2457///   using A::foo(); // <- a UsingDecl
2458///                   // Also creates a UsingShadowDecl for A::foo in B
2459/// }
2460///
2461class UsingShadowDecl : public NamedDecl {
2462  virtual void anchor();
2463
2464  /// The referenced declaration.
2465  NamedDecl *Underlying;
2466
2467  /// \brief The using declaration which introduced this decl or the next using
2468  /// shadow declaration contained in the aforementioned using declaration.
2469  NamedDecl *UsingOrNextShadow;
2470  friend class UsingDecl;
2471
2472  UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using,
2473                  NamedDecl *Target)
2474    : NamedDecl(UsingShadow, DC, Loc, DeclarationName()),
2475      Underlying(Target),
2476      UsingOrNextShadow(reinterpret_cast<NamedDecl *>(Using)) {
2477    if (Target) {
2478      setDeclName(Target->getDeclName());
2479      IdentifierNamespace = Target->getIdentifierNamespace();
2480    }
2481    setImplicit();
2482  }
2483
2484public:
2485  static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
2486                                 SourceLocation Loc, UsingDecl *Using,
2487                                 NamedDecl *Target) {
2488    return new (C) UsingShadowDecl(DC, Loc, Using, Target);
2489  }
2490
2491  static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2492
2493  /// \brief Gets the underlying declaration which has been brought into the
2494  /// local scope.
2495  NamedDecl *getTargetDecl() const { return Underlying; }
2496
2497  /// \brief Sets the underlying declaration which has been brought into the
2498  /// local scope.
2499  void setTargetDecl(NamedDecl* ND) {
2500    assert(ND && "Target decl is null!");
2501    Underlying = ND;
2502    IdentifierNamespace = ND->getIdentifierNamespace();
2503  }
2504
2505  /// \brief Gets the using declaration to which this declaration is tied.
2506  UsingDecl *getUsingDecl() const;
2507
2508  /// \brief The next using shadow declaration contained in the shadow decl
2509  /// chain of the using declaration which introduced this decl.
2510  UsingShadowDecl *getNextUsingShadowDecl() const {
2511    return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow);
2512  }
2513
2514  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2515  static bool classof(const UsingShadowDecl *D) { return true; }
2516  static bool classofKind(Kind K) { return K == Decl::UsingShadow; }
2517
2518  friend class ASTDeclReader;
2519  friend class ASTDeclWriter;
2520};
2521
2522/// UsingDecl - Represents a C++ using-declaration. For example:
2523///    using someNameSpace::someIdentifier;
2524class UsingDecl : public NamedDecl {
2525  virtual void anchor();
2526
2527  /// \brief The source location of the "using" location itself.
2528  SourceLocation UsingLocation;
2529
2530  /// \brief The nested-name-specifier that precedes the name.
2531  NestedNameSpecifierLoc QualifierLoc;
2532
2533  /// DNLoc - Provides source/type location info for the
2534  /// declaration name embedded in the ValueDecl base class.
2535  DeclarationNameLoc DNLoc;
2536
2537  /// \brief The first shadow declaration of the shadow decl chain associated
2538  /// with this using declaration. The bool member of the pair store whether
2539  /// this decl has the 'typename' keyword.
2540  llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow;
2541
2542  UsingDecl(DeclContext *DC, SourceLocation UL,
2543            NestedNameSpecifierLoc QualifierLoc,
2544            const DeclarationNameInfo &NameInfo, bool IsTypeNameArg)
2545    : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()),
2546      UsingLocation(UL), QualifierLoc(QualifierLoc),
2547      DNLoc(NameInfo.getInfo()), FirstUsingShadow(0, IsTypeNameArg) {
2548  }
2549
2550public:
2551  /// \brief Returns the source location of the "using" keyword.
2552  SourceLocation getUsingLocation() const { return UsingLocation; }
2553
2554  /// \brief Set the source location of the 'using' keyword.
2555  void setUsingLocation(SourceLocation L) { UsingLocation = L; }
2556
2557  /// \brief Retrieve the nested-name-specifier that qualifies the name,
2558  /// with source-location information.
2559  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2560
2561  /// \brief Retrieve the nested-name-specifier that qualifies the name.
2562  NestedNameSpecifier *getQualifier() const {
2563    return QualifierLoc.getNestedNameSpecifier();
2564  }
2565
2566  DeclarationNameInfo getNameInfo() const {
2567    return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
2568  }
2569
2570  /// \brief Return true if the using declaration has 'typename'.
2571  bool isTypeName() const { return FirstUsingShadow.getInt(); }
2572
2573  /// \brief Sets whether the using declaration has 'typename'.
2574  void setTypeName(bool TN) { FirstUsingShadow.setInt(TN); }
2575
2576  /// \brief Iterates through the using shadow declarations assosiated with
2577  /// this using declaration.
2578  class shadow_iterator {
2579    /// \brief The current using shadow declaration.
2580    UsingShadowDecl *Current;
2581
2582  public:
2583    typedef UsingShadowDecl*          value_type;
2584    typedef UsingShadowDecl*          reference;
2585    typedef UsingShadowDecl*          pointer;
2586    typedef std::forward_iterator_tag iterator_category;
2587    typedef std::ptrdiff_t            difference_type;
2588
2589    shadow_iterator() : Current(0) { }
2590    explicit shadow_iterator(UsingShadowDecl *C) : Current(C) { }
2591
2592    reference operator*() const { return Current; }
2593    pointer operator->() const { return Current; }
2594
2595    shadow_iterator& operator++() {
2596      Current = Current->getNextUsingShadowDecl();
2597      return *this;
2598    }
2599
2600    shadow_iterator operator++(int) {
2601      shadow_iterator tmp(*this);
2602      ++(*this);
2603      return tmp;
2604    }
2605
2606    friend bool operator==(shadow_iterator x, shadow_iterator y) {
2607      return x.Current == y.Current;
2608    }
2609    friend bool operator!=(shadow_iterator x, shadow_iterator y) {
2610      return x.Current != y.Current;
2611    }
2612  };
2613
2614  shadow_iterator shadow_begin() const {
2615    return shadow_iterator(FirstUsingShadow.getPointer());
2616  }
2617  shadow_iterator shadow_end() const { return shadow_iterator(); }
2618
2619  /// \brief Return the number of shadowed declarations associated with this
2620  /// using declaration.
2621  unsigned shadow_size() const {
2622    return std::distance(shadow_begin(), shadow_end());
2623  }
2624
2625  void addShadowDecl(UsingShadowDecl *S);
2626  void removeShadowDecl(UsingShadowDecl *S);
2627
2628  static UsingDecl *Create(ASTContext &C, DeclContext *DC,
2629                           SourceLocation UsingL,
2630                           NestedNameSpecifierLoc QualifierLoc,
2631                           const DeclarationNameInfo &NameInfo,
2632                           bool IsTypeNameArg);
2633
2634  static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2635
2636  SourceRange getSourceRange() const {
2637    return SourceRange(UsingLocation, getNameInfo().getEndLoc());
2638  }
2639
2640  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2641  static bool classof(const UsingDecl *D) { return true; }
2642  static bool classofKind(Kind K) { return K == Using; }
2643
2644  friend class ASTDeclReader;
2645  friend class ASTDeclWriter;
2646};
2647
2648/// UnresolvedUsingValueDecl - Represents a dependent using
2649/// declaration which was not marked with 'typename'.  Unlike
2650/// non-dependent using declarations, these *only* bring through
2651/// non-types; otherwise they would break two-phase lookup.
2652///
2653/// template <class T> class A : public Base<T> {
2654///   using Base<T>::foo;
2655/// };
2656class UnresolvedUsingValueDecl : public ValueDecl {
2657  virtual void anchor();
2658
2659  /// \brief The source location of the 'using' keyword
2660  SourceLocation UsingLocation;
2661
2662  /// \brief The nested-name-specifier that precedes the name.
2663  NestedNameSpecifierLoc QualifierLoc;
2664
2665  /// DNLoc - Provides source/type location info for the
2666  /// declaration name embedded in the ValueDecl base class.
2667  DeclarationNameLoc DNLoc;
2668
2669  UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
2670                           SourceLocation UsingLoc,
2671                           NestedNameSpecifierLoc QualifierLoc,
2672                           const DeclarationNameInfo &NameInfo)
2673    : ValueDecl(UnresolvedUsingValue, DC,
2674                NameInfo.getLoc(), NameInfo.getName(), Ty),
2675      UsingLocation(UsingLoc), QualifierLoc(QualifierLoc),
2676      DNLoc(NameInfo.getInfo())
2677  { }
2678
2679public:
2680  /// \brief Returns the source location of the 'using' keyword.
2681  SourceLocation getUsingLoc() const { return UsingLocation; }
2682
2683  /// \brief Set the source location of the 'using' keyword.
2684  void setUsingLoc(SourceLocation L) { UsingLocation = L; }
2685
2686  /// \brief Retrieve the nested-name-specifier that qualifies the name,
2687  /// with source-location information.
2688  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2689
2690  /// \brief Retrieve the nested-name-specifier that qualifies the name.
2691  NestedNameSpecifier *getQualifier() const {
2692    return QualifierLoc.getNestedNameSpecifier();
2693  }
2694
2695  DeclarationNameInfo getNameInfo() const {
2696    return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
2697  }
2698
2699  static UnresolvedUsingValueDecl *
2700    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
2701           NestedNameSpecifierLoc QualifierLoc,
2702           const DeclarationNameInfo &NameInfo);
2703
2704  static UnresolvedUsingValueDecl *
2705  CreateDeserialized(ASTContext &C, unsigned ID);
2706
2707  SourceRange getSourceRange() const {
2708    return SourceRange(UsingLocation, getNameInfo().getEndLoc());
2709  }
2710
2711  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2712  static bool classof(const UnresolvedUsingValueDecl *D) { return true; }
2713  static bool classofKind(Kind K) { return K == UnresolvedUsingValue; }
2714
2715  friend class ASTDeclReader;
2716  friend class ASTDeclWriter;
2717};
2718
2719/// UnresolvedUsingTypenameDecl - Represents a dependent using
2720/// declaration which was marked with 'typename'.
2721///
2722/// template <class T> class A : public Base<T> {
2723///   using typename Base<T>::foo;
2724/// };
2725///
2726/// The type associated with a unresolved using typename decl is
2727/// currently always a typename type.
2728class UnresolvedUsingTypenameDecl : public TypeDecl {
2729  virtual void anchor();
2730
2731  /// \brief The source location of the 'using' keyword
2732  SourceLocation UsingLocation;
2733
2734  /// \brief The source location of the 'typename' keyword
2735  SourceLocation TypenameLocation;
2736
2737  /// \brief The nested-name-specifier that precedes the name.
2738  NestedNameSpecifierLoc QualifierLoc;
2739
2740  UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
2741                              SourceLocation TypenameLoc,
2742                              NestedNameSpecifierLoc QualifierLoc,
2743                              SourceLocation TargetNameLoc,
2744                              IdentifierInfo *TargetName)
2745    : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName,
2746               UsingLoc),
2747      TypenameLocation(TypenameLoc), QualifierLoc(QualifierLoc) { }
2748
2749  friend class ASTDeclReader;
2750
2751public:
2752  /// \brief Returns the source location of the 'using' keyword.
2753  SourceLocation getUsingLoc() const { return getLocStart(); }
2754
2755  /// \brief Returns the source location of the 'typename' keyword.
2756  SourceLocation getTypenameLoc() const { return TypenameLocation; }
2757
2758  /// \brief Retrieve the nested-name-specifier that qualifies the name,
2759  /// with source-location information.
2760  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2761
2762  /// \brief Retrieve the nested-name-specifier that qualifies the name.
2763  NestedNameSpecifier *getQualifier() const {
2764    return QualifierLoc.getNestedNameSpecifier();
2765  }
2766
2767  static UnresolvedUsingTypenameDecl *
2768    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
2769           SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc,
2770           SourceLocation TargetNameLoc, DeclarationName TargetName);
2771
2772  static UnresolvedUsingTypenameDecl *
2773  CreateDeserialized(ASTContext &C, unsigned ID);
2774
2775  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2776  static bool classof(const UnresolvedUsingTypenameDecl *D) { return true; }
2777  static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; }
2778};
2779
2780/// StaticAssertDecl - Represents a C++0x static_assert declaration.
2781class StaticAssertDecl : public Decl {
2782  virtual void anchor();
2783  Expr *AssertExpr;
2784  StringLiteral *Message;
2785  SourceLocation RParenLoc;
2786
2787  StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc,
2788                   Expr *assertexpr, StringLiteral *message,
2789                   SourceLocation RParenLoc)
2790  : Decl(StaticAssert, DC, StaticAssertLoc), AssertExpr(assertexpr),
2791    Message(message), RParenLoc(RParenLoc) { }
2792
2793public:
2794  static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
2795                                  SourceLocation StaticAssertLoc,
2796                                  Expr *AssertExpr, StringLiteral *Message,
2797                                  SourceLocation RParenLoc);
2798  static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2799
2800  Expr *getAssertExpr() { return AssertExpr; }
2801  const Expr *getAssertExpr() const { return AssertExpr; }
2802
2803  StringLiteral *getMessage() { return Message; }
2804  const StringLiteral *getMessage() const { return Message; }
2805
2806  SourceLocation getRParenLoc() const { return RParenLoc; }
2807  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2808
2809  SourceRange getSourceRange() const {
2810    return SourceRange(getLocation(), getRParenLoc());
2811  }
2812
2813  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2814  static bool classof(StaticAssertDecl *D) { return true; }
2815  static bool classofKind(Kind K) { return K == StaticAssert; }
2816
2817  friend class ASTDeclReader;
2818};
2819
2820/// Insertion operator for diagnostics.  This allows sending AccessSpecifier's
2821/// into a diagnostic with <<.
2822const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
2823                                    AccessSpecifier AS);
2824
2825const PartialDiagnostic &operator<<(const PartialDiagnostic &DB,
2826                                    AccessSpecifier AS);
2827
2828} // end namespace clang
2829
2830#endif
2831