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