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