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