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