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