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