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