DeclCXX.h revision 245431
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//===----------------------------------------------------------------------===//
9193326Sed//
10205219Srdivacky//  This file defines the C++ Decl subclasses, other than those for
11205219Srdivacky//  templates (in DeclTemplate.h) and friends (in DeclFriend.h).
12193326Sed//
13193326Sed//===----------------------------------------------------------------------===//
14193326Sed
15193326Sed#ifndef LLVM_CLANG_AST_DECLCXX_H
16193326Sed#define LLVM_CLANG_AST_DECLCXX_H
17193326Sed
18198092Srdivacky#include "clang/AST/Expr.h"
19235633Sdim#include "clang/AST/ExprCXX.h"
20193326Sed#include "clang/AST/Decl.h"
21212904Sdim#include "clang/AST/TypeLoc.h"
22202879Srdivacky#include "clang/AST/UnresolvedSet.h"
23235633Sdim#include "llvm/ADT/DenseMap.h"
24235633Sdim#include "llvm/ADT/PointerIntPair.h"
25198092Srdivacky#include "llvm/ADT/SmallPtrSet.h"
26235633Sdim#include "llvm/Support/Compiler.h"
27193326Sed
28193326Sednamespace clang {
29193326Sed
30193326Sedclass ClassTemplateDecl;
31198092Srdivackyclass ClassTemplateSpecializationDecl;
32198092Srdivackyclass CXXBasePath;
33198092Srdivackyclass CXXBasePaths;
34193326Sedclass CXXConstructorDecl;
35198092Srdivackyclass CXXConversionDecl;
36193326Sedclass CXXDestructorDecl;
37193326Sedclass CXXMethodDecl;
38198092Srdivackyclass CXXRecordDecl;
39198092Srdivackyclass CXXMemberLookupCriteria;
40206084Srdivackyclass CXXFinalOverriderMap;
41218893Sdimclass CXXIndirectPrimaryBaseSet;
42205219Srdivackyclass FriendDecl;
43235633Sdimclass LambdaExpr;
44245431Sdimclass UsingDecl;
45235633Sdim
46198092Srdivacky/// \brief Represents any kind of function declaration, whether it is a
47195099Sed/// concrete function or a function template.
48195099Sedclass AnyFunctionDecl {
49195099Sed  NamedDecl *Function;
50198092Srdivacky
51195341Sed  AnyFunctionDecl(NamedDecl *ND) : Function(ND) { }
52198092Srdivacky
53195099Sedpublic:
54195099Sed  AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { }
55195099Sed  AnyFunctionDecl(FunctionTemplateDecl *FTD);
56198092Srdivacky
57198092Srdivacky  /// \brief Implicily converts any function or function template into a
58195099Sed  /// named declaration.
59195099Sed  operator NamedDecl *() const { return Function; }
60198092Srdivacky
61195099Sed  /// \brief Retrieve the underlying function or function template.
62195099Sed  NamedDecl *get() const { return Function; }
63198092Srdivacky
64198092Srdivacky  static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) {
65195341Sed    return AnyFunctionDecl(ND);
66195341Sed  }
67195099Sed};
68198092Srdivacky
69195099Sed} // end namespace clang
70195099Sed
71195099Sednamespace llvm {
72198092Srdivacky  /// Implement simplify_type for AnyFunctionDecl, so that we can dyn_cast from
73195099Sed  /// AnyFunctionDecl to any function or function template declaration.
74195099Sed  template<> struct simplify_type<const ::clang::AnyFunctionDecl> {
75195099Sed    typedef ::clang::NamedDecl* SimpleType;
76195099Sed    static SimpleType getSimplifiedValue(const ::clang::AnyFunctionDecl &Val) {
77195099Sed      return Val;
78195099Sed    }
79195099Sed  };
80195099Sed  template<> struct simplify_type< ::clang::AnyFunctionDecl>
81195099Sed  : public simplify_type<const ::clang::AnyFunctionDecl> {};
82198092Srdivacky
83195341Sed  // Provide PointerLikeTypeTraits for non-cvr pointers.
84195341Sed  template<>
85195341Sed  class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
86195341Sed  public:
87195341Sed    static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
88198092Srdivacky      return F.get();
89195341Sed    }
90195341Sed    static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
91195341Sed      return ::clang::AnyFunctionDecl::getFromNamedDecl(
92195341Sed                                      static_cast< ::clang::NamedDecl*>(P));
93195341Sed    }
94198092Srdivacky
95195341Sed    enum { NumLowBitsAvailable = 2 };
96195341Sed  };
97198092Srdivacky
98195099Sed} // end namespace llvm
99195099Sed
100195099Sednamespace clang {
101198092Srdivacky
102245431Sdim/// @brief Represents an access specifier followed by colon ':'.
103210299Sed///
104210299Sed/// An objects of this class represents sugar for the syntactic occurrence
105210299Sed/// of an access specifier followed by a colon in the list of member
106210299Sed/// specifiers of a C++ class definition.
107210299Sed///
108210299Sed/// Note that they do not represent other uses of access specifiers,
109210299Sed/// such as those occurring in a list of base specifiers.
110210299Sed/// Also note that this class has nothing to do with so-called
111210299Sed/// "access declarations" (C++98 11.3 [class.access.dcl]).
112210299Sedclass AccessSpecDecl : public Decl {
113235633Sdim  virtual void anchor();
114245431Sdim  /// \brief The location of the ':'.
115210299Sed  SourceLocation ColonLoc;
116210299Sed
117210299Sed  AccessSpecDecl(AccessSpecifier AS, DeclContext *DC,
118210299Sed                 SourceLocation ASLoc, SourceLocation ColonLoc)
119210299Sed    : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) {
120210299Sed    setAccess(AS);
121210299Sed  }
122218893Sdim  AccessSpecDecl(EmptyShell Empty)
123218893Sdim    : Decl(AccessSpec, Empty) { }
124210299Sedpublic:
125245431Sdim  /// \brief The location of the access specifier.
126210299Sed  SourceLocation getAccessSpecifierLoc() const { return getLocation(); }
127245431Sdim  /// \brief Sets the location of the access specifier.
128210299Sed  void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); }
129210299Sed
130245431Sdim  /// \brief The location of the colon following the access specifier.
131210299Sed  SourceLocation getColonLoc() const { return ColonLoc; }
132245431Sdim  /// \brief Sets the location of the colon.
133210299Sed  void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; }
134210299Sed
135235633Sdim  SourceRange getSourceRange() const LLVM_READONLY {
136210299Sed    return SourceRange(getAccessSpecifierLoc(), getColonLoc());
137210299Sed  }
138210299Sed
139210299Sed  static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS,
140210299Sed                                DeclContext *DC, SourceLocation ASLoc,
141210299Sed                                SourceLocation ColonLoc) {
142210299Sed    return new (C) AccessSpecDecl(AS, DC, ASLoc, ColonLoc);
143210299Sed  }
144235633Sdim  static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
145210299Sed
146210299Sed  // Implement isa/cast/dyncast/etc.
147210299Sed  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
148210299Sed  static bool classofKind(Kind K) { return K == AccessSpec; }
149210299Sed};
150210299Sed
151210299Sed
152245431Sdim/// \brief Represents a base class of a C++ class.
153193326Sed///
154193326Sed/// Each CXXBaseSpecifier represents a single, direct base class (or
155193326Sed/// struct) of a C++ class (or struct). It specifies the type of that
156193326Sed/// base class, whether it is a virtual or non-virtual base, and what
157193326Sed/// level of access (public, protected, private) is used for the
158193326Sed/// derivation. For example:
159193326Sed///
160193326Sed/// @code
161193326Sed///   class A { };
162193326Sed///   class B { };
163193326Sed///   class C : public virtual A, protected B { };
164193326Sed/// @endcode
165193326Sed///
166193326Sed/// In this code, C will have two CXXBaseSpecifiers, one for "public
167193326Sed/// virtual A" and the other for "protected B".
168193326Sedclass CXXBaseSpecifier {
169193326Sed  /// Range - The source code range that covers the full base
170193326Sed  /// specifier, including the "virtual" (if present) and access
171193326Sed  /// specifier (if present).
172193326Sed  SourceRange Range;
173193326Sed
174218893Sdim  /// \brief The source location of the ellipsis, if this is a pack
175218893Sdim  /// expansion.
176218893Sdim  SourceLocation EllipsisLoc;
177235633Sdim
178245431Sdim  /// \brief Whether this is a virtual base class or not.
179193326Sed  bool Virtual : 1;
180193326Sed
181193326Sed  /// BaseOfClass - Whether this is the base of a class (true) or of a
182193326Sed  /// struct (false). This determines the mapping from the access
183193326Sed  /// specifier as written in the source code to the access specifier
184193326Sed  /// used for semantic analysis.
185198092Srdivacky  bool BaseOfClass : 1;
186193326Sed
187193326Sed  /// Access - Access specifier as written in the source code (which
188193326Sed  /// may be AS_none). The actual type of data stored here is an
189193326Sed  /// AccessSpecifier, but we use "unsigned" here to work around a
190193326Sed  /// VC++ bug.
191193326Sed  unsigned Access : 2;
192193326Sed
193218893Sdim  /// InheritConstructors - Whether the class contains a using declaration
194218893Sdim  /// to inherit the named class's constructors.
195218893Sdim  bool InheritConstructors : 1;
196218893Sdim
197212904Sdim  /// BaseTypeInfo - The type of the base class. This will be a class or struct
198212904Sdim  /// (or a typedef of such). The source code range does not include the
199212904Sdim  /// "virtual" or access specifier.
200212904Sdim  TypeSourceInfo *BaseTypeInfo;
201198092Srdivacky
202193326Sedpublic:
203193326Sed  CXXBaseSpecifier() { }
204193326Sed
205212904Sdim  CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A,
206218893Sdim                   TypeSourceInfo *TInfo, SourceLocation EllipsisLoc)
207235633Sdim    : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC),
208218893Sdim      Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) { }
209193326Sed
210193326Sed  /// getSourceRange - Retrieves the source range that contains the
211193326Sed  /// entire base specifier.
212235633Sdim  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
213235633Sdim  SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
214235633Sdim  SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
215198092Srdivacky
216193326Sed  /// isVirtual - Determines whether the base class is a virtual base
217193326Sed  /// class (or not).
218193326Sed  bool isVirtual() const { return Virtual; }
219193326Sed
220212904Sdim  /// \brief Determine whether this base class is a base of a class declared
221203955Srdivacky  /// with the 'class' keyword (vs. one declared with the 'struct' keyword).
222203955Srdivacky  bool isBaseOfClass() const { return BaseOfClass; }
223235633Sdim
224218893Sdim  /// \brief Determine whether this base specifier is a pack expansion.
225218893Sdim  bool isPackExpansion() const { return EllipsisLoc.isValid(); }
226218893Sdim
227218893Sdim  /// \brief Determine whether this base class's constructors get inherited.
228218893Sdim  bool getInheritConstructors() const { return InheritConstructors; }
229218893Sdim
230218893Sdim  /// \brief Set that this base class's constructors should be inherited.
231218893Sdim  void setInheritConstructors(bool Inherit = true) {
232218893Sdim    InheritConstructors = Inherit;
233218893Sdim  }
234218893Sdim
235218893Sdim  /// \brief For a pack expansion, determine the location of the ellipsis.
236218893Sdim  SourceLocation getEllipsisLoc() const {
237218893Sdim    return EllipsisLoc;
238218893Sdim  }
239218893Sdim
240193326Sed  /// getAccessSpecifier - Returns the access specifier for this base
241193326Sed  /// specifier. This is the actual base specifier as used for
242193326Sed  /// semantic analysis, so the result can never be AS_none. To
243193326Sed  /// retrieve the access specifier as written in the source code, use
244193326Sed  /// getAccessSpecifierAsWritten().
245198092Srdivacky  AccessSpecifier getAccessSpecifier() const {
246193326Sed    if ((AccessSpecifier)Access == AS_none)
247193326Sed      return BaseOfClass? AS_private : AS_public;
248193326Sed    else
249198092Srdivacky      return (AccessSpecifier)Access;
250193326Sed  }
251193326Sed
252193326Sed  /// getAccessSpecifierAsWritten - Retrieves the access specifier as
253193326Sed  /// written in the source code (which may mean that no access
254193326Sed  /// specifier was explicitly written). Use getAccessSpecifier() to
255193326Sed  /// retrieve the access specifier for use in semantic analysis.
256193326Sed  AccessSpecifier getAccessSpecifierAsWritten() const {
257193326Sed    return (AccessSpecifier)Access;
258193326Sed  }
259193326Sed
260193326Sed  /// getType - Retrieves the type of the base class. This type will
261193326Sed  /// always be an unqualified class type.
262212904Sdim  QualType getType() const { return BaseTypeInfo->getType(); }
263212904Sdim
264212904Sdim  /// getTypeLoc - Retrieves the type and source location of the base class.
265212904Sdim  TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; }
266193326Sed};
267193326Sed
268193326Sed/// CXXRecordDecl - Represents a C++ struct/union/class.
269193326Sed/// FIXME: This class will disappear once we've properly taught RecordDecl
270193326Sed/// to deal with C++-specific things.
271193326Sedclass CXXRecordDecl : public RecordDecl {
272193326Sed
273203955Srdivacky  friend void TagDecl::startDefinition();
274193326Sed
275203955Srdivacky  struct DefinitionData {
276203955Srdivacky    DefinitionData(CXXRecordDecl *D);
277193326Sed
278203955Srdivacky    /// UserDeclaredConstructor - True when this class has a
279203955Srdivacky    /// user-declared constructor.
280203955Srdivacky    bool UserDeclaredConstructor : 1;
281193326Sed
282203955Srdivacky    /// UserDeclaredCopyConstructor - True when this class has a
283203955Srdivacky    /// user-declared copy constructor.
284203955Srdivacky    bool UserDeclaredCopyConstructor : 1;
285193326Sed
286223017Sdim    /// UserDeclareMoveConstructor - True when this class has a
287223017Sdim    /// user-declared move constructor.
288223017Sdim    bool UserDeclaredMoveConstructor : 1;
289223017Sdim
290203955Srdivacky    /// UserDeclaredCopyAssignment - True when this class has a
291203955Srdivacky    /// user-declared copy assignment operator.
292203955Srdivacky    bool UserDeclaredCopyAssignment : 1;
293193326Sed
294223017Sdim    /// UserDeclareMoveAssignment - True when this class has a
295223017Sdim    /// user-declared move assignment.
296223017Sdim    bool UserDeclaredMoveAssignment : 1;
297223017Sdim
298203955Srdivacky    /// UserDeclaredDestructor - True when this class has a
299203955Srdivacky    /// user-declared destructor.
300203955Srdivacky    bool UserDeclaredDestructor : 1;
301198092Srdivacky
302203955Srdivacky    /// Aggregate - True when this class is an aggregate.
303203955Srdivacky    bool Aggregate : 1;
304193326Sed
305203955Srdivacky    /// PlainOldData - True when this class is a POD-type.
306203955Srdivacky    bool PlainOldData : 1;
307198092Srdivacky
308203955Srdivacky    /// Empty - true when this class is empty for traits purposes,
309203955Srdivacky    /// i.e. has no data members other than 0-width bit-fields, has no
310203955Srdivacky    /// virtual function/base, and doesn't inherit from a non-empty
311203955Srdivacky    /// class. Doesn't take union-ness into account.
312203955Srdivacky    bool Empty : 1;
313198092Srdivacky
314203955Srdivacky    /// Polymorphic - True when this class is polymorphic, i.e. has at
315203955Srdivacky    /// least one virtual member or derives from a polymorphic class.
316203955Srdivacky    bool Polymorphic : 1;
317198092Srdivacky
318203955Srdivacky    /// Abstract - True when this class is abstract, i.e. has at least
319203955Srdivacky    /// one pure virtual function, (that can come from a base class).
320203955Srdivacky    bool Abstract : 1;
321198092Srdivacky
322221345Sdim    /// IsStandardLayout - True when this class has standard layout.
323221345Sdim    ///
324221345Sdim    /// C++0x [class]p7.  A standard-layout class is a class that:
325221345Sdim    /// * has no non-static data members of type non-standard-layout class (or
326221345Sdim    ///   array of such types) or reference,
327221345Sdim    /// * has no virtual functions (10.3) and no virtual base classes (10.1),
328235633Sdim    /// * has the same access control (Clause 11) for all non-static data
329235633Sdim    ///   members
330221345Sdim    /// * has no non-standard-layout base classes,
331221345Sdim    /// * either has no non-static data members in the most derived class and at
332221345Sdim    ///   most one base class with non-static data members, or has no base
333221345Sdim    ///   classes with non-static data members, and
334221345Sdim    /// * has no base classes of the same type as the first non-static data
335221345Sdim    ///   member.
336221345Sdim    bool IsStandardLayout : 1;
337221345Sdim
338221345Sdim    /// HasNoNonEmptyBases - True when there are no non-empty base classes.
339221345Sdim    ///
340221345Sdim    /// This is a helper bit of state used to implement IsStandardLayout more
341221345Sdim    /// efficiently.
342221345Sdim    bool HasNoNonEmptyBases : 1;
343221345Sdim
344221345Sdim    /// HasPrivateFields - True when there are private non-static data members.
345221345Sdim    bool HasPrivateFields : 1;
346221345Sdim
347221345Sdim    /// HasProtectedFields - True when there are protected non-static data
348221345Sdim    /// members.
349221345Sdim    bool HasProtectedFields : 1;
350221345Sdim
351221345Sdim    /// HasPublicFields - True when there are private non-static data members.
352221345Sdim    bool HasPublicFields : 1;
353221345Sdim
354223017Sdim    /// \brief True if this class (or any subobject) has mutable fields.
355223017Sdim    bool HasMutableFields : 1;
356235633Sdim
357235633Sdim    /// \brief True if there no non-field members declared by the user.
358235633Sdim    bool HasOnlyCMembers : 1;
359235633Sdim
360245431Sdim    /// \brief True if any field has an in-class initializer.
361245431Sdim    bool HasInClassInitializer : 1;
362245431Sdim
363223017Sdim    /// HasTrivialDefaultConstructor - True when, if this class has a default
364223017Sdim    /// constructor, this default constructor is trivial.
365203955Srdivacky    ///
366223017Sdim    /// C++0x [class.ctor]p5
367223017Sdim    ///    A default constructor is trivial if it is not user-provided and if
368223017Sdim    ///     -- its class has no virtual functions and no virtual base classes,
369223017Sdim    ///        and
370223017Sdim    ///     -- no non-static data member of its class has a
371223017Sdim    ///        brace-or-equal-initializer, and
372223017Sdim    ///     -- all the direct base classes of its class have trivial
373223017Sdim    ///        default constructors, and
374223017Sdim    ///     -- for all the nonstatic data members of its class that are of class
375223017Sdim    ///        type (or array thereof), each such class has a trivial
376223017Sdim    ///        default constructor.
377223017Sdim    bool HasTrivialDefaultConstructor : 1;
378198092Srdivacky
379226890Sdim    /// HasConstexprNonCopyMoveConstructor - True when this class has at least
380235633Sdim    /// one user-declared constexpr constructor which is neither the copy nor
381235633Sdim    /// move constructor.
382226890Sdim    bool HasConstexprNonCopyMoveConstructor : 1;
383221345Sdim
384235633Sdim    /// DefaultedDefaultConstructorIsConstexpr - True if a defaulted default
385235633Sdim    /// constructor for this class would be constexpr.
386235633Sdim    bool DefaultedDefaultConstructorIsConstexpr : 1;
387235633Sdim
388235633Sdim    /// HasConstexprDefaultConstructor - True if this class has a constexpr
389235633Sdim    /// default constructor (either user-declared or implicitly declared).
390235633Sdim    bool HasConstexprDefaultConstructor : 1;
391235633Sdim
392203955Srdivacky    /// HasTrivialCopyConstructor - True when this class has a trivial copy
393203955Srdivacky    /// constructor.
394203955Srdivacky    ///
395221345Sdim    /// C++0x [class.copy]p13:
396221345Sdim    ///   A copy/move constructor for class X is trivial if it is neither
397223017Sdim    ///   user-provided and if
398221345Sdim    ///    -- class X has no virtual functions and no virtual base classes, and
399221345Sdim    ///    -- the constructor selected to copy/move each direct base class
400221345Sdim    ///       subobject is trivial, and
401221345Sdim    ///    -- for each non-static data member of X that is of class type (or an
402221345Sdim    ///       array thereof), the constructor selected to copy/move that member
403221345Sdim    ///       is trivial;
404221345Sdim    ///   otherwise the copy/move constructor is non-trivial.
405203955Srdivacky    bool HasTrivialCopyConstructor : 1;
406203955Srdivacky
407221345Sdim    /// HasTrivialMoveConstructor - True when this class has a trivial move
408221345Sdim    /// constructor.
409221345Sdim    ///
410221345Sdim    /// C++0x [class.copy]p13:
411221345Sdim    ///   A copy/move constructor for class X is trivial if it is neither
412223017Sdim    ///   user-provided and if
413221345Sdim    ///    -- class X has no virtual functions and no virtual base classes, and
414221345Sdim    ///    -- the constructor selected to copy/move each direct base class
415221345Sdim    ///       subobject is trivial, and
416221345Sdim    ///    -- for each non-static data member of X that is of class type (or an
417221345Sdim    ///       array thereof), the constructor selected to copy/move that member
418221345Sdim    ///       is trivial;
419221345Sdim    ///   otherwise the copy/move constructor is non-trivial.
420221345Sdim    bool HasTrivialMoveConstructor : 1;
421221345Sdim
422203955Srdivacky    /// HasTrivialCopyAssignment - True when this class has a trivial copy
423203955Srdivacky    /// assignment operator.
424203955Srdivacky    ///
425221345Sdim    /// C++0x [class.copy]p27:
426221345Sdim    ///   A copy/move assignment operator for class X is trivial if it is
427221345Sdim    ///   neither user-provided nor deleted and if
428221345Sdim    ///    -- class X has no virtual functions and no virtual base classes, and
429221345Sdim    ///    -- the assignment operator selected to copy/move each direct base
430221345Sdim    ///       class subobject is trivial, and
431221345Sdim    ///    -- for each non-static data member of X that is of class type (or an
432221345Sdim    ///       array thereof), the assignment operator selected to copy/move
433221345Sdim    ///       that member is trivial;
434221345Sdim    ///   otherwise the copy/move assignment operator is non-trivial.
435203955Srdivacky    bool HasTrivialCopyAssignment : 1;
436203955Srdivacky
437221345Sdim    /// HasTrivialMoveAssignment - True when this class has a trivial move
438221345Sdim    /// assignment operator.
439221345Sdim    ///
440221345Sdim    /// C++0x [class.copy]p27:
441221345Sdim    ///   A copy/move assignment operator for class X is trivial if it is
442221345Sdim    ///   neither user-provided nor deleted and if
443221345Sdim    ///    -- class X has no virtual functions and no virtual base classes, and
444221345Sdim    ///    -- the assignment operator selected to copy/move each direct base
445221345Sdim    ///       class subobject is trivial, and
446221345Sdim    ///    -- for each non-static data member of X that is of class type (or an
447221345Sdim    ///       array thereof), the assignment operator selected to copy/move
448221345Sdim    ///       that member is trivial;
449221345Sdim    ///   otherwise the copy/move assignment operator is non-trivial.
450221345Sdim    bool HasTrivialMoveAssignment : 1;
451221345Sdim
452203955Srdivacky    /// HasTrivialDestructor - True when this class has a trivial destructor.
453203955Srdivacky    ///
454203955Srdivacky    /// C++ [class.dtor]p3.  A destructor is trivial if it is an
455203955Srdivacky    /// implicitly-declared destructor and if:
456203955Srdivacky    /// * all of the direct base classes of its class have trivial destructors
457203955Srdivacky    ///   and
458203955Srdivacky    /// * for all of the non-static data members of its class that are of class
459203955Srdivacky    ///   type (or array thereof), each such class has a trivial destructor.
460203955Srdivacky    bool HasTrivialDestructor : 1;
461203955Srdivacky
462235633Sdim    /// HasIrrelevantDestructor - True when this class has a destructor with no
463235633Sdim    /// semantic effect.
464235633Sdim    bool HasIrrelevantDestructor : 1;
465235633Sdim
466221345Sdim    /// HasNonLiteralTypeFieldsOrBases - True when this class contains at least
467235633Sdim    /// one non-static data member or base class of non-literal or volatile
468235633Sdim    /// type.
469221345Sdim    bool HasNonLiteralTypeFieldsOrBases : 1;
470221345Sdim
471203955Srdivacky    /// ComputedVisibleConversions - True when visible conversion functions are
472203955Srdivacky    /// already computed and are available.
473203955Srdivacky    bool ComputedVisibleConversions : 1;
474210299Sed
475223017Sdim    /// \brief Whether we have a C++0x user-provided default constructor (not
476223017Sdim    /// explicitly deleted or defaulted).
477223017Sdim    bool UserProvidedDefaultConstructor : 1;
478223017Sdim
479223017Sdim    /// \brief Whether we have already declared the default constructor.
480210299Sed    bool DeclaredDefaultConstructor : 1;
481210299Sed
482210299Sed    /// \brief Whether we have already declared the copy constructor.
483210299Sed    bool DeclaredCopyConstructor : 1;
484223017Sdim
485223017Sdim    /// \brief Whether we have already declared the move constructor.
486223017Sdim    bool DeclaredMoveConstructor : 1;
487235633Sdim
488210299Sed    /// \brief Whether we have already declared the copy-assignment operator.
489210299Sed    bool DeclaredCopyAssignment : 1;
490223017Sdim
491223017Sdim    /// \brief Whether we have already declared the move-assignment operator.
492223017Sdim    bool DeclaredMoveAssignment : 1;
493235633Sdim
494210299Sed    /// \brief Whether we have already declared a destructor within the class.
495210299Sed    bool DeclaredDestructor : 1;
496218893Sdim
497226890Sdim    /// \brief Whether an implicit move constructor was attempted to be declared
498226890Sdim    /// but would have been deleted.
499226890Sdim    bool FailedImplicitMoveConstructor : 1;
500226890Sdim
501226890Sdim    /// \brief Whether an implicit move assignment operator was attempted to be
502226890Sdim    /// declared but would have been deleted.
503226890Sdim    bool FailedImplicitMoveAssignment : 1;
504226890Sdim
505235633Sdim    /// \brief Whether this class describes a C++ lambda.
506235633Sdim    bool IsLambda : 1;
507235633Sdim
508218893Sdim    /// NumBases - The number of base class specifiers in Bases.
509218893Sdim    unsigned NumBases;
510235633Sdim
511218893Sdim    /// NumVBases - The number of virtual base class specifiers in VBases.
512218893Sdim    unsigned NumVBases;
513218893Sdim
514203955Srdivacky    /// Bases - Base classes of this class.
515203955Srdivacky    /// FIXME: This is wasted space for a union.
516218893Sdim    LazyCXXBaseSpecifiersPtr Bases;
517193326Sed
518203955Srdivacky    /// VBases - direct and indirect virtual base classes of this class.
519218893Sdim    LazyCXXBaseSpecifiersPtr VBases;
520198092Srdivacky
521203955Srdivacky    /// Conversions - Overload set containing the conversion functions
522203955Srdivacky    /// of this C++ class (but not its inherited conversion
523203955Srdivacky    /// functions). Each of the entries in this overload set is a
524203955Srdivacky    /// CXXConversionDecl.
525203955Srdivacky    UnresolvedSet<4> Conversions;
526193326Sed
527203955Srdivacky    /// VisibleConversions - Overload set containing the conversion
528203955Srdivacky    /// functions of this C++ class and all those inherited conversion
529203955Srdivacky    /// functions that are visible in this class. Each of the entries
530203955Srdivacky    /// in this overload set is a CXXConversionDecl or a
531203955Srdivacky    /// FunctionTemplateDecl.
532203955Srdivacky    UnresolvedSet<4> VisibleConversions;
533203955Srdivacky
534203955Srdivacky    /// Definition - The declaration which defines this record.
535203955Srdivacky    CXXRecordDecl *Definition;
536203955Srdivacky
537205219Srdivacky    /// FirstFriend - The first friend declaration in this class, or
538205219Srdivacky    /// null if there aren't any.  This is actually currently stored
539205219Srdivacky    /// in reverse order.
540205219Srdivacky    FriendDecl *FirstFriend;
541205219Srdivacky
542235633Sdim    /// \brief Retrieve the set of direct base classes.
543218893Sdim    CXXBaseSpecifier *getBases() const {
544245431Sdim      if (!Bases.isOffset())
545245431Sdim        return Bases.get(0);
546245431Sdim      return getBasesSlowCase();
547218893Sdim    }
548218893Sdim
549235633Sdim    /// \brief Retrieve the set of virtual base classes.
550218893Sdim    CXXBaseSpecifier *getVBases() const {
551245431Sdim      if (!VBases.isOffset())
552245431Sdim        return VBases.get(0);
553245431Sdim      return getVBasesSlowCase();
554218893Sdim    }
555245431Sdim
556245431Sdim  private:
557245431Sdim    CXXBaseSpecifier *getBasesSlowCase() const;
558245431Sdim    CXXBaseSpecifier *getVBasesSlowCase() const;
559203955Srdivacky  } *DefinitionData;
560203955Srdivacky
561235633Sdim  /// \brief Describes a C++ closure type (generated by a lambda expression).
562235633Sdim  struct LambdaDefinitionData : public DefinitionData {
563235633Sdim    typedef LambdaExpr::Capture Capture;
564235633Sdim
565245431Sdim    LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info, bool Dependent)
566235633Sdim      : DefinitionData(D), Dependent(Dependent), NumCaptures(0),
567245431Sdim        NumExplicitCaptures(0), ManglingNumber(0), ContextDecl(0), Captures(0),
568245431Sdim        MethodTyInfo(Info)
569235633Sdim    {
570235633Sdim      IsLambda = true;
571235633Sdim    }
572235633Sdim
573235633Sdim    /// \brief Whether this lambda is known to be dependent, even if its
574235633Sdim    /// context isn't dependent.
575235633Sdim    ///
576235633Sdim    /// A lambda with a non-dependent context can be dependent if it occurs
577235633Sdim    /// within the default argument of a function template, because the
578235633Sdim    /// lambda will have been created with the enclosing context as its
579235633Sdim    /// declaration context, rather than function. This is an unfortunate
580235633Sdim    /// artifact of having to parse the default arguments before
581235633Sdim    unsigned Dependent : 1;
582235633Sdim
583235633Sdim    /// \brief The number of captures in this lambda.
584235633Sdim    unsigned NumCaptures : 16;
585235633Sdim
586235633Sdim    /// \brief The number of explicit captures in this lambda.
587235633Sdim    unsigned NumExplicitCaptures : 15;
588235633Sdim
589235633Sdim    /// \brief The number used to indicate this lambda expression for name
590235633Sdim    /// mangling in the Itanium C++ ABI.
591235633Sdim    unsigned ManglingNumber;
592235633Sdim
593235633Sdim    /// \brief The declaration that provides context for this lambda, if the
594235633Sdim    /// actual DeclContext does not suffice. This is used for lambdas that
595235633Sdim    /// occur within default arguments of function parameters within the class
596235633Sdim    /// or within a data member initializer.
597235633Sdim    Decl *ContextDecl;
598235633Sdim
599235633Sdim    /// \brief The list of captures, both explicit and implicit, for this
600235633Sdim    /// lambda.
601245431Sdim    Capture *Captures;
602245431Sdim
603245431Sdim    /// \brief The type of the call method.
604245431Sdim    TypeSourceInfo *MethodTyInfo;
605235633Sdim  };
606235633Sdim
607203955Srdivacky  struct DefinitionData &data() {
608203955Srdivacky    assert(DefinitionData && "queried property of class with no definition");
609203955Srdivacky    return *DefinitionData;
610203955Srdivacky  }
611203955Srdivacky
612203955Srdivacky  const struct DefinitionData &data() const {
613203955Srdivacky    assert(DefinitionData && "queried property of class with no definition");
614203955Srdivacky    return *DefinitionData;
615203955Srdivacky  }
616235633Sdim
617235633Sdim  struct LambdaDefinitionData &getLambdaData() const {
618235633Sdim    assert(DefinitionData && "queried property of lambda with no definition");
619235633Sdim    assert(DefinitionData->IsLambda &&
620235633Sdim           "queried lambda property of non-lambda class");
621235633Sdim    return static_cast<LambdaDefinitionData &>(*DefinitionData);
622235633Sdim  }
623198092Srdivacky
624193326Sed  /// \brief The template or declaration that this declaration
625193326Sed  /// describes or was instantiated from, respectively.
626198092Srdivacky  ///
627193326Sed  /// For non-templates, this value will be NULL. For record
628193326Sed  /// declarations that describe a class template, this will be a
629193326Sed  /// pointer to a ClassTemplateDecl. For member
630193326Sed  /// classes of class template specializations, this will be the
631235633Sdim  /// MemberSpecializationInfo referring to the member class that was
632198092Srdivacky  /// instantiated or specialized.
633198092Srdivacky  llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*>
634193326Sed    TemplateOrInstantiation;
635206084Srdivacky
636218893Sdim  friend class DeclContext;
637235633Sdim  friend class LambdaExpr;
638235633Sdim
639218893Sdim  /// \brief Notify the class that member has been added.
640218893Sdim  ///
641235633Sdim  /// This routine helps maintain information about the class based on which
642218893Sdim  /// members have been added. It will be invoked by DeclContext::addDecl()
643218893Sdim  /// whenever a member is added to this record.
644218893Sdim  void addedMember(Decl *D);
645218893Sdim
646218893Sdim  void markedVirtualFunctionPure();
647218893Sdim  friend void FunctionDecl::setPure(bool);
648235633Sdim
649245431Sdim  void markedConstructorConstexpr(CXXConstructorDecl *CD);
650245431Sdim  friend void FunctionDecl::setConstexpr(bool);
651245431Sdim
652235633Sdim  friend class ASTNodeImporter;
653235633Sdim
654193326Sedprotected:
655193326Sed  CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
656221345Sdim                SourceLocation StartLoc, SourceLocation IdLoc,
657221345Sdim                IdentifierInfo *Id, CXXRecordDecl *PrevDecl);
658193326Sed
659193326Sedpublic:
660193326Sed  /// base_class_iterator - Iterator that traverses the base classes
661198092Srdivacky  /// of a class.
662193326Sed  typedef CXXBaseSpecifier*       base_class_iterator;
663193326Sed
664193326Sed  /// base_class_const_iterator - Iterator that traverses the base
665198092Srdivacky  /// classes of a class.
666193326Sed  typedef const CXXBaseSpecifier* base_class_const_iterator;
667193326Sed
668198092Srdivacky  /// reverse_base_class_iterator = Iterator that traverses the base classes
669198092Srdivacky  /// of a class in reverse order.
670198092Srdivacky  typedef std::reverse_iterator<base_class_iterator>
671198092Srdivacky    reverse_base_class_iterator;
672198092Srdivacky
673198092Srdivacky  /// reverse_base_class_iterator = Iterator that traverses the base classes
674198092Srdivacky  /// of a class in reverse order.
675198092Srdivacky  typedef std::reverse_iterator<base_class_const_iterator>
676198092Srdivacky    reverse_base_class_const_iterator;
677198092Srdivacky
678198092Srdivacky  virtual CXXRecordDecl *getCanonicalDecl() {
679198092Srdivacky    return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
680198092Srdivacky  }
681199482Srdivacky  virtual const CXXRecordDecl *getCanonicalDecl() const {
682199482Srdivacky    return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
683199482Srdivacky  }
684235633Sdim
685235633Sdim  const CXXRecordDecl *getPreviousDecl() const {
686235633Sdim    return cast_or_null<CXXRecordDecl>(RecordDecl::getPreviousDecl());
687210299Sed  }
688235633Sdim  CXXRecordDecl *getPreviousDecl() {
689235633Sdim    return cast_or_null<CXXRecordDecl>(RecordDecl::getPreviousDecl());
690210299Sed  }
691198092Srdivacky
692235633Sdim  const CXXRecordDecl *getMostRecentDecl() const {
693235633Sdim    return cast_or_null<CXXRecordDecl>(RecordDecl::getMostRecentDecl());
694235633Sdim  }
695235633Sdim  CXXRecordDecl *getMostRecentDecl() {
696235633Sdim    return cast_or_null<CXXRecordDecl>(RecordDecl::getMostRecentDecl());
697235633Sdim  }
698235633Sdim
699203955Srdivacky  CXXRecordDecl *getDefinition() const {
700203955Srdivacky    if (!DefinitionData) return 0;
701203955Srdivacky    return data().Definition;
702203955Srdivacky  }
703203955Srdivacky
704203955Srdivacky  bool hasDefinition() const { return DefinitionData != 0; }
705203955Srdivacky
706218893Sdim  static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
707221345Sdim                               SourceLocation StartLoc, SourceLocation IdLoc,
708221345Sdim                               IdentifierInfo *Id, CXXRecordDecl* PrevDecl=0,
709193326Sed                               bool DelayTypeCreation = false);
710235633Sdim  static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC,
711245431Sdim                                     TypeSourceInfo *Info, SourceLocation Loc,
712245431Sdim                                     bool DependentLambda);
713235633Sdim  static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
714198092Srdivacky
715198092Srdivacky  bool isDynamicClass() const {
716203955Srdivacky    return data().Polymorphic || data().NumVBases != 0;
717198092Srdivacky  }
718198092Srdivacky
719193326Sed  /// setBases - Sets the base classes of this struct or class.
720203955Srdivacky  void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
721193326Sed
722193326Sed  /// getNumBases - Retrieves the number of base classes of this
723193326Sed  /// class.
724203955Srdivacky  unsigned getNumBases() const { return data().NumBases; }
725193326Sed
726218893Sdim  base_class_iterator bases_begin() { return data().getBases(); }
727218893Sdim  base_class_const_iterator bases_begin() const { return data().getBases(); }
728203955Srdivacky  base_class_iterator bases_end() { return bases_begin() + data().NumBases; }
729203955Srdivacky  base_class_const_iterator bases_end() const {
730203955Srdivacky    return bases_begin() + data().NumBases;
731203955Srdivacky  }
732198092Srdivacky  reverse_base_class_iterator       bases_rbegin() {
733198092Srdivacky    return reverse_base_class_iterator(bases_end());
734198092Srdivacky  }
735198092Srdivacky  reverse_base_class_const_iterator bases_rbegin() const {
736198092Srdivacky    return reverse_base_class_const_iterator(bases_end());
737198092Srdivacky  }
738198092Srdivacky  reverse_base_class_iterator bases_rend() {
739198092Srdivacky    return reverse_base_class_iterator(bases_begin());
740198092Srdivacky  }
741198092Srdivacky  reverse_base_class_const_iterator bases_rend() const {
742198092Srdivacky    return reverse_base_class_const_iterator(bases_begin());
743198092Srdivacky  }
744193326Sed
745198092Srdivacky  /// getNumVBases - Retrieves the number of virtual base classes of this
746198092Srdivacky  /// class.
747203955Srdivacky  unsigned getNumVBases() const { return data().NumVBases; }
748198092Srdivacky
749218893Sdim  base_class_iterator vbases_begin() { return data().getVBases(); }
750218893Sdim  base_class_const_iterator vbases_begin() const { return data().getVBases(); }
751203955Srdivacky  base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; }
752203955Srdivacky  base_class_const_iterator vbases_end() const {
753203955Srdivacky    return vbases_begin() + data().NumVBases;
754203955Srdivacky  }
755198092Srdivacky  reverse_base_class_iterator vbases_rbegin() {
756198092Srdivacky    return reverse_base_class_iterator(vbases_end());
757198092Srdivacky  }
758198092Srdivacky  reverse_base_class_const_iterator vbases_rbegin() const {
759198092Srdivacky    return reverse_base_class_const_iterator(vbases_end());
760198092Srdivacky  }
761198092Srdivacky  reverse_base_class_iterator vbases_rend() {
762198092Srdivacky    return reverse_base_class_iterator(vbases_begin());
763198092Srdivacky  }
764198092Srdivacky  reverse_base_class_const_iterator vbases_rend() const {
765198092Srdivacky    return reverse_base_class_const_iterator(vbases_begin());
766198092Srdivacky }
767198092Srdivacky
768202379Srdivacky  /// \brief Determine whether this class has any dependent base classes.
769202379Srdivacky  bool hasAnyDependentBases() const;
770202379Srdivacky
771198092Srdivacky  /// Iterator access to method members.  The method iterator visits
772198092Srdivacky  /// all method members of the class, including non-instance methods,
773198092Srdivacky  /// special methods, etc.
774198092Srdivacky  typedef specific_decl_iterator<CXXMethodDecl> method_iterator;
775198092Srdivacky
776198092Srdivacky  /// method_begin - Method begin iterator.  Iterates in the order the methods
777198092Srdivacky  /// were declared.
778198092Srdivacky  method_iterator method_begin() const {
779198092Srdivacky    return method_iterator(decls_begin());
780198092Srdivacky  }
781198092Srdivacky  /// method_end - Method end iterator.
782198092Srdivacky  method_iterator method_end() const {
783198092Srdivacky    return method_iterator(decls_end());
784198092Srdivacky  }
785198092Srdivacky
786198092Srdivacky  /// Iterator access to constructor members.
787198092Srdivacky  typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator;
788198092Srdivacky
789198092Srdivacky  ctor_iterator ctor_begin() const {
790198092Srdivacky    return ctor_iterator(decls_begin());
791198092Srdivacky  }
792198092Srdivacky  ctor_iterator ctor_end() const {
793198092Srdivacky    return ctor_iterator(decls_end());
794198092Srdivacky  }
795198092Srdivacky
796205219Srdivacky  /// An iterator over friend declarations.  All of these are defined
797205219Srdivacky  /// in DeclFriend.h.
798205219Srdivacky  class friend_iterator;
799205219Srdivacky  friend_iterator friend_begin() const;
800205219Srdivacky  friend_iterator friend_end() const;
801205219Srdivacky  void pushFriendDecl(FriendDecl *FD);
802205219Srdivacky
803207619Srdivacky  /// Determines whether this record has any friends.
804207619Srdivacky  bool hasFriends() const {
805207619Srdivacky    return data().FirstFriend != 0;
806207619Srdivacky  }
807207619Srdivacky
808223017Sdim  /// \brief Determine if we need to declare a default constructor for
809223017Sdim  /// this class.
810210299Sed  ///
811210299Sed  /// This value is used for lazy creation of default constructors.
812223017Sdim  bool needsImplicitDefaultConstructor() const {
813235633Sdim    return !data().UserDeclaredConstructor &&
814223017Sdim           !data().DeclaredDefaultConstructor;
815223017Sdim  }
816223017Sdim
817223017Sdim  /// hasDeclaredDefaultConstructor - Whether this class's default constructor
818223017Sdim  /// has been declared (either explicitly or implicitly).
819210299Sed  bool hasDeclaredDefaultConstructor() const {
820210299Sed    return data().DeclaredDefaultConstructor;
821210299Sed  }
822223017Sdim
823193326Sed  /// hasConstCopyConstructor - Determines whether this class has a
824193326Sed  /// copy constructor that accepts a const-qualified argument.
825223017Sdim  bool hasConstCopyConstructor() const;
826193326Sed
827194711Sed  /// getCopyConstructor - Returns the copy constructor for this class
828223017Sdim  CXXConstructorDecl *getCopyConstructor(unsigned TypeQuals) const;
829194711Sed
830223017Sdim  /// getMoveConstructor - Returns the move constructor for this class
831235633Sdim  CXXConstructorDecl *getMoveConstructor() const;
832223017Sdim
833210299Sed  /// \brief Retrieve the copy-assignment operator for this class, if available.
834210299Sed  ///
835235633Sdim  /// This routine attempts to find the copy-assignment operator for this
836210299Sed  /// class, using a simplistic form of overload resolution.
837210299Sed  ///
838210299Sed  /// \param ArgIsConst Whether the argument to the copy-assignment operator
839210299Sed  /// is const-qualified.
840210299Sed  ///
841210299Sed  /// \returns The copy-assignment operator that can be invoked, or NULL if
842210299Sed  /// a unique copy-assignment operator could not be found.
843210299Sed  CXXMethodDecl *getCopyAssignmentOperator(bool ArgIsConst) const;
844223017Sdim
845223017Sdim  /// getMoveAssignmentOperator - Returns the move assignment operator for this
846223017Sdim  /// class
847223017Sdim  CXXMethodDecl *getMoveAssignmentOperator() const;
848235633Sdim
849193326Sed  /// hasUserDeclaredConstructor - Whether this class has any
850193326Sed  /// user-declared constructors. When true, a default constructor
851193326Sed  /// will not be implicitly declared.
852198092Srdivacky  bool hasUserDeclaredConstructor() const {
853203955Srdivacky    return data().UserDeclaredConstructor;
854198092Srdivacky  }
855193326Sed
856223017Sdim  /// hasUserProvidedDefaultconstructor - Whether this class has a
857223017Sdim  /// user-provided default constructor per C++0x.
858223017Sdim  bool hasUserProvidedDefaultConstructor() const {
859223017Sdim    return data().UserProvidedDefaultConstructor;
860223017Sdim  }
861223017Sdim
862193326Sed  /// hasUserDeclaredCopyConstructor - Whether this class has a
863193326Sed  /// user-declared copy constructor. When false, a copy constructor
864193326Sed  /// will be implicitly declared.
865193326Sed  bool hasUserDeclaredCopyConstructor() const {
866203955Srdivacky    return data().UserDeclaredCopyConstructor;
867193326Sed  }
868193326Sed
869235633Sdim  /// \brief Determine whether this class has had its copy constructor
870210299Sed  /// declared, either via the user or via an implicit declaration.
871210299Sed  ///
872210299Sed  /// This value is used for lazy creation of copy constructors.
873210299Sed  bool hasDeclaredCopyConstructor() const {
874210299Sed    return data().DeclaredCopyConstructor;
875210299Sed  }
876223017Sdim
877223017Sdim  /// hasUserDeclaredMoveOperation - Whether this class has a user-
878223017Sdim  /// declared move constructor or assignment operator. When false, a
879223017Sdim  /// move constructor and assignment operator may be implicitly declared.
880223017Sdim  bool hasUserDeclaredMoveOperation() const {
881223017Sdim    return data().UserDeclaredMoveConstructor ||
882223017Sdim           data().UserDeclaredMoveAssignment;
883223017Sdim  }
884223017Sdim
885223017Sdim  /// \brief Determine whether this class has had a move constructor
886223017Sdim  /// declared by the user.
887223017Sdim  bool hasUserDeclaredMoveConstructor() const {
888223017Sdim    return data().UserDeclaredMoveConstructor;
889223017Sdim  }
890223017Sdim
891223017Sdim  /// \brief Determine whether this class has had a move constructor
892223017Sdim  /// declared.
893223017Sdim  bool hasDeclaredMoveConstructor() const {
894223017Sdim    return data().DeclaredMoveConstructor;
895223017Sdim  }
896223017Sdim
897226890Sdim  /// \brief Determine whether implicit move constructor generation for this
898226890Sdim  /// class has failed before.
899226890Sdim  bool hasFailedImplicitMoveConstructor() const {
900226890Sdim    return data().FailedImplicitMoveConstructor;
901226890Sdim  }
902226890Sdim
903226890Sdim  /// \brief Set whether implicit move constructor generation for this class
904226890Sdim  /// has failed before.
905226890Sdim  void setFailedImplicitMoveConstructor(bool Failed = true) {
906226890Sdim    data().FailedImplicitMoveConstructor = Failed;
907226890Sdim  }
908226890Sdim
909226890Sdim  /// \brief Determine whether this class should get an implicit move
910226890Sdim  /// constructor or if any existing special member function inhibits this.
911226890Sdim  ///
912226890Sdim  /// Covers all bullets of C++0x [class.copy]p9 except the last, that the
913226890Sdim  /// constructor wouldn't be deleted, which is only looked up from a cached
914226890Sdim  /// result.
915226890Sdim  bool needsImplicitMoveConstructor() const {
916226890Sdim    return !hasFailedImplicitMoveConstructor() &&
917226890Sdim           !hasDeclaredMoveConstructor() &&
918226890Sdim           !hasUserDeclaredCopyConstructor() &&
919226890Sdim           !hasUserDeclaredCopyAssignment() &&
920226890Sdim           !hasUserDeclaredMoveAssignment() &&
921226890Sdim           !hasUserDeclaredDestructor();
922226890Sdim  }
923226890Sdim
924193326Sed  /// hasUserDeclaredCopyAssignment - Whether this class has a
925193326Sed  /// user-declared copy assignment operator. When false, a copy
926193326Sed  /// assigment operator will be implicitly declared.
927193326Sed  bool hasUserDeclaredCopyAssignment() const {
928203955Srdivacky    return data().UserDeclaredCopyAssignment;
929193326Sed  }
930193326Sed
931235633Sdim  /// \brief Determine whether this class has had its copy assignment operator
932210299Sed  /// declared, either via the user or via an implicit declaration.
933210299Sed  ///
934210299Sed  /// This value is used for lazy creation of copy assignment operators.
935210299Sed  bool hasDeclaredCopyAssignment() const {
936210299Sed    return data().DeclaredCopyAssignment;
937210299Sed  }
938223017Sdim
939223017Sdim  /// \brief Determine whether this class has had a move assignment
940223017Sdim  /// declared by the user.
941223017Sdim  bool hasUserDeclaredMoveAssignment() const {
942223017Sdim    return data().UserDeclaredMoveAssignment;
943223017Sdim  }
944223017Sdim
945223017Sdim  /// hasDeclaredMoveAssignment - Whether this class has a
946223017Sdim  /// declared move assignment operator.
947223017Sdim  bool hasDeclaredMoveAssignment() const {
948223017Sdim    return data().DeclaredMoveAssignment;
949223017Sdim  }
950223017Sdim
951226890Sdim  /// \brief Determine whether implicit move assignment generation for this
952226890Sdim  /// class has failed before.
953226890Sdim  bool hasFailedImplicitMoveAssignment() const {
954226890Sdim    return data().FailedImplicitMoveAssignment;
955226890Sdim  }
956226890Sdim
957226890Sdim  /// \brief Set whether implicit move assignment generation for this class
958226890Sdim  /// has failed before.
959226890Sdim  void setFailedImplicitMoveAssignment(bool Failed = true) {
960226890Sdim    data().FailedImplicitMoveAssignment = Failed;
961226890Sdim  }
962226890Sdim
963226890Sdim  /// \brief Determine whether this class should get an implicit move
964226890Sdim  /// assignment operator or if any existing special member function inhibits
965226890Sdim  /// this.
966226890Sdim  ///
967226890Sdim  /// Covers all bullets of C++0x [class.copy]p20 except the last, that the
968226890Sdim  /// constructor wouldn't be deleted.
969226890Sdim  bool needsImplicitMoveAssignment() const {
970226890Sdim    return !hasFailedImplicitMoveAssignment() &&
971226890Sdim           !hasDeclaredMoveAssignment() &&
972226890Sdim           !hasUserDeclaredCopyConstructor() &&
973226890Sdim           !hasUserDeclaredCopyAssignment() &&
974226890Sdim           !hasUserDeclaredMoveConstructor() &&
975226890Sdim           !hasUserDeclaredDestructor();
976226890Sdim  }
977226890Sdim
978193326Sed  /// hasUserDeclaredDestructor - Whether this class has a
979193326Sed  /// user-declared destructor. When false, a destructor will be
980193326Sed  /// implicitly declared.
981203955Srdivacky  bool hasUserDeclaredDestructor() const {
982203955Srdivacky    return data().UserDeclaredDestructor;
983203955Srdivacky  }
984193326Sed
985210299Sed  /// \brief Determine whether this class has had its destructor declared,
986210299Sed  /// either via the user or via an implicit declaration.
987210299Sed  ///
988210299Sed  /// This value is used for lazy creation of destructors.
989210299Sed  bool hasDeclaredDestructor() const { return data().DeclaredDestructor; }
990218893Sdim
991235633Sdim  /// \brief Determine whether this class describes a lambda function object.
992235633Sdim  bool isLambda() const { return hasDefinition() && data().IsLambda; }
993235633Sdim
994235633Sdim  /// \brief For a closure type, retrieve the mapping from captured
995235633Sdim  /// variables and this to the non-static data members that store the
996235633Sdim  /// values or references of the captures.
997235633Sdim  ///
998235633Sdim  /// \param Captures Will be populated with the mapping from captured
999235633Sdim  /// variables to the corresponding fields.
1000235633Sdim  ///
1001235633Sdim  /// \param ThisCapture Will be set to the field declaration for the
1002235633Sdim  /// 'this' capture.
1003235633Sdim  void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures,
1004235633Sdim                        FieldDecl *&ThisCapture) const;
1005235633Sdim
1006235633Sdim  typedef const LambdaExpr::Capture* capture_const_iterator;
1007235633Sdim  capture_const_iterator captures_begin() const {
1008235633Sdim    return isLambda() ? getLambdaData().Captures : NULL;
1009235633Sdim  }
1010235633Sdim  capture_const_iterator captures_end() const {
1011235633Sdim    return isLambda() ? captures_begin() + getLambdaData().NumCaptures : NULL;
1012235633Sdim  }
1013235633Sdim
1014193326Sed  /// getConversions - Retrieve the overload set containing all of the
1015193326Sed  /// conversion functions in this class.
1016202879Srdivacky  UnresolvedSetImpl *getConversionFunctions() {
1017203955Srdivacky    return &data().Conversions;
1018193326Sed  }
1019202879Srdivacky  const UnresolvedSetImpl *getConversionFunctions() const {
1020203955Srdivacky    return &data().Conversions;
1021193326Sed  }
1022193326Sed
1023202879Srdivacky  typedef UnresolvedSetImpl::iterator conversion_iterator;
1024203955Srdivacky  conversion_iterator conversion_begin() const {
1025203955Srdivacky    return getConversionFunctions()->begin();
1026203955Srdivacky  }
1027203955Srdivacky  conversion_iterator conversion_end() const {
1028203955Srdivacky    return getConversionFunctions()->end();
1029203955Srdivacky  }
1030199990Srdivacky
1031206084Srdivacky  /// Removes a conversion function from this class.  The conversion
1032206084Srdivacky  /// function must currently be a member of this class.  Furthermore,
1033206084Srdivacky  /// this class must currently be in the process of being defined.
1034206084Srdivacky  void removeConversion(const NamedDecl *Old);
1035206084Srdivacky
1036198092Srdivacky  /// getVisibleConversionFunctions - get all conversion functions visible
1037198092Srdivacky  /// in current class; including conversion function templates.
1038202879Srdivacky  const UnresolvedSetImpl *getVisibleConversionFunctions();
1039199990Srdivacky
1040193326Sed  /// isAggregate - Whether this class is an aggregate (C++
1041193326Sed  /// [dcl.init.aggr]), which is a class with no user-declared
1042193326Sed  /// constructors, no private or protected non-static data members,
1043193326Sed  /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1).
1044203955Srdivacky  bool isAggregate() const { return data().Aggregate; }
1045193326Sed
1046245431Sdim  /// hasInClassInitializer - Whether this class has any in-class initializers
1047245431Sdim  /// for non-static data members.
1048245431Sdim  bool hasInClassInitializer() const { return data().HasInClassInitializer; }
1049245431Sdim
1050193326Sed  /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class
1051193326Sed  /// that is an aggregate that has no non-static non-POD data members, no
1052193326Sed  /// reference data members, no user-defined copy assignment operator and no
1053193326Sed  /// user-defined destructor.
1054203955Srdivacky  bool isPOD() const { return data().PlainOldData; }
1055193326Sed
1056235633Sdim  /// \brief True if this class is C-like, without C++-specific features, e.g.
1057235633Sdim  /// it contains only public fields, no bases, tag kind is not 'class', etc.
1058235633Sdim  bool isCLike() const;
1059235633Sdim
1060198092Srdivacky  /// isEmpty - Whether this class is empty (C++0x [meta.unary.prop]), which
1061198092Srdivacky  /// means it has a virtual function, virtual base, data member (other than
1062198092Srdivacky  /// 0-width bit-field) or inherits from a non-empty class. Does NOT include
1063198092Srdivacky  /// a check for union-ness.
1064203955Srdivacky  bool isEmpty() const { return data().Empty; }
1065198092Srdivacky
1066193326Sed  /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]),
1067193326Sed  /// which means that the class contains or inherits a virtual function.
1068203955Srdivacky  bool isPolymorphic() const { return data().Polymorphic; }
1069193326Sed
1070193326Sed  /// isAbstract - Whether this class is abstract (C++ [class.abstract]),
1071193326Sed  /// which means that the class contains or inherits a pure virtual function.
1072203955Srdivacky  bool isAbstract() const { return data().Abstract; }
1073198092Srdivacky
1074221345Sdim  /// isStandardLayout - Whether this class has standard layout
1075221345Sdim  /// (C++ [class]p7)
1076221345Sdim  bool isStandardLayout() const { return data().IsStandardLayout; }
1077221345Sdim
1078223017Sdim  /// \brief Whether this class, or any of its class subobjects, contains a
1079223017Sdim  /// mutable field.
1080223017Sdim  bool hasMutableFields() const { return data().HasMutableFields; }
1081235633Sdim
1082235633Sdim  /// hasTrivialDefaultConstructor - Whether this class has a trivial default
1083235633Sdim  /// constructor (C++11 [class.ctor]p5).
1084223017Sdim  bool hasTrivialDefaultConstructor() const {
1085223017Sdim    return data().HasTrivialDefaultConstructor &&
1086223017Sdim           (!data().UserDeclaredConstructor ||
1087223017Sdim             data().DeclaredDefaultConstructor);
1088223017Sdim  }
1089198092Srdivacky
1090235633Sdim  /// hasConstexprNonCopyMoveConstructor - Whether this class has at least one
1091235633Sdim  /// constexpr constructor other than the copy or move constructors.
1092226890Sdim  bool hasConstexprNonCopyMoveConstructor() const {
1093235633Sdim    return data().HasConstexprNonCopyMoveConstructor ||
1094235633Sdim           (!hasUserDeclaredConstructor() &&
1095235633Sdim            defaultedDefaultConstructorIsConstexpr());
1096221345Sdim  }
1097221345Sdim
1098235633Sdim  /// defaultedDefaultConstructorIsConstexpr - Whether a defaulted default
1099235633Sdim  /// constructor for this class would be constexpr.
1100235633Sdim  bool defaultedDefaultConstructorIsConstexpr() const {
1101245431Sdim    return data().DefaultedDefaultConstructorIsConstexpr &&
1102245431Sdim           (!isUnion() || hasInClassInitializer());
1103235633Sdim  }
1104235633Sdim
1105235633Sdim  /// hasConstexprDefaultConstructor - Whether this class has a constexpr
1106235633Sdim  /// default constructor.
1107235633Sdim  bool hasConstexprDefaultConstructor() const {
1108235633Sdim    return data().HasConstexprDefaultConstructor ||
1109235633Sdim           (!data().UserDeclaredConstructor &&
1110245431Sdim            defaultedDefaultConstructorIsConstexpr());
1111235633Sdim  }
1112235633Sdim
1113198092Srdivacky  // hasTrivialCopyConstructor - Whether this class has a trivial copy
1114221345Sdim  // constructor (C++ [class.copy]p6, C++0x [class.copy]p13)
1115203955Srdivacky  bool hasTrivialCopyConstructor() const {
1116203955Srdivacky    return data().HasTrivialCopyConstructor;
1117203955Srdivacky  }
1118198092Srdivacky
1119221345Sdim  // hasTrivialMoveConstructor - Whether this class has a trivial move
1120221345Sdim  // constructor (C++0x [class.copy]p13)
1121221345Sdim  bool hasTrivialMoveConstructor() const {
1122221345Sdim    return data().HasTrivialMoveConstructor;
1123221345Sdim  }
1124221345Sdim
1125198092Srdivacky  // hasTrivialCopyAssignment - Whether this class has a trivial copy
1126221345Sdim  // assignment operator (C++ [class.copy]p11, C++0x [class.copy]p27)
1127203955Srdivacky  bool hasTrivialCopyAssignment() const {
1128203955Srdivacky    return data().HasTrivialCopyAssignment;
1129203955Srdivacky  }
1130198092Srdivacky
1131221345Sdim  // hasTrivialMoveAssignment - Whether this class has a trivial move
1132221345Sdim  // assignment operator (C++0x [class.copy]p27)
1133221345Sdim  bool hasTrivialMoveAssignment() const {
1134221345Sdim    return data().HasTrivialMoveAssignment;
1135221345Sdim  }
1136221345Sdim
1137193326Sed  // hasTrivialDestructor - Whether this class has a trivial destructor
1138193326Sed  // (C++ [class.dtor]p3)
1139203955Srdivacky  bool hasTrivialDestructor() const { return data().HasTrivialDestructor; }
1140198092Srdivacky
1141235633Sdim  // hasIrrelevantDestructor - Whether this class has a destructor which has no
1142235633Sdim  // semantic effect. Any such destructor will be trivial, public, defaulted
1143235633Sdim  // and not deleted, and will call only irrelevant destructors.
1144235633Sdim  bool hasIrrelevantDestructor() const {
1145235633Sdim    return data().HasIrrelevantDestructor;
1146235633Sdim  }
1147235633Sdim
1148235633Sdim  // hasNonLiteralTypeFieldsOrBases - Whether this class has a non-literal or
1149235633Sdim  // volatile type non-static data member or base class.
1150221345Sdim  bool hasNonLiteralTypeFieldsOrBases() const {
1151221345Sdim    return data().HasNonLiteralTypeFieldsOrBases;
1152221345Sdim  }
1153221345Sdim
1154221345Sdim  // isTriviallyCopyable - Whether this class is considered trivially copyable
1155223017Sdim  // (C++0x [class]p6).
1156221345Sdim  bool isTriviallyCopyable() const;
1157221345Sdim
1158223017Sdim  // isTrivial - Whether this class is considered trivial
1159223017Sdim  //
1160223017Sdim  // C++0x [class]p6
1161223017Sdim  //    A trivial class is a class that has a trivial default constructor and
1162223017Sdim  //    is trivially copiable.
1163223017Sdim  bool isTrivial() const {
1164223017Sdim    return isTriviallyCopyable() && hasTrivialDefaultConstructor();
1165223017Sdim  }
1166223017Sdim
1167226890Sdim  // isLiteral - Whether this class is a literal type.
1168226890Sdim  //
1169235633Sdim  // C++11 [basic.types]p10
1170226890Sdim  //   A class type that has all the following properties:
1171235633Sdim  //     -- it has a trivial destructor
1172226890Sdim  //     -- every constructor call and full-expression in the
1173226890Sdim  //        brace-or-equal-intializers for non-static data members (if any) is
1174226890Sdim  //        a constant expression.
1175226890Sdim  //     -- it is an aggregate type or has at least one constexpr constructor or
1176226890Sdim  //        constructor template that is not a copy or move constructor, and
1177235633Sdim  //     -- all of its non-static data members and base classes are of literal
1178235633Sdim  //        types
1179226890Sdim  //
1180235633Sdim  // We resolve DR1361 by ignoring the second bullet. We resolve DR1452 by
1181235633Sdim  // treating types with trivial default constructors as literal types.
1182226890Sdim  bool isLiteral() const {
1183226890Sdim    return hasTrivialDestructor() &&
1184235633Sdim           (isAggregate() || hasConstexprNonCopyMoveConstructor() ||
1185235633Sdim            hasTrivialDefaultConstructor()) &&
1186226890Sdim           !hasNonLiteralTypeFieldsOrBases();
1187226890Sdim  }
1188226890Sdim
1189193326Sed  /// \brief If this record is an instantiation of a member class,
1190193326Sed  /// retrieves the member class from which it was instantiated.
1191193326Sed  ///
1192193326Sed  /// This routine will return non-NULL for (non-templated) member
1193193326Sed  /// classes of class templates. For example, given:
1194193326Sed  ///
1195245431Sdim  /// @code
1196193326Sed  /// template<typename T>
1197193326Sed  /// struct X {
1198193326Sed  ///   struct A { };
1199193326Sed  /// };
1200245431Sdim  /// @endcode
1201193326Sed  ///
1202193326Sed  /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
1203193326Sed  /// whose parent is the class template specialization X<int>. For
1204193326Sed  /// this declaration, getInstantiatedFromMemberClass() will return
1205193326Sed  /// the CXXRecordDecl X<T>::A. When a complete definition of
1206193326Sed  /// X<int>::A is required, it will be instantiated from the
1207193326Sed  /// declaration returned by getInstantiatedFromMemberClass().
1208198092Srdivacky  CXXRecordDecl *getInstantiatedFromMemberClass() const;
1209235633Sdim
1210198092Srdivacky  /// \brief If this class is an instantiation of a member class of a
1211198092Srdivacky  /// class template specialization, retrieves the member specialization
1212198092Srdivacky  /// information.
1213198092Srdivacky  MemberSpecializationInfo *getMemberSpecializationInfo() const;
1214235633Sdim
1215193326Sed  /// \brief Specify that this record is an instantiation of the
1216193326Sed  /// member class RD.
1217198092Srdivacky  void setInstantiationOfMemberClass(CXXRecordDecl *RD,
1218198092Srdivacky                                     TemplateSpecializationKind TSK);
1219193326Sed
1220193326Sed  /// \brief Retrieves the class template that is described by this
1221193326Sed  /// class declaration.
1222193326Sed  ///
1223193326Sed  /// Every class template is represented as a ClassTemplateDecl and a
1224193326Sed  /// CXXRecordDecl. The former contains template properties (such as
1225193326Sed  /// the template parameter lists) while the latter contains the
1226193326Sed  /// actual description of the template's
1227193326Sed  /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
1228193326Sed  /// CXXRecordDecl that from a ClassTemplateDecl, while
1229193326Sed  /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
1230193326Sed  /// a CXXRecordDecl.
1231193326Sed  ClassTemplateDecl *getDescribedClassTemplate() const {
1232193326Sed    return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>();
1233193326Sed  }
1234193326Sed
1235193326Sed  void setDescribedClassTemplate(ClassTemplateDecl *Template) {
1236193326Sed    TemplateOrInstantiation = Template;
1237193326Sed  }
1238193326Sed
1239198092Srdivacky  /// \brief Determine whether this particular class is a specialization or
1240198092Srdivacky  /// instantiation of a class template or member class of a class template,
1241198092Srdivacky  /// and how it was instantiated or specialized.
1242200583Srdivacky  TemplateSpecializationKind getTemplateSpecializationKind() const;
1243235633Sdim
1244198092Srdivacky  /// \brief Set the kind of specialization or template instantiation this is.
1245198092Srdivacky  void setTemplateSpecializationKind(TemplateSpecializationKind TSK);
1246198092Srdivacky
1247193326Sed  /// getDestructor - Returns the destructor decl for this class.
1248210299Sed  CXXDestructorDecl *getDestructor() const;
1249198092Srdivacky
1250195099Sed  /// isLocalClass - If the class is a local class [class.local], returns
1251195099Sed  /// the enclosing function declaration.
1252195099Sed  const FunctionDecl *isLocalClass() const {
1253195099Sed    if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
1254195099Sed      return RD->isLocalClass();
1255198092Srdivacky
1256195099Sed    return dyn_cast<FunctionDecl>(getDeclContext());
1257195099Sed  }
1258198092Srdivacky
1259198092Srdivacky  /// \brief Determine whether this class is derived from the class \p Base.
1260198092Srdivacky  ///
1261198092Srdivacky  /// This routine only determines whether this class is derived from \p Base,
1262198092Srdivacky  /// but does not account for factors that may make a Derived -> Base class
1263198092Srdivacky  /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1264198092Srdivacky  /// base class subobjects.
1265198092Srdivacky  ///
1266198092Srdivacky  /// \param Base the base class we are searching for.
1267198092Srdivacky  ///
1268198092Srdivacky  /// \returns true if this class is derived from Base, false otherwise.
1269218893Sdim  bool isDerivedFrom(const CXXRecordDecl *Base) const;
1270235633Sdim
1271198092Srdivacky  /// \brief Determine whether this class is derived from the type \p Base.
1272198092Srdivacky  ///
1273198092Srdivacky  /// This routine only determines whether this class is derived from \p Base,
1274198092Srdivacky  /// but does not account for factors that may make a Derived -> Base class
1275198092Srdivacky  /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1276198092Srdivacky  /// base class subobjects.
1277198092Srdivacky  ///
1278198092Srdivacky  /// \param Base the base class we are searching for.
1279198092Srdivacky  ///
1280198092Srdivacky  /// \param Paths will contain the paths taken from the current class to the
1281198092Srdivacky  /// given \p Base class.
1282198092Srdivacky  ///
1283198092Srdivacky  /// \returns true if this class is derived from Base, false otherwise.
1284198092Srdivacky  ///
1285235633Sdim  /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than
1286235633Sdim  /// tangling input and output in \p Paths
1287218893Sdim  bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const;
1288200583Srdivacky
1289204643Srdivacky  /// \brief Determine whether this class is virtually derived from
1290204643Srdivacky  /// the class \p Base.
1291204643Srdivacky  ///
1292204643Srdivacky  /// This routine only determines whether this class is virtually
1293204643Srdivacky  /// derived from \p Base, but does not account for factors that may
1294204643Srdivacky  /// make a Derived -> Base class ill-formed, such as
1295204643Srdivacky  /// private/protected inheritance or multiple, ambiguous base class
1296204643Srdivacky  /// subobjects.
1297204643Srdivacky  ///
1298204643Srdivacky  /// \param Base the base class we are searching for.
1299204643Srdivacky  ///
1300204643Srdivacky  /// \returns true if this class is virtually derived from Base,
1301204643Srdivacky  /// false otherwise.
1302245431Sdim  bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const;
1303204643Srdivacky
1304200583Srdivacky  /// \brief Determine whether this class is provably not derived from
1305200583Srdivacky  /// the type \p Base.
1306200583Srdivacky  bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
1307200583Srdivacky
1308200583Srdivacky  /// \brief Function type used by forallBases() as a callback.
1309200583Srdivacky  ///
1310245431Sdim  /// \param BaseDefinition the definition of the base class
1311200583Srdivacky  ///
1312200583Srdivacky  /// \returns true if this base matched the search criteria
1313200583Srdivacky  typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition,
1314200583Srdivacky                                   void *UserData);
1315200583Srdivacky
1316200583Srdivacky  /// \brief Determines if the given callback holds for all the direct
1317200583Srdivacky  /// or indirect base classes of this type.
1318200583Srdivacky  ///
1319200583Srdivacky  /// The class itself does not count as a base class.  This routine
1320200583Srdivacky  /// returns false if the class has non-computable base classes.
1321235633Sdim  ///
1322200583Srdivacky  /// \param AllowShortCircuit if false, forces the callback to be called
1323200583Srdivacky  /// for every base class, even if a dependent or non-matching base was
1324200583Srdivacky  /// found.
1325200583Srdivacky  bool forallBases(ForallBasesCallback *BaseMatches, void *UserData,
1326200583Srdivacky                   bool AllowShortCircuit = true) const;
1327235633Sdim
1328235633Sdim  /// \brief Function type used by lookupInBases() to determine whether a
1329198092Srdivacky  /// specific base class subobject matches the lookup criteria.
1330198092Srdivacky  ///
1331235633Sdim  /// \param Specifier the base-class specifier that describes the inheritance
1332198092Srdivacky  /// from the base class we are trying to match.
1333198092Srdivacky  ///
1334235633Sdim  /// \param Path the current path, from the most-derived class down to the
1335198092Srdivacky  /// base named by the \p Specifier.
1336198092Srdivacky  ///
1337198092Srdivacky  /// \param UserData a single pointer to user-specified data, provided to
1338198092Srdivacky  /// lookupInBases().
1339198092Srdivacky  ///
1340198092Srdivacky  /// \returns true if this base matched the search criteria, false otherwise.
1341199482Srdivacky  typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier,
1342198092Srdivacky                                   CXXBasePath &Path,
1343198092Srdivacky                                   void *UserData);
1344235633Sdim
1345198092Srdivacky  /// \brief Look for entities within the base classes of this C++ class,
1346198092Srdivacky  /// transitively searching all base class subobjects.
1347198092Srdivacky  ///
1348235633Sdim  /// This routine uses the callback function \p BaseMatches to find base
1349198092Srdivacky  /// classes meeting some search criteria, walking all base class subobjects
1350235633Sdim  /// and populating the given \p Paths structure with the paths through the
1351198092Srdivacky  /// inheritance hierarchy that resulted in a match. On a successful search,
1352198092Srdivacky  /// the \p Paths structure can be queried to retrieve the matching paths and
1353198092Srdivacky  /// to determine if there were any ambiguities.
1354198092Srdivacky  ///
1355198092Srdivacky  /// \param BaseMatches callback function used to determine whether a given
1356198092Srdivacky  /// base matches the user-defined search criteria.
1357198092Srdivacky  ///
1358198092Srdivacky  /// \param UserData user data pointer that will be provided to \p BaseMatches.
1359198092Srdivacky  ///
1360198092Srdivacky  /// \param Paths used to record the paths from this class to its base class
1361198092Srdivacky  /// subobjects that match the search criteria.
1362198092Srdivacky  ///
1363198092Srdivacky  /// \returns true if there exists any path from this class to a base class
1364198092Srdivacky  /// subobject that matches the search criteria.
1365198092Srdivacky  bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData,
1366199482Srdivacky                     CXXBasePaths &Paths) const;
1367235633Sdim
1368198092Srdivacky  /// \brief Base-class lookup callback that determines whether the given
1369198092Srdivacky  /// base class specifier refers to a specific class declaration.
1370198092Srdivacky  ///
1371198092Srdivacky  /// This callback can be used with \c lookupInBases() to determine whether
1372198092Srdivacky  /// a given derived class has is a base class subobject of a particular type.
1373198092Srdivacky  /// The user data pointer should refer to the canonical CXXRecordDecl of the
1374198092Srdivacky  /// base class that we are searching for.
1375199482Srdivacky  static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
1376199482Srdivacky                            CXXBasePath &Path, void *BaseRecord);
1377204643Srdivacky
1378204643Srdivacky  /// \brief Base-class lookup callback that determines whether the
1379204643Srdivacky  /// given base class specifier refers to a specific class
1380204643Srdivacky  /// declaration and describes virtual derivation.
1381204643Srdivacky  ///
1382204643Srdivacky  /// This callback can be used with \c lookupInBases() to determine
1383204643Srdivacky  /// whether a given derived class has is a virtual base class
1384204643Srdivacky  /// subobject of a particular type.  The user data pointer should
1385204643Srdivacky  /// refer to the canonical CXXRecordDecl of the base class that we
1386204643Srdivacky  /// are searching for.
1387204643Srdivacky  static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
1388204643Srdivacky                                   CXXBasePath &Path, void *BaseRecord);
1389235633Sdim
1390198092Srdivacky  /// \brief Base-class lookup callback that determines whether there exists
1391198092Srdivacky  /// a tag with the given name.
1392198092Srdivacky  ///
1393198092Srdivacky  /// This callback can be used with \c lookupInBases() to find tag members
1394198092Srdivacky  /// of the given name within a C++ class hierarchy. The user data pointer
1395198092Srdivacky  /// is an opaque \c DeclarationName pointer.
1396199482Srdivacky  static bool FindTagMember(const CXXBaseSpecifier *Specifier,
1397199482Srdivacky                            CXXBasePath &Path, void *Name);
1398198092Srdivacky
1399198092Srdivacky  /// \brief Base-class lookup callback that determines whether there exists
1400198092Srdivacky  /// a member with the given name.
1401198092Srdivacky  ///
1402198092Srdivacky  /// This callback can be used with \c lookupInBases() to find members
1403198092Srdivacky  /// of the given name within a C++ class hierarchy. The user data pointer
1404198092Srdivacky  /// is an opaque \c DeclarationName pointer.
1405199482Srdivacky  static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
1406199482Srdivacky                                 CXXBasePath &Path, void *Name);
1407235633Sdim
1408198092Srdivacky  /// \brief Base-class lookup callback that determines whether there exists
1409198092Srdivacky  /// a member with the given name that can be used in a nested-name-specifier.
1410198092Srdivacky  ///
1411198092Srdivacky  /// This callback can be used with \c lookupInBases() to find membes of
1412198092Srdivacky  /// the given name within a C++ class hierarchy that can occur within
1413198092Srdivacky  /// nested-name-specifiers.
1414199482Srdivacky  static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier,
1415198092Srdivacky                                            CXXBasePath &Path,
1416198092Srdivacky                                            void *UserData);
1417206084Srdivacky
1418206084Srdivacky  /// \brief Retrieve the final overriders for each virtual member
1419206084Srdivacky  /// function in the class hierarchy where this class is the
1420206084Srdivacky  /// most-derived class in the class hierarchy.
1421206084Srdivacky  void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const;
1422206084Srdivacky
1423218893Sdim  /// \brief Get the indirect primary bases for this class.
1424218893Sdim  void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const;
1425218893Sdim
1426193326Sed  /// viewInheritance - Renders and displays an inheritance diagram
1427193326Sed  /// for this C++ class and all of its base classes (transitively) using
1428193326Sed  /// GraphViz.
1429193326Sed  void viewInheritance(ASTContext& Context) const;
1430193326Sed
1431202879Srdivacky  /// MergeAccess - Calculates the access of a decl that is reached
1432202879Srdivacky  /// along a path.
1433202879Srdivacky  static AccessSpecifier MergeAccess(AccessSpecifier PathAccess,
1434202879Srdivacky                                     AccessSpecifier DeclAccess) {
1435202879Srdivacky    assert(DeclAccess != AS_none);
1436202879Srdivacky    if (DeclAccess == AS_private) return AS_none;
1437202879Srdivacky    return (PathAccess > DeclAccess ? PathAccess : DeclAccess);
1438202879Srdivacky  }
1439202879Srdivacky
1440218893Sdim  /// \brief Indicates that the definition of this class is now complete.
1441218893Sdim  virtual void completeDefinition();
1442218893Sdim
1443235633Sdim  /// \brief Indicates that the definition of this class is now complete,
1444218893Sdim  /// and provides a final overrider map to help determine
1445235633Sdim  ///
1446218893Sdim  /// \param FinalOverriders The final overrider map for this class, which can
1447218893Sdim  /// be provided as an optimization for abstract-class checking. If NULL,
1448218893Sdim  /// final overriders will be computed if they are needed to complete the
1449218893Sdim  /// definition.
1450218893Sdim  void completeDefinition(CXXFinalOverriderMap *FinalOverriders);
1451235633Sdim
1452218893Sdim  /// \brief Determine whether this class may end up being abstract, even though
1453218893Sdim  /// it is not yet known to be abstract.
1454218893Sdim  ///
1455218893Sdim  /// \returns true if this class is not known to be abstract but has any
1456218893Sdim  /// base classes that are abstract. In this case, \c completeDefinition()
1457218893Sdim  /// will need to compute final overriders to determine whether the class is
1458218893Sdim  /// actually abstract.
1459218893Sdim  bool mayBeAbstract() const;
1460235633Sdim
1461235633Sdim  /// \brief If this is the closure type of a lambda expression, retrieve the
1462235633Sdim  /// number to be used for name mangling in the Itanium C++ ABI.
1463235633Sdim  ///
1464235633Sdim  /// Zero indicates that this closure type has internal linkage, so the
1465235633Sdim  /// mangling number does not matter, while a non-zero value indicates which
1466235633Sdim  /// lambda expression this is in this particular context.
1467235633Sdim  unsigned getLambdaManglingNumber() const {
1468235633Sdim    assert(isLambda() && "Not a lambda closure type!");
1469235633Sdim    return getLambdaData().ManglingNumber;
1470235633Sdim  }
1471218893Sdim
1472235633Sdim  /// \brief Retrieve the declaration that provides additional context for a
1473235633Sdim  /// lambda, when the normal declaration context is not specific enough.
1474235633Sdim  ///
1475235633Sdim  /// Certain contexts (default arguments of in-class function parameters and
1476235633Sdim  /// the initializers of data members) have separate name mangling rules for
1477235633Sdim  /// lambdas within the Itanium C++ ABI. For these cases, this routine provides
1478235633Sdim  /// the declaration in which the lambda occurs, e.g., the function parameter
1479235633Sdim  /// or the non-static data member. Otherwise, it returns NULL to imply that
1480235633Sdim  /// the declaration context suffices.
1481235633Sdim  Decl *getLambdaContextDecl() const {
1482235633Sdim    assert(isLambda() && "Not a lambda closure type!");
1483235633Sdim    return getLambdaData().ContextDecl;
1484235633Sdim  }
1485235633Sdim
1486235633Sdim  /// \brief Set the mangling number and context declaration for a lambda
1487235633Sdim  /// class.
1488235633Sdim  void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl) {
1489235633Sdim    getLambdaData().ManglingNumber = ManglingNumber;
1490235633Sdim    getLambdaData().ContextDecl = ContextDecl;
1491235633Sdim  }
1492235633Sdim
1493235633Sdim  /// \brief Determine whether this lambda expression was known to be dependent
1494235633Sdim  /// at the time it was created, even if its context does not appear to be
1495235633Sdim  /// dependent.
1496235633Sdim  ///
1497235633Sdim  /// This flag is a workaround for an issue with parsing, where default
1498235633Sdim  /// arguments are parsed before their enclosing function declarations have
1499235633Sdim  /// been created. This means that any lambda expressions within those
1500235633Sdim  /// default arguments will have as their DeclContext the context enclosing
1501235633Sdim  /// the function declaration, which may be non-dependent even when the
1502235633Sdim  /// function declaration itself is dependent. This flag indicates when we
1503235633Sdim  /// know that the lambda is dependent despite that.
1504235633Sdim  bool isDependentLambda() const {
1505235633Sdim    return isLambda() && getLambdaData().Dependent;
1506235633Sdim  }
1507245431Sdim
1508245431Sdim  TypeSourceInfo *getLambdaTypeInfo() const {
1509245431Sdim    return getLambdaData().MethodTyInfo;
1510245431Sdim  }
1511245431Sdim
1512203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1513203955Srdivacky  static bool classofKind(Kind K) {
1514210299Sed    return K >= firstCXXRecord && K <= lastCXXRecord;
1515193326Sed  }
1516210299Sed
1517212904Sdim  friend class ASTDeclReader;
1518212904Sdim  friend class ASTDeclWriter;
1519218893Sdim  friend class ASTReader;
1520218893Sdim  friend class ASTWriter;
1521193326Sed};
1522193326Sed
1523193326Sed/// CXXMethodDecl - Represents a static or instance method of a
1524193326Sed/// struct/union/class.
1525193326Sedclass CXXMethodDecl : public FunctionDecl {
1526235633Sdim  virtual void anchor();
1527193326Sedprotected:
1528221345Sdim  CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation StartLoc,
1529212904Sdim                const DeclarationNameInfo &NameInfo,
1530212904Sdim                QualType T, TypeSourceInfo *TInfo,
1531221345Sdim                bool isStatic, StorageClass SCAsWritten, bool isInline,
1532226890Sdim                bool isConstexpr, SourceLocation EndLocation)
1533221345Sdim    : FunctionDecl(DK, RD, StartLoc, NameInfo, T, TInfo,
1534221345Sdim                   (isStatic ? SC_Static : SC_None),
1535226890Sdim                   SCAsWritten, isInline, isConstexpr) {
1536235633Sdim    if (EndLocation.isValid())
1537235633Sdim      setRangeEnd(EndLocation);
1538235633Sdim  }
1539193326Sed
1540193326Sedpublic:
1541193326Sed  static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1542221345Sdim                               SourceLocation StartLoc,
1543212904Sdim                               const DeclarationNameInfo &NameInfo,
1544212904Sdim                               QualType T, TypeSourceInfo *TInfo,
1545221345Sdim                               bool isStatic,
1546221345Sdim                               StorageClass SCAsWritten,
1547221345Sdim                               bool isInline,
1548226890Sdim                               bool isConstexpr,
1549221345Sdim                               SourceLocation EndLocation);
1550198092Srdivacky
1551235633Sdim  static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1552235633Sdim
1553212904Sdim  bool isStatic() const { return getStorageClass() == SC_Static; }
1554193326Sed  bool isInstance() const { return !isStatic(); }
1555193326Sed
1556245431Sdim  bool isConst() const { return getType()->castAs<FunctionType>()->isConst(); }
1557245431Sdim  bool isVolatile() const { return getType()->castAs<FunctionType>()->isVolatile(); }
1558245431Sdim
1559198092Srdivacky  bool isVirtual() const {
1560235633Sdim    CXXMethodDecl *CD =
1561198092Srdivacky      cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl());
1562198092Srdivacky
1563245431Sdim    // Methods declared in interfaces are automatically (pure) virtual.
1564245431Sdim    if (CD->isVirtualAsWritten() ||
1565245431Sdim          (CD->getParent()->isInterface() && CD->isUserProvided()))
1566198092Srdivacky      return true;
1567235633Sdim
1568198092Srdivacky    return (CD->begin_overridden_methods() != CD->end_overridden_methods());
1569193326Sed  }
1570206084Srdivacky
1571198092Srdivacky  /// \brief Determine whether this is a usual deallocation function
1572198092Srdivacky  /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded
1573198092Srdivacky  /// delete or delete[] operator with a particular signature.
1574198092Srdivacky  bool isUsualDeallocationFunction() const;
1575235633Sdim
1576207619Srdivacky  /// \brief Determine whether this is a copy-assignment operator, regardless
1577207619Srdivacky  /// of whether it was declared implicitly or explicitly.
1578207619Srdivacky  bool isCopyAssignmentOperator() const;
1579223017Sdim
1580223017Sdim  /// \brief Determine whether this is a move assignment operator.
1581223017Sdim  bool isMoveAssignmentOperator() const;
1582235633Sdim
1583198092Srdivacky  const CXXMethodDecl *getCanonicalDecl() const {
1584198092Srdivacky    return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
1585198092Srdivacky  }
1586198092Srdivacky  CXXMethodDecl *getCanonicalDecl() {
1587198092Srdivacky    return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
1588198092Srdivacky  }
1589223017Sdim
1590245431Sdim  /// isUserProvided - True if this method is user-declared and was not
1591245431Sdim  /// deleted or defaulted on its first declaration.
1592223017Sdim  bool isUserProvided() const {
1593223017Sdim    return !(isDeleted() || getCanonicalDecl()->isDefaulted());
1594223017Sdim  }
1595235633Sdim
1596198092Srdivacky  ///
1597198092Srdivacky  void addOverriddenMethod(const CXXMethodDecl *MD);
1598193326Sed
1599235633Sdim  typedef const CXXMethodDecl *const* method_iterator;
1600198092Srdivacky
1601193326Sed  method_iterator begin_overridden_methods() const;
1602193326Sed  method_iterator end_overridden_methods() const;
1603210299Sed  unsigned size_overridden_methods() const;
1604198092Srdivacky
1605193326Sed  /// getParent - Returns the parent of this method declaration, which
1606193326Sed  /// is the class in which this method is defined.
1607198092Srdivacky  const CXXRecordDecl *getParent() const {
1608198092Srdivacky    return cast<CXXRecordDecl>(FunctionDecl::getParent());
1609193326Sed  }
1610198092Srdivacky
1611193326Sed  /// getParent - Returns the parent of this method declaration, which
1612193326Sed  /// is the class in which this method is defined.
1613198092Srdivacky  CXXRecordDecl *getParent() {
1614193326Sed    return const_cast<CXXRecordDecl *>(
1615193326Sed             cast<CXXRecordDecl>(FunctionDecl::getParent()));
1616193326Sed  }
1617193326Sed
1618193326Sed  /// getThisType - Returns the type of 'this' pointer.
1619193326Sed  /// Should only be called for instance methods.
1620193326Sed  QualType getThisType(ASTContext &C) const;
1621193326Sed
1622193326Sed  unsigned getTypeQualifiers() const {
1623198092Srdivacky    return getType()->getAs<FunctionProtoType>()->getTypeQuals();
1624193326Sed  }
1625193326Sed
1626218893Sdim  /// \brief Retrieve the ref-qualifier associated with this method.
1627218893Sdim  ///
1628218893Sdim  /// In the following example, \c f() has an lvalue ref-qualifier, \c g()
1629218893Sdim  /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier.
1630245431Sdim  /// @code
1631218893Sdim  /// struct X {
1632218893Sdim  ///   void f() &;
1633218893Sdim  ///   void g() &&;
1634218893Sdim  ///   void h();
1635218893Sdim  /// };
1636245431Sdim  /// @endcode
1637218893Sdim  RefQualifierKind getRefQualifier() const {
1638218893Sdim    return getType()->getAs<FunctionProtoType>()->getRefQualifier();
1639218893Sdim  }
1640235633Sdim
1641200583Srdivacky  bool hasInlineBody() const;
1642200583Srdivacky
1643235633Sdim  /// \brief Determine whether this is a lambda closure type's static member
1644235633Sdim  /// function that is used for the result of the lambda's conversion to
1645235633Sdim  /// function pointer (for a lambda with no captures).
1646235633Sdim  ///
1647235633Sdim  /// The function itself, if used, will have a placeholder body that will be
1648235633Sdim  /// supplied by IR generation to either forward to the function call operator
1649235633Sdim  /// or clone the function call operator.
1650235633Sdim  bool isLambdaStaticInvoker() const;
1651245431Sdim
1652245431Sdim  /// \brief Find the method in RD that corresponds to this one.
1653245431Sdim  ///
1654245431Sdim  /// Find if RD or one of the classes it inherits from override this method.
1655245431Sdim  /// If so, return it. RD is assumed to be a subclass of the class defining
1656245431Sdim  /// this method (or be the class itself), unless MayBeBase is set to true.
1657245431Sdim  CXXMethodDecl *
1658245431Sdim  getCorrespondingMethodInClass(const CXXRecordDecl *RD,
1659245431Sdim                                bool MayBeBase = false);
1660245431Sdim
1661245431Sdim  const CXXMethodDecl *
1662245431Sdim  getCorrespondingMethodInClass(const CXXRecordDecl *RD,
1663245431Sdim                                bool MayBeBase = false) const {
1664245431Sdim    return const_cast<CXXMethodDecl *>(this)
1665245431Sdim              ->getCorrespondingMethodInClass(RD, MayBeBase);
1666245431Sdim  }
1667245431Sdim
1668193326Sed  // Implement isa/cast/dyncast/etc.
1669203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1670203955Srdivacky  static bool classofKind(Kind K) {
1671210299Sed    return K >= firstCXXMethod && K <= lastCXXMethod;
1672193326Sed  }
1673193326Sed};
1674193326Sed
1675218893Sdim/// CXXCtorInitializer - Represents a C++ base or member
1676193326Sed/// initializer, which is part of a constructor initializer that
1677193326Sed/// initializes one non-static member variable or one base class. For
1678193326Sed/// example, in the following, both 'A(a)' and 'f(3.14159)' are member
1679193326Sed/// initializers:
1680193326Sed///
1681193326Sed/// @code
1682193326Sed/// class A { };
1683193326Sed/// class B : public A {
1684193326Sed///   float f;
1685193326Sed/// public:
1686193326Sed///   B(A& a) : A(a), f(3.14159) { }
1687193326Sed/// };
1688194613Sed/// @endcode
1689218893Sdimclass CXXCtorInitializer {
1690235633Sdim  /// \brief Either the base class name/delegating constructor type (stored as
1691235633Sdim  /// a TypeSourceInfo*), an normal field (FieldDecl), or an anonymous field
1692235633Sdim  /// (IndirectFieldDecl*) being initialized.
1693235633Sdim  llvm::PointerUnion3<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *>
1694218893Sdim    Initializee;
1695235633Sdim
1696218893Sdim  /// \brief The source location for the field name or, for a base initializer
1697221345Sdim  /// pack expansion, the location of the ellipsis. In the case of a delegating
1698221345Sdim  /// constructor, it will still include the type's source location as the
1699221345Sdim  /// Initializee points to the CXXConstructorDecl (to allow loop detection).
1700218893Sdim  SourceLocation MemberOrEllipsisLocation;
1701235633Sdim
1702203955Srdivacky  /// \brief The argument used to initialize the base or member, which may
1703203955Srdivacky  /// end up constructing an object (when multiple arguments are involved).
1704235633Sdim  /// If 0, this is a field initializer, and the in-class member initializer
1705223017Sdim  /// will be used.
1706203955Srdivacky  Stmt *Init;
1707235633Sdim
1708200583Srdivacky  /// LParenLoc - Location of the left paren of the ctor-initializer.
1709200583Srdivacky  SourceLocation LParenLoc;
1710193326Sed
1711198092Srdivacky  /// RParenLoc - Location of the right paren of the ctor-initializer.
1712198092Srdivacky  SourceLocation RParenLoc;
1713198092Srdivacky
1714235633Sdim  /// \brief If the initializee is a type, whether that type makes this
1715235633Sdim  /// a delegating initialization.
1716235633Sdim  bool IsDelegating : 1;
1717235633Sdim
1718208600Srdivacky  /// IsVirtual - If the initializer is a base initializer, this keeps track
1719208600Srdivacky  /// of whether the base is virtual or not.
1720208600Srdivacky  bool IsVirtual : 1;
1721208600Srdivacky
1722208600Srdivacky  /// IsWritten - Whether or not the initializer is explicitly written
1723208600Srdivacky  /// in the sources.
1724208600Srdivacky  bool IsWritten : 1;
1725218893Sdim
1726208600Srdivacky  /// SourceOrderOrNumArrayIndices - If IsWritten is true, then this
1727208600Srdivacky  /// number keeps track of the textual order of this initializer in the
1728208600Srdivacky  /// original sources, counting from 0; otherwise, if IsWritten is false,
1729208600Srdivacky  /// it stores the number of array index variables stored after this
1730208600Srdivacky  /// object in memory.
1731235633Sdim  unsigned SourceOrderOrNumArrayIndices : 13;
1732208600Srdivacky
1733218893Sdim  CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
1734218893Sdim                     SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1735218893Sdim                     SourceLocation R, VarDecl **Indices, unsigned NumIndices);
1736235633Sdim
1737193326Sedpublic:
1738218893Sdim  /// CXXCtorInitializer - Creates a new base-class initializer.
1739198092Srdivacky  explicit
1740218893Sdim  CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual,
1741218893Sdim                     SourceLocation L, Expr *Init, SourceLocation R,
1742218893Sdim                     SourceLocation EllipsisLoc);
1743193326Sed
1744218893Sdim  /// CXXCtorInitializer - Creates a new member initializer.
1745198092Srdivacky  explicit
1746218893Sdim  CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
1747218893Sdim                     SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1748218893Sdim                     SourceLocation R);
1749193326Sed
1750221345Sdim  /// CXXCtorInitializer - Creates a new anonymous field initializer.
1751218893Sdim  explicit
1752218893Sdim  CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member,
1753218893Sdim                     SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1754218893Sdim                     SourceLocation R);
1755218893Sdim
1756221345Sdim  /// CXXCtorInitializer - Creates a new delegating Initializer.
1757221345Sdim  explicit
1758235633Sdim  CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo,
1759235633Sdim                     SourceLocation L, Expr *Init, SourceLocation R);
1760221345Sdim
1761235633Sdim  /// \brief Creates a new member initializer that optionally contains
1762208600Srdivacky  /// array indices used to describe an elementwise initialization.
1763218893Sdim  static CXXCtorInitializer *Create(ASTContext &Context, FieldDecl *Member,
1764218893Sdim                                    SourceLocation MemberLoc, SourceLocation L,
1765218893Sdim                                    Expr *Init, SourceLocation R,
1766218893Sdim                                    VarDecl **Indices, unsigned NumIndices);
1767235633Sdim
1768193326Sed  /// isBaseInitializer - Returns true when this initializer is
1769193326Sed  /// initializing a base class.
1770235633Sdim  bool isBaseInitializer() const {
1771235633Sdim    return Initializee.is<TypeSourceInfo*>() && !IsDelegating;
1772235633Sdim  }
1773193326Sed
1774193326Sed  /// isMemberInitializer - Returns true when this initializer is
1775193326Sed  /// initializing a non-static data member.
1776218893Sdim  bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); }
1777193326Sed
1778235633Sdim  bool isAnyMemberInitializer() const {
1779218893Sdim    return isMemberInitializer() || isIndirectMemberInitializer();
1780218893Sdim  }
1781218893Sdim
1782218893Sdim  bool isIndirectMemberInitializer() const {
1783218893Sdim    return Initializee.is<IndirectFieldDecl*>();
1784218893Sdim  }
1785218893Sdim
1786223017Sdim  /// isInClassMemberInitializer - Returns true when this initializer is an
1787223017Sdim  /// implicit ctor initializer generated for a field with an initializer
1788223017Sdim  /// defined on the member declaration.
1789223017Sdim  bool isInClassMemberInitializer() const {
1790223017Sdim    return !Init;
1791223017Sdim  }
1792223017Sdim
1793221345Sdim  /// isDelegatingInitializer - Returns true when this initializer is creating
1794221345Sdim  /// a delegating constructor.
1795221345Sdim  bool isDelegatingInitializer() const {
1796235633Sdim    return Initializee.is<TypeSourceInfo*>() && IsDelegating;
1797221345Sdim  }
1798221345Sdim
1799218893Sdim  /// \brief Determine whether this initializer is a pack expansion.
1800235633Sdim  bool isPackExpansion() const {
1801235633Sdim    return isBaseInitializer() && MemberOrEllipsisLocation.isValid();
1802218893Sdim  }
1803235633Sdim
1804218893Sdim  // \brief For a pack expansion, returns the location of the ellipsis.
1805218893Sdim  SourceLocation getEllipsisLoc() const {
1806218893Sdim    assert(isPackExpansion() && "Initializer is not a pack expansion");
1807218893Sdim    return MemberOrEllipsisLocation;
1808218893Sdim  }
1809235633Sdim
1810235633Sdim  /// If this is a base class initializer, returns the type of the
1811200583Srdivacky  /// base class with location information. Otherwise, returns an NULL
1812200583Srdivacky  /// type location.
1813200583Srdivacky  TypeLoc getBaseClassLoc() const;
1814193326Sed
1815200583Srdivacky  /// If this is a base class initializer, returns the type of the base class.
1816200583Srdivacky  /// Otherwise, returns NULL.
1817200583Srdivacky  const Type *getBaseClass() const;
1818207619Srdivacky
1819207619Srdivacky  /// Returns whether the base is virtual or not.
1820207619Srdivacky  bool isBaseVirtual() const {
1821207619Srdivacky    assert(isBaseInitializer() && "Must call this on base initializer!");
1822235633Sdim
1823207619Srdivacky    return IsVirtual;
1824207619Srdivacky  }
1825207619Srdivacky
1826235633Sdim  /// \brief Returns the declarator information for a base class or delegating
1827235633Sdim  /// initializer.
1828235633Sdim  TypeSourceInfo *getTypeSourceInfo() const {
1829218893Sdim    return Initializee.dyn_cast<TypeSourceInfo *>();
1830193326Sed  }
1831235633Sdim
1832193326Sed  /// getMember - If this is a member initializer, returns the
1833193326Sed  /// declaration of the non-static data member being
1834193326Sed  /// initialized. Otherwise, returns NULL.
1835212904Sdim  FieldDecl *getMember() const {
1836193326Sed    if (isMemberInitializer())
1837218893Sdim      return Initializee.get<FieldDecl*>();
1838235633Sdim    return 0;
1839193326Sed  }
1840218893Sdim  FieldDecl *getAnyMember() const {
1841218893Sdim    if (isMemberInitializer())
1842218893Sdim      return Initializee.get<FieldDecl*>();
1843235633Sdim    if (isIndirectMemberInitializer())
1844218893Sdim      return Initializee.get<IndirectFieldDecl*>()->getAnonField();
1845235633Sdim    return 0;
1846218893Sdim  }
1847193326Sed
1848218893Sdim  IndirectFieldDecl *getIndirectMember() const {
1849218893Sdim    if (isIndirectMemberInitializer())
1850218893Sdim      return Initializee.get<IndirectFieldDecl*>();
1851235633Sdim    return 0;
1852198092Srdivacky  }
1853198092Srdivacky
1854235633Sdim  SourceLocation getMemberLocation() const {
1855235633Sdim    return MemberOrEllipsisLocation;
1856221345Sdim  }
1857221345Sdim
1858200583Srdivacky  /// \brief Determine the source location of the initializer.
1859200583Srdivacky  SourceLocation getSourceLocation() const;
1860235633Sdim
1861200583Srdivacky  /// \brief Determine the source range covering the entire initializer.
1862235633Sdim  SourceRange getSourceRange() const LLVM_READONLY;
1863208600Srdivacky
1864208600Srdivacky  /// isWritten - Returns true if this initializer is explicitly written
1865208600Srdivacky  /// in the source code.
1866208600Srdivacky  bool isWritten() const { return IsWritten; }
1867208600Srdivacky
1868208600Srdivacky  /// \brief Return the source position of the initializer, counting from 0.
1869208600Srdivacky  /// If the initializer was implicit, -1 is returned.
1870208600Srdivacky  int getSourceOrder() const {
1871208600Srdivacky    return IsWritten ? static_cast<int>(SourceOrderOrNumArrayIndices) : -1;
1872208600Srdivacky  }
1873208600Srdivacky
1874208600Srdivacky  /// \brief Set the source order of this initializer. This method can only
1875208600Srdivacky  /// be called once for each initializer; it cannot be called on an
1876208600Srdivacky  /// initializer having a positive number of (implicit) array indices.
1877208600Srdivacky  void setSourceOrder(int pos) {
1878208600Srdivacky    assert(!IsWritten &&
1879208600Srdivacky           "calling twice setSourceOrder() on the same initializer");
1880208600Srdivacky    assert(SourceOrderOrNumArrayIndices == 0 &&
1881208600Srdivacky           "setSourceOrder() used when there are implicit array indices");
1882208600Srdivacky    assert(pos >= 0 &&
1883208600Srdivacky           "setSourceOrder() used to make an initializer implicit");
1884208600Srdivacky    IsWritten = true;
1885208600Srdivacky    SourceOrderOrNumArrayIndices = static_cast<unsigned>(pos);
1886208600Srdivacky  }
1887198092Srdivacky
1888200583Srdivacky  SourceLocation getLParenLoc() const { return LParenLoc; }
1889198092Srdivacky  SourceLocation getRParenLoc() const { return RParenLoc; }
1890193326Sed
1891208600Srdivacky  /// \brief Determine the number of implicit array indices used while
1892208600Srdivacky  /// described an array member initialization.
1893208600Srdivacky  unsigned getNumArrayIndices() const {
1894208600Srdivacky    return IsWritten ? 0 : SourceOrderOrNumArrayIndices;
1895208600Srdivacky  }
1896208600Srdivacky
1897235633Sdim  /// \brief Retrieve a particular array index variable used to
1898208600Srdivacky  /// describe an array member initialization.
1899208600Srdivacky  VarDecl *getArrayIndex(unsigned I) {
1900208600Srdivacky    assert(I < getNumArrayIndices() && "Out of bounds member array index");
1901208600Srdivacky    return reinterpret_cast<VarDecl **>(this + 1)[I];
1902208600Srdivacky  }
1903208600Srdivacky  const VarDecl *getArrayIndex(unsigned I) const {
1904208600Srdivacky    assert(I < getNumArrayIndices() && "Out of bounds member array index");
1905208600Srdivacky    return reinterpret_cast<const VarDecl * const *>(this + 1)[I];
1906208600Srdivacky  }
1907208600Srdivacky  void setArrayIndex(unsigned I, VarDecl *Index) {
1908208600Srdivacky    assert(I < getNumArrayIndices() && "Out of bounds member array index");
1909208600Srdivacky    reinterpret_cast<VarDecl **>(this + 1)[I] = Index;
1910208600Srdivacky  }
1911235633Sdim  ArrayRef<VarDecl *> getArrayIndexes() {
1912235633Sdim    assert(getNumArrayIndices() != 0 && "Getting indexes for non-array init");
1913235633Sdim    return ArrayRef<VarDecl *>(reinterpret_cast<VarDecl **>(this + 1),
1914235633Sdim                               getNumArrayIndices());
1915235633Sdim  }
1916235633Sdim
1917223017Sdim  /// \brief Get the initializer. This is 0 if this is an in-class initializer
1918223017Sdim  /// for a non-static data member which has not yet been parsed.
1919223017Sdim  Expr *getInit() const {
1920223017Sdim    if (!Init)
1921223017Sdim      return getAnyMember()->getInClassInitializer();
1922223017Sdim
1923223017Sdim    return static_cast<Expr*>(Init);
1924223017Sdim  }
1925193326Sed};
1926193326Sed
1927193326Sed/// CXXConstructorDecl - Represents a C++ constructor within a
1928193326Sed/// class. For example:
1929198092Srdivacky///
1930193326Sed/// @code
1931193326Sed/// class X {
1932193326Sed/// public:
1933193326Sed///   explicit X(int); // represented by a CXXConstructorDecl.
1934193326Sed/// };
1935193326Sed/// @endcode
1936193326Sedclass CXXConstructorDecl : public CXXMethodDecl {
1937235633Sdim  virtual void anchor();
1938203955Srdivacky  /// IsExplicitSpecified - Whether this constructor declaration has the
1939203955Srdivacky  /// 'explicit' keyword specified.
1940203955Srdivacky  bool IsExplicitSpecified : 1;
1941193326Sed
1942193326Sed  /// ImplicitlyDefined - Whether this constructor was implicitly
1943193326Sed  /// defined by the compiler. When false, the constructor was defined
1944193326Sed  /// by the user. In C++03, this flag will have the same value as
1945193326Sed  /// Implicit. In C++0x, however, a constructor that is
1946193326Sed  /// explicitly defaulted (i.e., defined with " = default") will have
1947193326Sed  /// @c !Implicit && ImplicitlyDefined.
1948193326Sed  bool ImplicitlyDefined : 1;
1949198092Srdivacky
1950195341Sed  /// Support for base and member initializers.
1951218893Sdim  /// CtorInitializers - The arguments used to initialize the base
1952195341Sed  /// or member.
1953218893Sdim  CXXCtorInitializer **CtorInitializers;
1954218893Sdim  unsigned NumCtorInitializers;
1955198092Srdivacky
1956221345Sdim  CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
1957221345Sdim                     const DeclarationNameInfo &NameInfo,
1958212904Sdim                     QualType T, TypeSourceInfo *TInfo,
1959235633Sdim                     bool isExplicitSpecified, bool isInline,
1960226890Sdim                     bool isImplicitlyDeclared, bool isConstexpr)
1961221345Sdim    : CXXMethodDecl(CXXConstructor, RD, StartLoc, NameInfo, T, TInfo, false,
1962226890Sdim                    SC_None, isInline, isConstexpr, SourceLocation()),
1963203955Srdivacky      IsExplicitSpecified(isExplicitSpecified), ImplicitlyDefined(false),
1964218893Sdim      CtorInitializers(0), NumCtorInitializers(0) {
1965193326Sed    setImplicit(isImplicitlyDeclared);
1966193326Sed  }
1967198092Srdivacky
1968193326Sedpublic:
1969235633Sdim  static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1970193326Sed  static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1971221345Sdim                                    SourceLocation StartLoc,
1972212904Sdim                                    const DeclarationNameInfo &NameInfo,
1973200583Srdivacky                                    QualType T, TypeSourceInfo *TInfo,
1974198092Srdivacky                                    bool isExplicit,
1975226890Sdim                                    bool isInline, bool isImplicitlyDeclared,
1976226890Sdim                                    bool isConstexpr);
1977193326Sed
1978203955Srdivacky  /// isExplicitSpecified - Whether this constructor declaration has the
1979203955Srdivacky  /// 'explicit' keyword specified.
1980203955Srdivacky  bool isExplicitSpecified() const { return IsExplicitSpecified; }
1981235633Sdim
1982198092Srdivacky  /// isExplicit - Whether this constructor was marked "explicit" or not.
1983203955Srdivacky  bool isExplicit() const {
1984203955Srdivacky    return cast<CXXConstructorDecl>(getFirstDeclaration())
1985203955Srdivacky      ->isExplicitSpecified();
1986203955Srdivacky  }
1987193326Sed
1988193326Sed  /// isImplicitlyDefined - Whether this constructor was implicitly
1989193326Sed  /// defined. If false, then this constructor was defined by the
1990193326Sed  /// user. This operation can only be invoked if the constructor has
1991193326Sed  /// already been defined.
1992207619Srdivacky  bool isImplicitlyDefined() const {
1993198092Srdivacky    assert(isThisDeclarationADefinition() &&
1994195341Sed           "Can only get the implicit-definition flag once the "
1995195341Sed           "constructor has been defined");
1996198092Srdivacky    return ImplicitlyDefined;
1997193326Sed  }
1998193326Sed
1999193326Sed  /// setImplicitlyDefined - Set whether this constructor was
2000193326Sed  /// implicitly defined or not.
2001198092Srdivacky  void setImplicitlyDefined(bool ID) {
2002198092Srdivacky    assert(isThisDeclarationADefinition() &&
2003195341Sed           "Can only set the implicit-definition flag once the constructor "
2004195341Sed           "has been defined");
2005198092Srdivacky    ImplicitlyDefined = ID;
2006193326Sed  }
2007198092Srdivacky
2008195341Sed  /// init_iterator - Iterates through the member/base initializer list.
2009218893Sdim  typedef CXXCtorInitializer **init_iterator;
2010198092Srdivacky
2011195341Sed  /// init_const_iterator - Iterates through the memberbase initializer list.
2012218893Sdim  typedef CXXCtorInitializer * const * init_const_iterator;
2013198092Srdivacky
2014198092Srdivacky  /// init_begin() - Retrieve an iterator to the first initializer.
2015218893Sdim  init_iterator       init_begin()       { return CtorInitializers; }
2016195341Sed  /// begin() - Retrieve an iterator to the first initializer.
2017218893Sdim  init_const_iterator init_begin() const { return CtorInitializers; }
2018198092Srdivacky
2019198092Srdivacky  /// init_end() - Retrieve an iterator past the last initializer.
2020198092Srdivacky  init_iterator       init_end()       {
2021218893Sdim    return CtorInitializers + NumCtorInitializers;
2022195341Sed  }
2023195341Sed  /// end() - Retrieve an iterator past the last initializer.
2024198092Srdivacky  init_const_iterator init_end() const {
2025218893Sdim    return CtorInitializers + NumCtorInitializers;
2026195341Sed  }
2027198092Srdivacky
2028218893Sdim  typedef std::reverse_iterator<init_iterator> init_reverse_iterator;
2029235633Sdim  typedef std::reverse_iterator<init_const_iterator>
2030235633Sdim          init_const_reverse_iterator;
2031218893Sdim
2032218893Sdim  init_reverse_iterator init_rbegin() {
2033218893Sdim    return init_reverse_iterator(init_end());
2034218893Sdim  }
2035218893Sdim  init_const_reverse_iterator init_rbegin() const {
2036218893Sdim    return init_const_reverse_iterator(init_end());
2037218893Sdim  }
2038218893Sdim
2039218893Sdim  init_reverse_iterator init_rend() {
2040218893Sdim    return init_reverse_iterator(init_begin());
2041218893Sdim  }
2042218893Sdim  init_const_reverse_iterator init_rend() const {
2043218893Sdim    return init_const_reverse_iterator(init_begin());
2044218893Sdim  }
2045218893Sdim
2046195341Sed  /// getNumArgs - Determine the number of arguments used to
2047195341Sed  /// initialize the member or base.
2048218893Sdim  unsigned getNumCtorInitializers() const {
2049218893Sdim      return NumCtorInitializers;
2050195341Sed  }
2051198092Srdivacky
2052218893Sdim  void setNumCtorInitializers(unsigned numCtorInitializers) {
2053218893Sdim    NumCtorInitializers = numCtorInitializers;
2054198092Srdivacky  }
2055198092Srdivacky
2056218893Sdim  void setCtorInitializers(CXXCtorInitializer ** initializers) {
2057218893Sdim    CtorInitializers = initializers;
2058198092Srdivacky  }
2059221345Sdim
2060221345Sdim  /// isDelegatingConstructor - Whether this constructor is a
2061221345Sdim  /// delegating constructor
2062221345Sdim  bool isDelegatingConstructor() const {
2063221345Sdim    return (getNumCtorInitializers() == 1) &&
2064221345Sdim      CtorInitializers[0]->isDelegatingInitializer();
2065221345Sdim  }
2066221345Sdim
2067221345Sdim  /// getTargetConstructor - When this constructor delegates to
2068221345Sdim  /// another, retrieve the target
2069235633Sdim  CXXConstructorDecl *getTargetConstructor() const;
2070221345Sdim
2071193326Sed  /// isDefaultConstructor - Whether this constructor is a default
2072193326Sed  /// constructor (C++ [class.ctor]p5), which can be used to
2073193326Sed  /// default-initialize a class of this type.
2074193326Sed  bool isDefaultConstructor() const;
2075193326Sed
2076193326Sed  /// isCopyConstructor - Whether this constructor is a copy
2077193326Sed  /// constructor (C++ [class.copy]p2, which can be used to copy the
2078193326Sed  /// class. @p TypeQuals will be set to the qualifiers on the
2079193326Sed  /// argument type. For example, @p TypeQuals would be set to @c
2080193326Sed  /// QualType::Const for the following copy constructor:
2081193326Sed  ///
2082193326Sed  /// @code
2083193326Sed  /// class X {
2084193326Sed  /// public:
2085193326Sed  ///   X(const X&);
2086193326Sed  /// };
2087193326Sed  /// @endcode
2088201361Srdivacky  bool isCopyConstructor(unsigned &TypeQuals) const;
2089193326Sed
2090193326Sed  /// isCopyConstructor - Whether this constructor is a copy
2091193326Sed  /// constructor (C++ [class.copy]p2, which can be used to copy the
2092193326Sed  /// class.
2093201361Srdivacky  bool isCopyConstructor() const {
2094193326Sed    unsigned TypeQuals = 0;
2095201361Srdivacky    return isCopyConstructor(TypeQuals);
2096193326Sed  }
2097193326Sed
2098218893Sdim  /// \brief Determine whether this constructor is a move constructor
2099218893Sdim  /// (C++0x [class.copy]p3), which can be used to move values of the class.
2100218893Sdim  ///
2101218893Sdim  /// \param TypeQuals If this constructor is a move constructor, will be set
2102218893Sdim  /// to the type qualifiers on the referent of the first parameter's type.
2103218893Sdim  bool isMoveConstructor(unsigned &TypeQuals) const;
2104218893Sdim
2105218893Sdim  /// \brief Determine whether this constructor is a move constructor
2106218893Sdim  /// (C++0x [class.copy]p3), which can be used to move values of the class.
2107221345Sdim  bool isMoveConstructor() const {
2108221345Sdim    unsigned TypeQuals = 0;
2109221345Sdim    return isMoveConstructor(TypeQuals);
2110221345Sdim  }
2111221345Sdim
2112218893Sdim  /// \brief Determine whether this is a copy or move constructor.
2113218893Sdim  ///
2114218893Sdim  /// \param TypeQuals Will be set to the type qualifiers on the reference
2115218893Sdim  /// parameter, if in fact this is a copy or move constructor.
2116218893Sdim  bool isCopyOrMoveConstructor(unsigned &TypeQuals) const;
2117218893Sdim
2118218893Sdim  /// \brief Determine whether this a copy or move constructor.
2119218893Sdim  bool isCopyOrMoveConstructor() const {
2120218893Sdim    unsigned Quals;
2121218893Sdim    return isCopyOrMoveConstructor(Quals);
2122218893Sdim  }
2123218893Sdim
2124193326Sed  /// isConvertingConstructor - Whether this constructor is a
2125193326Sed  /// converting constructor (C++ [class.conv.ctor]), which can be
2126193326Sed  /// used for user-defined conversions.
2127198092Srdivacky  bool isConvertingConstructor(bool AllowExplicit) const;
2128193326Sed
2129199482Srdivacky  /// \brief Determine whether this is a member template specialization that
2130218893Sdim  /// would copy the object to itself. Such constructors are never used to copy
2131199482Srdivacky  /// an object.
2132218893Sdim  bool isSpecializationCopyingObject() const;
2133218893Sdim
2134218893Sdim  /// \brief Get the constructor that this inheriting constructor is based on.
2135218893Sdim  const CXXConstructorDecl *getInheritedConstructor() const;
2136218893Sdim
2137218893Sdim  /// \brief Set the constructor that this inheriting constructor is based on.
2138218893Sdim  void setInheritedConstructor(const CXXConstructorDecl *BaseCtor);
2139223017Sdim
2140223017Sdim  const CXXConstructorDecl *getCanonicalDecl() const {
2141223017Sdim    return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
2142223017Sdim  }
2143223017Sdim  CXXConstructorDecl *getCanonicalDecl() {
2144223017Sdim    return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
2145223017Sdim  }
2146235633Sdim
2147193326Sed  // Implement isa/cast/dyncast/etc.
2148203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2149203955Srdivacky  static bool classofKind(Kind K) { return K == CXXConstructor; }
2150235633Sdim
2151212904Sdim  friend class ASTDeclReader;
2152212904Sdim  friend class ASTDeclWriter;
2153193326Sed};
2154193326Sed
2155193326Sed/// CXXDestructorDecl - Represents a C++ destructor within a
2156193326Sed/// class. For example:
2157198092Srdivacky///
2158193326Sed/// @code
2159193326Sed/// class X {
2160193326Sed/// public:
2161193326Sed///   ~X(); // represented by a CXXDestructorDecl.
2162193326Sed/// };
2163193326Sed/// @endcode
2164193326Sedclass CXXDestructorDecl : public CXXMethodDecl {
2165235633Sdim  virtual void anchor();
2166193326Sed  /// ImplicitlyDefined - Whether this destructor was implicitly
2167193326Sed  /// defined by the compiler. When false, the destructor was defined
2168193326Sed  /// by the user. In C++03, this flag will have the same value as
2169193326Sed  /// Implicit. In C++0x, however, a destructor that is
2170193326Sed  /// explicitly defaulted (i.e., defined with " = default") will have
2171193326Sed  /// @c !Implicit && ImplicitlyDefined.
2172193326Sed  bool ImplicitlyDefined : 1;
2173193326Sed
2174199482Srdivacky  FunctionDecl *OperatorDelete;
2175235633Sdim
2176221345Sdim  CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
2177221345Sdim                    const DeclarationNameInfo &NameInfo,
2178218893Sdim                    QualType T, TypeSourceInfo *TInfo,
2179218893Sdim                    bool isInline, bool isImplicitlyDeclared)
2180221345Sdim    : CXXMethodDecl(CXXDestructor, RD, StartLoc, NameInfo, T, TInfo, false,
2181226890Sdim                    SC_None, isInline, /*isConstexpr=*/false, SourceLocation()),
2182199482Srdivacky      ImplicitlyDefined(false), OperatorDelete(0) {
2183193326Sed    setImplicit(isImplicitlyDeclared);
2184193326Sed  }
2185193326Sed
2186193326Sedpublic:
2187193326Sed  static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2188221345Sdim                                   SourceLocation StartLoc,
2189212904Sdim                                   const DeclarationNameInfo &NameInfo,
2190218893Sdim                                   QualType T, TypeSourceInfo* TInfo,
2191218893Sdim                                   bool isInline,
2192193326Sed                                   bool isImplicitlyDeclared);
2193235633Sdim  static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID);
2194193326Sed
2195193326Sed  /// isImplicitlyDefined - Whether this destructor was implicitly
2196193326Sed  /// defined. If false, then this destructor was defined by the
2197193326Sed  /// user. This operation can only be invoked if the destructor has
2198193326Sed  /// already been defined.
2199198092Srdivacky  bool isImplicitlyDefined() const {
2200198092Srdivacky    assert(isThisDeclarationADefinition() &&
2201235633Sdim           "Can only get the implicit-definition flag once the destructor has "
2202235633Sdim           "been defined");
2203198092Srdivacky    return ImplicitlyDefined;
2204193326Sed  }
2205193326Sed
2206193326Sed  /// setImplicitlyDefined - Set whether this destructor was
2207193326Sed  /// implicitly defined or not.
2208198092Srdivacky  void setImplicitlyDefined(bool ID) {
2209198092Srdivacky    assert(isThisDeclarationADefinition() &&
2210235633Sdim           "Can only set the implicit-definition flag once the destructor has "
2211235633Sdim           "been defined");
2212198092Srdivacky    ImplicitlyDefined = ID;
2213193326Sed  }
2214193326Sed
2215199482Srdivacky  void setOperatorDelete(FunctionDecl *OD) { OperatorDelete = OD; }
2216199482Srdivacky  const FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
2217198092Srdivacky
2218193326Sed  // Implement isa/cast/dyncast/etc.
2219203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2220203955Srdivacky  static bool classofKind(Kind K) { return K == CXXDestructor; }
2221235633Sdim
2222212904Sdim  friend class ASTDeclReader;
2223212904Sdim  friend class ASTDeclWriter;
2224193326Sed};
2225193326Sed
2226193326Sed/// CXXConversionDecl - Represents a C++ conversion function within a
2227193326Sed/// class. For example:
2228198092Srdivacky///
2229193326Sed/// @code
2230193326Sed/// class X {
2231193326Sed/// public:
2232193326Sed///   operator bool();
2233193326Sed/// };
2234193326Sed/// @endcode
2235193326Sedclass CXXConversionDecl : public CXXMethodDecl {
2236235633Sdim  virtual void anchor();
2237235633Sdim  /// IsExplicitSpecified - Whether this conversion function declaration is
2238203955Srdivacky  /// marked "explicit", meaning that it can only be applied when the user
2239193326Sed  /// explicitly wrote a cast. This is a C++0x feature.
2240203955Srdivacky  bool IsExplicitSpecified : 1;
2241193326Sed
2242221345Sdim  CXXConversionDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
2243221345Sdim                    const DeclarationNameInfo &NameInfo,
2244212904Sdim                    QualType T, TypeSourceInfo *TInfo,
2245221345Sdim                    bool isInline, bool isExplicitSpecified,
2246226890Sdim                    bool isConstexpr, SourceLocation EndLocation)
2247221345Sdim    : CXXMethodDecl(CXXConversion, RD, StartLoc, NameInfo, T, TInfo, false,
2248226890Sdim                    SC_None, isInline, isConstexpr, EndLocation),
2249203955Srdivacky      IsExplicitSpecified(isExplicitSpecified) { }
2250193326Sed
2251193326Sedpublic:
2252193326Sed  static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2253221345Sdim                                   SourceLocation StartLoc,
2254212904Sdim                                   const DeclarationNameInfo &NameInfo,
2255200583Srdivacky                                   QualType T, TypeSourceInfo *TInfo,
2256221345Sdim                                   bool isInline, bool isExplicit,
2257226890Sdim                                   bool isConstexpr,
2258221345Sdim                                   SourceLocation EndLocation);
2259235633Sdim  static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2260193326Sed
2261235633Sdim  /// IsExplicitSpecified - Whether this conversion function declaration is
2262203955Srdivacky  /// marked "explicit", meaning that it can only be applied when the user
2263203955Srdivacky  /// explicitly wrote a cast. This is a C++0x feature.
2264203955Srdivacky  bool isExplicitSpecified() const { return IsExplicitSpecified; }
2265203955Srdivacky
2266193326Sed  /// isExplicit - Whether this is an explicit conversion operator
2267193326Sed  /// (C++0x only). Explicit conversion operators are only considered
2268193326Sed  /// when the user has explicitly written a cast.
2269203955Srdivacky  bool isExplicit() const {
2270203955Srdivacky    return cast<CXXConversionDecl>(getFirstDeclaration())
2271203955Srdivacky      ->isExplicitSpecified();
2272203955Srdivacky  }
2273193326Sed
2274193326Sed  /// getConversionType - Returns the type that this conversion
2275193326Sed  /// function is converting to.
2276198092Srdivacky  QualType getConversionType() const {
2277198092Srdivacky    return getType()->getAs<FunctionType>()->getResultType();
2278193326Sed  }
2279193326Sed
2280235633Sdim  /// \brief Determine whether this conversion function is a conversion from
2281235633Sdim  /// a lambda closure type to a block pointer.
2282235633Sdim  bool isLambdaToBlockPointerConversion() const;
2283235633Sdim
2284193326Sed  // Implement isa/cast/dyncast/etc.
2285203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2286203955Srdivacky  static bool classofKind(Kind K) { return K == CXXConversion; }
2287235633Sdim
2288212904Sdim  friend class ASTDeclReader;
2289212904Sdim  friend class ASTDeclWriter;
2290193326Sed};
2291193326Sed
2292193326Sed/// LinkageSpecDecl - This represents a linkage specification.  For example:
2293193326Sed///   extern "C" void foo();
2294193326Sed///
2295193326Sedclass LinkageSpecDecl : public Decl, public DeclContext {
2296235633Sdim  virtual void anchor();
2297193326Sedpublic:
2298193326Sed  /// LanguageIDs - Used to represent the language in a linkage
2299193326Sed  /// specification.  The values are part of the serialization abi for
2300193326Sed  /// ASTs and cannot be changed without altering that abi.  To help
2301193326Sed  /// ensure a stable abi for this, we choose the DW_LANG_ encodings
2302193326Sed  /// from the dwarf standard.
2303208600Srdivacky  enum LanguageIDs {
2304208600Srdivacky    lang_c = /* DW_LANG_C */ 0x0002,
2305208600Srdivacky    lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004
2306208600Srdivacky  };
2307193326Sedprivate:
2308193326Sed  /// Language - The language for this linkage specification.
2309193326Sed  LanguageIDs Language;
2310221345Sdim  /// ExternLoc - The source location for the extern keyword.
2311221345Sdim  SourceLocation ExternLoc;
2312221345Sdim  /// RBraceLoc - The source location for the right brace (if valid).
2313221345Sdim  SourceLocation RBraceLoc;
2314193326Sed
2315221345Sdim  LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
2316221345Sdim                  SourceLocation LangLoc, LanguageIDs lang,
2317221345Sdim                  SourceLocation RBLoc)
2318221345Sdim    : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec),
2319221345Sdim      Language(lang), ExternLoc(ExternLoc), RBraceLoc(RBLoc) { }
2320193326Sed
2321193326Sedpublic:
2322198092Srdivacky  static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
2323221345Sdim                                 SourceLocation ExternLoc,
2324221345Sdim                                 SourceLocation LangLoc, LanguageIDs Lang,
2325221345Sdim                                 SourceLocation RBraceLoc = SourceLocation());
2326235633Sdim  static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2327235633Sdim
2328208600Srdivacky  /// \brief Return the language specified by this linkage specification.
2329193326Sed  LanguageIDs getLanguage() const { return Language; }
2330208600Srdivacky  /// \brief Set the language specified by this linkage specification.
2331208600Srdivacky  void setLanguage(LanguageIDs L) { Language = L; }
2332208600Srdivacky
2333208600Srdivacky  /// \brief Determines whether this linkage specification had braces in
2334208600Srdivacky  /// its syntactic form.
2335221345Sdim  bool hasBraces() const { return RBraceLoc.isValid(); }
2336193326Sed
2337221345Sdim  SourceLocation getExternLoc() const { return ExternLoc; }
2338221345Sdim  SourceLocation getRBraceLoc() const { return RBraceLoc; }
2339221345Sdim  void setExternLoc(SourceLocation L) { ExternLoc = L; }
2340221345Sdim  void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
2341208600Srdivacky
2342235633Sdim  SourceLocation getLocEnd() const LLVM_READONLY {
2343221345Sdim    if (hasBraces())
2344221345Sdim      return getRBraceLoc();
2345221345Sdim    // No braces: get the end location of the (only) declaration in context
2346221345Sdim    // (if present).
2347221345Sdim    return decls_empty() ? getLocation() : decls_begin()->getLocEnd();
2348221345Sdim  }
2349221345Sdim
2350235633Sdim  SourceRange getSourceRange() const LLVM_READONLY {
2351221345Sdim    return SourceRange(ExternLoc, getLocEnd());
2352221345Sdim  }
2353221345Sdim
2354203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2355203955Srdivacky  static bool classofKind(Kind K) { return K == LinkageSpec; }
2356193326Sed  static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
2357193326Sed    return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
2358193326Sed  }
2359193326Sed  static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
2360193326Sed    return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
2361193326Sed  }
2362193326Sed};
2363193326Sed
2364193326Sed/// UsingDirectiveDecl - Represents C++ using-directive. For example:
2365193326Sed///
2366193326Sed///    using namespace std;
2367193326Sed///
2368193326Sed// NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide
2369235633Sdim// artificial names for all using-directives in order to store
2370193326Sed// them in DeclContext effectively.
2371193326Sedclass UsingDirectiveDecl : public NamedDecl {
2372235633Sdim  virtual void anchor();
2373212904Sdim  /// \brief The location of the "using" keyword.
2374212904Sdim  SourceLocation UsingLoc;
2375235633Sdim
2376193326Sed  /// SourceLocation - Location of 'namespace' token.
2377193326Sed  SourceLocation NamespaceLoc;
2378193326Sed
2379219077Sdim  /// \brief The nested-name-specifier that precedes the namespace.
2380219077Sdim  NestedNameSpecifierLoc QualifierLoc;
2381193326Sed
2382193326Sed  /// NominatedNamespace - Namespace nominated by using-directive.
2383199990Srdivacky  NamedDecl *NominatedNamespace;
2384193326Sed
2385199990Srdivacky  /// Enclosing context containing both using-directive and nominated
2386193326Sed  /// namespace.
2387193326Sed  DeclContext *CommonAncestor;
2388193326Sed
2389193326Sed  /// getUsingDirectiveName - Returns special DeclarationName used by
2390193326Sed  /// using-directives. This is only used by DeclContext for storing
2391193326Sed  /// UsingDirectiveDecls in its lookup structure.
2392193326Sed  static DeclarationName getName() {
2393193326Sed    return DeclarationName::getUsingDirectiveName();
2394193326Sed  }
2395193326Sed
2396212904Sdim  UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc,
2397193326Sed                     SourceLocation NamespcLoc,
2398219077Sdim                     NestedNameSpecifierLoc QualifierLoc,
2399193326Sed                     SourceLocation IdentLoc,
2400199990Srdivacky                     NamedDecl *Nominated,
2401193326Sed                     DeclContext *CommonAncestor)
2402212904Sdim    : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc),
2403219077Sdim      NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc),
2404219077Sdim      NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) { }
2405193326Sed
2406193326Sedpublic:
2407193326Sed  /// \brief Retrieve the nested-name-specifier that qualifies the
2408219077Sdim  /// name of the namespace, with source-location information.
2409219077Sdim  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2410235633Sdim
2411219077Sdim  /// \brief Retrieve the nested-name-specifier that qualifies the
2412193326Sed  /// name of the namespace.
2413235633Sdim  NestedNameSpecifier *getQualifier() const {
2414235633Sdim    return QualifierLoc.getNestedNameSpecifier();
2415219077Sdim  }
2416193326Sed
2417199990Srdivacky  NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
2418199990Srdivacky  const NamedDecl *getNominatedNamespaceAsWritten() const {
2419199990Srdivacky    return NominatedNamespace;
2420199990Srdivacky  }
2421199990Srdivacky
2422193326Sed  /// getNominatedNamespace - Returns namespace nominated by using-directive.
2423199990Srdivacky  NamespaceDecl *getNominatedNamespace();
2424193326Sed
2425193326Sed  const NamespaceDecl *getNominatedNamespace() const {
2426193326Sed    return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
2427193326Sed  }
2428193326Sed
2429208600Srdivacky  /// \brief Returns the common ancestor context of this using-directive and
2430208600Srdivacky  /// its nominated namespace.
2431193326Sed  DeclContext *getCommonAncestor() { return CommonAncestor; }
2432193326Sed  const DeclContext *getCommonAncestor() const { return CommonAncestor; }
2433193326Sed
2434212904Sdim  /// \brief Return the location of the "using" keyword.
2435212904Sdim  SourceLocation getUsingLoc() const { return UsingLoc; }
2436235633Sdim
2437208600Srdivacky  // FIXME: Could omit 'Key' in name.
2438193326Sed  /// getNamespaceKeyLocation - Returns location of namespace keyword.
2439193326Sed  SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
2440193326Sed
2441193326Sed  /// getIdentLocation - Returns location of identifier.
2442212904Sdim  SourceLocation getIdentLocation() const { return getLocation(); }
2443193326Sed
2444193326Sed  static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
2445212904Sdim                                    SourceLocation UsingLoc,
2446193326Sed                                    SourceLocation NamespaceLoc,
2447219077Sdim                                    NestedNameSpecifierLoc QualifierLoc,
2448193326Sed                                    SourceLocation IdentLoc,
2449199990Srdivacky                                    NamedDecl *Nominated,
2450193326Sed                                    DeclContext *CommonAncestor);
2451235633Sdim  static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2452235633Sdim
2453235633Sdim  SourceRange getSourceRange() const LLVM_READONLY {
2454212904Sdim    return SourceRange(UsingLoc, getLocation());
2455212904Sdim  }
2456235633Sdim
2457203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2458210299Sed  static bool classofKind(Kind K) { return K == UsingDirective; }
2459193326Sed
2460193326Sed  // Friend for getUsingDirectiveName.
2461193326Sed  friend class DeclContext;
2462235633Sdim
2463212904Sdim  friend class ASTDeclReader;
2464193326Sed};
2465193326Sed
2466245431Sdim/// \brief Represents a C++ namespace alias.
2467193326Sed///
2468245431Sdim/// For example:
2469245431Sdim///
2470193326Sed/// @code
2471193326Sed/// namespace Foo = Bar;
2472193326Sed/// @endcode
2473193326Sedclass NamespaceAliasDecl : public NamedDecl {
2474235633Sdim  virtual void anchor();
2475235633Sdim
2476212904Sdim  /// \brief The location of the "namespace" keyword.
2477212904Sdim  SourceLocation NamespaceLoc;
2478193326Sed
2479208600Srdivacky  /// IdentLoc - Location of namespace identifier. Accessed by TargetNameLoc.
2480193326Sed  SourceLocation IdentLoc;
2481235633Sdim
2482219077Sdim  /// \brief The nested-name-specifier that precedes the namespace.
2483219077Sdim  NestedNameSpecifierLoc QualifierLoc;
2484235633Sdim
2485198092Srdivacky  /// Namespace - The Decl that this alias points to. Can either be a
2486193326Sed  /// NamespaceDecl or a NamespaceAliasDecl.
2487193326Sed  NamedDecl *Namespace;
2488198092Srdivacky
2489212904Sdim  NamespaceAliasDecl(DeclContext *DC, SourceLocation NamespaceLoc,
2490198092Srdivacky                     SourceLocation AliasLoc, IdentifierInfo *Alias,
2491219077Sdim                     NestedNameSpecifierLoc QualifierLoc,
2492193326Sed                     SourceLocation IdentLoc, NamedDecl *Namespace)
2493235633Sdim    : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias),
2494219077Sdim      NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc),
2495219077Sdim      QualifierLoc(QualifierLoc), Namespace(Namespace) { }
2496193326Sed
2497212904Sdim  friend class ASTDeclReader;
2498235633Sdim
2499193326Sedpublic:
2500193326Sed  /// \brief Retrieve the nested-name-specifier that qualifies the
2501219077Sdim  /// name of the namespace, with source-location information.
2502219077Sdim  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2503235633Sdim
2504219077Sdim  /// \brief Retrieve the nested-name-specifier that qualifies the
2505193326Sed  /// name of the namespace.
2506235633Sdim  NestedNameSpecifier *getQualifier() const {
2507235633Sdim    return QualifierLoc.getNestedNameSpecifier();
2508219077Sdim  }
2509235633Sdim
2510208600Srdivacky  /// \brief Retrieve the namespace declaration aliased by this directive.
2511193326Sed  NamespaceDecl *getNamespace() {
2512193326Sed    if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
2513193326Sed      return AD->getNamespace();
2514193326Sed
2515193326Sed    return cast<NamespaceDecl>(Namespace);
2516193326Sed  }
2517198092Srdivacky
2518193326Sed  const NamespaceDecl *getNamespace() const {
2519193326Sed    return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
2520193326Sed  }
2521193326Sed
2522203955Srdivacky  /// Returns the location of the alias name, i.e. 'foo' in
2523203955Srdivacky  /// "namespace foo = ns::bar;".
2524212904Sdim  SourceLocation getAliasLoc() const { return getLocation(); }
2525203955Srdivacky
2526203955Srdivacky  /// Returns the location of the 'namespace' keyword.
2527212904Sdim  SourceLocation getNamespaceLoc() const { return NamespaceLoc; }
2528203955Srdivacky
2529203955Srdivacky  /// Returns the location of the identifier in the named namespace.
2530203955Srdivacky  SourceLocation getTargetNameLoc() const { return IdentLoc; }
2531203955Srdivacky
2532193326Sed  /// \brief Retrieve the namespace that this alias refers to, which
2533193326Sed  /// may either be a NamespaceDecl or a NamespaceAliasDecl.
2534193326Sed  NamedDecl *getAliasedNamespace() const { return Namespace; }
2535193326Sed
2536198092Srdivacky  static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
2537235633Sdim                                    SourceLocation NamespaceLoc,
2538212904Sdim                                    SourceLocation AliasLoc,
2539198092Srdivacky                                    IdentifierInfo *Alias,
2540219077Sdim                                    NestedNameSpecifierLoc QualifierLoc,
2541198092Srdivacky                                    SourceLocation IdentLoc,
2542193326Sed                                    NamedDecl *Namespace);
2543198092Srdivacky
2544235633Sdim  static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2545235633Sdim
2546235633Sdim  virtual SourceRange getSourceRange() const LLVM_READONLY {
2547212904Sdim    return SourceRange(NamespaceLoc, IdentLoc);
2548212904Sdim  }
2549235633Sdim
2550203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2551210299Sed  static bool classofKind(Kind K) { return K == NamespaceAlias; }
2552193326Sed};
2553194613Sed
2554245431Sdim/// \brief Represents a shadow declaration introduced into a scope by a
2555245431Sdim/// (resolved) using declaration.
2556199482Srdivacky///
2557245431Sdim/// For example,
2558245431Sdim/// @code
2559199482Srdivacky/// namespace A {
2560199482Srdivacky///   void foo();
2561199482Srdivacky/// }
2562199482Srdivacky/// namespace B {
2563245431Sdim///   using A::foo; // <- a UsingDecl
2564245431Sdim///                 // Also creates a UsingShadowDecl for A::foo() in B
2565199482Srdivacky/// }
2566245431Sdim/// @endcode
2567199482Srdivackyclass UsingShadowDecl : public NamedDecl {
2568235633Sdim  virtual void anchor();
2569235633Sdim
2570199482Srdivacky  /// The referenced declaration.
2571199482Srdivacky  NamedDecl *Underlying;
2572199482Srdivacky
2573218893Sdim  /// \brief The using declaration which introduced this decl or the next using
2574218893Sdim  /// shadow declaration contained in the aforementioned using declaration.
2575218893Sdim  NamedDecl *UsingOrNextShadow;
2576218893Sdim  friend class UsingDecl;
2577199482Srdivacky
2578199482Srdivacky  UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using,
2579199482Srdivacky                  NamedDecl *Target)
2580210299Sed    : NamedDecl(UsingShadow, DC, Loc, DeclarationName()),
2581218893Sdim      Underlying(Target),
2582218893Sdim      UsingOrNextShadow(reinterpret_cast<NamedDecl *>(Using)) {
2583210299Sed    if (Target) {
2584210299Sed      setDeclName(Target->getDeclName());
2585210299Sed      IdentifierNamespace = Target->getIdentifierNamespace();
2586210299Sed    }
2587199482Srdivacky    setImplicit();
2588199482Srdivacky  }
2589199482Srdivacky
2590199482Srdivackypublic:
2591199482Srdivacky  static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
2592199482Srdivacky                                 SourceLocation Loc, UsingDecl *Using,
2593199482Srdivacky                                 NamedDecl *Target) {
2594199482Srdivacky    return new (C) UsingShadowDecl(DC, Loc, Using, Target);
2595199482Srdivacky  }
2596199482Srdivacky
2597235633Sdim  static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2598235633Sdim
2599208600Srdivacky  /// \brief Gets the underlying declaration which has been brought into the
2600199482Srdivacky  /// local scope.
2601208600Srdivacky  NamedDecl *getTargetDecl() const { return Underlying; }
2602199482Srdivacky
2603208600Srdivacky  /// \brief Sets the underlying declaration which has been brought into the
2604208600Srdivacky  /// local scope.
2605210299Sed  void setTargetDecl(NamedDecl* ND) {
2606210299Sed    assert(ND && "Target decl is null!");
2607210299Sed    Underlying = ND;
2608210299Sed    IdentifierNamespace = ND->getIdentifierNamespace();
2609210299Sed  }
2610199482Srdivacky
2611208600Srdivacky  /// \brief Gets the using declaration to which this declaration is tied.
2612218893Sdim  UsingDecl *getUsingDecl() const;
2613208600Srdivacky
2614218893Sdim  /// \brief The next using shadow declaration contained in the shadow decl
2615218893Sdim  /// chain of the using declaration which introduced this decl.
2616218893Sdim  UsingShadowDecl *getNextUsingShadowDecl() const {
2617218893Sdim    return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow);
2618218893Sdim  }
2619208600Srdivacky
2620203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2621203955Srdivacky  static bool classofKind(Kind K) { return K == Decl::UsingShadow; }
2622218893Sdim
2623218893Sdim  friend class ASTDeclReader;
2624218893Sdim  friend class ASTDeclWriter;
2625199482Srdivacky};
2626199482Srdivacky
2627245431Sdim/// \brief Represents a C++ using-declaration.
2628245431Sdim///
2629245431Sdim/// For example:
2630245431Sdim/// @code
2631194613Sed///    using someNameSpace::someIdentifier;
2632245431Sdim/// @endcode
2633194613Sedclass UsingDecl : public NamedDecl {
2634235633Sdim  virtual void anchor();
2635235633Sdim
2636194613Sed  /// \brief The source location of the "using" location itself.
2637194613Sed  SourceLocation UsingLocation;
2638198092Srdivacky
2639219077Sdim  /// \brief The nested-name-specifier that precedes the name.
2640219077Sdim  NestedNameSpecifierLoc QualifierLoc;
2641194613Sed
2642212904Sdim  /// DNLoc - Provides source/type location info for the
2643212904Sdim  /// declaration name embedded in the ValueDecl base class.
2644212904Sdim  DeclarationNameLoc DNLoc;
2645212904Sdim
2646218893Sdim  /// \brief The first shadow declaration of the shadow decl chain associated
2647245431Sdim  /// with this using declaration.
2648245431Sdim  ///
2649245431Sdim  /// The bool member of the pair store whether this decl has the \c typename
2650245431Sdim  /// keyword.
2651235633Sdim  llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow;
2652199482Srdivacky
2653235633Sdim  UsingDecl(DeclContext *DC, SourceLocation UL,
2654219077Sdim            NestedNameSpecifierLoc QualifierLoc,
2655212904Sdim            const DeclarationNameInfo &NameInfo, bool IsTypeNameArg)
2656212904Sdim    : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()),
2657219077Sdim      UsingLocation(UL), QualifierLoc(QualifierLoc),
2658235633Sdim      DNLoc(NameInfo.getInfo()), FirstUsingShadow(0, IsTypeNameArg) {
2659194613Sed  }
2660194613Sed
2661194613Sedpublic:
2662208600Srdivacky  /// \brief Returns the source location of the "using" keyword.
2663212904Sdim  SourceLocation getUsingLocation() const { return UsingLocation; }
2664198092Srdivacky
2665208600Srdivacky  /// \brief Set the source location of the 'using' keyword.
2666208600Srdivacky  void setUsingLocation(SourceLocation L) { UsingLocation = L; }
2667208600Srdivacky
2668219077Sdim  /// \brief Retrieve the nested-name-specifier that qualifies the name,
2669219077Sdim  /// with source-location information.
2670219077Sdim  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2671219077Sdim
2672219077Sdim  /// \brief Retrieve the nested-name-specifier that qualifies the name.
2673235633Sdim  NestedNameSpecifier *getQualifier() const {
2674235633Sdim    return QualifierLoc.getNestedNameSpecifier();
2675195099Sed  }
2676198092Srdivacky
2677212904Sdim  DeclarationNameInfo getNameInfo() const {
2678212904Sdim    return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
2679212904Sdim  }
2680212904Sdim
2681208600Srdivacky  /// \brief Return true if the using declaration has 'typename'.
2682235633Sdim  bool isTypeName() const { return FirstUsingShadow.getInt(); }
2683194613Sed
2684208600Srdivacky  /// \brief Sets whether the using declaration has 'typename'.
2685235633Sdim  void setTypeName(bool TN) { FirstUsingShadow.setInt(TN); }
2686208600Srdivacky
2687218893Sdim  /// \brief Iterates through the using shadow declarations assosiated with
2688218893Sdim  /// this using declaration.
2689218893Sdim  class shadow_iterator {
2690218893Sdim    /// \brief The current using shadow declaration.
2691218893Sdim    UsingShadowDecl *Current;
2692199482Srdivacky
2693218893Sdim  public:
2694218893Sdim    typedef UsingShadowDecl*          value_type;
2695218893Sdim    typedef UsingShadowDecl*          reference;
2696218893Sdim    typedef UsingShadowDecl*          pointer;
2697218893Sdim    typedef std::forward_iterator_tag iterator_category;
2698218893Sdim    typedef std::ptrdiff_t            difference_type;
2699218893Sdim
2700218893Sdim    shadow_iterator() : Current(0) { }
2701218893Sdim    explicit shadow_iterator(UsingShadowDecl *C) : Current(C) { }
2702218893Sdim
2703218893Sdim    reference operator*() const { return Current; }
2704218893Sdim    pointer operator->() const { return Current; }
2705218893Sdim
2706218893Sdim    shadow_iterator& operator++() {
2707218893Sdim      Current = Current->getNextUsingShadowDecl();
2708218893Sdim      return *this;
2709199482Srdivacky    }
2710218893Sdim
2711218893Sdim    shadow_iterator operator++(int) {
2712218893Sdim      shadow_iterator tmp(*this);
2713218893Sdim      ++(*this);
2714218893Sdim      return tmp;
2715199482Srdivacky    }
2716218893Sdim
2717218893Sdim    friend bool operator==(shadow_iterator x, shadow_iterator y) {
2718218893Sdim      return x.Current == y.Current;
2719218893Sdim    }
2720218893Sdim    friend bool operator!=(shadow_iterator x, shadow_iterator y) {
2721218893Sdim      return x.Current != y.Current;
2722218893Sdim    }
2723218893Sdim  };
2724218893Sdim
2725218893Sdim  shadow_iterator shadow_begin() const {
2726235633Sdim    return shadow_iterator(FirstUsingShadow.getPointer());
2727199482Srdivacky  }
2728218893Sdim  shadow_iterator shadow_end() const { return shadow_iterator(); }
2729199482Srdivacky
2730208600Srdivacky  /// \brief Return the number of shadowed declarations associated with this
2731208600Srdivacky  /// using declaration.
2732218893Sdim  unsigned shadow_size() const {
2733218893Sdim    return std::distance(shadow_begin(), shadow_end());
2734208600Srdivacky  }
2735208600Srdivacky
2736218893Sdim  void addShadowDecl(UsingShadowDecl *S);
2737218893Sdim  void removeShadowDecl(UsingShadowDecl *S);
2738218893Sdim
2739194613Sed  static UsingDecl *Create(ASTContext &C, DeclContext *DC,
2740219077Sdim                           SourceLocation UsingL,
2741219077Sdim                           NestedNameSpecifierLoc QualifierLoc,
2742212904Sdim                           const DeclarationNameInfo &NameInfo,
2743212904Sdim                           bool IsTypeNameArg);
2744194613Sed
2745235633Sdim  static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2746235633Sdim
2747235633Sdim  SourceRange getSourceRange() const LLVM_READONLY {
2748212904Sdim    return SourceRange(UsingLocation, getNameInfo().getEndLoc());
2749212904Sdim  }
2750212904Sdim
2751203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2752210299Sed  static bool classofKind(Kind K) { return K == Using; }
2753210299Sed
2754212904Sdim  friend class ASTDeclReader;
2755212904Sdim  friend class ASTDeclWriter;
2756194613Sed};
2757198092Srdivacky
2758245431Sdim/// \brief Represents a dependent using declaration which was not marked with
2759245431Sdim/// \c typename.
2760245431Sdim///
2761245431Sdim/// Unlike non-dependent using declarations, these *only* bring through
2762199482Srdivacky/// non-types; otherwise they would break two-phase lookup.
2763199482Srdivacky///
2764245431Sdim/// @code
2765245431Sdim/// template \<class T> class A : public Base<T> {
2766199482Srdivacky///   using Base<T>::foo;
2767199482Srdivacky/// };
2768245431Sdim/// @endcode
2769199482Srdivackyclass UnresolvedUsingValueDecl : public ValueDecl {
2770235633Sdim  virtual void anchor();
2771235633Sdim
2772199482Srdivacky  /// \brief The source location of the 'using' keyword
2773199482Srdivacky  SourceLocation UsingLocation;
2774198092Srdivacky
2775219077Sdim  /// \brief The nested-name-specifier that precedes the name.
2776219077Sdim  NestedNameSpecifierLoc QualifierLoc;
2777198092Srdivacky
2778212904Sdim  /// DNLoc - Provides source/type location info for the
2779212904Sdim  /// declaration name embedded in the ValueDecl base class.
2780212904Sdim  DeclarationNameLoc DNLoc;
2781212904Sdim
2782199482Srdivacky  UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
2783235633Sdim                           SourceLocation UsingLoc,
2784219077Sdim                           NestedNameSpecifierLoc QualifierLoc,
2785212904Sdim                           const DeclarationNameInfo &NameInfo)
2786212904Sdim    : ValueDecl(UnresolvedUsingValue, DC,
2787212904Sdim                NameInfo.getLoc(), NameInfo.getName(), Ty),
2788219077Sdim      UsingLocation(UsingLoc), QualifierLoc(QualifierLoc),
2789219077Sdim      DNLoc(NameInfo.getInfo())
2790199482Srdivacky  { }
2791198092Srdivacky
2792199482Srdivackypublic:
2793199482Srdivacky  /// \brief Returns the source location of the 'using' keyword.
2794199482Srdivacky  SourceLocation getUsingLoc() const { return UsingLocation; }
2795199482Srdivacky
2796208600Srdivacky  /// \brief Set the source location of the 'using' keyword.
2797208600Srdivacky  void setUsingLoc(SourceLocation L) { UsingLocation = L; }
2798208600Srdivacky
2799219077Sdim  /// \brief Retrieve the nested-name-specifier that qualifies the name,
2800219077Sdim  /// with source-location information.
2801219077Sdim  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2802219077Sdim
2803219077Sdim  /// \brief Retrieve the nested-name-specifier that qualifies the name.
2804235633Sdim  NestedNameSpecifier *getQualifier() const {
2805235633Sdim    return QualifierLoc.getNestedNameSpecifier();
2806219077Sdim  }
2807235633Sdim
2808212904Sdim  DeclarationNameInfo getNameInfo() const {
2809212904Sdim    return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
2810212904Sdim  }
2811212904Sdim
2812199482Srdivacky  static UnresolvedUsingValueDecl *
2813199482Srdivacky    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
2814235633Sdim           NestedNameSpecifierLoc QualifierLoc,
2815212904Sdim           const DeclarationNameInfo &NameInfo);
2816199482Srdivacky
2817235633Sdim  static UnresolvedUsingValueDecl *
2818235633Sdim  CreateDeserialized(ASTContext &C, unsigned ID);
2819235633Sdim
2820235633Sdim  SourceRange getSourceRange() const LLVM_READONLY {
2821212904Sdim    return SourceRange(UsingLocation, getNameInfo().getEndLoc());
2822212904Sdim  }
2823212904Sdim
2824203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2825210299Sed  static bool classofKind(Kind K) { return K == UnresolvedUsingValue; }
2826218893Sdim
2827218893Sdim  friend class ASTDeclReader;
2828218893Sdim  friend class ASTDeclWriter;
2829199482Srdivacky};
2830199482Srdivacky
2831245431Sdim/// @brief Represents a dependent using declaration which was marked with
2832245431Sdim/// \c typename.
2833199482Srdivacky///
2834245431Sdim/// @code
2835245431Sdim/// template \<class T> class A : public Base<T> {
2836199482Srdivacky///   using typename Base<T>::foo;
2837199482Srdivacky/// };
2838245431Sdim/// @endcode
2839199482Srdivacky///
2840245431Sdim/// The type associated with an unresolved using typename decl is
2841199482Srdivacky/// currently always a typename type.
2842199482Srdivackyclass UnresolvedUsingTypenameDecl : public TypeDecl {
2843235633Sdim  virtual void anchor();
2844235633Sdim
2845199482Srdivacky  /// \brief The source location of the 'using' keyword
2846199482Srdivacky  SourceLocation UsingLocation;
2847199482Srdivacky
2848199482Srdivacky  /// \brief The source location of the 'typename' keyword
2849199482Srdivacky  SourceLocation TypenameLocation;
2850199482Srdivacky
2851219077Sdim  /// \brief The nested-name-specifier that precedes the name.
2852219077Sdim  NestedNameSpecifierLoc QualifierLoc;
2853199482Srdivacky
2854199482Srdivacky  UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
2855219077Sdim                              SourceLocation TypenameLoc,
2856219077Sdim                              NestedNameSpecifierLoc QualifierLoc,
2857235633Sdim                              SourceLocation TargetNameLoc,
2858219077Sdim                              IdentifierInfo *TargetName)
2859221345Sdim    : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName,
2860221345Sdim               UsingLoc),
2861221345Sdim      TypenameLocation(TypenameLoc), QualifierLoc(QualifierLoc) { }
2862199482Srdivacky
2863212904Sdim  friend class ASTDeclReader;
2864235633Sdim
2865198092Srdivackypublic:
2866199482Srdivacky  /// \brief Returns the source location of the 'using' keyword.
2867221345Sdim  SourceLocation getUsingLoc() const { return getLocStart(); }
2868198092Srdivacky
2869199482Srdivacky  /// \brief Returns the source location of the 'typename' keyword.
2870199482Srdivacky  SourceLocation getTypenameLoc() const { return TypenameLocation; }
2871198092Srdivacky
2872219077Sdim  /// \brief Retrieve the nested-name-specifier that qualifies the name,
2873219077Sdim  /// with source-location information.
2874219077Sdim  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2875219077Sdim
2876219077Sdim  /// \brief Retrieve the nested-name-specifier that qualifies the name.
2877235633Sdim  NestedNameSpecifier *getQualifier() const {
2878235633Sdim    return QualifierLoc.getNestedNameSpecifier();
2879219077Sdim  }
2880219077Sdim
2881199482Srdivacky  static UnresolvedUsingTypenameDecl *
2882199482Srdivacky    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
2883219077Sdim           SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc,
2884199482Srdivacky           SourceLocation TargetNameLoc, DeclarationName TargetName);
2885198092Srdivacky
2886235633Sdim  static UnresolvedUsingTypenameDecl *
2887235633Sdim  CreateDeserialized(ASTContext &C, unsigned ID);
2888235633Sdim
2889203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2890210299Sed  static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; }
2891198092Srdivacky};
2892198092Srdivacky
2893245431Sdim/// \brief Represents a C++11 static_assert declaration.
2894193326Sedclass StaticAssertDecl : public Decl {
2895235633Sdim  virtual void anchor();
2896245431Sdim  llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed;
2897193326Sed  StringLiteral *Message;
2898221345Sdim  SourceLocation RParenLoc;
2899193326Sed
2900221345Sdim  StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc,
2901245431Sdim                   Expr *AssertExpr, StringLiteral *Message,
2902245431Sdim                   SourceLocation RParenLoc, bool Failed)
2903245431Sdim    : Decl(StaticAssert, DC, StaticAssertLoc),
2904245431Sdim      AssertExprAndFailed(AssertExpr, Failed), Message(Message),
2905245431Sdim      RParenLoc(RParenLoc) { }
2906198092Srdivacky
2907193326Sedpublic:
2908193326Sed  static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
2909221345Sdim                                  SourceLocation StaticAssertLoc,
2910221345Sdim                                  Expr *AssertExpr, StringLiteral *Message,
2911245431Sdim                                  SourceLocation RParenLoc, bool Failed);
2912235633Sdim  static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2913235633Sdim
2914245431Sdim  Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); }
2915245431Sdim  const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); }
2916198092Srdivacky
2917193326Sed  StringLiteral *getMessage() { return Message; }
2918193326Sed  const StringLiteral *getMessage() const { return Message; }
2919198092Srdivacky
2920245431Sdim  bool isFailed() const { return AssertExprAndFailed.getInt(); }
2921245431Sdim
2922221345Sdim  SourceLocation getRParenLoc() const { return RParenLoc; }
2923221345Sdim
2924235633Sdim  SourceRange getSourceRange() const LLVM_READONLY {
2925221345Sdim    return SourceRange(getLocation(), getRParenLoc());
2926221345Sdim  }
2927221345Sdim
2928203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2929210299Sed  static bool classofKind(Kind K) { return K == StaticAssert; }
2930212904Sdim
2931212904Sdim  friend class ASTDeclReader;
2932193326Sed};
2933193326Sed
2934245431Sdim/// Insertion operator for diagnostics.  This allows sending an AccessSpecifier
2935193326Sed/// into a diagnostic with <<.
2936193326Sedconst DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
2937193326Sed                                    AccessSpecifier AS);
2938198092Srdivacky
2939235633Sdimconst PartialDiagnostic &operator<<(const PartialDiagnostic &DB,
2940235633Sdim                                    AccessSpecifier AS);
2941235633Sdim
2942193326Sed} // end namespace clang
2943193326Sed
2944193326Sed#endif
2945