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