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