1193326Sed//===-- DeclCXX.h - Classes for representing C++ declarations -*- C++ -*-=====//
2193326Sed//
3193326Sed//                     The LLVM Compiler Infrastructure
4193326Sed//
5193326Sed// This file is distributed under the University of Illinois Open Source
6193326Sed// License. See LICENSE.TXT for details.
7193326Sed//
8193326Sed//===----------------------------------------------------------------------===//
9263509Sdim///
10263509Sdim/// \file
11263509Sdim/// \brief Defines the C++ Decl subclasses, other than those for templates
12263509Sdim/// (found in DeclTemplate.h) and friends (in DeclFriend.h).
13263509Sdim///
14193326Sed//===----------------------------------------------------------------------===//
15193326Sed
16193326Sed#ifndef LLVM_CLANG_AST_DECLCXX_H
17193326Sed#define LLVM_CLANG_AST_DECLCXX_H
18193326Sed
19252723Sdim#include "clang/AST/ASTUnresolvedSet.h"
20252723Sdim#include "clang/AST/Decl.h"
21198092Srdivacky#include "clang/AST/Expr.h"
22235633Sdim#include "clang/AST/ExprCXX.h"
23212904Sdim#include "clang/AST/TypeLoc.h"
24235633Sdim#include "llvm/ADT/DenseMap.h"
25235633Sdim#include "llvm/ADT/PointerIntPair.h"
26198092Srdivacky#include "llvm/ADT/SmallPtrSet.h"
27235633Sdim#include "llvm/Support/Compiler.h"
28193326Sed
29193326Sednamespace clang {
30193326Sed
31193326Sedclass ClassTemplateDecl;
32198092Srdivackyclass ClassTemplateSpecializationDecl;
33198092Srdivackyclass CXXBasePath;
34198092Srdivackyclass CXXBasePaths;
35193326Sedclass CXXConstructorDecl;
36198092Srdivackyclass CXXConversionDecl;
37193326Sedclass CXXDestructorDecl;
38193326Sedclass CXXMethodDecl;
39198092Srdivackyclass CXXRecordDecl;
40198092Srdivackyclass CXXMemberLookupCriteria;
41206084Srdivackyclass CXXFinalOverriderMap;
42218893Sdimclass CXXIndirectPrimaryBaseSet;
43205219Srdivackyclass FriendDecl;
44235633Sdimclass LambdaExpr;
45245431Sdimclass UsingDecl;
46235633Sdim
47198092Srdivacky/// \brief Represents any kind of function declaration, whether it is a
48195099Sed/// concrete function or a function template.
49195099Sedclass AnyFunctionDecl {
50195099Sed  NamedDecl *Function;
51198092Srdivacky
52195341Sed  AnyFunctionDecl(NamedDecl *ND) : Function(ND) { }
53198092Srdivacky
54195099Sedpublic:
55195099Sed  AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { }
56195099Sed  AnyFunctionDecl(FunctionTemplateDecl *FTD);
57198092Srdivacky
58198092Srdivacky  /// \brief Implicily converts any function or function template into a
59195099Sed  /// named declaration.
60195099Sed  operator NamedDecl *() const { return Function; }
61198092Srdivacky
62195099Sed  /// \brief Retrieve the underlying function or function template.
63195099Sed  NamedDecl *get() const { return Function; }
64198092Srdivacky
65198092Srdivacky  static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) {
66195341Sed    return AnyFunctionDecl(ND);
67195341Sed  }
68195099Sed};
69198092Srdivacky
70195099Sed} // end namespace clang
71195099Sed
72195099Sednamespace llvm {
73195341Sed  // Provide PointerLikeTypeTraits for non-cvr pointers.
74195341Sed  template<>
75195341Sed  class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
76195341Sed  public:
77195341Sed    static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
78198092Srdivacky      return F.get();
79195341Sed    }
80195341Sed    static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
81195341Sed      return ::clang::AnyFunctionDecl::getFromNamedDecl(
82195341Sed                                      static_cast< ::clang::NamedDecl*>(P));
83195341Sed    }
84198092Srdivacky
85195341Sed    enum { NumLowBitsAvailable = 2 };
86195341Sed  };
87198092Srdivacky
88195099Sed} // end namespace llvm
89195099Sed
90195099Sednamespace clang {
91198092Srdivacky
92263509Sdim/// \brief Represents an access specifier followed by colon ':'.
93210299Sed///
94210299Sed/// An objects of this class represents sugar for the syntactic occurrence
95210299Sed/// of an access specifier followed by a colon in the list of member
96210299Sed/// specifiers of a C++ class definition.
97210299Sed///
98210299Sed/// Note that they do not represent other uses of access specifiers,
99210299Sed/// such as those occurring in a list of base specifiers.
100210299Sed/// Also note that this class has nothing to do with so-called
101210299Sed/// "access declarations" (C++98 11.3 [class.access.dcl]).
102210299Sedclass AccessSpecDecl : public Decl {
103235633Sdim  virtual void anchor();
104245431Sdim  /// \brief The location of the ':'.
105210299Sed  SourceLocation ColonLoc;
106210299Sed
107210299Sed  AccessSpecDecl(AccessSpecifier AS, DeclContext *DC,
108210299Sed                 SourceLocation ASLoc, SourceLocation ColonLoc)
109210299Sed    : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) {
110210299Sed    setAccess(AS);
111210299Sed  }
112218893Sdim  AccessSpecDecl(EmptyShell Empty)
113218893Sdim    : Decl(AccessSpec, Empty) { }
114210299Sedpublic:
115245431Sdim  /// \brief The location of the access specifier.
116210299Sed  SourceLocation getAccessSpecifierLoc() const { return getLocation(); }
117245431Sdim  /// \brief Sets the location of the access specifier.
118210299Sed  void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); }
119210299Sed
120245431Sdim  /// \brief The location of the colon following the access specifier.
121210299Sed  SourceLocation getColonLoc() const { return ColonLoc; }
122245431Sdim  /// \brief Sets the location of the colon.
123210299Sed  void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; }
124210299Sed
125235633Sdim  SourceRange getSourceRange() const LLVM_READONLY {
126210299Sed    return SourceRange(getAccessSpecifierLoc(), getColonLoc());
127210299Sed  }
128210299Sed
129210299Sed  static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS,
130210299Sed                                DeclContext *DC, SourceLocation ASLoc,
131210299Sed                                SourceLocation ColonLoc) {
132210299Sed    return new (C) AccessSpecDecl(AS, DC, ASLoc, ColonLoc);
133210299Sed  }
134235633Sdim  static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
135210299Sed
136210299Sed  // Implement isa/cast/dyncast/etc.
137210299Sed  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
138210299Sed  static bool classofKind(Kind K) { return K == AccessSpec; }
139210299Sed};
140210299Sed
141210299Sed
142245431Sdim/// \brief Represents a base class of a C++ class.
143193326Sed///
144193326Sed/// Each CXXBaseSpecifier represents a single, direct base class (or
145193326Sed/// struct) of a C++ class (or struct). It specifies the type of that
146193326Sed/// base class, whether it is a virtual or non-virtual base, and what
147193326Sed/// level of access (public, protected, private) is used for the
148193326Sed/// derivation. For example:
149193326Sed///
150263509Sdim/// \code
151193326Sed///   class A { };
152193326Sed///   class B { };
153193326Sed///   class C : public virtual A, protected B { };
154263509Sdim/// \endcode
155193326Sed///
156193326Sed/// In this code, C will have two CXXBaseSpecifiers, one for "public
157193326Sed/// virtual A" and the other for "protected B".
158193326Sedclass CXXBaseSpecifier {
159263509Sdim  /// \brief The source code range that covers the full base
160193326Sed  /// specifier, including the "virtual" (if present) and access
161193326Sed  /// specifier (if present).
162193326Sed  SourceRange Range;
163193326Sed
164218893Sdim  /// \brief The source location of the ellipsis, if this is a pack
165218893Sdim  /// expansion.
166218893Sdim  SourceLocation EllipsisLoc;
167235633Sdim
168245431Sdim  /// \brief Whether this is a virtual base class or not.
169193326Sed  bool Virtual : 1;
170193326Sed
171263509Sdim  /// \brief Whether this is the base of a class (true) or of a struct (false).
172263509Sdim  ///
173263509Sdim  /// This determines the mapping from the access specifier as written in the
174263509Sdim  /// source code to the access specifier used for semantic analysis.
175198092Srdivacky  bool BaseOfClass : 1;
176193326Sed
177263509Sdim  /// \brief Access specifier as written in the source code (may be AS_none).
178263509Sdim  ///
179263509Sdim  /// The actual type of data stored here is an AccessSpecifier, but we use
180263509Sdim  /// "unsigned" here to work around a VC++ bug.
181193326Sed  unsigned Access : 2;
182193326Sed
183263509Sdim  /// \brief Whether the class contains a using declaration
184218893Sdim  /// to inherit the named class's constructors.
185218893Sdim  bool InheritConstructors : 1;
186218893Sdim
187263509Sdim  /// \brief The type of the base class.
188263509Sdim  ///
189263509Sdim  /// This will be a class or struct (or a typedef of such). The source code
190263509Sdim  /// range does not include the \c virtual or the access specifier.
191212904Sdim  TypeSourceInfo *BaseTypeInfo;
192198092Srdivacky
193193326Sedpublic:
194193326Sed  CXXBaseSpecifier() { }
195193326Sed
196212904Sdim  CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A,
197218893Sdim                   TypeSourceInfo *TInfo, SourceLocation EllipsisLoc)
198235633Sdim    : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC),
199218893Sdim      Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) { }
200193326Sed
201263509Sdim  /// \brief Retrieves the source range that contains the entire base specifier.
202235633Sdim  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
203235633Sdim  SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
204235633Sdim  SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
205198092Srdivacky
206263509Sdim  /// \brief Determines whether the base class is a virtual base class (or not).
207193326Sed  bool isVirtual() const { return Virtual; }
208193326Sed
209212904Sdim  /// \brief Determine whether this base class is a base of a class declared
210203955Srdivacky  /// with the 'class' keyword (vs. one declared with the 'struct' keyword).
211203955Srdivacky  bool isBaseOfClass() const { return BaseOfClass; }
212235633Sdim
213218893Sdim  /// \brief Determine whether this base specifier is a pack expansion.
214218893Sdim  bool isPackExpansion() const { return EllipsisLoc.isValid(); }
215218893Sdim
216218893Sdim  /// \brief Determine whether this base class's constructors get inherited.
217218893Sdim  bool getInheritConstructors() const { return InheritConstructors; }
218218893Sdim
219218893Sdim  /// \brief Set that this base class's constructors should be inherited.
220218893Sdim  void setInheritConstructors(bool Inherit = true) {
221218893Sdim    InheritConstructors = Inherit;
222218893Sdim  }
223218893Sdim
224218893Sdim  /// \brief For a pack expansion, determine the location of the ellipsis.
225218893Sdim  SourceLocation getEllipsisLoc() const {
226218893Sdim    return EllipsisLoc;
227218893Sdim  }
228218893Sdim
229263509Sdim  /// \brief Returns the access specifier for this base specifier.
230263509Sdim  ///
231263509Sdim  /// This is the actual base specifier as used for semantic analysis, so
232263509Sdim  /// the result can never be AS_none. To retrieve the access specifier as
233263509Sdim  /// written in the source code, use getAccessSpecifierAsWritten().
234198092Srdivacky  AccessSpecifier getAccessSpecifier() const {
235193326Sed    if ((AccessSpecifier)Access == AS_none)
236193326Sed      return BaseOfClass? AS_private : AS_public;
237193326Sed    else
238198092Srdivacky      return (AccessSpecifier)Access;
239193326Sed  }
240193326Sed
241263509Sdim  /// \brief Retrieves the access specifier as written in the source code
242263509Sdim  /// (which may mean that no access specifier was explicitly written).
243263509Sdim  ///
244263509Sdim  /// Use getAccessSpecifier() to retrieve the access specifier for use in
245263509Sdim  /// semantic analysis.
246193326Sed  AccessSpecifier getAccessSpecifierAsWritten() const {
247193326Sed    return (AccessSpecifier)Access;
248193326Sed  }
249193326Sed
250263509Sdim  /// \brief Retrieves the type of the base class.
251263509Sdim  ///
252263509Sdim  /// This type will always be an unqualified class type.
253263509Sdim  QualType getType() const {
254263509Sdim    return BaseTypeInfo->getType().getUnqualifiedType();
255263509Sdim  }
256212904Sdim
257263509Sdim  /// \brief Retrieves the type and source location of the base class.
258212904Sdim  TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; }
259193326Sed};
260193326Sed
261252723Sdim/// The inheritance model to use for member pointers of a given CXXRecordDecl.
262252723Sdimenum MSInheritanceModel {
263252723Sdim  MSIM_Single,
264252723Sdim  MSIM_SinglePolymorphic,
265252723Sdim  MSIM_Multiple,
266252723Sdim  MSIM_MultiplePolymorphic,
267252723Sdim  MSIM_Virtual,
268252723Sdim  MSIM_Unspecified
269252723Sdim};
270252723Sdim
271263509Sdim/// \brief Represents a C++ struct/union/class.
272263509Sdim///
273193326Sed/// FIXME: This class will disappear once we've properly taught RecordDecl
274193326Sed/// to deal with C++-specific things.
275193326Sedclass CXXRecordDecl : public RecordDecl {
276193326Sed
277203955Srdivacky  friend void TagDecl::startDefinition();
278193326Sed
279252723Sdim  /// Values used in DefinitionData fields to represent special members.
280252723Sdim  enum SpecialMemberFlags {
281252723Sdim    SMF_DefaultConstructor = 0x1,
282252723Sdim    SMF_CopyConstructor = 0x2,
283252723Sdim    SMF_MoveConstructor = 0x4,
284252723Sdim    SMF_CopyAssignment = 0x8,
285252723Sdim    SMF_MoveAssignment = 0x10,
286252723Sdim    SMF_Destructor = 0x20,
287252723Sdim    SMF_All = 0x3f
288252723Sdim  };
289252723Sdim
290203955Srdivacky  struct DefinitionData {
291203955Srdivacky    DefinitionData(CXXRecordDecl *D);
292193326Sed
293252723Sdim    /// \brief True if this class has any user-declared constructors.
294203955Srdivacky    bool UserDeclaredConstructor : 1;
295193326Sed
296263509Sdim    /// \brief The user-declared special members which this class has.
297252723Sdim    unsigned UserDeclaredSpecialMembers : 6;
298193326Sed
299263509Sdim    /// \brief True when this class is an aggregate.
300203955Srdivacky    bool Aggregate : 1;
301193326Sed
302263509Sdim    /// \brief True when this class is a POD-type.
303203955Srdivacky    bool PlainOldData : 1;
304198092Srdivacky
305263509Sdim    /// true when this class is empty for traits purposes,
306203955Srdivacky    /// i.e. has no data members other than 0-width bit-fields, has no
307203955Srdivacky    /// virtual function/base, and doesn't inherit from a non-empty
308203955Srdivacky    /// class. Doesn't take union-ness into account.
309203955Srdivacky    bool Empty : 1;
310198092Srdivacky
311263509Sdim    /// \brief True when this class is polymorphic, i.e., has at
312203955Srdivacky    /// least one virtual member or derives from a polymorphic class.
313203955Srdivacky    bool Polymorphic : 1;
314198092Srdivacky
315263509Sdim    /// \brief True when this class is abstract, i.e., has at least
316203955Srdivacky    /// one pure virtual function, (that can come from a base class).
317203955Srdivacky    bool Abstract : 1;
318198092Srdivacky
319263509Sdim    /// \brief True when this class has standard layout.
320221345Sdim    ///
321263509Sdim    /// C++11 [class]p7.  A standard-layout class is a class that:
322221345Sdim    /// * has no non-static data members of type non-standard-layout class (or
323221345Sdim    ///   array of such types) or reference,
324221345Sdim    /// * has no virtual functions (10.3) and no virtual base classes (10.1),
325235633Sdim    /// * has the same access control (Clause 11) for all non-static data
326235633Sdim    ///   members
327221345Sdim    /// * has no non-standard-layout base classes,
328221345Sdim    /// * either has no non-static data members in the most derived class and at
329221345Sdim    ///   most one base class with non-static data members, or has no base
330221345Sdim    ///   classes with non-static data members, and
331221345Sdim    /// * has no base classes of the same type as the first non-static data
332221345Sdim    ///   member.
333221345Sdim    bool IsStandardLayout : 1;
334221345Sdim
335263509Sdim    /// \brief True when there are no non-empty base classes.
336221345Sdim    ///
337221345Sdim    /// This is a helper bit of state used to implement IsStandardLayout more
338221345Sdim    /// efficiently.
339221345Sdim    bool HasNoNonEmptyBases : 1;
340221345Sdim
341263509Sdim    /// \brief True when there are private non-static data members.
342221345Sdim    bool HasPrivateFields : 1;
343221345Sdim
344263509Sdim    /// \brief True when there are protected non-static data members.
345221345Sdim    bool HasProtectedFields : 1;
346221345Sdim
347263509Sdim    /// \brief True when there are private non-static data members.
348221345Sdim    bool HasPublicFields : 1;
349221345Sdim
350223017Sdim    /// \brief True if this class (or any subobject) has mutable fields.
351223017Sdim    bool HasMutableFields : 1;
352235633Sdim
353235633Sdim    /// \brief True if there no non-field members declared by the user.
354235633Sdim    bool HasOnlyCMembers : 1;
355235633Sdim
356245431Sdim    /// \brief True if any field has an in-class initializer.
357245431Sdim    bool HasInClassInitializer : 1;
358245431Sdim
359252723Sdim    /// \brief True if any field is of reference type, and does not have an
360263509Sdim    /// in-class initializer.
361263509Sdim    ///
362263509Sdim    /// In this case, value-initialization of this class is illegal in C++98
363263509Sdim    /// even if the class has a trivial default constructor.
364252723Sdim    bool HasUninitializedReferenceMember : 1;
365252723Sdim
366252723Sdim    /// \brief These flags are \c true if a defaulted corresponding special
367252723Sdim    /// member can't be fully analyzed without performing overload resolution.
368252723Sdim    /// @{
369252723Sdim    bool NeedOverloadResolutionForMoveConstructor : 1;
370252723Sdim    bool NeedOverloadResolutionForMoveAssignment : 1;
371252723Sdim    bool NeedOverloadResolutionForDestructor : 1;
372252723Sdim    /// @}
373252723Sdim
374252723Sdim    /// \brief These flags are \c true if an implicit defaulted corresponding
375252723Sdim    /// special member would be defined as deleted.
376252723Sdim    /// @{
377252723Sdim    bool DefaultedMoveConstructorIsDeleted : 1;
378252723Sdim    bool DefaultedMoveAssignmentIsDeleted : 1;
379252723Sdim    bool DefaultedDestructorIsDeleted : 1;
380252723Sdim    /// @}
381252723Sdim
382252723Sdim    /// \brief The trivial special members which this class has, per
383252723Sdim    /// C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25,
384252723Sdim    /// C++11 [class.dtor]p5, or would have if the member were not suppressed.
385203955Srdivacky    ///
386252723Sdim    /// This excludes any user-declared but not user-provided special members
387252723Sdim    /// which have been declared but not yet defined.
388252723Sdim    unsigned HasTrivialSpecialMembers : 6;
389198092Srdivacky
390252723Sdim    /// \brief The declared special members of this class which are known to be
391252723Sdim    /// non-trivial.
392252723Sdim    ///
393252723Sdim    /// This excludes any user-declared but not user-provided special members
394252723Sdim    /// which have been declared but not yet defined, and any implicit special
395252723Sdim    /// members which have not yet been declared.
396252723Sdim    unsigned DeclaredNonTrivialSpecialMembers : 6;
397252723Sdim
398263509Sdim    /// \brief True when this class has a destructor with no semantic effect.
399252723Sdim    bool HasIrrelevantDestructor : 1;
400252723Sdim
401263509Sdim    /// \brief True when this class has at least one user-declared constexpr
402263509Sdim    /// constructor which is neither the copy nor move constructor.
403226890Sdim    bool HasConstexprNonCopyMoveConstructor : 1;
404221345Sdim
405263509Sdim    /// \brief True if a defaulted default constructor for this class would
406263509Sdim    /// be constexpr.
407235633Sdim    bool DefaultedDefaultConstructorIsConstexpr : 1;
408235633Sdim
409263509Sdim    /// \brief True if this class has a constexpr default constructor.
410263509Sdim    ///
411263509Sdim    /// This is true for either a user-declared constexpr default constructor
412263509Sdim    /// or an implicitly declared constexpr default constructor..
413235633Sdim    bool HasConstexprDefaultConstructor : 1;
414235633Sdim
415263509Sdim    /// \brief True when this class contains at least one non-static data
416263509Sdim    /// member or base class of non-literal or volatile type.
417221345Sdim    bool HasNonLiteralTypeFieldsOrBases : 1;
418221345Sdim
419263509Sdim    /// \brief True when visible conversion functions are already computed
420263509Sdim    /// and are available.
421203955Srdivacky    bool ComputedVisibleConversions : 1;
422210299Sed
423252723Sdim    /// \brief Whether we have a C++11 user-provided default constructor (not
424223017Sdim    /// explicitly deleted or defaulted).
425223017Sdim    bool UserProvidedDefaultConstructor : 1;
426223017Sdim
427252723Sdim    /// \brief The special members which have been declared for this class,
428252723Sdim    /// either by the user or implicitly.
429252723Sdim    unsigned DeclaredSpecialMembers : 6;
430210299Sed
431252723Sdim    /// \brief Whether an implicit copy constructor would have a const-qualified
432252723Sdim    /// parameter.
433252723Sdim    bool ImplicitCopyConstructorHasConstParam : 1;
434223017Sdim
435252723Sdim    /// \brief Whether an implicit copy assignment operator would have a
436252723Sdim    /// const-qualified parameter.
437252723Sdim    bool ImplicitCopyAssignmentHasConstParam : 1;
438235633Sdim
439252723Sdim    /// \brief Whether any declared copy constructor has a const-qualified
440252723Sdim    /// parameter.
441252723Sdim    bool HasDeclaredCopyConstructorWithConstParam : 1;
442223017Sdim
443252723Sdim    /// \brief Whether any declared copy assignment operator has either a
444252723Sdim    /// const-qualified reference parameter or a non-reference parameter.
445252723Sdim    bool HasDeclaredCopyAssignmentWithConstParam : 1;
446235633Sdim
447235633Sdim    /// \brief Whether this class describes a C++ lambda.
448235633Sdim    bool IsLambda : 1;
449235633Sdim
450263509Sdim    /// \brief The number of base class specifiers in Bases.
451218893Sdim    unsigned NumBases;
452235633Sdim
453263509Sdim    /// \brief The number of virtual base class specifiers in VBases.
454218893Sdim    unsigned NumVBases;
455218893Sdim
456263509Sdim    /// \brief Base classes of this class.
457263509Sdim    ///
458203955Srdivacky    /// FIXME: This is wasted space for a union.
459218893Sdim    LazyCXXBaseSpecifiersPtr Bases;
460193326Sed
461263509Sdim    /// \brief direct and indirect virtual base classes of this class.
462218893Sdim    LazyCXXBaseSpecifiersPtr VBases;
463198092Srdivacky
464263509Sdim    /// \brief The conversion functions of this C++ class (but not its
465263509Sdim    /// inherited conversion functions).
466263509Sdim    ///
467263509Sdim    /// Each of the entries in this overload set is a CXXConversionDecl.
468263509Sdim    LazyASTUnresolvedSet Conversions;
469193326Sed
470263509Sdim    /// \brief The conversion functions of this C++ class and all those
471263509Sdim    /// inherited conversion functions that are visible in this class.
472263509Sdim    ///
473263509Sdim    /// Each of the entries in this overload set is a CXXConversionDecl or a
474203955Srdivacky    /// FunctionTemplateDecl.
475263509Sdim    LazyASTUnresolvedSet VisibleConversions;
476203955Srdivacky
477263509Sdim    /// \brief The declaration which defines this record.
478203955Srdivacky    CXXRecordDecl *Definition;
479203955Srdivacky
480263509Sdim    /// \brief The first friend declaration in this class, or null if there
481263509Sdim    /// aren't any.
482263509Sdim    ///
483263509Sdim    /// This is actually currently stored in reverse order.
484263509Sdim    LazyDeclPtr FirstFriend;
485205219Srdivacky
486235633Sdim    /// \brief Retrieve the set of direct base classes.
487218893Sdim    CXXBaseSpecifier *getBases() const {
488245431Sdim      if (!Bases.isOffset())
489245431Sdim        return Bases.get(0);
490245431Sdim      return getBasesSlowCase();
491218893Sdim    }
492218893Sdim
493235633Sdim    /// \brief Retrieve the set of virtual base classes.
494218893Sdim    CXXBaseSpecifier *getVBases() const {
495245431Sdim      if (!VBases.isOffset())
496245431Sdim        return VBases.get(0);
497245431Sdim      return getVBasesSlowCase();
498218893Sdim    }
499245431Sdim
500245431Sdim  private:
501245431Sdim    CXXBaseSpecifier *getBasesSlowCase() const;
502245431Sdim    CXXBaseSpecifier *getVBasesSlowCase() const;
503203955Srdivacky  } *DefinitionData;
504203955Srdivacky
505235633Sdim  /// \brief Describes a C++ closure type (generated by a lambda expression).
506235633Sdim  struct LambdaDefinitionData : public DefinitionData {
507235633Sdim    typedef LambdaExpr::Capture Capture;
508235633Sdim
509263509Sdim       LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info,
510263509Sdim                         bool Dependent, bool IsGeneric,
511263509Sdim                         LambdaCaptureDefault CaptureDefault)
512263509Sdim      : DefinitionData(D), Dependent(Dependent), IsGenericLambda(IsGeneric),
513263509Sdim        CaptureDefault(CaptureDefault), NumCaptures(0), NumExplicitCaptures(0),
514263509Sdim        ManglingNumber(0), ContextDecl(0), Captures(0), MethodTyInfo(Info)
515235633Sdim    {
516235633Sdim      IsLambda = true;
517235633Sdim    }
518235633Sdim
519235633Sdim    /// \brief Whether this lambda is known to be dependent, even if its
520235633Sdim    /// context isn't dependent.
521235633Sdim    ///
522235633Sdim    /// A lambda with a non-dependent context can be dependent if it occurs
523235633Sdim    /// within the default argument of a function template, because the
524235633Sdim    /// lambda will have been created with the enclosing context as its
525235633Sdim    /// declaration context, rather than function. This is an unfortunate
526263509Sdim    /// artifact of having to parse the default arguments before.
527235633Sdim    unsigned Dependent : 1;
528235633Sdim
529263509Sdim    /// \brief Whether this lambda is a generic lambda.
530263509Sdim    unsigned IsGenericLambda : 1;
531235633Sdim
532263509Sdim    /// \brief The Default Capture.
533263509Sdim    unsigned CaptureDefault : 2;
534263509Sdim
535263509Sdim    /// \brief The number of captures in this lambda is limited 2^NumCaptures.
536263509Sdim    unsigned NumCaptures : 15;
537263509Sdim
538235633Sdim    /// \brief The number of explicit captures in this lambda.
539263509Sdim    unsigned NumExplicitCaptures : 13;
540235633Sdim
541235633Sdim    /// \brief The number used to indicate this lambda expression for name
542235633Sdim    /// mangling in the Itanium C++ ABI.
543235633Sdim    unsigned ManglingNumber;
544235633Sdim
545235633Sdim    /// \brief The declaration that provides context for this lambda, if the
546235633Sdim    /// actual DeclContext does not suffice. This is used for lambdas that
547235633Sdim    /// occur within default arguments of function parameters within the class
548235633Sdim    /// or within a data member initializer.
549235633Sdim    Decl *ContextDecl;
550235633Sdim
551235633Sdim    /// \brief The list of captures, both explicit and implicit, for this
552235633Sdim    /// lambda.
553245431Sdim    Capture *Captures;
554245431Sdim
555245431Sdim    /// \brief The type of the call method.
556245431Sdim    TypeSourceInfo *MethodTyInfo;
557263509Sdim
558235633Sdim  };
559235633Sdim
560203955Srdivacky  struct DefinitionData &data() {
561203955Srdivacky    assert(DefinitionData && "queried property of class with no definition");
562203955Srdivacky    return *DefinitionData;
563203955Srdivacky  }
564203955Srdivacky
565203955Srdivacky  const struct DefinitionData &data() const {
566203955Srdivacky    assert(DefinitionData && "queried property of class with no definition");
567203955Srdivacky    return *DefinitionData;
568203955Srdivacky  }
569235633Sdim
570235633Sdim  struct LambdaDefinitionData &getLambdaData() const {
571235633Sdim    assert(DefinitionData && "queried property of lambda with no definition");
572235633Sdim    assert(DefinitionData->IsLambda &&
573235633Sdim           "queried lambda property of non-lambda class");
574235633Sdim    return static_cast<LambdaDefinitionData &>(*DefinitionData);
575235633Sdim  }
576198092Srdivacky
577193326Sed  /// \brief The template or declaration that this declaration
578193326Sed  /// describes or was instantiated from, respectively.
579198092Srdivacky  ///
580263509Sdim  /// For non-templates, this value will be null. For record
581193326Sed  /// declarations that describe a class template, this will be a
582193326Sed  /// pointer to a ClassTemplateDecl. For member
583193326Sed  /// classes of class template specializations, this will be the
584235633Sdim  /// MemberSpecializationInfo referring to the member class that was
585198092Srdivacky  /// instantiated or specialized.
586198092Srdivacky  llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*>
587193326Sed    TemplateOrInstantiation;
588206084Srdivacky
589218893Sdim  friend class DeclContext;
590235633Sdim  friend class LambdaExpr;
591235633Sdim
592252723Sdim  /// \brief Called from setBases and addedMember to notify the class that a
593252723Sdim  /// direct or virtual base class or a member of class type has been added.
594252723Sdim  void addedClassSubobject(CXXRecordDecl *Base);
595252723Sdim
596218893Sdim  /// \brief Notify the class that member has been added.
597218893Sdim  ///
598235633Sdim  /// This routine helps maintain information about the class based on which
599218893Sdim  /// members have been added. It will be invoked by DeclContext::addDecl()
600218893Sdim  /// whenever a member is added to this record.
601218893Sdim  void addedMember(Decl *D);
602218893Sdim
603218893Sdim  void markedVirtualFunctionPure();
604218893Sdim  friend void FunctionDecl::setPure(bool);
605235633Sdim
606235633Sdim  friend class ASTNodeImporter;
607235633Sdim
608263509Sdim  /// \brief Get the head of our list of friend declarations, possibly
609263509Sdim  /// deserializing the friends from an external AST source.
610263509Sdim  FriendDecl *getFirstFriend() const;
611263509Sdim
612193326Sedprotected:
613193326Sed  CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
614221345Sdim                SourceLocation StartLoc, SourceLocation IdLoc,
615221345Sdim                IdentifierInfo *Id, CXXRecordDecl *PrevDecl);
616193326Sed
617193326Sedpublic:
618263509Sdim  /// \brief Iterator that traverses the base classes of a class.
619193326Sed  typedef CXXBaseSpecifier*       base_class_iterator;
620193326Sed
621263509Sdim  /// \brief Iterator that traverses the base classes of a class.
622193326Sed  typedef const CXXBaseSpecifier* base_class_const_iterator;
623193326Sed
624263509Sdim  /// \brief Iterator that traverses the base classes of a class in reverse
625263509Sdim  /// order.
626198092Srdivacky  typedef std::reverse_iterator<base_class_iterator>
627198092Srdivacky    reverse_base_class_iterator;
628198092Srdivacky
629263509Sdim  /// \brief Iterator that traverses the base classes of a class in reverse
630263509Sdim  /// order.
631198092Srdivacky  typedef std::reverse_iterator<base_class_const_iterator>
632198092Srdivacky    reverse_base_class_const_iterator;
633198092Srdivacky
634198092Srdivacky  virtual CXXRecordDecl *getCanonicalDecl() {
635198092Srdivacky    return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
636198092Srdivacky  }
637199482Srdivacky  virtual const CXXRecordDecl *getCanonicalDecl() const {
638199482Srdivacky    return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
639199482Srdivacky  }
640235633Sdim
641263509Sdim  CXXRecordDecl *getPreviousDecl() {
642263509Sdim    return cast_or_null<CXXRecordDecl>(
643263509Sdim            static_cast<RecordDecl *>(this)->getPreviousDecl());
644263509Sdim  }
645235633Sdim  const CXXRecordDecl *getPreviousDecl() const {
646263509Sdim    return const_cast<CXXRecordDecl*>(this)->getPreviousDecl();
647210299Sed  }
648263509Sdim
649263509Sdim  CXXRecordDecl *getMostRecentDecl() {
650263509Sdim    return cast<CXXRecordDecl>(
651263509Sdim            static_cast<RecordDecl *>(this)->getMostRecentDecl());
652210299Sed  }
653198092Srdivacky
654235633Sdim  const CXXRecordDecl *getMostRecentDecl() const {
655263509Sdim    return const_cast<CXXRecordDecl*>(this)->getMostRecentDecl();
656235633Sdim  }
657235633Sdim
658203955Srdivacky  CXXRecordDecl *getDefinition() const {
659203955Srdivacky    if (!DefinitionData) return 0;
660203955Srdivacky    return data().Definition;
661203955Srdivacky  }
662203955Srdivacky
663203955Srdivacky  bool hasDefinition() const { return DefinitionData != 0; }
664203955Srdivacky
665218893Sdim  static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
666221345Sdim                               SourceLocation StartLoc, SourceLocation IdLoc,
667221345Sdim                               IdentifierInfo *Id, CXXRecordDecl* PrevDecl=0,
668193326Sed                               bool DelayTypeCreation = false);
669235633Sdim  static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC,
670245431Sdim                                     TypeSourceInfo *Info, SourceLocation Loc,
671263509Sdim                                     bool DependentLambda, bool IsGeneric,
672263509Sdim                                     LambdaCaptureDefault CaptureDefault);
673235633Sdim  static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
674198092Srdivacky
675198092Srdivacky  bool isDynamicClass() const {
676203955Srdivacky    return data().Polymorphic || data().NumVBases != 0;
677198092Srdivacky  }
678198092Srdivacky
679263509Sdim  /// \brief Sets the base classes of this struct or class.
680203955Srdivacky  void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
681193326Sed
682263509Sdim  /// \brief Retrieves the number of base classes of this class.
683203955Srdivacky  unsigned getNumBases() const { return data().NumBases; }
684193326Sed
685218893Sdim  base_class_iterator bases_begin() { return data().getBases(); }
686218893Sdim  base_class_const_iterator bases_begin() const { return data().getBases(); }
687203955Srdivacky  base_class_iterator bases_end() { return bases_begin() + data().NumBases; }
688203955Srdivacky  base_class_const_iterator bases_end() const {
689203955Srdivacky    return bases_begin() + data().NumBases;
690203955Srdivacky  }
691198092Srdivacky  reverse_base_class_iterator       bases_rbegin() {
692198092Srdivacky    return reverse_base_class_iterator(bases_end());
693198092Srdivacky  }
694198092Srdivacky  reverse_base_class_const_iterator bases_rbegin() const {
695198092Srdivacky    return reverse_base_class_const_iterator(bases_end());
696198092Srdivacky  }
697198092Srdivacky  reverse_base_class_iterator bases_rend() {
698198092Srdivacky    return reverse_base_class_iterator(bases_begin());
699198092Srdivacky  }
700198092Srdivacky  reverse_base_class_const_iterator bases_rend() const {
701198092Srdivacky    return reverse_base_class_const_iterator(bases_begin());
702198092Srdivacky  }
703193326Sed
704263509Sdim  /// \brief Retrieves the number of virtual base classes of this class.
705203955Srdivacky  unsigned getNumVBases() const { return data().NumVBases; }
706198092Srdivacky
707218893Sdim  base_class_iterator vbases_begin() { return data().getVBases(); }
708218893Sdim  base_class_const_iterator vbases_begin() const { return data().getVBases(); }
709203955Srdivacky  base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; }
710203955Srdivacky  base_class_const_iterator vbases_end() const {
711203955Srdivacky    return vbases_begin() + data().NumVBases;
712203955Srdivacky  }
713198092Srdivacky  reverse_base_class_iterator vbases_rbegin() {
714198092Srdivacky    return reverse_base_class_iterator(vbases_end());
715198092Srdivacky  }
716198092Srdivacky  reverse_base_class_const_iterator vbases_rbegin() const {
717198092Srdivacky    return reverse_base_class_const_iterator(vbases_end());
718198092Srdivacky  }
719198092Srdivacky  reverse_base_class_iterator vbases_rend() {
720198092Srdivacky    return reverse_base_class_iterator(vbases_begin());
721198092Srdivacky  }
722198092Srdivacky  reverse_base_class_const_iterator vbases_rend() const {
723198092Srdivacky    return reverse_base_class_const_iterator(vbases_begin());
724198092Srdivacky }
725198092Srdivacky
726252723Sdim  /// \brief Determine whether this class has any dependent base classes which
727252723Sdim  /// are not the current instantiation.
728202379Srdivacky  bool hasAnyDependentBases() const;
729202379Srdivacky
730198092Srdivacky  /// Iterator access to method members.  The method iterator visits
731198092Srdivacky  /// all method members of the class, including non-instance methods,
732198092Srdivacky  /// special methods, etc.
733198092Srdivacky  typedef specific_decl_iterator<CXXMethodDecl> method_iterator;
734198092Srdivacky
735263509Sdim  /// \brief Method begin iterator.  Iterates in the order the methods
736198092Srdivacky  /// were declared.
737198092Srdivacky  method_iterator method_begin() const {
738198092Srdivacky    return method_iterator(decls_begin());
739198092Srdivacky  }
740263509Sdim  /// \brief Method past-the-end iterator.
741198092Srdivacky  method_iterator method_end() const {
742198092Srdivacky    return method_iterator(decls_end());
743198092Srdivacky  }
744198092Srdivacky
745198092Srdivacky  /// Iterator access to constructor members.
746198092Srdivacky  typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator;
747198092Srdivacky
748198092Srdivacky  ctor_iterator ctor_begin() const {
749198092Srdivacky    return ctor_iterator(decls_begin());
750198092Srdivacky  }
751198092Srdivacky  ctor_iterator ctor_end() const {
752198092Srdivacky    return ctor_iterator(decls_end());
753198092Srdivacky  }
754198092Srdivacky
755205219Srdivacky  /// An iterator over friend declarations.  All of these are defined
756205219Srdivacky  /// in DeclFriend.h.
757205219Srdivacky  class friend_iterator;
758205219Srdivacky  friend_iterator friend_begin() const;
759205219Srdivacky  friend_iterator friend_end() const;
760205219Srdivacky  void pushFriendDecl(FriendDecl *FD);
761205219Srdivacky
762207619Srdivacky  /// Determines whether this record has any friends.
763207619Srdivacky  bool hasFriends() const {
764263509Sdim    return data().FirstFriend.isValid();
765207619Srdivacky  }
766207619Srdivacky
767252723Sdim  /// \brief \c true if we know for sure that this class has a single,
768252723Sdim  /// accessible, unambiguous move constructor that is not deleted.
769252723Sdim  bool hasSimpleMoveConstructor() const {
770263509Sdim    return !hasUserDeclaredMoveConstructor() && hasMoveConstructor() &&
771263509Sdim           !data().DefaultedMoveConstructorIsDeleted;
772252723Sdim  }
773252723Sdim  /// \brief \c true if we know for sure that this class has a single,
774252723Sdim  /// accessible, unambiguous move assignment operator that is not deleted.
775252723Sdim  bool hasSimpleMoveAssignment() const {
776263509Sdim    return !hasUserDeclaredMoveAssignment() && hasMoveAssignment() &&
777263509Sdim           !data().DefaultedMoveAssignmentIsDeleted;
778252723Sdim  }
779252723Sdim  /// \brief \c true if we know for sure that this class has an accessible
780252723Sdim  /// destructor that is not deleted.
781252723Sdim  bool hasSimpleDestructor() const {
782252723Sdim    return !hasUserDeclaredDestructor() &&
783252723Sdim           !data().DefaultedDestructorIsDeleted;
784252723Sdim  }
785252723Sdim
786252723Sdim  /// \brief Determine whether this class has any default constructors.
787252723Sdim  bool hasDefaultConstructor() const {
788252723Sdim    return (data().DeclaredSpecialMembers & SMF_DefaultConstructor) ||
789252723Sdim           needsImplicitDefaultConstructor();
790252723Sdim  }
791252723Sdim
792223017Sdim  /// \brief Determine if we need to declare a default constructor for
793223017Sdim  /// this class.
794210299Sed  ///
795210299Sed  /// This value is used for lazy creation of default constructors.
796223017Sdim  bool needsImplicitDefaultConstructor() const {
797235633Sdim    return !data().UserDeclaredConstructor &&
798252723Sdim           !(data().DeclaredSpecialMembers & SMF_DefaultConstructor);
799223017Sdim  }
800223017Sdim
801263509Sdim  /// \brief Determine whether this class has any user-declared constructors.
802263509Sdim  ///
803263509Sdim  /// When true, a default constructor will not be implicitly declared.
804198092Srdivacky  bool hasUserDeclaredConstructor() const {
805203955Srdivacky    return data().UserDeclaredConstructor;
806198092Srdivacky  }
807193326Sed
808263509Sdim  /// \brief Whether this class has a user-provided default constructor
809263509Sdim  /// per C++11.
810223017Sdim  bool hasUserProvidedDefaultConstructor() const {
811223017Sdim    return data().UserProvidedDefaultConstructor;
812223017Sdim  }
813223017Sdim
814263509Sdim  /// \brief Determine whether this class has a user-declared copy constructor.
815263509Sdim  ///
816263509Sdim  /// When false, a copy constructor will be implicitly declared.
817193326Sed  bool hasUserDeclaredCopyConstructor() const {
818252723Sdim    return data().UserDeclaredSpecialMembers & SMF_CopyConstructor;
819193326Sed  }
820193326Sed
821252723Sdim  /// \brief Determine whether this class needs an implicit copy
822252723Sdim  /// constructor to be lazily declared.
823252723Sdim  bool needsImplicitCopyConstructor() const {
824252723Sdim    return !(data().DeclaredSpecialMembers & SMF_CopyConstructor);
825210299Sed  }
826223017Sdim
827252723Sdim  /// \brief Determine whether we need to eagerly declare a defaulted copy
828252723Sdim  /// constructor for this class.
829252723Sdim  bool needsOverloadResolutionForCopyConstructor() const {
830252723Sdim    return data().HasMutableFields;
831252723Sdim  }
832252723Sdim
833252723Sdim  /// \brief Determine whether an implicit copy constructor for this type
834252723Sdim  /// would have a parameter with a const-qualified reference type.
835252723Sdim  bool implicitCopyConstructorHasConstParam() const {
836252723Sdim    return data().ImplicitCopyConstructorHasConstParam;
837252723Sdim  }
838252723Sdim
839252723Sdim  /// \brief Determine whether this class has a copy constructor with
840252723Sdim  /// a parameter type which is a reference to a const-qualified type.
841252723Sdim  bool hasCopyConstructorWithConstParam() const {
842252723Sdim    return data().HasDeclaredCopyConstructorWithConstParam ||
843252723Sdim           (needsImplicitCopyConstructor() &&
844252723Sdim            implicitCopyConstructorHasConstParam());
845252723Sdim  }
846252723Sdim
847263509Sdim  /// \brief Whether this class has a user-declared move constructor or
848263509Sdim  /// assignment operator.
849263509Sdim  ///
850263509Sdim  /// When false, a move constructor and assignment operator may be
851263509Sdim  /// implicitly declared.
852223017Sdim  bool hasUserDeclaredMoveOperation() const {
853252723Sdim    return data().UserDeclaredSpecialMembers &
854252723Sdim             (SMF_MoveConstructor | SMF_MoveAssignment);
855223017Sdim  }
856223017Sdim
857223017Sdim  /// \brief Determine whether this class has had a move constructor
858223017Sdim  /// declared by the user.
859223017Sdim  bool hasUserDeclaredMoveConstructor() const {
860252723Sdim    return data().UserDeclaredSpecialMembers & SMF_MoveConstructor;
861223017Sdim  }
862223017Sdim
863252723Sdim  /// \brief Determine whether this class has a move constructor.
864252723Sdim  bool hasMoveConstructor() const {
865252723Sdim    return (data().DeclaredSpecialMembers & SMF_MoveConstructor) ||
866252723Sdim           needsImplicitMoveConstructor();
867223017Sdim  }
868223017Sdim
869263509Sdim  /// \brief Set that we attempted to declare an implicitly move
870263509Sdim  /// constructor, but overload resolution failed so we deleted it.
871263509Sdim  void setImplicitMoveConstructorIsDeleted() {
872263509Sdim    assert((data().DefaultedMoveConstructorIsDeleted ||
873263509Sdim            needsOverloadResolutionForMoveConstructor()) &&
874263509Sdim           "move constructor should not be deleted");
875263509Sdim    data().DefaultedMoveConstructorIsDeleted = true;
876226890Sdim  }
877226890Sdim
878226890Sdim  /// \brief Determine whether this class should get an implicit move
879226890Sdim  /// constructor or if any existing special member function inhibits this.
880226890Sdim  bool needsImplicitMoveConstructor() const {
881263509Sdim    return !(data().DeclaredSpecialMembers & SMF_MoveConstructor) &&
882226890Sdim           !hasUserDeclaredCopyConstructor() &&
883226890Sdim           !hasUserDeclaredCopyAssignment() &&
884226890Sdim           !hasUserDeclaredMoveAssignment() &&
885263509Sdim           !hasUserDeclaredDestructor();
886226890Sdim  }
887226890Sdim
888252723Sdim  /// \brief Determine whether we need to eagerly declare a defaulted move
889252723Sdim  /// constructor for this class.
890252723Sdim  bool needsOverloadResolutionForMoveConstructor() const {
891252723Sdim    return data().NeedOverloadResolutionForMoveConstructor;
892252723Sdim  }
893252723Sdim
894263509Sdim  /// \brief Determine whether this class has a user-declared copy assignment
895263509Sdim  /// operator.
896263509Sdim  ///
897263509Sdim  /// When false, a copy assigment operator will be implicitly declared.
898193326Sed  bool hasUserDeclaredCopyAssignment() const {
899252723Sdim    return data().UserDeclaredSpecialMembers & SMF_CopyAssignment;
900193326Sed  }
901193326Sed
902252723Sdim  /// \brief Determine whether this class needs an implicit copy
903252723Sdim  /// assignment operator to be lazily declared.
904252723Sdim  bool needsImplicitCopyAssignment() const {
905252723Sdim    return !(data().DeclaredSpecialMembers & SMF_CopyAssignment);
906210299Sed  }
907223017Sdim
908252723Sdim  /// \brief Determine whether we need to eagerly declare a defaulted copy
909252723Sdim  /// assignment operator for this class.
910252723Sdim  bool needsOverloadResolutionForCopyAssignment() const {
911252723Sdim    return data().HasMutableFields;
912252723Sdim  }
913252723Sdim
914252723Sdim  /// \brief Determine whether an implicit copy assignment operator for this
915252723Sdim  /// type would have a parameter with a const-qualified reference type.
916252723Sdim  bool implicitCopyAssignmentHasConstParam() const {
917252723Sdim    return data().ImplicitCopyAssignmentHasConstParam;
918252723Sdim  }
919252723Sdim
920252723Sdim  /// \brief Determine whether this class has a copy assignment operator with
921252723Sdim  /// a parameter type which is a reference to a const-qualified type or is not
922263509Sdim  /// a reference.
923252723Sdim  bool hasCopyAssignmentWithConstParam() const {
924252723Sdim    return data().HasDeclaredCopyAssignmentWithConstParam ||
925252723Sdim           (needsImplicitCopyAssignment() &&
926252723Sdim            implicitCopyAssignmentHasConstParam());
927252723Sdim  }
928252723Sdim
929223017Sdim  /// \brief Determine whether this class has had a move assignment
930223017Sdim  /// declared by the user.
931223017Sdim  bool hasUserDeclaredMoveAssignment() const {
932252723Sdim    return data().UserDeclaredSpecialMembers & SMF_MoveAssignment;
933223017Sdim  }
934223017Sdim
935252723Sdim  /// \brief Determine whether this class has a move assignment operator.
936252723Sdim  bool hasMoveAssignment() const {
937252723Sdim    return (data().DeclaredSpecialMembers & SMF_MoveAssignment) ||
938252723Sdim           needsImplicitMoveAssignment();
939223017Sdim  }
940223017Sdim
941263509Sdim  /// \brief Set that we attempted to declare an implicit move assignment
942263509Sdim  /// operator, but overload resolution failed so we deleted it.
943263509Sdim  void setImplicitMoveAssignmentIsDeleted() {
944263509Sdim    assert((data().DefaultedMoveAssignmentIsDeleted ||
945263509Sdim            needsOverloadResolutionForMoveAssignment()) &&
946263509Sdim           "move assignment should not be deleted");
947263509Sdim    data().DefaultedMoveAssignmentIsDeleted = true;
948226890Sdim  }
949226890Sdim
950226890Sdim  /// \brief Determine whether this class should get an implicit move
951226890Sdim  /// assignment operator or if any existing special member function inhibits
952226890Sdim  /// this.
953226890Sdim  bool needsImplicitMoveAssignment() const {
954263509Sdim    return !(data().DeclaredSpecialMembers & SMF_MoveAssignment) &&
955226890Sdim           !hasUserDeclaredCopyConstructor() &&
956226890Sdim           !hasUserDeclaredCopyAssignment() &&
957226890Sdim           !hasUserDeclaredMoveConstructor() &&
958263509Sdim           !hasUserDeclaredDestructor();
959226890Sdim  }
960226890Sdim
961252723Sdim  /// \brief Determine whether we need to eagerly declare a move assignment
962252723Sdim  /// operator for this class.
963252723Sdim  bool needsOverloadResolutionForMoveAssignment() const {
964252723Sdim    return data().NeedOverloadResolutionForMoveAssignment;
965252723Sdim  }
966252723Sdim
967263509Sdim  /// \brief Determine whether this class has a user-declared destructor.
968263509Sdim  ///
969263509Sdim  /// When false, a destructor will be implicitly declared.
970203955Srdivacky  bool hasUserDeclaredDestructor() const {
971252723Sdim    return data().UserDeclaredSpecialMembers & SMF_Destructor;
972203955Srdivacky  }
973193326Sed
974252723Sdim  /// \brief Determine whether this class needs an implicit destructor to
975252723Sdim  /// be lazily declared.
976252723Sdim  bool needsImplicitDestructor() const {
977252723Sdim    return !(data().DeclaredSpecialMembers & SMF_Destructor);
978252723Sdim  }
979218893Sdim
980252723Sdim  /// \brief Determine whether we need to eagerly declare a destructor for this
981252723Sdim  /// class.
982252723Sdim  bool needsOverloadResolutionForDestructor() const {
983252723Sdim    return data().NeedOverloadResolutionForDestructor;
984252723Sdim  }
985252723Sdim
986235633Sdim  /// \brief Determine whether this class describes a lambda function object.
987235633Sdim  bool isLambda() const { return hasDefinition() && data().IsLambda; }
988252723Sdim
989263509Sdim  /// \brief Determine whether this class describes a generic
990263509Sdim  /// lambda function object (i.e. function call operator is
991263509Sdim  /// a template).
992263509Sdim  bool isGenericLambda() const;
993263509Sdim
994263509Sdim  /// \brief Retrieve the lambda call operator of the closure type
995263509Sdim  /// if this is a closure type.
996263509Sdim  CXXMethodDecl *getLambdaCallOperator() const;
997263509Sdim
998263509Sdim  /// \brief Retrieve the lambda static invoker, the address of which
999263509Sdim  /// is returned by the conversion operator, and the body of which
1000263509Sdim  /// is forwarded to the lambda call operator.
1001263509Sdim  CXXMethodDecl *getLambdaStaticInvoker() const;
1002263509Sdim
1003263509Sdim  /// \brief Retrieve the generic lambda's template parameter list.
1004263509Sdim  /// Returns null if the class does not represent a lambda or a generic
1005263509Sdim  /// lambda.
1006263509Sdim  TemplateParameterList *getGenericLambdaTemplateParameterList() const;
1007263509Sdim
1008263509Sdim  LambdaCaptureDefault getLambdaCaptureDefault() const {
1009263509Sdim    assert(isLambda());
1010263509Sdim    return static_cast<LambdaCaptureDefault>(getLambdaData().CaptureDefault);
1011263509Sdim  }
1012263509Sdim
1013235633Sdim  /// \brief For a closure type, retrieve the mapping from captured
1014263509Sdim  /// variables and \c this to the non-static data members that store the
1015235633Sdim  /// values or references of the captures.
1016235633Sdim  ///
1017235633Sdim  /// \param Captures Will be populated with the mapping from captured
1018235633Sdim  /// variables to the corresponding fields.
1019235633Sdim  ///
1020235633Sdim  /// \param ThisCapture Will be set to the field declaration for the
1021263509Sdim  /// \c this capture.
1022263509Sdim  ///
1023263509Sdim  /// \note No entries will be added for init-captures, as they do not capture
1024263509Sdim  /// variables.
1025235633Sdim  void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures,
1026235633Sdim                        FieldDecl *&ThisCapture) const;
1027235633Sdim
1028235633Sdim  typedef const LambdaExpr::Capture* capture_const_iterator;
1029235633Sdim  capture_const_iterator captures_begin() const {
1030235633Sdim    return isLambda() ? getLambdaData().Captures : NULL;
1031235633Sdim  }
1032235633Sdim  capture_const_iterator captures_end() const {
1033235633Sdim    return isLambda() ? captures_begin() + getLambdaData().NumCaptures : NULL;
1034235633Sdim  }
1035235633Sdim
1036252723Sdim  typedef UnresolvedSetIterator conversion_iterator;
1037203955Srdivacky  conversion_iterator conversion_begin() const {
1038263509Sdim    return data().Conversions.get(getASTContext()).begin();
1039203955Srdivacky  }
1040203955Srdivacky  conversion_iterator conversion_end() const {
1041263509Sdim    return data().Conversions.get(getASTContext()).end();
1042203955Srdivacky  }
1043199990Srdivacky
1044206084Srdivacky  /// Removes a conversion function from this class.  The conversion
1045206084Srdivacky  /// function must currently be a member of this class.  Furthermore,
1046206084Srdivacky  /// this class must currently be in the process of being defined.
1047206084Srdivacky  void removeConversion(const NamedDecl *Old);
1048206084Srdivacky
1049263509Sdim  /// \brief Get all conversion functions visible in current class,
1050263509Sdim  /// including conversion function templates.
1051252723Sdim  std::pair<conversion_iterator, conversion_iterator>
1052252723Sdim    getVisibleConversionFunctions();
1053199990Srdivacky
1054263509Sdim  /// Determine whether this class is an aggregate (C++ [dcl.init.aggr]),
1055263509Sdim  /// which is a class with no user-declared constructors, no private
1056263509Sdim  /// or protected non-static data members, no base classes, and no virtual
1057263509Sdim  /// functions (C++ [dcl.init.aggr]p1).
1058203955Srdivacky  bool isAggregate() const { return data().Aggregate; }
1059193326Sed
1060263509Sdim  /// \brief Whether this class has any in-class initializers
1061245431Sdim  /// for non-static data members.
1062245431Sdim  bool hasInClassInitializer() const { return data().HasInClassInitializer; }
1063245431Sdim
1064252723Sdim  /// \brief Whether this class or any of its subobjects has any members of
1065263509Sdim  /// reference type which would make value-initialization ill-formed.
1066263509Sdim  ///
1067263509Sdim  /// Per C++03 [dcl.init]p5:
1068263509Sdim  ///  - if T is a non-union class type without a user-declared constructor,
1069263509Sdim  ///    then every non-static data member and base-class component of T is
1070263509Sdim  ///    value-initialized [...] A program that calls for [...]
1071263509Sdim  ///    value-initialization of an entity of reference type is ill-formed.
1072252723Sdim  bool hasUninitializedReferenceMember() const {
1073252723Sdim    return !isUnion() && !hasUserDeclaredConstructor() &&
1074252723Sdim           data().HasUninitializedReferenceMember;
1075252723Sdim  }
1076252723Sdim
1077263509Sdim  /// \brief Whether this class is a POD-type (C++ [class]p4)
1078263509Sdim  ///
1079263509Sdim  /// For purposes of this function a class is POD if it is an aggregate
1080263509Sdim  /// that has no non-static non-POD data members, no reference data
1081263509Sdim  /// members, no user-defined copy assignment operator and no
1082193326Sed  /// user-defined destructor.
1083252723Sdim  ///
1084252723Sdim  /// Note that this is the C++ TR1 definition of POD.
1085203955Srdivacky  bool isPOD() const { return data().PlainOldData; }
1086193326Sed
1087235633Sdim  /// \brief True if this class is C-like, without C++-specific features, e.g.
1088235633Sdim  /// it contains only public fields, no bases, tag kind is not 'class', etc.
1089235633Sdim  bool isCLike() const;
1090235633Sdim
1091263509Sdim  /// \brief Determine whether this is an empty class in the sense of
1092263509Sdim  /// (C++11 [meta.unary.prop]).
1093263509Sdim  ///
1094263509Sdim  /// A non-union class is empty iff it has a virtual function, virtual base,
1095263509Sdim  /// data member (other than 0-width bit-field) or inherits from a non-empty
1096263509Sdim  /// class.
1097263509Sdim  ///
1098263509Sdim  /// \note This does NOT include a check for union-ness.
1099203955Srdivacky  bool isEmpty() const { return data().Empty; }
1100198092Srdivacky
1101263509Sdim  /// Whether this class is polymorphic (C++ [class.virtual]),
1102193326Sed  /// which means that the class contains or inherits a virtual function.
1103203955Srdivacky  bool isPolymorphic() const { return data().Polymorphic; }
1104193326Sed
1105263509Sdim  /// \brief Determine whether this class has a pure virtual function.
1106263509Sdim  ///
1107263509Sdim  /// The class is is abstract per (C++ [class.abstract]p2) if it declares
1108263509Sdim  /// a pure virtual function or inherits a pure virtual function that is
1109263509Sdim  /// not overridden.
1110203955Srdivacky  bool isAbstract() const { return data().Abstract; }
1111198092Srdivacky
1112263509Sdim  /// \brief Determine whether this class has standard layout per
1113221345Sdim  /// (C++ [class]p7)
1114221345Sdim  bool isStandardLayout() const { return data().IsStandardLayout; }
1115221345Sdim
1116263509Sdim  /// \brief Determine whether this class, or any of its class subobjects,
1117263509Sdim  /// contains a mutable field.
1118223017Sdim  bool hasMutableFields() const { return data().HasMutableFields; }
1119235633Sdim
1120252723Sdim  /// \brief Determine whether this class has a trivial default constructor
1121252723Sdim  /// (C++11 [class.ctor]p5).
1122223017Sdim  bool hasTrivialDefaultConstructor() const {
1123252723Sdim    return hasDefaultConstructor() &&
1124252723Sdim           (data().HasTrivialSpecialMembers & SMF_DefaultConstructor);
1125223017Sdim  }
1126198092Srdivacky
1127252723Sdim  /// \brief Determine whether this class has a non-trivial default constructor
1128252723Sdim  /// (C++11 [class.ctor]p5).
1129252723Sdim  bool hasNonTrivialDefaultConstructor() const {
1130252723Sdim    return (data().DeclaredNonTrivialSpecialMembers & SMF_DefaultConstructor) ||
1131252723Sdim           (needsImplicitDefaultConstructor() &&
1132252723Sdim            !(data().HasTrivialSpecialMembers & SMF_DefaultConstructor));
1133252723Sdim  }
1134252723Sdim
1135252723Sdim  /// \brief Determine whether this class has at least one constexpr constructor
1136252723Sdim  /// other than the copy or move constructors.
1137226890Sdim  bool hasConstexprNonCopyMoveConstructor() const {
1138235633Sdim    return data().HasConstexprNonCopyMoveConstructor ||
1139252723Sdim           (needsImplicitDefaultConstructor() &&
1140235633Sdim            defaultedDefaultConstructorIsConstexpr());
1141221345Sdim  }
1142221345Sdim
1143252723Sdim  /// \brief Determine whether a defaulted default constructor for this class
1144252723Sdim  /// would be constexpr.
1145235633Sdim  bool defaultedDefaultConstructorIsConstexpr() const {
1146245431Sdim    return data().DefaultedDefaultConstructorIsConstexpr &&
1147245431Sdim           (!isUnion() || hasInClassInitializer());
1148235633Sdim  }
1149235633Sdim
1150252723Sdim  /// \brief Determine whether this class has a constexpr default constructor.
1151235633Sdim  bool hasConstexprDefaultConstructor() const {
1152235633Sdim    return data().HasConstexprDefaultConstructor ||
1153252723Sdim           (needsImplicitDefaultConstructor() &&
1154245431Sdim            defaultedDefaultConstructorIsConstexpr());
1155235633Sdim  }
1156235633Sdim
1157252723Sdim  /// \brief Determine whether this class has a trivial copy constructor
1158252723Sdim  /// (C++ [class.copy]p6, C++11 [class.copy]p12)
1159203955Srdivacky  bool hasTrivialCopyConstructor() const {
1160252723Sdim    return data().HasTrivialSpecialMembers & SMF_CopyConstructor;
1161203955Srdivacky  }
1162198092Srdivacky
1163252723Sdim  /// \brief Determine whether this class has a non-trivial copy constructor
1164252723Sdim  /// (C++ [class.copy]p6, C++11 [class.copy]p12)
1165252723Sdim  bool hasNonTrivialCopyConstructor() const {
1166252723Sdim    return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor ||
1167252723Sdim           !hasTrivialCopyConstructor();
1168252723Sdim  }
1169252723Sdim
1170252723Sdim  /// \brief Determine whether this class has a trivial move constructor
1171252723Sdim  /// (C++11 [class.copy]p12)
1172221345Sdim  bool hasTrivialMoveConstructor() const {
1173252723Sdim    return hasMoveConstructor() &&
1174252723Sdim           (data().HasTrivialSpecialMembers & SMF_MoveConstructor);
1175221345Sdim  }
1176221345Sdim
1177252723Sdim  /// \brief Determine whether this class has a non-trivial move constructor
1178252723Sdim  /// (C++11 [class.copy]p12)
1179252723Sdim  bool hasNonTrivialMoveConstructor() const {
1180252723Sdim    return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveConstructor) ||
1181252723Sdim           (needsImplicitMoveConstructor() &&
1182252723Sdim            !(data().HasTrivialSpecialMembers & SMF_MoveConstructor));
1183252723Sdim  }
1184252723Sdim
1185252723Sdim  /// \brief Determine whether this class has a trivial copy assignment operator
1186252723Sdim  /// (C++ [class.copy]p11, C++11 [class.copy]p25)
1187203955Srdivacky  bool hasTrivialCopyAssignment() const {
1188252723Sdim    return data().HasTrivialSpecialMembers & SMF_CopyAssignment;
1189203955Srdivacky  }
1190198092Srdivacky
1191252723Sdim  /// \brief Determine whether this class has a non-trivial copy assignment
1192252723Sdim  /// operator (C++ [class.copy]p11, C++11 [class.copy]p25)
1193252723Sdim  bool hasNonTrivialCopyAssignment() const {
1194252723Sdim    return data().DeclaredNonTrivialSpecialMembers & SMF_CopyAssignment ||
1195252723Sdim           !hasTrivialCopyAssignment();
1196252723Sdim  }
1197252723Sdim
1198252723Sdim  /// \brief Determine whether this class has a trivial move assignment operator
1199252723Sdim  /// (C++11 [class.copy]p25)
1200221345Sdim  bool hasTrivialMoveAssignment() const {
1201252723Sdim    return hasMoveAssignment() &&
1202252723Sdim           (data().HasTrivialSpecialMembers & SMF_MoveAssignment);
1203221345Sdim  }
1204221345Sdim
1205252723Sdim  /// \brief Determine whether this class has a non-trivial move assignment
1206252723Sdim  /// operator (C++11 [class.copy]p25)
1207252723Sdim  bool hasNonTrivialMoveAssignment() const {
1208252723Sdim    return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveAssignment) ||
1209252723Sdim           (needsImplicitMoveAssignment() &&
1210252723Sdim            !(data().HasTrivialSpecialMembers & SMF_MoveAssignment));
1211252723Sdim  }
1212198092Srdivacky
1213252723Sdim  /// \brief Determine whether this class has a trivial destructor
1214252723Sdim  /// (C++ [class.dtor]p3)
1215252723Sdim  bool hasTrivialDestructor() const {
1216252723Sdim    return data().HasTrivialSpecialMembers & SMF_Destructor;
1217252723Sdim  }
1218252723Sdim
1219252723Sdim  /// \brief Determine whether this class has a non-trivial destructor
1220252723Sdim  /// (C++ [class.dtor]p3)
1221252723Sdim  bool hasNonTrivialDestructor() const {
1222252723Sdim    return !(data().HasTrivialSpecialMembers & SMF_Destructor);
1223252723Sdim  }
1224252723Sdim
1225263509Sdim  /// \brief Determine whether this class has a destructor which has no
1226263509Sdim  /// semantic effect.
1227263509Sdim  ///
1228263509Sdim  /// Any such destructor will be trivial, public, defaulted and not deleted,
1229263509Sdim  /// and will call only irrelevant destructors.
1230235633Sdim  bool hasIrrelevantDestructor() const {
1231235633Sdim    return data().HasIrrelevantDestructor;
1232235633Sdim  }
1233235633Sdim
1234263509Sdim  /// \brief Determine whether this class has a non-literal or/ volatile type
1235263509Sdim  /// non-static data member or base class.
1236221345Sdim  bool hasNonLiteralTypeFieldsOrBases() const {
1237221345Sdim    return data().HasNonLiteralTypeFieldsOrBases;
1238221345Sdim  }
1239221345Sdim
1240263509Sdim  /// \brief Determine whether this class is considered trivially copyable per
1241263509Sdim  /// (C++11 [class]p6).
1242221345Sdim  bool isTriviallyCopyable() const;
1243221345Sdim
1244263509Sdim  /// \brief Determine whether this class is considered trivial.
1245263509Sdim  ///
1246263509Sdim  /// C++11 [class]p6:
1247263509Sdim  ///    "A trivial class is a class that has a trivial default constructor and
1248263509Sdim  ///    is trivially copiable."
1249223017Sdim  bool isTrivial() const {
1250223017Sdim    return isTriviallyCopyable() && hasTrivialDefaultConstructor();
1251223017Sdim  }
1252223017Sdim
1253263509Sdim  /// \brief Determine whether this class is a literal type.
1254263509Sdim  ///
1255263509Sdim  /// C++11 [basic.types]p10:
1256263509Sdim  ///   A class type that has all the following properties:
1257263509Sdim  ///     - it has a trivial destructor
1258263509Sdim  ///     - every constructor call and full-expression in the
1259263509Sdim  ///       brace-or-equal-intializers for non-static data members (if any) is
1260263509Sdim  ///       a constant expression.
1261263509Sdim  ///     - it is an aggregate type or has at least one constexpr constructor
1262263509Sdim  ///       or constructor template that is not a copy or move constructor, and
1263263509Sdim  ///     - all of its non-static data members and base classes are of literal
1264263509Sdim  ///       types
1265263509Sdim  ///
1266263509Sdim  /// We resolve DR1361 by ignoring the second bullet. We resolve DR1452 by
1267263509Sdim  /// treating types with trivial default constructors as literal types.
1268226890Sdim  bool isLiteral() const {
1269226890Sdim    return hasTrivialDestructor() &&
1270235633Sdim           (isAggregate() || hasConstexprNonCopyMoveConstructor() ||
1271235633Sdim            hasTrivialDefaultConstructor()) &&
1272226890Sdim           !hasNonLiteralTypeFieldsOrBases();
1273226890Sdim  }
1274226890Sdim
1275193326Sed  /// \brief If this record is an instantiation of a member class,
1276193326Sed  /// retrieves the member class from which it was instantiated.
1277193326Sed  ///
1278263509Sdim  /// This routine will return non-null for (non-templated) member
1279193326Sed  /// classes of class templates. For example, given:
1280193326Sed  ///
1281263509Sdim  /// \code
1282193326Sed  /// template<typename T>
1283193326Sed  /// struct X {
1284193326Sed  ///   struct A { };
1285193326Sed  /// };
1286263509Sdim  /// \endcode
1287193326Sed  ///
1288193326Sed  /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
1289193326Sed  /// whose parent is the class template specialization X<int>. For
1290193326Sed  /// this declaration, getInstantiatedFromMemberClass() will return
1291193326Sed  /// the CXXRecordDecl X<T>::A. When a complete definition of
1292193326Sed  /// X<int>::A is required, it will be instantiated from the
1293193326Sed  /// declaration returned by getInstantiatedFromMemberClass().
1294198092Srdivacky  CXXRecordDecl *getInstantiatedFromMemberClass() const;
1295235633Sdim
1296198092Srdivacky  /// \brief If this class is an instantiation of a member class of a
1297198092Srdivacky  /// class template specialization, retrieves the member specialization
1298198092Srdivacky  /// information.
1299252723Sdim  MemberSpecializationInfo *getMemberSpecializationInfo() const {
1300252723Sdim    return TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>();
1301252723Sdim  }
1302235633Sdim
1303193326Sed  /// \brief Specify that this record is an instantiation of the
1304263509Sdim  /// member class \p RD.
1305198092Srdivacky  void setInstantiationOfMemberClass(CXXRecordDecl *RD,
1306198092Srdivacky                                     TemplateSpecializationKind TSK);
1307193326Sed
1308193326Sed  /// \brief Retrieves the class template that is described by this
1309193326Sed  /// class declaration.
1310193326Sed  ///
1311193326Sed  /// Every class template is represented as a ClassTemplateDecl and a
1312193326Sed  /// CXXRecordDecl. The former contains template properties (such as
1313193326Sed  /// the template parameter lists) while the latter contains the
1314193326Sed  /// actual description of the template's
1315193326Sed  /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
1316193326Sed  /// CXXRecordDecl that from a ClassTemplateDecl, while
1317193326Sed  /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
1318193326Sed  /// a CXXRecordDecl.
1319193326Sed  ClassTemplateDecl *getDescribedClassTemplate() const {
1320193326Sed    return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>();
1321193326Sed  }
1322193326Sed
1323193326Sed  void setDescribedClassTemplate(ClassTemplateDecl *Template) {
1324193326Sed    TemplateOrInstantiation = Template;
1325193326Sed  }
1326193326Sed
1327198092Srdivacky  /// \brief Determine whether this particular class is a specialization or
1328198092Srdivacky  /// instantiation of a class template or member class of a class template,
1329198092Srdivacky  /// and how it was instantiated or specialized.
1330200583Srdivacky  TemplateSpecializationKind getTemplateSpecializationKind() const;
1331235633Sdim
1332198092Srdivacky  /// \brief Set the kind of specialization or template instantiation this is.
1333198092Srdivacky  void setTemplateSpecializationKind(TemplateSpecializationKind TSK);
1334198092Srdivacky
1335263509Sdim  /// \brief Returns the destructor decl for this class.
1336210299Sed  CXXDestructorDecl *getDestructor() const;
1337198092Srdivacky
1338263509Sdim  /// \brief If the class is a local class [class.local], returns
1339195099Sed  /// the enclosing function declaration.
1340195099Sed  const FunctionDecl *isLocalClass() const {
1341195099Sed    if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
1342195099Sed      return RD->isLocalClass();
1343198092Srdivacky
1344195099Sed    return dyn_cast<FunctionDecl>(getDeclContext());
1345195099Sed  }
1346198092Srdivacky
1347263509Sdim  FunctionDecl *isLocalClass() {
1348263509Sdim    return const_cast<FunctionDecl*>(
1349263509Sdim        const_cast<const CXXRecordDecl*>(this)->isLocalClass());
1350263509Sdim  }
1351263509Sdim
1352252723Sdim  /// \brief Determine whether this dependent class is a current instantiation,
1353252723Sdim  /// when viewed from within the given context.
1354252723Sdim  bool isCurrentInstantiation(const DeclContext *CurContext) const;
1355252723Sdim
1356198092Srdivacky  /// \brief Determine whether this class is derived from the class \p Base.
1357198092Srdivacky  ///
1358198092Srdivacky  /// This routine only determines whether this class is derived from \p Base,
1359198092Srdivacky  /// but does not account for factors that may make a Derived -> Base class
1360198092Srdivacky  /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1361198092Srdivacky  /// base class subobjects.
1362198092Srdivacky  ///
1363198092Srdivacky  /// \param Base the base class we are searching for.
1364198092Srdivacky  ///
1365198092Srdivacky  /// \returns true if this class is derived from Base, false otherwise.
1366218893Sdim  bool isDerivedFrom(const CXXRecordDecl *Base) const;
1367235633Sdim
1368198092Srdivacky  /// \brief Determine whether this class is derived from the type \p Base.
1369198092Srdivacky  ///
1370198092Srdivacky  /// This routine only determines whether this class is derived from \p Base,
1371198092Srdivacky  /// but does not account for factors that may make a Derived -> Base class
1372198092Srdivacky  /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1373198092Srdivacky  /// base class subobjects.
1374198092Srdivacky  ///
1375198092Srdivacky  /// \param Base the base class we are searching for.
1376198092Srdivacky  ///
1377198092Srdivacky  /// \param Paths will contain the paths taken from the current class to the
1378198092Srdivacky  /// given \p Base class.
1379198092Srdivacky  ///
1380263509Sdim  /// \returns true if this class is derived from \p Base, false otherwise.
1381198092Srdivacky  ///
1382235633Sdim  /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than
1383235633Sdim  /// tangling input and output in \p Paths
1384218893Sdim  bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const;
1385200583Srdivacky
1386204643Srdivacky  /// \brief Determine whether this class is virtually derived from
1387204643Srdivacky  /// the class \p Base.
1388204643Srdivacky  ///
1389204643Srdivacky  /// This routine only determines whether this class is virtually
1390204643Srdivacky  /// derived from \p Base, but does not account for factors that may
1391204643Srdivacky  /// make a Derived -> Base class ill-formed, such as
1392204643Srdivacky  /// private/protected inheritance or multiple, ambiguous base class
1393204643Srdivacky  /// subobjects.
1394204643Srdivacky  ///
1395204643Srdivacky  /// \param Base the base class we are searching for.
1396204643Srdivacky  ///
1397204643Srdivacky  /// \returns true if this class is virtually derived from Base,
1398204643Srdivacky  /// false otherwise.
1399245431Sdim  bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const;
1400204643Srdivacky
1401200583Srdivacky  /// \brief Determine whether this class is provably not derived from
1402200583Srdivacky  /// the type \p Base.
1403200583Srdivacky  bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
1404200583Srdivacky
1405200583Srdivacky  /// \brief Function type used by forallBases() as a callback.
1406200583Srdivacky  ///
1407245431Sdim  /// \param BaseDefinition the definition of the base class
1408200583Srdivacky  ///
1409200583Srdivacky  /// \returns true if this base matched the search criteria
1410200583Srdivacky  typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition,
1411200583Srdivacky                                   void *UserData);
1412200583Srdivacky
1413200583Srdivacky  /// \brief Determines if the given callback holds for all the direct
1414200583Srdivacky  /// or indirect base classes of this type.
1415200583Srdivacky  ///
1416200583Srdivacky  /// The class itself does not count as a base class.  This routine
1417200583Srdivacky  /// returns false if the class has non-computable base classes.
1418235633Sdim  ///
1419263509Sdim  /// \param BaseMatches Callback invoked for each (direct or indirect) base
1420263509Sdim  /// class of this type, or if \p AllowShortCircuit is true then until a call
1421263509Sdim  /// returns false.
1422263509Sdim  ///
1423263509Sdim  /// \param UserData Passed as the second argument of every call to
1424263509Sdim  /// \p BaseMatches.
1425263509Sdim  ///
1426200583Srdivacky  /// \param AllowShortCircuit if false, forces the callback to be called
1427200583Srdivacky  /// for every base class, even if a dependent or non-matching base was
1428200583Srdivacky  /// found.
1429200583Srdivacky  bool forallBases(ForallBasesCallback *BaseMatches, void *UserData,
1430200583Srdivacky                   bool AllowShortCircuit = true) const;
1431235633Sdim
1432235633Sdim  /// \brief Function type used by lookupInBases() to determine whether a
1433198092Srdivacky  /// specific base class subobject matches the lookup criteria.
1434198092Srdivacky  ///
1435235633Sdim  /// \param Specifier the base-class specifier that describes the inheritance
1436198092Srdivacky  /// from the base class we are trying to match.
1437198092Srdivacky  ///
1438235633Sdim  /// \param Path the current path, from the most-derived class down to the
1439198092Srdivacky  /// base named by the \p Specifier.
1440198092Srdivacky  ///
1441198092Srdivacky  /// \param UserData a single pointer to user-specified data, provided to
1442198092Srdivacky  /// lookupInBases().
1443198092Srdivacky  ///
1444198092Srdivacky  /// \returns true if this base matched the search criteria, false otherwise.
1445199482Srdivacky  typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier,
1446198092Srdivacky                                   CXXBasePath &Path,
1447198092Srdivacky                                   void *UserData);
1448235633Sdim
1449198092Srdivacky  /// \brief Look for entities within the base classes of this C++ class,
1450198092Srdivacky  /// transitively searching all base class subobjects.
1451198092Srdivacky  ///
1452235633Sdim  /// This routine uses the callback function \p BaseMatches to find base
1453198092Srdivacky  /// classes meeting some search criteria, walking all base class subobjects
1454235633Sdim  /// and populating the given \p Paths structure with the paths through the
1455198092Srdivacky  /// inheritance hierarchy that resulted in a match. On a successful search,
1456198092Srdivacky  /// the \p Paths structure can be queried to retrieve the matching paths and
1457198092Srdivacky  /// to determine if there were any ambiguities.
1458198092Srdivacky  ///
1459198092Srdivacky  /// \param BaseMatches callback function used to determine whether a given
1460198092Srdivacky  /// base matches the user-defined search criteria.
1461198092Srdivacky  ///
1462198092Srdivacky  /// \param UserData user data pointer that will be provided to \p BaseMatches.
1463198092Srdivacky  ///
1464198092Srdivacky  /// \param Paths used to record the paths from this class to its base class
1465198092Srdivacky  /// subobjects that match the search criteria.
1466198092Srdivacky  ///
1467198092Srdivacky  /// \returns true if there exists any path from this class to a base class
1468198092Srdivacky  /// subobject that matches the search criteria.
1469198092Srdivacky  bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData,
1470199482Srdivacky                     CXXBasePaths &Paths) const;
1471235633Sdim
1472198092Srdivacky  /// \brief Base-class lookup callback that determines whether the given
1473198092Srdivacky  /// base class specifier refers to a specific class declaration.
1474198092Srdivacky  ///
1475198092Srdivacky  /// This callback can be used with \c lookupInBases() to determine whether
1476198092Srdivacky  /// a given derived class has is a base class subobject of a particular type.
1477198092Srdivacky  /// The user data pointer should refer to the canonical CXXRecordDecl of the
1478198092Srdivacky  /// base class that we are searching for.
1479199482Srdivacky  static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
1480199482Srdivacky                            CXXBasePath &Path, void *BaseRecord);
1481204643Srdivacky
1482204643Srdivacky  /// \brief Base-class lookup callback that determines whether the
1483204643Srdivacky  /// given base class specifier refers to a specific class
1484204643Srdivacky  /// declaration and describes virtual derivation.
1485204643Srdivacky  ///
1486204643Srdivacky  /// This callback can be used with \c lookupInBases() to determine
1487204643Srdivacky  /// whether a given derived class has is a virtual base class
1488204643Srdivacky  /// subobject of a particular type.  The user data pointer should
1489204643Srdivacky  /// refer to the canonical CXXRecordDecl of the base class that we
1490204643Srdivacky  /// are searching for.
1491204643Srdivacky  static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
1492204643Srdivacky                                   CXXBasePath &Path, void *BaseRecord);
1493235633Sdim
1494198092Srdivacky  /// \brief Base-class lookup callback that determines whether there exists
1495198092Srdivacky  /// a tag with the given name.
1496198092Srdivacky  ///
1497198092Srdivacky  /// This callback can be used with \c lookupInBases() to find tag members
1498198092Srdivacky  /// of the given name within a C++ class hierarchy. The user data pointer
1499198092Srdivacky  /// is an opaque \c DeclarationName pointer.
1500199482Srdivacky  static bool FindTagMember(const CXXBaseSpecifier *Specifier,
1501199482Srdivacky                            CXXBasePath &Path, void *Name);
1502198092Srdivacky
1503198092Srdivacky  /// \brief Base-class lookup callback that determines whether there exists
1504198092Srdivacky  /// a member with the given name.
1505198092Srdivacky  ///
1506198092Srdivacky  /// This callback can be used with \c lookupInBases() to find members
1507198092Srdivacky  /// of the given name within a C++ class hierarchy. The user data pointer
1508198092Srdivacky  /// is an opaque \c DeclarationName pointer.
1509199482Srdivacky  static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
1510199482Srdivacky                                 CXXBasePath &Path, void *Name);
1511235633Sdim
1512198092Srdivacky  /// \brief Base-class lookup callback that determines whether there exists
1513198092Srdivacky  /// a member with the given name that can be used in a nested-name-specifier.
1514198092Srdivacky  ///
1515198092Srdivacky  /// This callback can be used with \c lookupInBases() to find membes of
1516198092Srdivacky  /// the given name within a C++ class hierarchy that can occur within
1517198092Srdivacky  /// nested-name-specifiers.
1518199482Srdivacky  static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier,
1519198092Srdivacky                                            CXXBasePath &Path,
1520198092Srdivacky                                            void *UserData);
1521206084Srdivacky
1522206084Srdivacky  /// \brief Retrieve the final overriders for each virtual member
1523206084Srdivacky  /// function in the class hierarchy where this class is the
1524206084Srdivacky  /// most-derived class in the class hierarchy.
1525206084Srdivacky  void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const;
1526206084Srdivacky
1527218893Sdim  /// \brief Get the indirect primary bases for this class.
1528218893Sdim  void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const;
1529218893Sdim
1530263509Sdim  /// Renders and displays an inheritance diagram
1531193326Sed  /// for this C++ class and all of its base classes (transitively) using
1532193326Sed  /// GraphViz.
1533193326Sed  void viewInheritance(ASTContext& Context) const;
1534193326Sed
1535263509Sdim  /// \brief Calculates the access of a decl that is reached
1536202879Srdivacky  /// along a path.
1537202879Srdivacky  static AccessSpecifier MergeAccess(AccessSpecifier PathAccess,
1538202879Srdivacky                                     AccessSpecifier DeclAccess) {
1539202879Srdivacky    assert(DeclAccess != AS_none);
1540202879Srdivacky    if (DeclAccess == AS_private) return AS_none;
1541202879Srdivacky    return (PathAccess > DeclAccess ? PathAccess : DeclAccess);
1542202879Srdivacky  }
1543202879Srdivacky
1544252723Sdim  /// \brief Indicates that the declaration of a defaulted or deleted special
1545252723Sdim  /// member function is now complete.
1546252723Sdim  void finishedDefaultedOrDeletedMember(CXXMethodDecl *MD);
1547252723Sdim
1548218893Sdim  /// \brief Indicates that the definition of this class is now complete.
1549218893Sdim  virtual void completeDefinition();
1550218893Sdim
1551235633Sdim  /// \brief Indicates that the definition of this class is now complete,
1552218893Sdim  /// and provides a final overrider map to help determine
1553235633Sdim  ///
1554218893Sdim  /// \param FinalOverriders The final overrider map for this class, which can
1555218893Sdim  /// be provided as an optimization for abstract-class checking. If NULL,
1556218893Sdim  /// final overriders will be computed if they are needed to complete the
1557218893Sdim  /// definition.
1558218893Sdim  void completeDefinition(CXXFinalOverriderMap *FinalOverriders);
1559235633Sdim
1560218893Sdim  /// \brief Determine whether this class may end up being abstract, even though
1561218893Sdim  /// it is not yet known to be abstract.
1562218893Sdim  ///
1563218893Sdim  /// \returns true if this class is not known to be abstract but has any
1564218893Sdim  /// base classes that are abstract. In this case, \c completeDefinition()
1565218893Sdim  /// will need to compute final overriders to determine whether the class is
1566218893Sdim  /// actually abstract.
1567218893Sdim  bool mayBeAbstract() const;
1568235633Sdim
1569235633Sdim  /// \brief If this is the closure type of a lambda expression, retrieve the
1570235633Sdim  /// number to be used for name mangling in the Itanium C++ ABI.
1571235633Sdim  ///
1572235633Sdim  /// Zero indicates that this closure type has internal linkage, so the
1573235633Sdim  /// mangling number does not matter, while a non-zero value indicates which
1574235633Sdim  /// lambda expression this is in this particular context.
1575235633Sdim  unsigned getLambdaManglingNumber() const {
1576235633Sdim    assert(isLambda() && "Not a lambda closure type!");
1577235633Sdim    return getLambdaData().ManglingNumber;
1578235633Sdim  }
1579218893Sdim
1580235633Sdim  /// \brief Retrieve the declaration that provides additional context for a
1581235633Sdim  /// lambda, when the normal declaration context is not specific enough.
1582235633Sdim  ///
1583235633Sdim  /// Certain contexts (default arguments of in-class function parameters and
1584235633Sdim  /// the initializers of data members) have separate name mangling rules for
1585235633Sdim  /// lambdas within the Itanium C++ ABI. For these cases, this routine provides
1586235633Sdim  /// the declaration in which the lambda occurs, e.g., the function parameter
1587235633Sdim  /// or the non-static data member. Otherwise, it returns NULL to imply that
1588235633Sdim  /// the declaration context suffices.
1589235633Sdim  Decl *getLambdaContextDecl() const {
1590235633Sdim    assert(isLambda() && "Not a lambda closure type!");
1591235633Sdim    return getLambdaData().ContextDecl;
1592235633Sdim  }
1593235633Sdim
1594235633Sdim  /// \brief Set the mangling number and context declaration for a lambda
1595235633Sdim  /// class.
1596235633Sdim  void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl) {
1597235633Sdim    getLambdaData().ManglingNumber = ManglingNumber;
1598235633Sdim    getLambdaData().ContextDecl = ContextDecl;
1599235633Sdim  }
1600235633Sdim
1601252723Sdim  /// \brief Returns the inheritance model used for this record.
1602252723Sdim  MSInheritanceModel getMSInheritanceModel() const;
1603252723Sdim
1604235633Sdim  /// \brief Determine whether this lambda expression was known to be dependent
1605235633Sdim  /// at the time it was created, even if its context does not appear to be
1606235633Sdim  /// dependent.
1607235633Sdim  ///
1608235633Sdim  /// This flag is a workaround for an issue with parsing, where default
1609235633Sdim  /// arguments are parsed before their enclosing function declarations have
1610235633Sdim  /// been created. This means that any lambda expressions within those
1611235633Sdim  /// default arguments will have as their DeclContext the context enclosing
1612235633Sdim  /// the function declaration, which may be non-dependent even when the
1613235633Sdim  /// function declaration itself is dependent. This flag indicates when we
1614235633Sdim  /// know that the lambda is dependent despite that.
1615235633Sdim  bool isDependentLambda() const {
1616235633Sdim    return isLambda() && getLambdaData().Dependent;
1617235633Sdim  }
1618245431Sdim
1619245431Sdim  TypeSourceInfo *getLambdaTypeInfo() const {
1620245431Sdim    return getLambdaData().MethodTyInfo;
1621245431Sdim  }
1622245431Sdim
1623203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1624203955Srdivacky  static bool classofKind(Kind K) {
1625210299Sed    return K >= firstCXXRecord && K <= lastCXXRecord;
1626193326Sed  }
1627210299Sed
1628212904Sdim  friend class ASTDeclReader;
1629212904Sdim  friend class ASTDeclWriter;
1630218893Sdim  friend class ASTReader;
1631218893Sdim  friend class ASTWriter;
1632193326Sed};
1633193326Sed
1634263509Sdim/// \brief Represents a static or instance method of a struct/union/class.
1635263509Sdim///
1636263509Sdim/// In the terminology of the C++ Standard, these are the (static and
1637263509Sdim/// non-static) member functions, whether virtual or not.
1638193326Sedclass CXXMethodDecl : public FunctionDecl {
1639235633Sdim  virtual void anchor();
1640193326Sedprotected:
1641221345Sdim  CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation StartLoc,
1642212904Sdim                const DeclarationNameInfo &NameInfo,
1643212904Sdim                QualType T, TypeSourceInfo *TInfo,
1644252723Sdim                StorageClass SC, bool isInline,
1645226890Sdim                bool isConstexpr, SourceLocation EndLocation)
1646221345Sdim    : FunctionDecl(DK, RD, StartLoc, NameInfo, T, TInfo,
1647252723Sdim                   SC, isInline, isConstexpr) {
1648235633Sdim    if (EndLocation.isValid())
1649235633Sdim      setRangeEnd(EndLocation);
1650235633Sdim  }
1651193326Sed
1652193326Sedpublic:
1653193326Sed  static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1654221345Sdim                               SourceLocation StartLoc,
1655212904Sdim                               const DeclarationNameInfo &NameInfo,
1656212904Sdim                               QualType T, TypeSourceInfo *TInfo,
1657252723Sdim                               StorageClass SC,
1658221345Sdim                               bool isInline,
1659226890Sdim                               bool isConstexpr,
1660221345Sdim                               SourceLocation EndLocation);
1661198092Srdivacky
1662235633Sdim  static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1663252723Sdim
1664252723Sdim  bool isStatic() const;
1665193326Sed  bool isInstance() const { return !isStatic(); }
1666193326Sed
1667263509Sdim  /// Returns true if the given operator is implicitly static in a record
1668263509Sdim  /// context.
1669263509Sdim  static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK) {
1670263509Sdim    // [class.free]p1:
1671263509Sdim    // Any allocation function for a class T is a static member
1672263509Sdim    // (even if not explicitly declared static).
1673263509Sdim    // [class.free]p6 Any deallocation function for a class X is a static member
1674263509Sdim    // (even if not explicitly declared static).
1675263509Sdim    return OOK == OO_New || OOK == OO_Array_New || OOK == OO_Delete ||
1676263509Sdim           OOK == OO_Array_Delete;
1677263509Sdim  }
1678263509Sdim
1679245431Sdim  bool isConst() const { return getType()->castAs<FunctionType>()->isConst(); }
1680245431Sdim  bool isVolatile() const { return getType()->castAs<FunctionType>()->isVolatile(); }
1681245431Sdim
1682198092Srdivacky  bool isVirtual() const {
1683235633Sdim    CXXMethodDecl *CD =
1684198092Srdivacky      cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl());
1685198092Srdivacky
1686245431Sdim    // Methods declared in interfaces are automatically (pure) virtual.
1687245431Sdim    if (CD->isVirtualAsWritten() ||
1688245431Sdim          (CD->getParent()->isInterface() && CD->isUserProvided()))
1689198092Srdivacky      return true;
1690235633Sdim
1691198092Srdivacky    return (CD->begin_overridden_methods() != CD->end_overridden_methods());
1692193326Sed  }
1693206084Srdivacky
1694198092Srdivacky  /// \brief Determine whether this is a usual deallocation function
1695198092Srdivacky  /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded
1696198092Srdivacky  /// delete or delete[] operator with a particular signature.
1697198092Srdivacky  bool isUsualDeallocationFunction() const;
1698235633Sdim
1699207619Srdivacky  /// \brief Determine whether this is a copy-assignment operator, regardless
1700207619Srdivacky  /// of whether it was declared implicitly or explicitly.
1701207619Srdivacky  bool isCopyAssignmentOperator() const;
1702223017Sdim
1703223017Sdim  /// \brief Determine whether this is a move assignment operator.
1704223017Sdim  bool isMoveAssignmentOperator() const;
1705235633Sdim
1706198092Srdivacky  CXXMethodDecl *getCanonicalDecl() {
1707198092Srdivacky    return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
1708198092Srdivacky  }
1709263509Sdim  const CXXMethodDecl *getCanonicalDecl() const {
1710263509Sdim    return const_cast<CXXMethodDecl*>(this)->getCanonicalDecl();
1711263509Sdim  }
1712223017Sdim
1713263509Sdim  CXXMethodDecl *getMostRecentDecl() {
1714263509Sdim    return cast<CXXMethodDecl>(
1715263509Sdim            static_cast<FunctionDecl *>(this)->getMostRecentDecl());
1716263509Sdim  }
1717263509Sdim  const CXXMethodDecl *getMostRecentDecl() const {
1718263509Sdim    return const_cast<CXXMethodDecl*>(this)->getMostRecentDecl();
1719263509Sdim  }
1720263509Sdim
1721263509Sdim  /// True if this method is user-declared and was not
1722245431Sdim  /// deleted or defaulted on its first declaration.
1723223017Sdim  bool isUserProvided() const {
1724223017Sdim    return !(isDeleted() || getCanonicalDecl()->isDefaulted());
1725223017Sdim  }
1726235633Sdim
1727198092Srdivacky  ///
1728198092Srdivacky  void addOverriddenMethod(const CXXMethodDecl *MD);
1729193326Sed
1730235633Sdim  typedef const CXXMethodDecl *const* method_iterator;
1731198092Srdivacky
1732193326Sed  method_iterator begin_overridden_methods() const;
1733193326Sed  method_iterator end_overridden_methods() const;
1734210299Sed  unsigned size_overridden_methods() const;
1735198092Srdivacky
1736263509Sdim  /// Returns the parent of this method declaration, which
1737193326Sed  /// is the class in which this method is defined.
1738198092Srdivacky  const CXXRecordDecl *getParent() const {
1739198092Srdivacky    return cast<CXXRecordDecl>(FunctionDecl::getParent());
1740193326Sed  }
1741198092Srdivacky
1742263509Sdim  /// Returns the parent of this method declaration, which
1743193326Sed  /// is the class in which this method is defined.
1744198092Srdivacky  CXXRecordDecl *getParent() {
1745193326Sed    return const_cast<CXXRecordDecl *>(
1746193326Sed             cast<CXXRecordDecl>(FunctionDecl::getParent()));
1747193326Sed  }
1748193326Sed
1749263509Sdim  /// \brief Returns the type of the \c this pointer.
1750263509Sdim  ///
1751263509Sdim  /// Should only be called for instance (i.e., non-static) methods.
1752193326Sed  QualType getThisType(ASTContext &C) const;
1753193326Sed
1754193326Sed  unsigned getTypeQualifiers() const {
1755198092Srdivacky    return getType()->getAs<FunctionProtoType>()->getTypeQuals();
1756193326Sed  }
1757193326Sed
1758218893Sdim  /// \brief Retrieve the ref-qualifier associated with this method.
1759218893Sdim  ///
1760218893Sdim  /// In the following example, \c f() has an lvalue ref-qualifier, \c g()
1761218893Sdim  /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier.
1762245431Sdim  /// @code
1763218893Sdim  /// struct X {
1764218893Sdim  ///   void f() &;
1765218893Sdim  ///   void g() &&;
1766218893Sdim  ///   void h();
1767218893Sdim  /// };
1768245431Sdim  /// @endcode
1769218893Sdim  RefQualifierKind getRefQualifier() const {
1770218893Sdim    return getType()->getAs<FunctionProtoType>()->getRefQualifier();
1771218893Sdim  }
1772235633Sdim
1773200583Srdivacky  bool hasInlineBody() const;
1774200583Srdivacky
1775235633Sdim  /// \brief Determine whether this is a lambda closure type's static member
1776235633Sdim  /// function that is used for the result of the lambda's conversion to
1777235633Sdim  /// function pointer (for a lambda with no captures).
1778235633Sdim  ///
1779235633Sdim  /// The function itself, if used, will have a placeholder body that will be
1780235633Sdim  /// supplied by IR generation to either forward to the function call operator
1781235633Sdim  /// or clone the function call operator.
1782235633Sdim  bool isLambdaStaticInvoker() const;
1783245431Sdim
1784263509Sdim  /// \brief Find the method in \p RD that corresponds to this one.
1785245431Sdim  ///
1786263509Sdim  /// Find if \p RD or one of the classes it inherits from override this method.
1787263509Sdim  /// If so, return it. \p RD is assumed to be a subclass of the class defining
1788263509Sdim  /// this method (or be the class itself), unless \p MayBeBase is set to true.
1789245431Sdim  CXXMethodDecl *
1790245431Sdim  getCorrespondingMethodInClass(const CXXRecordDecl *RD,
1791245431Sdim                                bool MayBeBase = false);
1792245431Sdim
1793245431Sdim  const CXXMethodDecl *
1794245431Sdim  getCorrespondingMethodInClass(const CXXRecordDecl *RD,
1795245431Sdim                                bool MayBeBase = false) const {
1796245431Sdim    return const_cast<CXXMethodDecl *>(this)
1797245431Sdim              ->getCorrespondingMethodInClass(RD, MayBeBase);
1798245431Sdim  }
1799245431Sdim
1800193326Sed  // Implement isa/cast/dyncast/etc.
1801203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1802203955Srdivacky  static bool classofKind(Kind K) {
1803210299Sed    return K >= firstCXXMethod && K <= lastCXXMethod;
1804193326Sed  }
1805193326Sed};
1806193326Sed
1807263509Sdim/// \brief Represents a C++ base or member initializer.
1808263509Sdim///
1809263509Sdim/// This is part of a constructor initializer that
1810193326Sed/// initializes one non-static member variable or one base class. For
1811193326Sed/// example, in the following, both 'A(a)' and 'f(3.14159)' are member
1812193326Sed/// initializers:
1813193326Sed///
1814263509Sdim/// \code
1815193326Sed/// class A { };
1816193326Sed/// class B : public A {
1817193326Sed///   float f;
1818193326Sed/// public:
1819193326Sed///   B(A& a) : A(a), f(3.14159) { }
1820193326Sed/// };
1821263509Sdim/// \endcode
1822218893Sdimclass CXXCtorInitializer {
1823235633Sdim  /// \brief Either the base class name/delegating constructor type (stored as
1824235633Sdim  /// a TypeSourceInfo*), an normal field (FieldDecl), or an anonymous field
1825235633Sdim  /// (IndirectFieldDecl*) being initialized.
1826235633Sdim  llvm::PointerUnion3<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *>
1827218893Sdim    Initializee;
1828235633Sdim
1829218893Sdim  /// \brief The source location for the field name or, for a base initializer
1830263509Sdim  /// pack expansion, the location of the ellipsis.
1831263509Sdim  ///
1832263509Sdim  /// In the case of a delegating
1833221345Sdim  /// constructor, it will still include the type's source location as the
1834221345Sdim  /// Initializee points to the CXXConstructorDecl (to allow loop detection).
1835218893Sdim  SourceLocation MemberOrEllipsisLocation;
1836235633Sdim
1837203955Srdivacky  /// \brief The argument used to initialize the base or member, which may
1838203955Srdivacky  /// end up constructing an object (when multiple arguments are involved).
1839203955Srdivacky  Stmt *Init;
1840235633Sdim
1841263509Sdim  /// \brief Location of the left paren of the ctor-initializer.
1842200583Srdivacky  SourceLocation LParenLoc;
1843193326Sed
1844263509Sdim  /// \brief Location of the right paren of the ctor-initializer.
1845198092Srdivacky  SourceLocation RParenLoc;
1846198092Srdivacky
1847235633Sdim  /// \brief If the initializee is a type, whether that type makes this
1848235633Sdim  /// a delegating initialization.
1849235633Sdim  bool IsDelegating : 1;
1850235633Sdim
1851263509Sdim  /// \brief If the initializer is a base initializer, this keeps track
1852208600Srdivacky  /// of whether the base is virtual or not.
1853208600Srdivacky  bool IsVirtual : 1;
1854208600Srdivacky
1855263509Sdim  /// \brief Whether or not the initializer is explicitly written
1856208600Srdivacky  /// in the sources.
1857208600Srdivacky  bool IsWritten : 1;
1858218893Sdim
1859263509Sdim  /// If IsWritten is true, then this number keeps track of the textual order
1860263509Sdim  /// of this initializer in the original sources, counting from 0; otherwise,
1861263509Sdim  /// it stores the number of array index variables stored after this object
1862263509Sdim  /// in memory.
1863235633Sdim  unsigned SourceOrderOrNumArrayIndices : 13;
1864208600Srdivacky
1865218893Sdim  CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
1866218893Sdim                     SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1867218893Sdim                     SourceLocation R, VarDecl **Indices, unsigned NumIndices);
1868235633Sdim
1869193326Sedpublic:
1870263509Sdim  /// \brief Creates a new base-class initializer.
1871198092Srdivacky  explicit
1872218893Sdim  CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual,
1873218893Sdim                     SourceLocation L, Expr *Init, SourceLocation R,
1874218893Sdim                     SourceLocation EllipsisLoc);
1875193326Sed
1876263509Sdim  /// \brief Creates a new member initializer.
1877198092Srdivacky  explicit
1878218893Sdim  CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
1879218893Sdim                     SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1880218893Sdim                     SourceLocation R);
1881193326Sed
1882263509Sdim  /// \brief Creates a new anonymous field initializer.
1883218893Sdim  explicit
1884218893Sdim  CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member,
1885218893Sdim                     SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1886218893Sdim                     SourceLocation R);
1887218893Sdim
1888263509Sdim  /// \brief Creates a new delegating initializer.
1889221345Sdim  explicit
1890235633Sdim  CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo,
1891235633Sdim                     SourceLocation L, Expr *Init, SourceLocation R);
1892221345Sdim
1893235633Sdim  /// \brief Creates a new member initializer that optionally contains
1894208600Srdivacky  /// array indices used to describe an elementwise initialization.
1895218893Sdim  static CXXCtorInitializer *Create(ASTContext &Context, FieldDecl *Member,
1896218893Sdim                                    SourceLocation MemberLoc, SourceLocation L,
1897218893Sdim                                    Expr *Init, SourceLocation R,
1898218893Sdim                                    VarDecl **Indices, unsigned NumIndices);
1899235633Sdim
1900263509Sdim  /// \brief Determine whether this initializer is initializing a base class.
1901235633Sdim  bool isBaseInitializer() const {
1902235633Sdim    return Initializee.is<TypeSourceInfo*>() && !IsDelegating;
1903235633Sdim  }
1904193326Sed
1905263509Sdim  /// \brief Determine whether this initializer is initializing a non-static
1906263509Sdim  /// data member.
1907218893Sdim  bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); }
1908193326Sed
1909235633Sdim  bool isAnyMemberInitializer() const {
1910218893Sdim    return isMemberInitializer() || isIndirectMemberInitializer();
1911218893Sdim  }
1912218893Sdim
1913218893Sdim  bool isIndirectMemberInitializer() const {
1914218893Sdim    return Initializee.is<IndirectFieldDecl*>();
1915218893Sdim  }
1916218893Sdim
1917263509Sdim  /// \brief Determine whether this initializer is an implicit initializer
1918263509Sdim  /// generated for a field with an initializer defined on the member
1919263509Sdim  /// declaration.
1920263509Sdim  ///
1921263509Sdim  /// In-class member initializers (also known as "non-static data member
1922263509Sdim  /// initializations", NSDMIs) were introduced in C++11.
1923223017Sdim  bool isInClassMemberInitializer() const {
1924252723Sdim    return isa<CXXDefaultInitExpr>(Init);
1925223017Sdim  }
1926223017Sdim
1927263509Sdim  /// \brief Determine whether this initializer is creating a delegating
1928263509Sdim  /// constructor.
1929221345Sdim  bool isDelegatingInitializer() const {
1930235633Sdim    return Initializee.is<TypeSourceInfo*>() && IsDelegating;
1931221345Sdim  }
1932221345Sdim
1933218893Sdim  /// \brief Determine whether this initializer is a pack expansion.
1934235633Sdim  bool isPackExpansion() const {
1935235633Sdim    return isBaseInitializer() && MemberOrEllipsisLocation.isValid();
1936218893Sdim  }
1937235633Sdim
1938218893Sdim  // \brief For a pack expansion, returns the location of the ellipsis.
1939218893Sdim  SourceLocation getEllipsisLoc() const {
1940218893Sdim    assert(isPackExpansion() && "Initializer is not a pack expansion");
1941218893Sdim    return MemberOrEllipsisLocation;
1942218893Sdim  }
1943235633Sdim
1944235633Sdim  /// If this is a base class initializer, returns the type of the
1945200583Srdivacky  /// base class with location information. Otherwise, returns an NULL
1946200583Srdivacky  /// type location.
1947200583Srdivacky  TypeLoc getBaseClassLoc() const;
1948193326Sed
1949200583Srdivacky  /// If this is a base class initializer, returns the type of the base class.
1950263509Sdim  /// Otherwise, returns null.
1951200583Srdivacky  const Type *getBaseClass() const;
1952207619Srdivacky
1953207619Srdivacky  /// Returns whether the base is virtual or not.
1954207619Srdivacky  bool isBaseVirtual() const {
1955207619Srdivacky    assert(isBaseInitializer() && "Must call this on base initializer!");
1956235633Sdim
1957207619Srdivacky    return IsVirtual;
1958207619Srdivacky  }
1959207619Srdivacky
1960235633Sdim  /// \brief Returns the declarator information for a base class or delegating
1961235633Sdim  /// initializer.
1962235633Sdim  TypeSourceInfo *getTypeSourceInfo() const {
1963218893Sdim    return Initializee.dyn_cast<TypeSourceInfo *>();
1964193326Sed  }
1965235633Sdim
1966263509Sdim  /// \brief If this is a member initializer, returns the declaration of the
1967263509Sdim  /// non-static data member being initialized. Otherwise, returns null.
1968212904Sdim  FieldDecl *getMember() const {
1969193326Sed    if (isMemberInitializer())
1970218893Sdim      return Initializee.get<FieldDecl*>();
1971235633Sdim    return 0;
1972193326Sed  }
1973218893Sdim  FieldDecl *getAnyMember() const {
1974218893Sdim    if (isMemberInitializer())
1975218893Sdim      return Initializee.get<FieldDecl*>();
1976235633Sdim    if (isIndirectMemberInitializer())
1977218893Sdim      return Initializee.get<IndirectFieldDecl*>()->getAnonField();
1978235633Sdim    return 0;
1979218893Sdim  }
1980193326Sed
1981218893Sdim  IndirectFieldDecl *getIndirectMember() const {
1982218893Sdim    if (isIndirectMemberInitializer())
1983218893Sdim      return Initializee.get<IndirectFieldDecl*>();
1984235633Sdim    return 0;
1985198092Srdivacky  }
1986198092Srdivacky
1987235633Sdim  SourceLocation getMemberLocation() const {
1988235633Sdim    return MemberOrEllipsisLocation;
1989221345Sdim  }
1990221345Sdim
1991200583Srdivacky  /// \brief Determine the source location of the initializer.
1992200583Srdivacky  SourceLocation getSourceLocation() const;
1993235633Sdim
1994200583Srdivacky  /// \brief Determine the source range covering the entire initializer.
1995235633Sdim  SourceRange getSourceRange() const LLVM_READONLY;
1996208600Srdivacky
1997263509Sdim  /// \brief Determine whether this initializer is explicitly written
1998208600Srdivacky  /// in the source code.
1999208600Srdivacky  bool isWritten() const { return IsWritten; }
2000208600Srdivacky
2001208600Srdivacky  /// \brief Return the source position of the initializer, counting from 0.
2002208600Srdivacky  /// If the initializer was implicit, -1 is returned.
2003208600Srdivacky  int getSourceOrder() const {
2004208600Srdivacky    return IsWritten ? static_cast<int>(SourceOrderOrNumArrayIndices) : -1;
2005208600Srdivacky  }
2006208600Srdivacky
2007263509Sdim  /// \brief Set the source order of this initializer.
2008263509Sdim  ///
2009263509Sdim  /// This can only be called once for each initializer; it cannot be called
2010263509Sdim  /// on an initializer having a positive number of (implicit) array indices.
2011263509Sdim  ///
2012263509Sdim  /// This assumes that the initialzier was written in the source code, and
2013263509Sdim  /// ensures that isWritten() returns true.
2014208600Srdivacky  void setSourceOrder(int pos) {
2015208600Srdivacky    assert(!IsWritten &&
2016208600Srdivacky           "calling twice setSourceOrder() on the same initializer");
2017208600Srdivacky    assert(SourceOrderOrNumArrayIndices == 0 &&
2018208600Srdivacky           "setSourceOrder() used when there are implicit array indices");
2019208600Srdivacky    assert(pos >= 0 &&
2020208600Srdivacky           "setSourceOrder() used to make an initializer implicit");
2021208600Srdivacky    IsWritten = true;
2022208600Srdivacky    SourceOrderOrNumArrayIndices = static_cast<unsigned>(pos);
2023208600Srdivacky  }
2024198092Srdivacky
2025200583Srdivacky  SourceLocation getLParenLoc() const { return LParenLoc; }
2026198092Srdivacky  SourceLocation getRParenLoc() const { return RParenLoc; }
2027193326Sed
2028208600Srdivacky  /// \brief Determine the number of implicit array indices used while
2029208600Srdivacky  /// described an array member initialization.
2030208600Srdivacky  unsigned getNumArrayIndices() const {
2031208600Srdivacky    return IsWritten ? 0 : SourceOrderOrNumArrayIndices;
2032208600Srdivacky  }
2033208600Srdivacky
2034235633Sdim  /// \brief Retrieve a particular array index variable used to
2035208600Srdivacky  /// describe an array member initialization.
2036208600Srdivacky  VarDecl *getArrayIndex(unsigned I) {
2037208600Srdivacky    assert(I < getNumArrayIndices() && "Out of bounds member array index");
2038208600Srdivacky    return reinterpret_cast<VarDecl **>(this + 1)[I];
2039208600Srdivacky  }
2040208600Srdivacky  const VarDecl *getArrayIndex(unsigned I) const {
2041208600Srdivacky    assert(I < getNumArrayIndices() && "Out of bounds member array index");
2042208600Srdivacky    return reinterpret_cast<const VarDecl * const *>(this + 1)[I];
2043208600Srdivacky  }
2044208600Srdivacky  void setArrayIndex(unsigned I, VarDecl *Index) {
2045208600Srdivacky    assert(I < getNumArrayIndices() && "Out of bounds member array index");
2046208600Srdivacky    reinterpret_cast<VarDecl **>(this + 1)[I] = Index;
2047208600Srdivacky  }
2048235633Sdim  ArrayRef<VarDecl *> getArrayIndexes() {
2049235633Sdim    assert(getNumArrayIndices() != 0 && "Getting indexes for non-array init");
2050235633Sdim    return ArrayRef<VarDecl *>(reinterpret_cast<VarDecl **>(this + 1),
2051235633Sdim                               getNumArrayIndices());
2052235633Sdim  }
2053235633Sdim
2054252723Sdim  /// \brief Get the initializer.
2055252723Sdim  Expr *getInit() const { return static_cast<Expr*>(Init); }
2056193326Sed};
2057193326Sed
2058263509Sdim/// \brief Represents a C++ constructor within a class.
2059198092Srdivacky///
2060263509Sdim/// For example:
2061263509Sdim///
2062263509Sdim/// \code
2063193326Sed/// class X {
2064193326Sed/// public:
2065193326Sed///   explicit X(int); // represented by a CXXConstructorDecl.
2066193326Sed/// };
2067263509Sdim/// \endcode
2068193326Sedclass CXXConstructorDecl : public CXXMethodDecl {
2069235633Sdim  virtual void anchor();
2070263509Sdim  /// \brief Whether this constructor declaration has the \c explicit keyword
2071263509Sdim  /// specified.
2072203955Srdivacky  bool IsExplicitSpecified : 1;
2073193326Sed
2074263509Sdim  /// \name Support for base and member initializers.
2075263509Sdim  /// \{
2076263509Sdim  /// \brief The arguments used to initialize the base or member.
2077218893Sdim  CXXCtorInitializer **CtorInitializers;
2078218893Sdim  unsigned NumCtorInitializers;
2079263509Sdim  /// \}
2080198092Srdivacky
2081221345Sdim  CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
2082221345Sdim                     const DeclarationNameInfo &NameInfo,
2083212904Sdim                     QualType T, TypeSourceInfo *TInfo,
2084235633Sdim                     bool isExplicitSpecified, bool isInline,
2085226890Sdim                     bool isImplicitlyDeclared, bool isConstexpr)
2086252723Sdim    : CXXMethodDecl(CXXConstructor, RD, StartLoc, NameInfo, T, TInfo,
2087226890Sdim                    SC_None, isInline, isConstexpr, SourceLocation()),
2088263509Sdim      IsExplicitSpecified(isExplicitSpecified), CtorInitializers(0),
2089263509Sdim      NumCtorInitializers(0) {
2090193326Sed    setImplicit(isImplicitlyDeclared);
2091193326Sed  }
2092198092Srdivacky
2093193326Sedpublic:
2094235633Sdim  static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2095193326Sed  static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2096221345Sdim                                    SourceLocation StartLoc,
2097212904Sdim                                    const DeclarationNameInfo &NameInfo,
2098200583Srdivacky                                    QualType T, TypeSourceInfo *TInfo,
2099198092Srdivacky                                    bool isExplicit,
2100226890Sdim                                    bool isInline, bool isImplicitlyDeclared,
2101226890Sdim                                    bool isConstexpr);
2102193326Sed
2103263509Sdim  /// \brief Determine whether this constructor declaration has the
2104263509Sdim  /// \c explicit keyword specified.
2105203955Srdivacky  bool isExplicitSpecified() const { return IsExplicitSpecified; }
2106235633Sdim
2107263509Sdim  /// \brief Determine whether this constructor was marked "explicit" or not.
2108203955Srdivacky  bool isExplicit() const {
2109263509Sdim    return cast<CXXConstructorDecl>(getFirstDecl())->isExplicitSpecified();
2110203955Srdivacky  }
2111193326Sed
2112263509Sdim  /// \brief Iterates through the member/base initializer list.
2113218893Sdim  typedef CXXCtorInitializer **init_iterator;
2114198092Srdivacky
2115263509Sdim  /// \brief Iterates through the member/base initializer list.
2116218893Sdim  typedef CXXCtorInitializer * const * init_const_iterator;
2117198092Srdivacky
2118263509Sdim  /// \brief Retrieve an iterator to the first initializer.
2119218893Sdim  init_iterator       init_begin()       { return CtorInitializers; }
2120263509Sdim  /// \brief Retrieve an iterator to the first initializer.
2121218893Sdim  init_const_iterator init_begin() const { return CtorInitializers; }
2122198092Srdivacky
2123263509Sdim  /// \brief Retrieve an iterator past the last initializer.
2124198092Srdivacky  init_iterator       init_end()       {
2125218893Sdim    return CtorInitializers + NumCtorInitializers;
2126195341Sed  }
2127263509Sdim  /// \brief Retrieve an iterator past the last initializer.
2128198092Srdivacky  init_const_iterator init_end() const {
2129218893Sdim    return CtorInitializers + NumCtorInitializers;
2130195341Sed  }
2131198092Srdivacky
2132218893Sdim  typedef std::reverse_iterator<init_iterator> init_reverse_iterator;
2133235633Sdim  typedef std::reverse_iterator<init_const_iterator>
2134235633Sdim          init_const_reverse_iterator;
2135218893Sdim
2136218893Sdim  init_reverse_iterator init_rbegin() {
2137218893Sdim    return init_reverse_iterator(init_end());
2138218893Sdim  }
2139218893Sdim  init_const_reverse_iterator init_rbegin() const {
2140218893Sdim    return init_const_reverse_iterator(init_end());
2141218893Sdim  }
2142218893Sdim
2143218893Sdim  init_reverse_iterator init_rend() {
2144218893Sdim    return init_reverse_iterator(init_begin());
2145218893Sdim  }
2146218893Sdim  init_const_reverse_iterator init_rend() const {
2147218893Sdim    return init_const_reverse_iterator(init_begin());
2148218893Sdim  }
2149218893Sdim
2150263509Sdim  /// \brief Determine the number of arguments used to initialize the member
2151263509Sdim  /// or base.
2152218893Sdim  unsigned getNumCtorInitializers() const {
2153218893Sdim      return NumCtorInitializers;
2154195341Sed  }
2155198092Srdivacky
2156218893Sdim  void setNumCtorInitializers(unsigned numCtorInitializers) {
2157218893Sdim    NumCtorInitializers = numCtorInitializers;
2158198092Srdivacky  }
2159198092Srdivacky
2160218893Sdim  void setCtorInitializers(CXXCtorInitializer ** initializers) {
2161218893Sdim    CtorInitializers = initializers;
2162198092Srdivacky  }
2163221345Sdim
2164263509Sdim  /// \brief Determine whether this constructor is a delegating constructor.
2165221345Sdim  bool isDelegatingConstructor() const {
2166221345Sdim    return (getNumCtorInitializers() == 1) &&
2167221345Sdim      CtorInitializers[0]->isDelegatingInitializer();
2168221345Sdim  }
2169221345Sdim
2170263509Sdim  /// \brief When this constructor delegates to another, retrieve the target.
2171235633Sdim  CXXConstructorDecl *getTargetConstructor() const;
2172221345Sdim
2173263509Sdim  /// Whether this constructor is a default
2174193326Sed  /// constructor (C++ [class.ctor]p5), which can be used to
2175193326Sed  /// default-initialize a class of this type.
2176193326Sed  bool isDefaultConstructor() const;
2177193326Sed
2178263509Sdim  /// \brief Whether this constructor is a copy constructor (C++ [class.copy]p2,
2179263509Sdim  /// which can be used to copy the class.
2180263509Sdim  ///
2181263509Sdim  /// \p TypeQuals will be set to the qualifiers on the
2182263509Sdim  /// argument type. For example, \p TypeQuals would be set to \c
2183252723Sdim  /// Qualifiers::Const for the following copy constructor:
2184193326Sed  ///
2185263509Sdim  /// \code
2186193326Sed  /// class X {
2187193326Sed  /// public:
2188193326Sed  ///   X(const X&);
2189193326Sed  /// };
2190263509Sdim  /// \endcode
2191201361Srdivacky  bool isCopyConstructor(unsigned &TypeQuals) const;
2192193326Sed
2193263509Sdim  /// Whether this constructor is a copy
2194193326Sed  /// constructor (C++ [class.copy]p2, which can be used to copy the
2195193326Sed  /// class.
2196201361Srdivacky  bool isCopyConstructor() const {
2197193326Sed    unsigned TypeQuals = 0;
2198201361Srdivacky    return isCopyConstructor(TypeQuals);
2199193326Sed  }
2200193326Sed
2201218893Sdim  /// \brief Determine whether this constructor is a move constructor
2202218893Sdim  /// (C++0x [class.copy]p3), which can be used to move values of the class.
2203218893Sdim  ///
2204218893Sdim  /// \param TypeQuals If this constructor is a move constructor, will be set
2205218893Sdim  /// to the type qualifiers on the referent of the first parameter's type.
2206218893Sdim  bool isMoveConstructor(unsigned &TypeQuals) const;
2207218893Sdim
2208218893Sdim  /// \brief Determine whether this constructor is a move constructor
2209218893Sdim  /// (C++0x [class.copy]p3), which can be used to move values of the class.
2210221345Sdim  bool isMoveConstructor() const {
2211221345Sdim    unsigned TypeQuals = 0;
2212221345Sdim    return isMoveConstructor(TypeQuals);
2213221345Sdim  }
2214221345Sdim
2215218893Sdim  /// \brief Determine whether this is a copy or move constructor.
2216218893Sdim  ///
2217218893Sdim  /// \param TypeQuals Will be set to the type qualifiers on the reference
2218218893Sdim  /// parameter, if in fact this is a copy or move constructor.
2219218893Sdim  bool isCopyOrMoveConstructor(unsigned &TypeQuals) const;
2220218893Sdim
2221218893Sdim  /// \brief Determine whether this a copy or move constructor.
2222218893Sdim  bool isCopyOrMoveConstructor() const {
2223218893Sdim    unsigned Quals;
2224218893Sdim    return isCopyOrMoveConstructor(Quals);
2225218893Sdim  }
2226218893Sdim
2227263509Sdim  /// Whether this constructor is a
2228193326Sed  /// converting constructor (C++ [class.conv.ctor]), which can be
2229193326Sed  /// used for user-defined conversions.
2230198092Srdivacky  bool isConvertingConstructor(bool AllowExplicit) const;
2231193326Sed
2232199482Srdivacky  /// \brief Determine whether this is a member template specialization that
2233218893Sdim  /// would copy the object to itself. Such constructors are never used to copy
2234199482Srdivacky  /// an object.
2235218893Sdim  bool isSpecializationCopyingObject() const;
2236218893Sdim
2237218893Sdim  /// \brief Get the constructor that this inheriting constructor is based on.
2238218893Sdim  const CXXConstructorDecl *getInheritedConstructor() const;
2239218893Sdim
2240218893Sdim  /// \brief Set the constructor that this inheriting constructor is based on.
2241218893Sdim  void setInheritedConstructor(const CXXConstructorDecl *BaseCtor);
2242223017Sdim
2243223017Sdim  const CXXConstructorDecl *getCanonicalDecl() const {
2244223017Sdim    return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
2245223017Sdim  }
2246223017Sdim  CXXConstructorDecl *getCanonicalDecl() {
2247223017Sdim    return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
2248223017Sdim  }
2249235633Sdim
2250193326Sed  // Implement isa/cast/dyncast/etc.
2251203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2252203955Srdivacky  static bool classofKind(Kind K) { return K == CXXConstructor; }
2253235633Sdim
2254212904Sdim  friend class ASTDeclReader;
2255212904Sdim  friend class ASTDeclWriter;
2256193326Sed};
2257193326Sed
2258263509Sdim/// \brief Represents a C++ destructor within a class.
2259198092Srdivacky///
2260263509Sdim/// For example:
2261263509Sdim///
2262263509Sdim/// \code
2263193326Sed/// class X {
2264193326Sed/// public:
2265193326Sed///   ~X(); // represented by a CXXDestructorDecl.
2266193326Sed/// };
2267263509Sdim/// \endcode
2268193326Sedclass CXXDestructorDecl : public CXXMethodDecl {
2269235633Sdim  virtual void anchor();
2270193326Sed
2271199482Srdivacky  FunctionDecl *OperatorDelete;
2272235633Sdim
2273221345Sdim  CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
2274221345Sdim                    const DeclarationNameInfo &NameInfo,
2275218893Sdim                    QualType T, TypeSourceInfo *TInfo,
2276218893Sdim                    bool isInline, bool isImplicitlyDeclared)
2277252723Sdim    : CXXMethodDecl(CXXDestructor, RD, StartLoc, NameInfo, T, TInfo,
2278226890Sdim                    SC_None, isInline, /*isConstexpr=*/false, SourceLocation()),
2279263509Sdim      OperatorDelete(0) {
2280193326Sed    setImplicit(isImplicitlyDeclared);
2281193326Sed  }
2282193326Sed
2283193326Sedpublic:
2284193326Sed  static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2285221345Sdim                                   SourceLocation StartLoc,
2286212904Sdim                                   const DeclarationNameInfo &NameInfo,
2287218893Sdim                                   QualType T, TypeSourceInfo* TInfo,
2288218893Sdim                                   bool isInline,
2289193326Sed                                   bool isImplicitlyDeclared);
2290235633Sdim  static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID);
2291193326Sed
2292199482Srdivacky  void setOperatorDelete(FunctionDecl *OD) { OperatorDelete = OD; }
2293199482Srdivacky  const FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
2294198092Srdivacky
2295193326Sed  // Implement isa/cast/dyncast/etc.
2296203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2297203955Srdivacky  static bool classofKind(Kind K) { return K == CXXDestructor; }
2298235633Sdim
2299212904Sdim  friend class ASTDeclReader;
2300212904Sdim  friend class ASTDeclWriter;
2301193326Sed};
2302193326Sed
2303263509Sdim/// \brief Represents a C++ conversion function within a class.
2304198092Srdivacky///
2305263509Sdim/// For example:
2306263509Sdim///
2307263509Sdim/// \code
2308193326Sed/// class X {
2309193326Sed/// public:
2310193326Sed///   operator bool();
2311193326Sed/// };
2312263509Sdim/// \endcode
2313193326Sedclass CXXConversionDecl : public CXXMethodDecl {
2314235633Sdim  virtual void anchor();
2315263509Sdim  /// Whether this conversion function declaration is marked
2316263509Sdim  /// "explicit", meaning that it can only be applied when the user
2317193326Sed  /// explicitly wrote a cast. This is a C++0x feature.
2318203955Srdivacky  bool IsExplicitSpecified : 1;
2319193326Sed
2320221345Sdim  CXXConversionDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
2321221345Sdim                    const DeclarationNameInfo &NameInfo,
2322212904Sdim                    QualType T, TypeSourceInfo *TInfo,
2323221345Sdim                    bool isInline, bool isExplicitSpecified,
2324226890Sdim                    bool isConstexpr, SourceLocation EndLocation)
2325252723Sdim    : CXXMethodDecl(CXXConversion, RD, StartLoc, NameInfo, T, TInfo,
2326226890Sdim                    SC_None, isInline, isConstexpr, EndLocation),
2327203955Srdivacky      IsExplicitSpecified(isExplicitSpecified) { }
2328193326Sed
2329193326Sedpublic:
2330193326Sed  static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2331221345Sdim                                   SourceLocation StartLoc,
2332212904Sdim                                   const DeclarationNameInfo &NameInfo,
2333200583Srdivacky                                   QualType T, TypeSourceInfo *TInfo,
2334221345Sdim                                   bool isInline, bool isExplicit,
2335226890Sdim                                   bool isConstexpr,
2336221345Sdim                                   SourceLocation EndLocation);
2337235633Sdim  static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2338193326Sed
2339263509Sdim  /// Whether this conversion function declaration is marked
2340263509Sdim  /// "explicit", meaning that it can only be used for direct initialization
2341263509Sdim  /// (including explitly written casts).  This is a C++11 feature.
2342203955Srdivacky  bool isExplicitSpecified() const { return IsExplicitSpecified; }
2343203955Srdivacky
2344263509Sdim  /// \brief Whether this is an explicit conversion operator (C++11 and later).
2345263509Sdim  ///
2346263509Sdim  /// Explicit conversion operators are only considered for direct
2347263509Sdim  /// initialization, e.g., when the user has explicitly written a cast.
2348203955Srdivacky  bool isExplicit() const {
2349263509Sdim    return cast<CXXConversionDecl>(getFirstDecl())->isExplicitSpecified();
2350203955Srdivacky  }
2351193326Sed
2352263509Sdim  /// \brief Returns the type that this conversion function is converting to.
2353198092Srdivacky  QualType getConversionType() const {
2354198092Srdivacky    return getType()->getAs<FunctionType>()->getResultType();
2355193326Sed  }
2356193326Sed
2357235633Sdim  /// \brief Determine whether this conversion function is a conversion from
2358235633Sdim  /// a lambda closure type to a block pointer.
2359235633Sdim  bool isLambdaToBlockPointerConversion() const;
2360235633Sdim
2361193326Sed  // Implement isa/cast/dyncast/etc.
2362203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2363203955Srdivacky  static bool classofKind(Kind K) { return K == CXXConversion; }
2364235633Sdim
2365212904Sdim  friend class ASTDeclReader;
2366212904Sdim  friend class ASTDeclWriter;
2367193326Sed};
2368193326Sed
2369263509Sdim/// \brief Represents a linkage specification.
2370263509Sdim///
2371263509Sdim/// For example:
2372263509Sdim/// \code
2373193326Sed///   extern "C" void foo();
2374263509Sdim/// \endcode
2375193326Sedclass LinkageSpecDecl : public Decl, public DeclContext {
2376235633Sdim  virtual void anchor();
2377193326Sedpublic:
2378263509Sdim  /// \brief Represents the language in a linkage specification.
2379263509Sdim  ///
2380263509Sdim  /// The values are part of the serialization ABI for
2381263509Sdim  /// ASTs and cannot be changed without altering that ABI.  To help
2382263509Sdim  /// ensure a stable ABI for this, we choose the DW_LANG_ encodings
2383193326Sed  /// from the dwarf standard.
2384208600Srdivacky  enum LanguageIDs {
2385208600Srdivacky    lang_c = /* DW_LANG_C */ 0x0002,
2386208600Srdivacky    lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004
2387208600Srdivacky  };
2388193326Sedprivate:
2389263509Sdim  /// \brief The language for this linkage specification.
2390252723Sdim  unsigned Language : 3;
2391263509Sdim  /// \brief True if this linkage spec has braces.
2392263509Sdim  ///
2393263509Sdim  /// This is needed so that hasBraces() returns the correct result while the
2394263509Sdim  /// linkage spec body is being parsed.  Once RBraceLoc has been set this is
2395263509Sdim  /// not used, so it doesn't need to be serialized.
2396252723Sdim  unsigned HasBraces : 1;
2397263509Sdim  /// \brief The source location for the extern keyword.
2398221345Sdim  SourceLocation ExternLoc;
2399263509Sdim  /// \brief The source location for the right brace (if valid).
2400221345Sdim  SourceLocation RBraceLoc;
2401193326Sed
2402221345Sdim  LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
2403252723Sdim                  SourceLocation LangLoc, LanguageIDs lang, bool HasBraces)
2404221345Sdim    : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec),
2405252723Sdim      Language(lang), HasBraces(HasBraces), ExternLoc(ExternLoc),
2406252723Sdim      RBraceLoc(SourceLocation()) { }
2407193326Sed
2408193326Sedpublic:
2409198092Srdivacky  static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
2410221345Sdim                                 SourceLocation ExternLoc,
2411221345Sdim                                 SourceLocation LangLoc, LanguageIDs Lang,
2412252723Sdim                                 bool HasBraces);
2413235633Sdim  static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2414235633Sdim
2415208600Srdivacky  /// \brief Return the language specified by this linkage specification.
2416252723Sdim  LanguageIDs getLanguage() const { return LanguageIDs(Language); }
2417208600Srdivacky  /// \brief Set the language specified by this linkage specification.
2418208600Srdivacky  void setLanguage(LanguageIDs L) { Language = L; }
2419208600Srdivacky
2420208600Srdivacky  /// \brief Determines whether this linkage specification had braces in
2421208600Srdivacky  /// its syntactic form.
2422252723Sdim  bool hasBraces() const {
2423252723Sdim    assert(!RBraceLoc.isValid() || HasBraces);
2424252723Sdim    return HasBraces;
2425252723Sdim  }
2426193326Sed
2427221345Sdim  SourceLocation getExternLoc() const { return ExternLoc; }
2428221345Sdim  SourceLocation getRBraceLoc() const { return RBraceLoc; }
2429221345Sdim  void setExternLoc(SourceLocation L) { ExternLoc = L; }
2430252723Sdim  void setRBraceLoc(SourceLocation L) {
2431252723Sdim    RBraceLoc = L;
2432252723Sdim    HasBraces = RBraceLoc.isValid();
2433252723Sdim  }
2434208600Srdivacky
2435235633Sdim  SourceLocation getLocEnd() const LLVM_READONLY {
2436221345Sdim    if (hasBraces())
2437221345Sdim      return getRBraceLoc();
2438221345Sdim    // No braces: get the end location of the (only) declaration in context
2439221345Sdim    // (if present).
2440221345Sdim    return decls_empty() ? getLocation() : decls_begin()->getLocEnd();
2441221345Sdim  }
2442221345Sdim
2443235633Sdim  SourceRange getSourceRange() const LLVM_READONLY {
2444221345Sdim    return SourceRange(ExternLoc, getLocEnd());
2445221345Sdim  }
2446221345Sdim
2447203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2448203955Srdivacky  static bool classofKind(Kind K) { return K == LinkageSpec; }
2449193326Sed  static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
2450193326Sed    return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
2451193326Sed  }
2452193326Sed  static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
2453193326Sed    return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
2454193326Sed  }
2455193326Sed};
2456193326Sed
2457263509Sdim/// \brief Represents C++ using-directive.
2458193326Sed///
2459263509Sdim/// For example:
2460263509Sdim/// \code
2461193326Sed///    using namespace std;
2462263509Sdim/// \endcode
2463193326Sed///
2464263509Sdim/// \note UsingDirectiveDecl should be Decl not NamedDecl, but we provide
2465263509Sdim/// artificial names for all using-directives in order to store
2466263509Sdim/// them in DeclContext effectively.
2467193326Sedclass UsingDirectiveDecl : public NamedDecl {
2468235633Sdim  virtual void anchor();
2469263509Sdim  /// \brief The location of the \c using keyword.
2470212904Sdim  SourceLocation UsingLoc;
2471235633Sdim
2472263509Sdim  /// \brief The location of the \c namespace keyword.
2473193326Sed  SourceLocation NamespaceLoc;
2474193326Sed
2475219077Sdim  /// \brief The nested-name-specifier that precedes the namespace.
2476219077Sdim  NestedNameSpecifierLoc QualifierLoc;
2477193326Sed
2478263509Sdim  /// \brief The namespace nominated by this using-directive.
2479199990Srdivacky  NamedDecl *NominatedNamespace;
2480193326Sed
2481199990Srdivacky  /// Enclosing context containing both using-directive and nominated
2482193326Sed  /// namespace.
2483193326Sed  DeclContext *CommonAncestor;
2484193326Sed
2485263509Sdim  /// \brief Returns special DeclarationName used by using-directives.
2486263509Sdim  ///
2487263509Sdim  /// This is only used by DeclContext for storing UsingDirectiveDecls in
2488263509Sdim  /// its lookup structure.
2489193326Sed  static DeclarationName getName() {
2490193326Sed    return DeclarationName::getUsingDirectiveName();
2491193326Sed  }
2492193326Sed
2493212904Sdim  UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc,
2494193326Sed                     SourceLocation NamespcLoc,
2495219077Sdim                     NestedNameSpecifierLoc QualifierLoc,
2496193326Sed                     SourceLocation IdentLoc,
2497199990Srdivacky                     NamedDecl *Nominated,
2498193326Sed                     DeclContext *CommonAncestor)
2499212904Sdim    : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc),
2500219077Sdim      NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc),
2501219077Sdim      NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) { }
2502193326Sed
2503193326Sedpublic:
2504193326Sed  /// \brief Retrieve the nested-name-specifier that qualifies the
2505219077Sdim  /// name of the namespace, with source-location information.
2506219077Sdim  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2507235633Sdim
2508219077Sdim  /// \brief Retrieve the nested-name-specifier that qualifies the
2509193326Sed  /// name of the namespace.
2510235633Sdim  NestedNameSpecifier *getQualifier() const {
2511235633Sdim    return QualifierLoc.getNestedNameSpecifier();
2512219077Sdim  }
2513193326Sed
2514199990Srdivacky  NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
2515199990Srdivacky  const NamedDecl *getNominatedNamespaceAsWritten() const {
2516199990Srdivacky    return NominatedNamespace;
2517199990Srdivacky  }
2518199990Srdivacky
2519263509Sdim  /// \brief Returns the namespace nominated by this using-directive.
2520199990Srdivacky  NamespaceDecl *getNominatedNamespace();
2521193326Sed
2522193326Sed  const NamespaceDecl *getNominatedNamespace() const {
2523193326Sed    return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
2524193326Sed  }
2525193326Sed
2526208600Srdivacky  /// \brief Returns the common ancestor context of this using-directive and
2527208600Srdivacky  /// its nominated namespace.
2528193326Sed  DeclContext *getCommonAncestor() { return CommonAncestor; }
2529193326Sed  const DeclContext *getCommonAncestor() const { return CommonAncestor; }
2530193326Sed
2531263509Sdim  /// \brief Return the location of the \c using keyword.
2532212904Sdim  SourceLocation getUsingLoc() const { return UsingLoc; }
2533235633Sdim
2534208600Srdivacky  // FIXME: Could omit 'Key' in name.
2535263509Sdim  /// \brief Returns the location of the \c namespace keyword.
2536193326Sed  SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
2537193326Sed
2538263509Sdim  /// \brief Returns the location of this using declaration's identifier.
2539212904Sdim  SourceLocation getIdentLocation() const { return getLocation(); }
2540193326Sed
2541193326Sed  static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
2542212904Sdim                                    SourceLocation UsingLoc,
2543193326Sed                                    SourceLocation NamespaceLoc,
2544219077Sdim                                    NestedNameSpecifierLoc QualifierLoc,
2545193326Sed                                    SourceLocation IdentLoc,
2546199990Srdivacky                                    NamedDecl *Nominated,
2547193326Sed                                    DeclContext *CommonAncestor);
2548235633Sdim  static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2549235633Sdim
2550235633Sdim  SourceRange getSourceRange() const LLVM_READONLY {
2551212904Sdim    return SourceRange(UsingLoc, getLocation());
2552212904Sdim  }
2553235633Sdim
2554203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2555210299Sed  static bool classofKind(Kind K) { return K == UsingDirective; }
2556193326Sed
2557193326Sed  // Friend for getUsingDirectiveName.
2558193326Sed  friend class DeclContext;
2559235633Sdim
2560212904Sdim  friend class ASTDeclReader;
2561193326Sed};
2562193326Sed
2563245431Sdim/// \brief Represents a C++ namespace alias.
2564193326Sed///
2565245431Sdim/// For example:
2566245431Sdim///
2567263509Sdim/// \code
2568193326Sed/// namespace Foo = Bar;
2569263509Sdim/// \endcode
2570193326Sedclass NamespaceAliasDecl : public NamedDecl {
2571235633Sdim  virtual void anchor();
2572235633Sdim
2573263509Sdim  /// \brief The location of the \c namespace keyword.
2574212904Sdim  SourceLocation NamespaceLoc;
2575193326Sed
2576263509Sdim  /// \brief The location of the namespace's identifier.
2577263509Sdim  ///
2578263509Sdim  /// This is accessed by TargetNameLoc.
2579193326Sed  SourceLocation IdentLoc;
2580235633Sdim
2581219077Sdim  /// \brief The nested-name-specifier that precedes the namespace.
2582219077Sdim  NestedNameSpecifierLoc QualifierLoc;
2583235633Sdim
2584263509Sdim  /// \brief The Decl that this alias points to, either a NamespaceDecl or
2585263509Sdim  /// a NamespaceAliasDecl.
2586193326Sed  NamedDecl *Namespace;
2587198092Srdivacky
2588212904Sdim  NamespaceAliasDecl(DeclContext *DC, SourceLocation NamespaceLoc,
2589198092Srdivacky                     SourceLocation AliasLoc, IdentifierInfo *Alias,
2590219077Sdim                     NestedNameSpecifierLoc QualifierLoc,
2591193326Sed                     SourceLocation IdentLoc, NamedDecl *Namespace)
2592235633Sdim    : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias),
2593219077Sdim      NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc),
2594219077Sdim      QualifierLoc(QualifierLoc), Namespace(Namespace) { }
2595193326Sed
2596212904Sdim  friend class ASTDeclReader;
2597235633Sdim
2598193326Sedpublic:
2599193326Sed  /// \brief Retrieve the nested-name-specifier that qualifies the
2600219077Sdim  /// name of the namespace, with source-location information.
2601219077Sdim  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2602235633Sdim
2603219077Sdim  /// \brief Retrieve the nested-name-specifier that qualifies the
2604193326Sed  /// name of the namespace.
2605235633Sdim  NestedNameSpecifier *getQualifier() const {
2606235633Sdim    return QualifierLoc.getNestedNameSpecifier();
2607219077Sdim  }
2608235633Sdim
2609208600Srdivacky  /// \brief Retrieve the namespace declaration aliased by this directive.
2610193326Sed  NamespaceDecl *getNamespace() {
2611193326Sed    if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
2612193326Sed      return AD->getNamespace();
2613193326Sed
2614193326Sed    return cast<NamespaceDecl>(Namespace);
2615193326Sed  }
2616198092Srdivacky
2617193326Sed  const NamespaceDecl *getNamespace() const {
2618193326Sed    return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
2619193326Sed  }
2620193326Sed
2621203955Srdivacky  /// Returns the location of the alias name, i.e. 'foo' in
2622203955Srdivacky  /// "namespace foo = ns::bar;".
2623212904Sdim  SourceLocation getAliasLoc() const { return getLocation(); }
2624203955Srdivacky
2625263509Sdim  /// Returns the location of the \c namespace keyword.
2626212904Sdim  SourceLocation getNamespaceLoc() const { return NamespaceLoc; }
2627203955Srdivacky
2628203955Srdivacky  /// Returns the location of the identifier in the named namespace.
2629203955Srdivacky  SourceLocation getTargetNameLoc() const { return IdentLoc; }
2630203955Srdivacky
2631193326Sed  /// \brief Retrieve the namespace that this alias refers to, which
2632193326Sed  /// may either be a NamespaceDecl or a NamespaceAliasDecl.
2633193326Sed  NamedDecl *getAliasedNamespace() const { return Namespace; }
2634193326Sed
2635198092Srdivacky  static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
2636235633Sdim                                    SourceLocation NamespaceLoc,
2637212904Sdim                                    SourceLocation AliasLoc,
2638198092Srdivacky                                    IdentifierInfo *Alias,
2639219077Sdim                                    NestedNameSpecifierLoc QualifierLoc,
2640198092Srdivacky                                    SourceLocation IdentLoc,
2641193326Sed                                    NamedDecl *Namespace);
2642198092Srdivacky
2643235633Sdim  static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2644235633Sdim
2645235633Sdim  virtual SourceRange getSourceRange() const LLVM_READONLY {
2646212904Sdim    return SourceRange(NamespaceLoc, IdentLoc);
2647212904Sdim  }
2648235633Sdim
2649203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2650210299Sed  static bool classofKind(Kind K) { return K == NamespaceAlias; }
2651193326Sed};
2652194613Sed
2653245431Sdim/// \brief Represents a shadow declaration introduced into a scope by a
2654245431Sdim/// (resolved) using declaration.
2655199482Srdivacky///
2656245431Sdim/// For example,
2657263509Sdim/// \code
2658199482Srdivacky/// namespace A {
2659199482Srdivacky///   void foo();
2660199482Srdivacky/// }
2661199482Srdivacky/// namespace B {
2662245431Sdim///   using A::foo; // <- a UsingDecl
2663245431Sdim///                 // Also creates a UsingShadowDecl for A::foo() in B
2664199482Srdivacky/// }
2665263509Sdim/// \endcode
2666263509Sdimclass UsingShadowDecl : public NamedDecl, public Redeclarable<UsingShadowDecl> {
2667235633Sdim  virtual void anchor();
2668235633Sdim
2669199482Srdivacky  /// The referenced declaration.
2670199482Srdivacky  NamedDecl *Underlying;
2671199482Srdivacky
2672218893Sdim  /// \brief The using declaration which introduced this decl or the next using
2673218893Sdim  /// shadow declaration contained in the aforementioned using declaration.
2674218893Sdim  NamedDecl *UsingOrNextShadow;
2675218893Sdim  friend class UsingDecl;
2676199482Srdivacky
2677199482Srdivacky  UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using,
2678199482Srdivacky                  NamedDecl *Target)
2679210299Sed    : NamedDecl(UsingShadow, DC, Loc, DeclarationName()),
2680218893Sdim      Underlying(Target),
2681218893Sdim      UsingOrNextShadow(reinterpret_cast<NamedDecl *>(Using)) {
2682210299Sed    if (Target) {
2683210299Sed      setDeclName(Target->getDeclName());
2684210299Sed      IdentifierNamespace = Target->getIdentifierNamespace();
2685210299Sed    }
2686199482Srdivacky    setImplicit();
2687199482Srdivacky  }
2688199482Srdivacky
2689263509Sdim  typedef Redeclarable<UsingShadowDecl> redeclarable_base;
2690263509Sdim  virtual UsingShadowDecl *getNextRedeclaration() {
2691263509Sdim    return RedeclLink.getNext();
2692263509Sdim  }
2693263509Sdim  virtual UsingShadowDecl *getPreviousDeclImpl() {
2694263509Sdim    return getPreviousDecl();
2695263509Sdim  }
2696263509Sdim  virtual UsingShadowDecl *getMostRecentDeclImpl() {
2697263509Sdim    return getMostRecentDecl();
2698263509Sdim  }
2699263509Sdim
2700199482Srdivackypublic:
2701199482Srdivacky  static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
2702199482Srdivacky                                 SourceLocation Loc, UsingDecl *Using,
2703199482Srdivacky                                 NamedDecl *Target) {
2704199482Srdivacky    return new (C) UsingShadowDecl(DC, Loc, Using, Target);
2705199482Srdivacky  }
2706199482Srdivacky
2707235633Sdim  static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2708263509Sdim
2709263509Sdim  typedef redeclarable_base::redecl_iterator redecl_iterator;
2710263509Sdim  using redeclarable_base::redecls_begin;
2711263509Sdim  using redeclarable_base::redecls_end;
2712263509Sdim  using redeclarable_base::getPreviousDecl;
2713263509Sdim  using redeclarable_base::getMostRecentDecl;
2714263509Sdim
2715263509Sdim  virtual UsingShadowDecl *getCanonicalDecl() {
2716263509Sdim    return getFirstDecl();
2717263509Sdim  }
2718263509Sdim  virtual const UsingShadowDecl *getCanonicalDecl() const {
2719263509Sdim    return getFirstDecl();
2720263509Sdim  }
2721263509Sdim
2722208600Srdivacky  /// \brief Gets the underlying declaration which has been brought into the
2723199482Srdivacky  /// local scope.
2724208600Srdivacky  NamedDecl *getTargetDecl() const { return Underlying; }
2725199482Srdivacky
2726208600Srdivacky  /// \brief Sets the underlying declaration which has been brought into the
2727208600Srdivacky  /// local scope.
2728210299Sed  void setTargetDecl(NamedDecl* ND) {
2729210299Sed    assert(ND && "Target decl is null!");
2730210299Sed    Underlying = ND;
2731210299Sed    IdentifierNamespace = ND->getIdentifierNamespace();
2732210299Sed  }
2733199482Srdivacky
2734208600Srdivacky  /// \brief Gets the using declaration to which this declaration is tied.
2735218893Sdim  UsingDecl *getUsingDecl() const;
2736208600Srdivacky
2737218893Sdim  /// \brief The next using shadow declaration contained in the shadow decl
2738218893Sdim  /// chain of the using declaration which introduced this decl.
2739218893Sdim  UsingShadowDecl *getNextUsingShadowDecl() const {
2740218893Sdim    return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow);
2741218893Sdim  }
2742208600Srdivacky
2743203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2744203955Srdivacky  static bool classofKind(Kind K) { return K == Decl::UsingShadow; }
2745218893Sdim
2746218893Sdim  friend class ASTDeclReader;
2747218893Sdim  friend class ASTDeclWriter;
2748199482Srdivacky};
2749199482Srdivacky
2750245431Sdim/// \brief Represents a C++ using-declaration.
2751245431Sdim///
2752245431Sdim/// For example:
2753263509Sdim/// \code
2754194613Sed///    using someNameSpace::someIdentifier;
2755263509Sdim/// \endcode
2756194613Sedclass UsingDecl : public NamedDecl {
2757235633Sdim  virtual void anchor();
2758235633Sdim
2759263509Sdim  /// \brief The source location of the 'using' keyword itself.
2760194613Sed  SourceLocation UsingLocation;
2761198092Srdivacky
2762219077Sdim  /// \brief The nested-name-specifier that precedes the name.
2763219077Sdim  NestedNameSpecifierLoc QualifierLoc;
2764194613Sed
2765263509Sdim  /// \brief Provides source/type location info for the declaration name
2766263509Sdim  /// embedded in the ValueDecl base class.
2767212904Sdim  DeclarationNameLoc DNLoc;
2768212904Sdim
2769218893Sdim  /// \brief The first shadow declaration of the shadow decl chain associated
2770245431Sdim  /// with this using declaration.
2771245431Sdim  ///
2772245431Sdim  /// The bool member of the pair store whether this decl has the \c typename
2773245431Sdim  /// keyword.
2774235633Sdim  llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow;
2775199482Srdivacky
2776235633Sdim  UsingDecl(DeclContext *DC, SourceLocation UL,
2777219077Sdim            NestedNameSpecifierLoc QualifierLoc,
2778263509Sdim            const DeclarationNameInfo &NameInfo, bool HasTypenameKeyword)
2779212904Sdim    : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()),
2780219077Sdim      UsingLocation(UL), QualifierLoc(QualifierLoc),
2781263509Sdim      DNLoc(NameInfo.getInfo()), FirstUsingShadow(0, HasTypenameKeyword) {
2782194613Sed  }
2783194613Sed
2784194613Sedpublic:
2785263509Sdim  /// \brief Return the source location of the 'using' keyword.
2786263509Sdim  SourceLocation getUsingLoc() const { return UsingLocation; }
2787198092Srdivacky
2788208600Srdivacky  /// \brief Set the source location of the 'using' keyword.
2789263509Sdim  void setUsingLoc(SourceLocation L) { UsingLocation = L; }
2790208600Srdivacky
2791219077Sdim  /// \brief Retrieve the nested-name-specifier that qualifies the name,
2792219077Sdim  /// with source-location information.
2793219077Sdim  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2794219077Sdim
2795219077Sdim  /// \brief Retrieve the nested-name-specifier that qualifies the name.
2796235633Sdim  NestedNameSpecifier *getQualifier() const {
2797235633Sdim    return QualifierLoc.getNestedNameSpecifier();
2798195099Sed  }
2799198092Srdivacky
2800212904Sdim  DeclarationNameInfo getNameInfo() const {
2801212904Sdim    return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
2802212904Sdim  }
2803212904Sdim
2804263509Sdim  /// \brief Return true if it is a C++03 access declaration (no 'using').
2805263509Sdim  bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
2806263509Sdim
2807208600Srdivacky  /// \brief Return true if the using declaration has 'typename'.
2808263509Sdim  bool hasTypename() const { return FirstUsingShadow.getInt(); }
2809194613Sed
2810208600Srdivacky  /// \brief Sets whether the using declaration has 'typename'.
2811263509Sdim  void setTypename(bool TN) { FirstUsingShadow.setInt(TN); }
2812208600Srdivacky
2813263509Sdim  /// \brief Iterates through the using shadow declarations associated with
2814218893Sdim  /// this using declaration.
2815218893Sdim  class shadow_iterator {
2816218893Sdim    /// \brief The current using shadow declaration.
2817218893Sdim    UsingShadowDecl *Current;
2818199482Srdivacky
2819218893Sdim  public:
2820218893Sdim    typedef UsingShadowDecl*          value_type;
2821218893Sdim    typedef UsingShadowDecl*          reference;
2822218893Sdim    typedef UsingShadowDecl*          pointer;
2823218893Sdim    typedef std::forward_iterator_tag iterator_category;
2824218893Sdim    typedef std::ptrdiff_t            difference_type;
2825218893Sdim
2826218893Sdim    shadow_iterator() : Current(0) { }
2827218893Sdim    explicit shadow_iterator(UsingShadowDecl *C) : Current(C) { }
2828218893Sdim
2829218893Sdim    reference operator*() const { return Current; }
2830218893Sdim    pointer operator->() const { return Current; }
2831218893Sdim
2832218893Sdim    shadow_iterator& operator++() {
2833218893Sdim      Current = Current->getNextUsingShadowDecl();
2834218893Sdim      return *this;
2835199482Srdivacky    }
2836218893Sdim
2837218893Sdim    shadow_iterator operator++(int) {
2838218893Sdim      shadow_iterator tmp(*this);
2839218893Sdim      ++(*this);
2840218893Sdim      return tmp;
2841199482Srdivacky    }
2842218893Sdim
2843218893Sdim    friend bool operator==(shadow_iterator x, shadow_iterator y) {
2844218893Sdim      return x.Current == y.Current;
2845218893Sdim    }
2846218893Sdim    friend bool operator!=(shadow_iterator x, shadow_iterator y) {
2847218893Sdim      return x.Current != y.Current;
2848218893Sdim    }
2849218893Sdim  };
2850218893Sdim
2851218893Sdim  shadow_iterator shadow_begin() const {
2852235633Sdim    return shadow_iterator(FirstUsingShadow.getPointer());
2853199482Srdivacky  }
2854218893Sdim  shadow_iterator shadow_end() const { return shadow_iterator(); }
2855199482Srdivacky
2856208600Srdivacky  /// \brief Return the number of shadowed declarations associated with this
2857208600Srdivacky  /// using declaration.
2858218893Sdim  unsigned shadow_size() const {
2859218893Sdim    return std::distance(shadow_begin(), shadow_end());
2860208600Srdivacky  }
2861208600Srdivacky
2862218893Sdim  void addShadowDecl(UsingShadowDecl *S);
2863218893Sdim  void removeShadowDecl(UsingShadowDecl *S);
2864218893Sdim
2865194613Sed  static UsingDecl *Create(ASTContext &C, DeclContext *DC,
2866219077Sdim                           SourceLocation UsingL,
2867219077Sdim                           NestedNameSpecifierLoc QualifierLoc,
2868212904Sdim                           const DeclarationNameInfo &NameInfo,
2869263509Sdim                           bool HasTypenameKeyword);
2870194613Sed
2871235633Sdim  static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2872212904Sdim
2873263509Sdim  SourceRange getSourceRange() const LLVM_READONLY;
2874263509Sdim
2875203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2876210299Sed  static bool classofKind(Kind K) { return K == Using; }
2877210299Sed
2878212904Sdim  friend class ASTDeclReader;
2879212904Sdim  friend class ASTDeclWriter;
2880194613Sed};
2881198092Srdivacky
2882245431Sdim/// \brief Represents a dependent using declaration which was not marked with
2883245431Sdim/// \c typename.
2884245431Sdim///
2885245431Sdim/// Unlike non-dependent using declarations, these *only* bring through
2886199482Srdivacky/// non-types; otherwise they would break two-phase lookup.
2887199482Srdivacky///
2888263509Sdim/// \code
2889245431Sdim/// template \<class T> class A : public Base<T> {
2890199482Srdivacky///   using Base<T>::foo;
2891199482Srdivacky/// };
2892263509Sdim/// \endcode
2893199482Srdivackyclass UnresolvedUsingValueDecl : public ValueDecl {
2894235633Sdim  virtual void anchor();
2895235633Sdim
2896199482Srdivacky  /// \brief The source location of the 'using' keyword
2897199482Srdivacky  SourceLocation UsingLocation;
2898198092Srdivacky
2899219077Sdim  /// \brief The nested-name-specifier that precedes the name.
2900219077Sdim  NestedNameSpecifierLoc QualifierLoc;
2901198092Srdivacky
2902263509Sdim  /// \brief Provides source/type location info for the declaration name
2903263509Sdim  /// embedded in the ValueDecl base class.
2904212904Sdim  DeclarationNameLoc DNLoc;
2905212904Sdim
2906199482Srdivacky  UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
2907235633Sdim                           SourceLocation UsingLoc,
2908219077Sdim                           NestedNameSpecifierLoc QualifierLoc,
2909212904Sdim                           const DeclarationNameInfo &NameInfo)
2910212904Sdim    : ValueDecl(UnresolvedUsingValue, DC,
2911212904Sdim                NameInfo.getLoc(), NameInfo.getName(), Ty),
2912219077Sdim      UsingLocation(UsingLoc), QualifierLoc(QualifierLoc),
2913219077Sdim      DNLoc(NameInfo.getInfo())
2914199482Srdivacky  { }
2915198092Srdivacky
2916199482Srdivackypublic:
2917199482Srdivacky  /// \brief Returns the source location of the 'using' keyword.
2918199482Srdivacky  SourceLocation getUsingLoc() const { return UsingLocation; }
2919199482Srdivacky
2920208600Srdivacky  /// \brief Set the source location of the 'using' keyword.
2921208600Srdivacky  void setUsingLoc(SourceLocation L) { UsingLocation = L; }
2922208600Srdivacky
2923263509Sdim  /// \brief Return true if it is a C++03 access declaration (no 'using').
2924263509Sdim  bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
2925263509Sdim
2926219077Sdim  /// \brief Retrieve the nested-name-specifier that qualifies the name,
2927219077Sdim  /// with source-location information.
2928219077Sdim  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2929219077Sdim
2930219077Sdim  /// \brief Retrieve the nested-name-specifier that qualifies the name.
2931235633Sdim  NestedNameSpecifier *getQualifier() const {
2932235633Sdim    return QualifierLoc.getNestedNameSpecifier();
2933219077Sdim  }
2934235633Sdim
2935212904Sdim  DeclarationNameInfo getNameInfo() const {
2936212904Sdim    return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
2937212904Sdim  }
2938212904Sdim
2939199482Srdivacky  static UnresolvedUsingValueDecl *
2940199482Srdivacky    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
2941235633Sdim           NestedNameSpecifierLoc QualifierLoc,
2942212904Sdim           const DeclarationNameInfo &NameInfo);
2943199482Srdivacky
2944235633Sdim  static UnresolvedUsingValueDecl *
2945235633Sdim  CreateDeserialized(ASTContext &C, unsigned ID);
2946235633Sdim
2947263509Sdim  SourceRange getSourceRange() const LLVM_READONLY;
2948212904Sdim
2949203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2950210299Sed  static bool classofKind(Kind K) { return K == UnresolvedUsingValue; }
2951218893Sdim
2952218893Sdim  friend class ASTDeclReader;
2953218893Sdim  friend class ASTDeclWriter;
2954199482Srdivacky};
2955199482Srdivacky
2956263509Sdim/// \brief Represents a dependent using declaration which was marked with
2957245431Sdim/// \c typename.
2958199482Srdivacky///
2959263509Sdim/// \code
2960245431Sdim/// template \<class T> class A : public Base<T> {
2961199482Srdivacky///   using typename Base<T>::foo;
2962199482Srdivacky/// };
2963263509Sdim/// \endcode
2964199482Srdivacky///
2965245431Sdim/// The type associated with an unresolved using typename decl is
2966199482Srdivacky/// currently always a typename type.
2967199482Srdivackyclass UnresolvedUsingTypenameDecl : public TypeDecl {
2968235633Sdim  virtual void anchor();
2969235633Sdim
2970199482Srdivacky  /// \brief The source location of the 'typename' keyword
2971199482Srdivacky  SourceLocation TypenameLocation;
2972199482Srdivacky
2973219077Sdim  /// \brief The nested-name-specifier that precedes the name.
2974219077Sdim  NestedNameSpecifierLoc QualifierLoc;
2975199482Srdivacky
2976199482Srdivacky  UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
2977219077Sdim                              SourceLocation TypenameLoc,
2978219077Sdim                              NestedNameSpecifierLoc QualifierLoc,
2979235633Sdim                              SourceLocation TargetNameLoc,
2980219077Sdim                              IdentifierInfo *TargetName)
2981221345Sdim    : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName,
2982221345Sdim               UsingLoc),
2983221345Sdim      TypenameLocation(TypenameLoc), QualifierLoc(QualifierLoc) { }
2984199482Srdivacky
2985212904Sdim  friend class ASTDeclReader;
2986235633Sdim
2987198092Srdivackypublic:
2988199482Srdivacky  /// \brief Returns the source location of the 'using' keyword.
2989221345Sdim  SourceLocation getUsingLoc() const { return getLocStart(); }
2990198092Srdivacky
2991199482Srdivacky  /// \brief Returns the source location of the 'typename' keyword.
2992199482Srdivacky  SourceLocation getTypenameLoc() const { return TypenameLocation; }
2993198092Srdivacky
2994219077Sdim  /// \brief Retrieve the nested-name-specifier that qualifies the name,
2995219077Sdim  /// with source-location information.
2996219077Sdim  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2997219077Sdim
2998219077Sdim  /// \brief Retrieve the nested-name-specifier that qualifies the name.
2999235633Sdim  NestedNameSpecifier *getQualifier() const {
3000235633Sdim    return QualifierLoc.getNestedNameSpecifier();
3001219077Sdim  }
3002219077Sdim
3003199482Srdivacky  static UnresolvedUsingTypenameDecl *
3004199482Srdivacky    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
3005219077Sdim           SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc,
3006199482Srdivacky           SourceLocation TargetNameLoc, DeclarationName TargetName);
3007198092Srdivacky
3008235633Sdim  static UnresolvedUsingTypenameDecl *
3009235633Sdim  CreateDeserialized(ASTContext &C, unsigned ID);
3010235633Sdim
3011203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3012210299Sed  static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; }
3013198092Srdivacky};
3014198092Srdivacky
3015245431Sdim/// \brief Represents a C++11 static_assert declaration.
3016193326Sedclass StaticAssertDecl : public Decl {
3017235633Sdim  virtual void anchor();
3018245431Sdim  llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed;
3019193326Sed  StringLiteral *Message;
3020221345Sdim  SourceLocation RParenLoc;
3021193326Sed
3022221345Sdim  StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc,
3023245431Sdim                   Expr *AssertExpr, StringLiteral *Message,
3024245431Sdim                   SourceLocation RParenLoc, bool Failed)
3025245431Sdim    : Decl(StaticAssert, DC, StaticAssertLoc),
3026245431Sdim      AssertExprAndFailed(AssertExpr, Failed), Message(Message),
3027245431Sdim      RParenLoc(RParenLoc) { }
3028198092Srdivacky
3029193326Sedpublic:
3030193326Sed  static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
3031221345Sdim                                  SourceLocation StaticAssertLoc,
3032221345Sdim                                  Expr *AssertExpr, StringLiteral *Message,
3033245431Sdim                                  SourceLocation RParenLoc, bool Failed);
3034235633Sdim  static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3035235633Sdim
3036245431Sdim  Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); }
3037245431Sdim  const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); }
3038198092Srdivacky
3039193326Sed  StringLiteral *getMessage() { return Message; }
3040193326Sed  const StringLiteral *getMessage() const { return Message; }
3041198092Srdivacky
3042245431Sdim  bool isFailed() const { return AssertExprAndFailed.getInt(); }
3043245431Sdim
3044221345Sdim  SourceLocation getRParenLoc() const { return RParenLoc; }
3045221345Sdim
3046235633Sdim  SourceRange getSourceRange() const LLVM_READONLY {
3047221345Sdim    return SourceRange(getLocation(), getRParenLoc());
3048221345Sdim  }
3049221345Sdim
3050203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3051210299Sed  static bool classofKind(Kind K) { return K == StaticAssert; }
3052212904Sdim
3053212904Sdim  friend class ASTDeclReader;
3054193326Sed};
3055193326Sed
3056252723Sdim/// An instance of this class represents the declaration of a property
3057252723Sdim/// member.  This is a Microsoft extension to C++, first introduced in
3058252723Sdim/// Visual Studio .NET 2003 as a parallel to similar features in C#
3059252723Sdim/// and Managed C++.
3060252723Sdim///
3061252723Sdim/// A property must always be a non-static class member.
3062252723Sdim///
3063252723Sdim/// A property member superficially resembles a non-static data
3064252723Sdim/// member, except preceded by a property attribute:
3065252723Sdim///   __declspec(property(get=GetX, put=PutX)) int x;
3066252723Sdim/// Either (but not both) of the 'get' and 'put' names may be omitted.
3067252723Sdim///
3068252723Sdim/// A reference to a property is always an lvalue.  If the lvalue
3069252723Sdim/// undergoes lvalue-to-rvalue conversion, then a getter name is
3070252723Sdim/// required, and that member is called with no arguments.
3071252723Sdim/// If the lvalue is assigned into, then a setter name is required,
3072252723Sdim/// and that member is called with one argument, the value assigned.
3073252723Sdim/// Both operations are potentially overloaded.  Compound assignments
3074252723Sdim/// are permitted, as are the increment and decrement operators.
3075252723Sdim///
3076252723Sdim/// The getter and putter methods are permitted to be overloaded,
3077252723Sdim/// although their return and parameter types are subject to certain
3078252723Sdim/// restrictions according to the type of the property.
3079252723Sdim///
3080252723Sdim/// A property declared using an incomplete array type may
3081252723Sdim/// additionally be subscripted, adding extra parameters to the getter
3082252723Sdim/// and putter methods.
3083252723Sdimclass MSPropertyDecl : public DeclaratorDecl {
3084252723Sdim  IdentifierInfo *GetterId, *SetterId;
3085252723Sdim
3086252723Sdimpublic:
3087252723Sdim  MSPropertyDecl(DeclContext *DC, SourceLocation L,
3088252723Sdim                 DeclarationName N, QualType T, TypeSourceInfo *TInfo,
3089252723Sdim                 SourceLocation StartL, IdentifierInfo *Getter,
3090252723Sdim                 IdentifierInfo *Setter):
3091252723Sdim  DeclaratorDecl(MSProperty, DC, L, N, T, TInfo, StartL), GetterId(Getter),
3092252723Sdim  SetterId(Setter) {}
3093252723Sdim
3094252723Sdim  static MSPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3095252723Sdim
3096252723Sdim  static bool classof(const Decl *D) { return D->getKind() == MSProperty; }
3097252723Sdim
3098252723Sdim  bool hasGetter() const { return GetterId != NULL; }
3099252723Sdim  IdentifierInfo* getGetterId() const { return GetterId; }
3100252723Sdim  bool hasSetter() const { return SetterId != NULL; }
3101252723Sdim  IdentifierInfo* getSetterId() const { return SetterId; }
3102252723Sdim
3103252723Sdim  friend class ASTDeclReader;
3104252723Sdim};
3105252723Sdim
3106245431Sdim/// Insertion operator for diagnostics.  This allows sending an AccessSpecifier
3107193326Sed/// into a diagnostic with <<.
3108193326Sedconst DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
3109193326Sed                                    AccessSpecifier AS);
3110198092Srdivacky
3111235633Sdimconst PartialDiagnostic &operator<<(const PartialDiagnostic &DB,
3112235633Sdim                                    AccessSpecifier AS);
3113235633Sdim
3114193326Sed} // end namespace clang
3115193326Sed
3116193326Sed#endif
3117