DeclCXX.h revision 235633
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;
44235633Sdim
45198092Srdivacky/// \brief Represents any kind of function declaration, whether it is a
46195099Sed/// concrete function or a function template.
47195099Sedclass AnyFunctionDecl {
48195099Sed  NamedDecl *Function;
49198092Srdivacky
50195341Sed  AnyFunctionDecl(NamedDecl *ND) : Function(ND) { }
51198092Srdivacky
52195099Sedpublic:
53195099Sed  AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { }
54195099Sed  AnyFunctionDecl(FunctionTemplateDecl *FTD);
55198092Srdivacky
56198092Srdivacky  /// \brief Implicily converts any function or function template into a
57195099Sed  /// named declaration.
58195099Sed  operator NamedDecl *() const { return Function; }
59198092Srdivacky
60195099Sed  /// \brief Retrieve the underlying function or function template.
61195099Sed  NamedDecl *get() const { return Function; }
62198092Srdivacky
63198092Srdivacky  static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) {
64195341Sed    return AnyFunctionDecl(ND);
65195341Sed  }
66195099Sed};
67198092Srdivacky
68195099Sed} // end namespace clang
69195099Sed
70195099Sednamespace llvm {
71198092Srdivacky  /// Implement simplify_type for AnyFunctionDecl, so that we can dyn_cast from
72195099Sed  /// AnyFunctionDecl to any function or function template declaration.
73195099Sed  template<> struct simplify_type<const ::clang::AnyFunctionDecl> {
74195099Sed    typedef ::clang::NamedDecl* SimpleType;
75195099Sed    static SimpleType getSimplifiedValue(const ::clang::AnyFunctionDecl &Val) {
76195099Sed      return Val;
77195099Sed    }
78195099Sed  };
79195099Sed  template<> struct simplify_type< ::clang::AnyFunctionDecl>
80195099Sed  : public simplify_type<const ::clang::AnyFunctionDecl> {};
81198092Srdivacky
82195341Sed  // Provide PointerLikeTypeTraits for non-cvr pointers.
83195341Sed  template<>
84195341Sed  class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
85195341Sed  public:
86195341Sed    static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
87198092Srdivacky      return F.get();
88195341Sed    }
89195341Sed    static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
90195341Sed      return ::clang::AnyFunctionDecl::getFromNamedDecl(
91195341Sed                                      static_cast< ::clang::NamedDecl*>(P));
92195341Sed    }
93198092Srdivacky
94195341Sed    enum { NumLowBitsAvailable = 2 };
95195341Sed  };
96198092Srdivacky
97195099Sed} // end namespace llvm
98195099Sed
99195099Sednamespace clang {
100198092Srdivacky
101210299Sed/// AccessSpecDecl - An access specifier followed by colon ':'.
102210299Sed///
103210299Sed/// An objects of this class represents sugar for the syntactic occurrence
104210299Sed/// of an access specifier followed by a colon in the list of member
105210299Sed/// specifiers of a C++ class definition.
106210299Sed///
107210299Sed/// Note that they do not represent other uses of access specifiers,
108210299Sed/// such as those occurring in a list of base specifiers.
109210299Sed/// Also note that this class has nothing to do with so-called
110210299Sed/// "access declarations" (C++98 11.3 [class.access.dcl]).
111210299Sedclass AccessSpecDecl : public Decl {
112235633Sdim  virtual void anchor();
113210299Sed  /// ColonLoc - The location of the ':'.
114210299Sed  SourceLocation ColonLoc;
115210299Sed
116210299Sed  AccessSpecDecl(AccessSpecifier AS, DeclContext *DC,
117210299Sed                 SourceLocation ASLoc, SourceLocation ColonLoc)
118210299Sed    : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) {
119210299Sed    setAccess(AS);
120210299Sed  }
121218893Sdim  AccessSpecDecl(EmptyShell Empty)
122218893Sdim    : Decl(AccessSpec, Empty) { }
123210299Sedpublic:
124210299Sed  /// getAccessSpecifierLoc - The location of the access specifier.
125210299Sed  SourceLocation getAccessSpecifierLoc() const { return getLocation(); }
126210299Sed  /// setAccessSpecifierLoc - Sets the location of the access specifier.
127210299Sed  void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); }
128210299Sed
129210299Sed  /// getColonLoc - The location of the colon following the access specifier.
130210299Sed  SourceLocation getColonLoc() const { return ColonLoc; }
131210299Sed  /// setColonLoc - Sets the location of the colon.
132210299Sed  void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; }
133210299Sed
134235633Sdim  SourceRange getSourceRange() const LLVM_READONLY {
135210299Sed    return SourceRange(getAccessSpecifierLoc(), getColonLoc());
136210299Sed  }
137210299Sed
138210299Sed  static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS,
139210299Sed                                DeclContext *DC, SourceLocation ASLoc,
140210299Sed                                SourceLocation ColonLoc) {
141210299Sed    return new (C) AccessSpecDecl(AS, DC, ASLoc, ColonLoc);
142210299Sed  }
143235633Sdim  static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
144210299Sed
145210299Sed  // Implement isa/cast/dyncast/etc.
146210299Sed  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
147210299Sed  static bool classof(const AccessSpecDecl *D) { return true; }
148210299Sed  static bool classofKind(Kind K) { return K == AccessSpec; }
149210299Sed};
150210299Sed
151210299Sed
152193326Sed/// CXXBaseSpecifier - 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
178193326Sed  /// Virtual - 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
360223017Sdim    /// HasTrivialDefaultConstructor - True when, if this class has a default
361223017Sdim    /// constructor, this default constructor is trivial.
362203955Srdivacky    ///
363223017Sdim    /// C++0x [class.ctor]p5
364223017Sdim    ///    A default constructor is trivial if it is not user-provided and if
365223017Sdim    ///     -- its class has no virtual functions and no virtual base classes,
366223017Sdim    ///        and
367223017Sdim    ///     -- no non-static data member of its class has a
368223017Sdim    ///        brace-or-equal-initializer, and
369223017Sdim    ///     -- all the direct base classes of its class have trivial
370223017Sdim    ///        default constructors, and
371223017Sdim    ///     -- for all the nonstatic data members of its class that are of class
372223017Sdim    ///        type (or array thereof), each such class has a trivial
373223017Sdim    ///        default constructor.
374223017Sdim    bool HasTrivialDefaultConstructor : 1;
375198092Srdivacky
376226890Sdim    /// HasConstexprNonCopyMoveConstructor - True when this class has at least
377235633Sdim    /// one user-declared constexpr constructor which is neither the copy nor
378235633Sdim    /// move constructor.
379226890Sdim    bool HasConstexprNonCopyMoveConstructor : 1;
380221345Sdim
381235633Sdim    /// DefaultedDefaultConstructorIsConstexpr - True if a defaulted default
382235633Sdim    /// constructor for this class would be constexpr.
383235633Sdim    bool DefaultedDefaultConstructorIsConstexpr : 1;
384235633Sdim
385235633Sdim    /// DefaultedCopyConstructorIsConstexpr - True if a defaulted copy
386235633Sdim    /// constructor for this class would be constexpr.
387235633Sdim    bool DefaultedCopyConstructorIsConstexpr : 1;
388235633Sdim
389235633Sdim    /// DefaultedMoveConstructorIsConstexpr - True if a defaulted move
390235633Sdim    /// constructor for this class would be constexpr.
391235633Sdim    bool DefaultedMoveConstructorIsConstexpr : 1;
392235633Sdim
393235633Sdim    /// HasConstexprDefaultConstructor - True if this class has a constexpr
394235633Sdim    /// default constructor (either user-declared or implicitly declared).
395235633Sdim    bool HasConstexprDefaultConstructor : 1;
396235633Sdim
397235633Sdim    /// HasConstexprCopyConstructor - True if this class has a constexpr copy
398235633Sdim    /// constructor (either user-declared or implicitly declared).
399235633Sdim    bool HasConstexprCopyConstructor : 1;
400235633Sdim
401235633Sdim    /// HasConstexprMoveConstructor - True if this class has a constexpr move
402235633Sdim    /// constructor (either user-declared or implicitly declared).
403235633Sdim    bool HasConstexprMoveConstructor : 1;
404235633Sdim
405203955Srdivacky    /// HasTrivialCopyConstructor - True when this class has a trivial copy
406203955Srdivacky    /// constructor.
407203955Srdivacky    ///
408221345Sdim    /// C++0x [class.copy]p13:
409221345Sdim    ///   A copy/move constructor for class X is trivial if it is neither
410223017Sdim    ///   user-provided and if
411221345Sdim    ///    -- class X has no virtual functions and no virtual base classes, and
412221345Sdim    ///    -- the constructor selected to copy/move each direct base class
413221345Sdim    ///       subobject is trivial, and
414221345Sdim    ///    -- for each non-static data member of X that is of class type (or an
415221345Sdim    ///       array thereof), the constructor selected to copy/move that member
416221345Sdim    ///       is trivial;
417221345Sdim    ///   otherwise the copy/move constructor is non-trivial.
418203955Srdivacky    bool HasTrivialCopyConstructor : 1;
419203955Srdivacky
420221345Sdim    /// HasTrivialMoveConstructor - True when this class has a trivial move
421221345Sdim    /// constructor.
422221345Sdim    ///
423221345Sdim    /// C++0x [class.copy]p13:
424221345Sdim    ///   A copy/move constructor for class X is trivial if it is neither
425223017Sdim    ///   user-provided and if
426221345Sdim    ///    -- class X has no virtual functions and no virtual base classes, and
427221345Sdim    ///    -- the constructor selected to copy/move each direct base class
428221345Sdim    ///       subobject is trivial, and
429221345Sdim    ///    -- for each non-static data member of X that is of class type (or an
430221345Sdim    ///       array thereof), the constructor selected to copy/move that member
431221345Sdim    ///       is trivial;
432221345Sdim    ///   otherwise the copy/move constructor is non-trivial.
433221345Sdim    bool HasTrivialMoveConstructor : 1;
434221345Sdim
435203955Srdivacky    /// HasTrivialCopyAssignment - True when this class has a trivial copy
436203955Srdivacky    /// assignment operator.
437203955Srdivacky    ///
438221345Sdim    /// C++0x [class.copy]p27:
439221345Sdim    ///   A copy/move assignment operator for class X is trivial if it is
440221345Sdim    ///   neither user-provided nor deleted and if
441221345Sdim    ///    -- class X has no virtual functions and no virtual base classes, and
442221345Sdim    ///    -- the assignment operator selected to copy/move each direct base
443221345Sdim    ///       class subobject is trivial, and
444221345Sdim    ///    -- for each non-static data member of X that is of class type (or an
445221345Sdim    ///       array thereof), the assignment operator selected to copy/move
446221345Sdim    ///       that member is trivial;
447221345Sdim    ///   otherwise the copy/move assignment operator is non-trivial.
448203955Srdivacky    bool HasTrivialCopyAssignment : 1;
449203955Srdivacky
450221345Sdim    /// HasTrivialMoveAssignment - True when this class has a trivial move
451221345Sdim    /// assignment operator.
452221345Sdim    ///
453221345Sdim    /// C++0x [class.copy]p27:
454221345Sdim    ///   A copy/move assignment operator for class X is trivial if it is
455221345Sdim    ///   neither user-provided nor deleted and if
456221345Sdim    ///    -- class X has no virtual functions and no virtual base classes, and
457221345Sdim    ///    -- the assignment operator selected to copy/move each direct base
458221345Sdim    ///       class subobject is trivial, and
459221345Sdim    ///    -- for each non-static data member of X that is of class type (or an
460221345Sdim    ///       array thereof), the assignment operator selected to copy/move
461221345Sdim    ///       that member is trivial;
462221345Sdim    ///   otherwise the copy/move assignment operator is non-trivial.
463221345Sdim    bool HasTrivialMoveAssignment : 1;
464221345Sdim
465203955Srdivacky    /// HasTrivialDestructor - True when this class has a trivial destructor.
466203955Srdivacky    ///
467203955Srdivacky    /// C++ [class.dtor]p3.  A destructor is trivial if it is an
468203955Srdivacky    /// implicitly-declared destructor and if:
469203955Srdivacky    /// * all of the direct base classes of its class have trivial destructors
470203955Srdivacky    ///   and
471203955Srdivacky    /// * for all of the non-static data members of its class that are of class
472203955Srdivacky    ///   type (or array thereof), each such class has a trivial destructor.
473203955Srdivacky    bool HasTrivialDestructor : 1;
474203955Srdivacky
475235633Sdim    /// HasIrrelevantDestructor - True when this class has a destructor with no
476235633Sdim    /// semantic effect.
477235633Sdim    bool HasIrrelevantDestructor : 1;
478235633Sdim
479221345Sdim    /// HasNonLiteralTypeFieldsOrBases - True when this class contains at least
480235633Sdim    /// one non-static data member or base class of non-literal or volatile
481235633Sdim    /// type.
482221345Sdim    bool HasNonLiteralTypeFieldsOrBases : 1;
483221345Sdim
484203955Srdivacky    /// ComputedVisibleConversions - True when visible conversion functions are
485203955Srdivacky    /// already computed and are available.
486203955Srdivacky    bool ComputedVisibleConversions : 1;
487210299Sed
488223017Sdim    /// \brief Whether we have a C++0x user-provided default constructor (not
489223017Sdim    /// explicitly deleted or defaulted).
490223017Sdim    bool UserProvidedDefaultConstructor : 1;
491223017Sdim
492223017Sdim    /// \brief Whether we have already declared the default constructor.
493210299Sed    bool DeclaredDefaultConstructor : 1;
494210299Sed
495210299Sed    /// \brief Whether we have already declared the copy constructor.
496210299Sed    bool DeclaredCopyConstructor : 1;
497223017Sdim
498223017Sdim    /// \brief Whether we have already declared the move constructor.
499223017Sdim    bool DeclaredMoveConstructor : 1;
500235633Sdim
501210299Sed    /// \brief Whether we have already declared the copy-assignment operator.
502210299Sed    bool DeclaredCopyAssignment : 1;
503223017Sdim
504223017Sdim    /// \brief Whether we have already declared the move-assignment operator.
505223017Sdim    bool DeclaredMoveAssignment : 1;
506235633Sdim
507210299Sed    /// \brief Whether we have already declared a destructor within the class.
508210299Sed    bool DeclaredDestructor : 1;
509218893Sdim
510226890Sdim    /// \brief Whether an implicit move constructor was attempted to be declared
511226890Sdim    /// but would have been deleted.
512226890Sdim    bool FailedImplicitMoveConstructor : 1;
513226890Sdim
514226890Sdim    /// \brief Whether an implicit move assignment operator was attempted to be
515226890Sdim    /// declared but would have been deleted.
516226890Sdim    bool FailedImplicitMoveAssignment : 1;
517226890Sdim
518235633Sdim    /// \brief Whether this class describes a C++ lambda.
519235633Sdim    bool IsLambda : 1;
520235633Sdim
521218893Sdim    /// NumBases - The number of base class specifiers in Bases.
522218893Sdim    unsigned NumBases;
523235633Sdim
524218893Sdim    /// NumVBases - The number of virtual base class specifiers in VBases.
525218893Sdim    unsigned NumVBases;
526218893Sdim
527203955Srdivacky    /// Bases - Base classes of this class.
528203955Srdivacky    /// FIXME: This is wasted space for a union.
529218893Sdim    LazyCXXBaseSpecifiersPtr Bases;
530193326Sed
531203955Srdivacky    /// VBases - direct and indirect virtual base classes of this class.
532218893Sdim    LazyCXXBaseSpecifiersPtr VBases;
533198092Srdivacky
534203955Srdivacky    /// Conversions - Overload set containing the conversion functions
535203955Srdivacky    /// of this C++ class (but not its inherited conversion
536203955Srdivacky    /// functions). Each of the entries in this overload set is a
537203955Srdivacky    /// CXXConversionDecl.
538203955Srdivacky    UnresolvedSet<4> Conversions;
539193326Sed
540203955Srdivacky    /// VisibleConversions - Overload set containing the conversion
541203955Srdivacky    /// functions of this C++ class and all those inherited conversion
542203955Srdivacky    /// functions that are visible in this class. Each of the entries
543203955Srdivacky    /// in this overload set is a CXXConversionDecl or a
544203955Srdivacky    /// FunctionTemplateDecl.
545203955Srdivacky    UnresolvedSet<4> VisibleConversions;
546203955Srdivacky
547203955Srdivacky    /// Definition - The declaration which defines this record.
548203955Srdivacky    CXXRecordDecl *Definition;
549203955Srdivacky
550205219Srdivacky    /// FirstFriend - The first friend declaration in this class, or
551205219Srdivacky    /// null if there aren't any.  This is actually currently stored
552205219Srdivacky    /// in reverse order.
553205219Srdivacky    FriendDecl *FirstFriend;
554205219Srdivacky
555235633Sdim    /// \brief Retrieve the set of direct base classes.
556218893Sdim    CXXBaseSpecifier *getBases() const {
557218893Sdim      return Bases.get(Definition->getASTContext().getExternalSource());
558218893Sdim    }
559218893Sdim
560235633Sdim    /// \brief Retrieve the set of virtual base classes.
561218893Sdim    CXXBaseSpecifier *getVBases() const {
562218893Sdim      return VBases.get(Definition->getASTContext().getExternalSource());
563218893Sdim    }
564203955Srdivacky  } *DefinitionData;
565203955Srdivacky
566235633Sdim  /// \brief Describes a C++ closure type (generated by a lambda expression).
567235633Sdim  struct LambdaDefinitionData : public DefinitionData {
568235633Sdim    typedef LambdaExpr::Capture Capture;
569235633Sdim
570235633Sdim    LambdaDefinitionData(CXXRecordDecl *D, bool Dependent)
571235633Sdim      : DefinitionData(D), Dependent(Dependent), NumCaptures(0),
572235633Sdim        NumExplicitCaptures(0), ManglingNumber(0), ContextDecl(0), Captures(0)
573235633Sdim    {
574235633Sdim      IsLambda = true;
575235633Sdim    }
576235633Sdim
577235633Sdim    /// \brief Whether this lambda is known to be dependent, even if its
578235633Sdim    /// context isn't dependent.
579235633Sdim    ///
580235633Sdim    /// A lambda with a non-dependent context can be dependent if it occurs
581235633Sdim    /// within the default argument of a function template, because the
582235633Sdim    /// lambda will have been created with the enclosing context as its
583235633Sdim    /// declaration context, rather than function. This is an unfortunate
584235633Sdim    /// artifact of having to parse the default arguments before
585235633Sdim    unsigned Dependent : 1;
586235633Sdim
587235633Sdim    /// \brief The number of captures in this lambda.
588235633Sdim    unsigned NumCaptures : 16;
589235633Sdim
590235633Sdim    /// \brief The number of explicit captures in this lambda.
591235633Sdim    unsigned NumExplicitCaptures : 15;
592235633Sdim
593235633Sdim    /// \brief The number used to indicate this lambda expression for name
594235633Sdim    /// mangling in the Itanium C++ ABI.
595235633Sdim    unsigned ManglingNumber;
596235633Sdim
597235633Sdim    /// \brief The declaration that provides context for this lambda, if the
598235633Sdim    /// actual DeclContext does not suffice. This is used for lambdas that
599235633Sdim    /// occur within default arguments of function parameters within the class
600235633Sdim    /// or within a data member initializer.
601235633Sdim    Decl *ContextDecl;
602235633Sdim
603235633Sdim    /// \brief The list of captures, both explicit and implicit, for this
604235633Sdim    /// lambda.
605235633Sdim    Capture *Captures;
606235633Sdim  };
607235633Sdim
608203955Srdivacky  struct DefinitionData &data() {
609203955Srdivacky    assert(DefinitionData && "queried property of class with no definition");
610203955Srdivacky    return *DefinitionData;
611203955Srdivacky  }
612203955Srdivacky
613203955Srdivacky  const struct DefinitionData &data() const {
614203955Srdivacky    assert(DefinitionData && "queried property of class with no definition");
615203955Srdivacky    return *DefinitionData;
616203955Srdivacky  }
617235633Sdim
618235633Sdim  struct LambdaDefinitionData &getLambdaData() const {
619235633Sdim    assert(DefinitionData && "queried property of lambda with no definition");
620235633Sdim    assert(DefinitionData->IsLambda &&
621235633Sdim           "queried lambda property of non-lambda class");
622235633Sdim    return static_cast<LambdaDefinitionData &>(*DefinitionData);
623235633Sdim  }
624198092Srdivacky
625193326Sed  /// \brief The template or declaration that this declaration
626193326Sed  /// describes or was instantiated from, respectively.
627198092Srdivacky  ///
628193326Sed  /// For non-templates, this value will be NULL. For record
629193326Sed  /// declarations that describe a class template, this will be a
630193326Sed  /// pointer to a ClassTemplateDecl. For member
631193326Sed  /// classes of class template specializations, this will be the
632235633Sdim  /// MemberSpecializationInfo referring to the member class that was
633198092Srdivacky  /// instantiated or specialized.
634198092Srdivacky  llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*>
635193326Sed    TemplateOrInstantiation;
636206084Srdivacky
637218893Sdim  friend class DeclContext;
638235633Sdim  friend class LambdaExpr;
639235633Sdim
640218893Sdim  /// \brief Notify the class that member has been added.
641218893Sdim  ///
642235633Sdim  /// This routine helps maintain information about the class based on which
643218893Sdim  /// members have been added. It will be invoked by DeclContext::addDecl()
644218893Sdim  /// whenever a member is added to this record.
645218893Sdim  void addedMember(Decl *D);
646218893Sdim
647218893Sdim  void markedVirtualFunctionPure();
648218893Sdim  friend void FunctionDecl::setPure(bool);
649235633Sdim
650235633Sdim  friend class ASTNodeImporter;
651235633Sdim
652193326Sedprotected:
653193326Sed  CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
654221345Sdim                SourceLocation StartLoc, SourceLocation IdLoc,
655221345Sdim                IdentifierInfo *Id, CXXRecordDecl *PrevDecl);
656193326Sed
657193326Sedpublic:
658193326Sed  /// base_class_iterator - Iterator that traverses the base classes
659198092Srdivacky  /// of a class.
660193326Sed  typedef CXXBaseSpecifier*       base_class_iterator;
661193326Sed
662193326Sed  /// base_class_const_iterator - Iterator that traverses the base
663198092Srdivacky  /// classes of a class.
664193326Sed  typedef const CXXBaseSpecifier* base_class_const_iterator;
665193326Sed
666198092Srdivacky  /// reverse_base_class_iterator = Iterator that traverses the base classes
667198092Srdivacky  /// of a class in reverse order.
668198092Srdivacky  typedef std::reverse_iterator<base_class_iterator>
669198092Srdivacky    reverse_base_class_iterator;
670198092Srdivacky
671198092Srdivacky  /// reverse_base_class_iterator = Iterator that traverses the base classes
672198092Srdivacky  /// of a class in reverse order.
673198092Srdivacky  typedef std::reverse_iterator<base_class_const_iterator>
674198092Srdivacky    reverse_base_class_const_iterator;
675198092Srdivacky
676198092Srdivacky  virtual CXXRecordDecl *getCanonicalDecl() {
677198092Srdivacky    return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
678198092Srdivacky  }
679199482Srdivacky  virtual const CXXRecordDecl *getCanonicalDecl() const {
680199482Srdivacky    return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
681199482Srdivacky  }
682235633Sdim
683235633Sdim  const CXXRecordDecl *getPreviousDecl() const {
684235633Sdim    return cast_or_null<CXXRecordDecl>(RecordDecl::getPreviousDecl());
685210299Sed  }
686235633Sdim  CXXRecordDecl *getPreviousDecl() {
687235633Sdim    return cast_or_null<CXXRecordDecl>(RecordDecl::getPreviousDecl());
688210299Sed  }
689198092Srdivacky
690235633Sdim  const CXXRecordDecl *getMostRecentDecl() const {
691235633Sdim    return cast_or_null<CXXRecordDecl>(RecordDecl::getMostRecentDecl());
692235633Sdim  }
693235633Sdim  CXXRecordDecl *getMostRecentDecl() {
694235633Sdim    return cast_or_null<CXXRecordDecl>(RecordDecl::getMostRecentDecl());
695235633Sdim  }
696235633Sdim
697203955Srdivacky  CXXRecordDecl *getDefinition() const {
698203955Srdivacky    if (!DefinitionData) return 0;
699203955Srdivacky    return data().Definition;
700203955Srdivacky  }
701203955Srdivacky
702203955Srdivacky  bool hasDefinition() const { return DefinitionData != 0; }
703203955Srdivacky
704218893Sdim  static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
705221345Sdim                               SourceLocation StartLoc, SourceLocation IdLoc,
706221345Sdim                               IdentifierInfo *Id, CXXRecordDecl* PrevDecl=0,
707193326Sed                               bool DelayTypeCreation = false);
708235633Sdim  static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC,
709235633Sdim                                     SourceLocation Loc, bool DependentLambda);
710235633Sdim  static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
711198092Srdivacky
712198092Srdivacky  bool isDynamicClass() const {
713203955Srdivacky    return data().Polymorphic || data().NumVBases != 0;
714198092Srdivacky  }
715198092Srdivacky
716193326Sed  /// setBases - Sets the base classes of this struct or class.
717203955Srdivacky  void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
718193326Sed
719193326Sed  /// getNumBases - Retrieves the number of base classes of this
720193326Sed  /// class.
721203955Srdivacky  unsigned getNumBases() const { return data().NumBases; }
722193326Sed
723218893Sdim  base_class_iterator bases_begin() { return data().getBases(); }
724218893Sdim  base_class_const_iterator bases_begin() const { return data().getBases(); }
725203955Srdivacky  base_class_iterator bases_end() { return bases_begin() + data().NumBases; }
726203955Srdivacky  base_class_const_iterator bases_end() const {
727203955Srdivacky    return bases_begin() + data().NumBases;
728203955Srdivacky  }
729198092Srdivacky  reverse_base_class_iterator       bases_rbegin() {
730198092Srdivacky    return reverse_base_class_iterator(bases_end());
731198092Srdivacky  }
732198092Srdivacky  reverse_base_class_const_iterator bases_rbegin() const {
733198092Srdivacky    return reverse_base_class_const_iterator(bases_end());
734198092Srdivacky  }
735198092Srdivacky  reverse_base_class_iterator bases_rend() {
736198092Srdivacky    return reverse_base_class_iterator(bases_begin());
737198092Srdivacky  }
738198092Srdivacky  reverse_base_class_const_iterator bases_rend() const {
739198092Srdivacky    return reverse_base_class_const_iterator(bases_begin());
740198092Srdivacky  }
741193326Sed
742198092Srdivacky  /// getNumVBases - Retrieves the number of virtual base classes of this
743198092Srdivacky  /// class.
744203955Srdivacky  unsigned getNumVBases() const { return data().NumVBases; }
745198092Srdivacky
746218893Sdim  base_class_iterator vbases_begin() { return data().getVBases(); }
747218893Sdim  base_class_const_iterator vbases_begin() const { return data().getVBases(); }
748203955Srdivacky  base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; }
749203955Srdivacky  base_class_const_iterator vbases_end() const {
750203955Srdivacky    return vbases_begin() + data().NumVBases;
751203955Srdivacky  }
752198092Srdivacky  reverse_base_class_iterator vbases_rbegin() {
753198092Srdivacky    return reverse_base_class_iterator(vbases_end());
754198092Srdivacky  }
755198092Srdivacky  reverse_base_class_const_iterator vbases_rbegin() const {
756198092Srdivacky    return reverse_base_class_const_iterator(vbases_end());
757198092Srdivacky  }
758198092Srdivacky  reverse_base_class_iterator vbases_rend() {
759198092Srdivacky    return reverse_base_class_iterator(vbases_begin());
760198092Srdivacky  }
761198092Srdivacky  reverse_base_class_const_iterator vbases_rend() const {
762198092Srdivacky    return reverse_base_class_const_iterator(vbases_begin());
763198092Srdivacky }
764198092Srdivacky
765202379Srdivacky  /// \brief Determine whether this class has any dependent base classes.
766202379Srdivacky  bool hasAnyDependentBases() const;
767202379Srdivacky
768198092Srdivacky  /// Iterator access to method members.  The method iterator visits
769198092Srdivacky  /// all method members of the class, including non-instance methods,
770198092Srdivacky  /// special methods, etc.
771198092Srdivacky  typedef specific_decl_iterator<CXXMethodDecl> method_iterator;
772198092Srdivacky
773198092Srdivacky  /// method_begin - Method begin iterator.  Iterates in the order the methods
774198092Srdivacky  /// were declared.
775198092Srdivacky  method_iterator method_begin() const {
776198092Srdivacky    return method_iterator(decls_begin());
777198092Srdivacky  }
778198092Srdivacky  /// method_end - Method end iterator.
779198092Srdivacky  method_iterator method_end() const {
780198092Srdivacky    return method_iterator(decls_end());
781198092Srdivacky  }
782198092Srdivacky
783198092Srdivacky  /// Iterator access to constructor members.
784198092Srdivacky  typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator;
785198092Srdivacky
786198092Srdivacky  ctor_iterator ctor_begin() const {
787198092Srdivacky    return ctor_iterator(decls_begin());
788198092Srdivacky  }
789198092Srdivacky  ctor_iterator ctor_end() const {
790198092Srdivacky    return ctor_iterator(decls_end());
791198092Srdivacky  }
792198092Srdivacky
793205219Srdivacky  /// An iterator over friend declarations.  All of these are defined
794205219Srdivacky  /// in DeclFriend.h.
795205219Srdivacky  class friend_iterator;
796205219Srdivacky  friend_iterator friend_begin() const;
797205219Srdivacky  friend_iterator friend_end() const;
798205219Srdivacky  void pushFriendDecl(FriendDecl *FD);
799205219Srdivacky
800207619Srdivacky  /// Determines whether this record has any friends.
801207619Srdivacky  bool hasFriends() const {
802207619Srdivacky    return data().FirstFriend != 0;
803207619Srdivacky  }
804207619Srdivacky
805223017Sdim  /// \brief Determine if we need to declare a default constructor for
806223017Sdim  /// this class.
807210299Sed  ///
808210299Sed  /// This value is used for lazy creation of default constructors.
809223017Sdim  bool needsImplicitDefaultConstructor() const {
810235633Sdim    return !data().UserDeclaredConstructor &&
811223017Sdim           !data().DeclaredDefaultConstructor;
812223017Sdim  }
813223017Sdim
814223017Sdim  /// hasDeclaredDefaultConstructor - Whether this class's default constructor
815223017Sdim  /// has been declared (either explicitly or implicitly).
816210299Sed  bool hasDeclaredDefaultConstructor() const {
817210299Sed    return data().DeclaredDefaultConstructor;
818210299Sed  }
819223017Sdim
820193326Sed  /// hasConstCopyConstructor - Determines whether this class has a
821193326Sed  /// copy constructor that accepts a const-qualified argument.
822223017Sdim  bool hasConstCopyConstructor() const;
823193326Sed
824194711Sed  /// getCopyConstructor - Returns the copy constructor for this class
825223017Sdim  CXXConstructorDecl *getCopyConstructor(unsigned TypeQuals) const;
826194711Sed
827223017Sdim  /// getMoveConstructor - Returns the move constructor for this class
828235633Sdim  CXXConstructorDecl *getMoveConstructor() const;
829223017Sdim
830210299Sed  /// \brief Retrieve the copy-assignment operator for this class, if available.
831210299Sed  ///
832235633Sdim  /// This routine attempts to find the copy-assignment operator for this
833210299Sed  /// class, using a simplistic form of overload resolution.
834210299Sed  ///
835210299Sed  /// \param ArgIsConst Whether the argument to the copy-assignment operator
836210299Sed  /// is const-qualified.
837210299Sed  ///
838210299Sed  /// \returns The copy-assignment operator that can be invoked, or NULL if
839210299Sed  /// a unique copy-assignment operator could not be found.
840210299Sed  CXXMethodDecl *getCopyAssignmentOperator(bool ArgIsConst) const;
841223017Sdim
842223017Sdim  /// getMoveAssignmentOperator - Returns the move assignment operator for this
843223017Sdim  /// class
844223017Sdim  CXXMethodDecl *getMoveAssignmentOperator() const;
845235633Sdim
846193326Sed  /// hasUserDeclaredConstructor - Whether this class has any
847193326Sed  /// user-declared constructors. When true, a default constructor
848193326Sed  /// will not be implicitly declared.
849198092Srdivacky  bool hasUserDeclaredConstructor() const {
850203955Srdivacky    return data().UserDeclaredConstructor;
851198092Srdivacky  }
852193326Sed
853223017Sdim  /// hasUserProvidedDefaultconstructor - Whether this class has a
854223017Sdim  /// user-provided default constructor per C++0x.
855223017Sdim  bool hasUserProvidedDefaultConstructor() const {
856223017Sdim    return data().UserProvidedDefaultConstructor;
857223017Sdim  }
858223017Sdim
859193326Sed  /// hasUserDeclaredCopyConstructor - Whether this class has a
860193326Sed  /// user-declared copy constructor. When false, a copy constructor
861193326Sed  /// will be implicitly declared.
862193326Sed  bool hasUserDeclaredCopyConstructor() const {
863203955Srdivacky    return data().UserDeclaredCopyConstructor;
864193326Sed  }
865193326Sed
866235633Sdim  /// \brief Determine whether this class has had its copy constructor
867210299Sed  /// declared, either via the user or via an implicit declaration.
868210299Sed  ///
869210299Sed  /// This value is used for lazy creation of copy constructors.
870210299Sed  bool hasDeclaredCopyConstructor() const {
871210299Sed    return data().DeclaredCopyConstructor;
872210299Sed  }
873223017Sdim
874223017Sdim  /// hasUserDeclaredMoveOperation - Whether this class has a user-
875223017Sdim  /// declared move constructor or assignment operator. When false, a
876223017Sdim  /// move constructor and assignment operator may be implicitly declared.
877223017Sdim  bool hasUserDeclaredMoveOperation() const {
878223017Sdim    return data().UserDeclaredMoveConstructor ||
879223017Sdim           data().UserDeclaredMoveAssignment;
880223017Sdim  }
881223017Sdim
882223017Sdim  /// \brief Determine whether this class has had a move constructor
883223017Sdim  /// declared by the user.
884223017Sdim  bool hasUserDeclaredMoveConstructor() const {
885223017Sdim    return data().UserDeclaredMoveConstructor;
886223017Sdim  }
887223017Sdim
888223017Sdim  /// \brief Determine whether this class has had a move constructor
889223017Sdim  /// declared.
890223017Sdim  bool hasDeclaredMoveConstructor() const {
891223017Sdim    return data().DeclaredMoveConstructor;
892223017Sdim  }
893223017Sdim
894226890Sdim  /// \brief Determine whether implicit move constructor generation for this
895226890Sdim  /// class has failed before.
896226890Sdim  bool hasFailedImplicitMoveConstructor() const {
897226890Sdim    return data().FailedImplicitMoveConstructor;
898226890Sdim  }
899226890Sdim
900226890Sdim  /// \brief Set whether implicit move constructor generation for this class
901226890Sdim  /// has failed before.
902226890Sdim  void setFailedImplicitMoveConstructor(bool Failed = true) {
903226890Sdim    data().FailedImplicitMoveConstructor = Failed;
904226890Sdim  }
905226890Sdim
906226890Sdim  /// \brief Determine whether this class should get an implicit move
907226890Sdim  /// constructor or if any existing special member function inhibits this.
908226890Sdim  ///
909226890Sdim  /// Covers all bullets of C++0x [class.copy]p9 except the last, that the
910226890Sdim  /// constructor wouldn't be deleted, which is only looked up from a cached
911226890Sdim  /// result.
912226890Sdim  bool needsImplicitMoveConstructor() const {
913226890Sdim    return !hasFailedImplicitMoveConstructor() &&
914226890Sdim           !hasDeclaredMoveConstructor() &&
915226890Sdim           !hasUserDeclaredCopyConstructor() &&
916226890Sdim           !hasUserDeclaredCopyAssignment() &&
917226890Sdim           !hasUserDeclaredMoveAssignment() &&
918226890Sdim           !hasUserDeclaredDestructor();
919226890Sdim  }
920226890Sdim
921193326Sed  /// hasUserDeclaredCopyAssignment - Whether this class has a
922193326Sed  /// user-declared copy assignment operator. When false, a copy
923193326Sed  /// assigment operator will be implicitly declared.
924193326Sed  bool hasUserDeclaredCopyAssignment() const {
925203955Srdivacky    return data().UserDeclaredCopyAssignment;
926193326Sed  }
927193326Sed
928235633Sdim  /// \brief Determine whether this class has had its copy assignment operator
929210299Sed  /// declared, either via the user or via an implicit declaration.
930210299Sed  ///
931210299Sed  /// This value is used for lazy creation of copy assignment operators.
932210299Sed  bool hasDeclaredCopyAssignment() const {
933210299Sed    return data().DeclaredCopyAssignment;
934210299Sed  }
935223017Sdim
936223017Sdim  /// \brief Determine whether this class has had a move assignment
937223017Sdim  /// declared by the user.
938223017Sdim  bool hasUserDeclaredMoveAssignment() const {
939223017Sdim    return data().UserDeclaredMoveAssignment;
940223017Sdim  }
941223017Sdim
942223017Sdim  /// hasDeclaredMoveAssignment - Whether this class has a
943223017Sdim  /// declared move assignment operator.
944223017Sdim  bool hasDeclaredMoveAssignment() const {
945223017Sdim    return data().DeclaredMoveAssignment;
946223017Sdim  }
947223017Sdim
948226890Sdim  /// \brief Determine whether implicit move assignment generation for this
949226890Sdim  /// class has failed before.
950226890Sdim  bool hasFailedImplicitMoveAssignment() const {
951226890Sdim    return data().FailedImplicitMoveAssignment;
952226890Sdim  }
953226890Sdim
954226890Sdim  /// \brief Set whether implicit move assignment generation for this class
955226890Sdim  /// has failed before.
956226890Sdim  void setFailedImplicitMoveAssignment(bool Failed = true) {
957226890Sdim    data().FailedImplicitMoveAssignment = Failed;
958226890Sdim  }
959226890Sdim
960226890Sdim  /// \brief Determine whether this class should get an implicit move
961226890Sdim  /// assignment operator or if any existing special member function inhibits
962226890Sdim  /// this.
963226890Sdim  ///
964226890Sdim  /// Covers all bullets of C++0x [class.copy]p20 except the last, that the
965226890Sdim  /// constructor wouldn't be deleted.
966226890Sdim  bool needsImplicitMoveAssignment() const {
967226890Sdim    return !hasFailedImplicitMoveAssignment() &&
968226890Sdim           !hasDeclaredMoveAssignment() &&
969226890Sdim           !hasUserDeclaredCopyConstructor() &&
970226890Sdim           !hasUserDeclaredCopyAssignment() &&
971226890Sdim           !hasUserDeclaredMoveConstructor() &&
972226890Sdim           !hasUserDeclaredDestructor();
973226890Sdim  }
974226890Sdim
975193326Sed  /// hasUserDeclaredDestructor - Whether this class has a
976193326Sed  /// user-declared destructor. When false, a destructor will be
977193326Sed  /// implicitly declared.
978203955Srdivacky  bool hasUserDeclaredDestructor() const {
979203955Srdivacky    return data().UserDeclaredDestructor;
980203955Srdivacky  }
981193326Sed
982210299Sed  /// \brief Determine whether this class has had its destructor declared,
983210299Sed  /// either via the user or via an implicit declaration.
984210299Sed  ///
985210299Sed  /// This value is used for lazy creation of destructors.
986210299Sed  bool hasDeclaredDestructor() const { return data().DeclaredDestructor; }
987218893Sdim
988235633Sdim  /// \brief Determine whether this class describes a lambda function object.
989235633Sdim  bool isLambda() const { return hasDefinition() && data().IsLambda; }
990235633Sdim
991235633Sdim  /// \brief For a closure type, retrieve the mapping from captured
992235633Sdim  /// variables and this to the non-static data members that store the
993235633Sdim  /// values or references of the captures.
994235633Sdim  ///
995235633Sdim  /// \param Captures Will be populated with the mapping from captured
996235633Sdim  /// variables to the corresponding fields.
997235633Sdim  ///
998235633Sdim  /// \param ThisCapture Will be set to the field declaration for the
999235633Sdim  /// 'this' capture.
1000235633Sdim  void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures,
1001235633Sdim                        FieldDecl *&ThisCapture) const;
1002235633Sdim
1003235633Sdim  typedef const LambdaExpr::Capture* capture_const_iterator;
1004235633Sdim  capture_const_iterator captures_begin() const {
1005235633Sdim    return isLambda() ? getLambdaData().Captures : NULL;
1006235633Sdim  }
1007235633Sdim  capture_const_iterator captures_end() const {
1008235633Sdim    return isLambda() ? captures_begin() + getLambdaData().NumCaptures : NULL;
1009235633Sdim  }
1010235633Sdim
1011193326Sed  /// getConversions - Retrieve the overload set containing all of the
1012193326Sed  /// conversion functions in this class.
1013202879Srdivacky  UnresolvedSetImpl *getConversionFunctions() {
1014203955Srdivacky    return &data().Conversions;
1015193326Sed  }
1016202879Srdivacky  const UnresolvedSetImpl *getConversionFunctions() const {
1017203955Srdivacky    return &data().Conversions;
1018193326Sed  }
1019193326Sed
1020202879Srdivacky  typedef UnresolvedSetImpl::iterator conversion_iterator;
1021203955Srdivacky  conversion_iterator conversion_begin() const {
1022203955Srdivacky    return getConversionFunctions()->begin();
1023203955Srdivacky  }
1024203955Srdivacky  conversion_iterator conversion_end() const {
1025203955Srdivacky    return getConversionFunctions()->end();
1026203955Srdivacky  }
1027199990Srdivacky
1028206084Srdivacky  /// Removes a conversion function from this class.  The conversion
1029206084Srdivacky  /// function must currently be a member of this class.  Furthermore,
1030206084Srdivacky  /// this class must currently be in the process of being defined.
1031206084Srdivacky  void removeConversion(const NamedDecl *Old);
1032206084Srdivacky
1033198092Srdivacky  /// getVisibleConversionFunctions - get all conversion functions visible
1034198092Srdivacky  /// in current class; including conversion function templates.
1035202879Srdivacky  const UnresolvedSetImpl *getVisibleConversionFunctions();
1036199990Srdivacky
1037193326Sed  /// isAggregate - Whether this class is an aggregate (C++
1038193326Sed  /// [dcl.init.aggr]), which is a class with no user-declared
1039193326Sed  /// constructors, no private or protected non-static data members,
1040193326Sed  /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1).
1041203955Srdivacky  bool isAggregate() const { return data().Aggregate; }
1042193326Sed
1043193326Sed  /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class
1044193326Sed  /// that is an aggregate that has no non-static non-POD data members, no
1045193326Sed  /// reference data members, no user-defined copy assignment operator and no
1046193326Sed  /// user-defined destructor.
1047203955Srdivacky  bool isPOD() const { return data().PlainOldData; }
1048193326Sed
1049235633Sdim  /// \brief True if this class is C-like, without C++-specific features, e.g.
1050235633Sdim  /// it contains only public fields, no bases, tag kind is not 'class', etc.
1051235633Sdim  bool isCLike() const;
1052235633Sdim
1053198092Srdivacky  /// isEmpty - Whether this class is empty (C++0x [meta.unary.prop]), which
1054198092Srdivacky  /// means it has a virtual function, virtual base, data member (other than
1055198092Srdivacky  /// 0-width bit-field) or inherits from a non-empty class. Does NOT include
1056198092Srdivacky  /// a check for union-ness.
1057203955Srdivacky  bool isEmpty() const { return data().Empty; }
1058198092Srdivacky
1059193326Sed  /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]),
1060193326Sed  /// which means that the class contains or inherits a virtual function.
1061203955Srdivacky  bool isPolymorphic() const { return data().Polymorphic; }
1062193326Sed
1063193326Sed  /// isAbstract - Whether this class is abstract (C++ [class.abstract]),
1064193326Sed  /// which means that the class contains or inherits a pure virtual function.
1065203955Srdivacky  bool isAbstract() const { return data().Abstract; }
1066198092Srdivacky
1067221345Sdim  /// isStandardLayout - Whether this class has standard layout
1068221345Sdim  /// (C++ [class]p7)
1069221345Sdim  bool isStandardLayout() const { return data().IsStandardLayout; }
1070221345Sdim
1071223017Sdim  /// \brief Whether this class, or any of its class subobjects, contains a
1072223017Sdim  /// mutable field.
1073223017Sdim  bool hasMutableFields() const { return data().HasMutableFields; }
1074235633Sdim
1075235633Sdim  /// hasTrivialDefaultConstructor - Whether this class has a trivial default
1076235633Sdim  /// constructor (C++11 [class.ctor]p5).
1077223017Sdim  bool hasTrivialDefaultConstructor() const {
1078223017Sdim    return data().HasTrivialDefaultConstructor &&
1079223017Sdim           (!data().UserDeclaredConstructor ||
1080223017Sdim             data().DeclaredDefaultConstructor);
1081223017Sdim  }
1082198092Srdivacky
1083235633Sdim  /// hasConstexprNonCopyMoveConstructor - Whether this class has at least one
1084235633Sdim  /// constexpr constructor other than the copy or move constructors.
1085226890Sdim  bool hasConstexprNonCopyMoveConstructor() const {
1086235633Sdim    return data().HasConstexprNonCopyMoveConstructor ||
1087235633Sdim           (!hasUserDeclaredConstructor() &&
1088235633Sdim            defaultedDefaultConstructorIsConstexpr());
1089221345Sdim  }
1090221345Sdim
1091235633Sdim  /// defaultedDefaultConstructorIsConstexpr - Whether a defaulted default
1092235633Sdim  /// constructor for this class would be constexpr.
1093235633Sdim  bool defaultedDefaultConstructorIsConstexpr() const {
1094235633Sdim    return data().DefaultedDefaultConstructorIsConstexpr;
1095235633Sdim  }
1096235633Sdim
1097235633Sdim  /// defaultedCopyConstructorIsConstexpr - Whether a defaulted copy
1098235633Sdim  /// constructor for this class would be constexpr.
1099235633Sdim  bool defaultedCopyConstructorIsConstexpr() const {
1100235633Sdim    return data().DefaultedCopyConstructorIsConstexpr;
1101235633Sdim  }
1102235633Sdim
1103235633Sdim  /// defaultedMoveConstructorIsConstexpr - Whether a defaulted move
1104235633Sdim  /// constructor for this class would be constexpr.
1105235633Sdim  bool defaultedMoveConstructorIsConstexpr() const {
1106235633Sdim    return data().DefaultedMoveConstructorIsConstexpr;
1107235633Sdim  }
1108235633Sdim
1109235633Sdim  /// hasConstexprDefaultConstructor - Whether this class has a constexpr
1110235633Sdim  /// default constructor.
1111235633Sdim  bool hasConstexprDefaultConstructor() const {
1112235633Sdim    return data().HasConstexprDefaultConstructor ||
1113235633Sdim           (!data().UserDeclaredConstructor &&
1114235633Sdim            data().DefaultedDefaultConstructorIsConstexpr && isLiteral());
1115235633Sdim  }
1116235633Sdim
1117235633Sdim  /// hasConstexprCopyConstructor - Whether this class has a constexpr copy
1118235633Sdim  /// constructor.
1119235633Sdim  bool hasConstexprCopyConstructor() const {
1120235633Sdim    return data().HasConstexprCopyConstructor ||
1121235633Sdim           (!data().DeclaredCopyConstructor &&
1122235633Sdim            data().DefaultedCopyConstructorIsConstexpr && isLiteral());
1123235633Sdim  }
1124235633Sdim
1125235633Sdim  /// hasConstexprMoveConstructor - Whether this class has a constexpr move
1126235633Sdim  /// constructor.
1127235633Sdim  bool hasConstexprMoveConstructor() const {
1128235633Sdim    return data().HasConstexprMoveConstructor ||
1129235633Sdim           (needsImplicitMoveConstructor() &&
1130235633Sdim            data().DefaultedMoveConstructorIsConstexpr && isLiteral());
1131235633Sdim  }
1132235633Sdim
1133198092Srdivacky  // hasTrivialCopyConstructor - Whether this class has a trivial copy
1134221345Sdim  // constructor (C++ [class.copy]p6, C++0x [class.copy]p13)
1135203955Srdivacky  bool hasTrivialCopyConstructor() const {
1136203955Srdivacky    return data().HasTrivialCopyConstructor;
1137203955Srdivacky  }
1138198092Srdivacky
1139221345Sdim  // hasTrivialMoveConstructor - Whether this class has a trivial move
1140221345Sdim  // constructor (C++0x [class.copy]p13)
1141221345Sdim  bool hasTrivialMoveConstructor() const {
1142221345Sdim    return data().HasTrivialMoveConstructor;
1143221345Sdim  }
1144221345Sdim
1145198092Srdivacky  // hasTrivialCopyAssignment - Whether this class has a trivial copy
1146221345Sdim  // assignment operator (C++ [class.copy]p11, C++0x [class.copy]p27)
1147203955Srdivacky  bool hasTrivialCopyAssignment() const {
1148203955Srdivacky    return data().HasTrivialCopyAssignment;
1149203955Srdivacky  }
1150198092Srdivacky
1151221345Sdim  // hasTrivialMoveAssignment - Whether this class has a trivial move
1152221345Sdim  // assignment operator (C++0x [class.copy]p27)
1153221345Sdim  bool hasTrivialMoveAssignment() const {
1154221345Sdim    return data().HasTrivialMoveAssignment;
1155221345Sdim  }
1156221345Sdim
1157193326Sed  // hasTrivialDestructor - Whether this class has a trivial destructor
1158193326Sed  // (C++ [class.dtor]p3)
1159203955Srdivacky  bool hasTrivialDestructor() const { return data().HasTrivialDestructor; }
1160198092Srdivacky
1161235633Sdim  // hasIrrelevantDestructor - Whether this class has a destructor which has no
1162235633Sdim  // semantic effect. Any such destructor will be trivial, public, defaulted
1163235633Sdim  // and not deleted, and will call only irrelevant destructors.
1164235633Sdim  bool hasIrrelevantDestructor() const {
1165235633Sdim    return data().HasIrrelevantDestructor;
1166235633Sdim  }
1167235633Sdim
1168235633Sdim  // hasNonLiteralTypeFieldsOrBases - Whether this class has a non-literal or
1169235633Sdim  // volatile type non-static data member or base class.
1170221345Sdim  bool hasNonLiteralTypeFieldsOrBases() const {
1171221345Sdim    return data().HasNonLiteralTypeFieldsOrBases;
1172221345Sdim  }
1173221345Sdim
1174221345Sdim  // isTriviallyCopyable - Whether this class is considered trivially copyable
1175223017Sdim  // (C++0x [class]p6).
1176221345Sdim  bool isTriviallyCopyable() const;
1177221345Sdim
1178223017Sdim  // isTrivial - Whether this class is considered trivial
1179223017Sdim  //
1180223017Sdim  // C++0x [class]p6
1181223017Sdim  //    A trivial class is a class that has a trivial default constructor and
1182223017Sdim  //    is trivially copiable.
1183223017Sdim  bool isTrivial() const {
1184223017Sdim    return isTriviallyCopyable() && hasTrivialDefaultConstructor();
1185223017Sdim  }
1186223017Sdim
1187226890Sdim  // isLiteral - Whether this class is a literal type.
1188226890Sdim  //
1189235633Sdim  // C++11 [basic.types]p10
1190226890Sdim  //   A class type that has all the following properties:
1191235633Sdim  //     -- it has a trivial destructor
1192226890Sdim  //     -- every constructor call and full-expression in the
1193226890Sdim  //        brace-or-equal-intializers for non-static data members (if any) is
1194226890Sdim  //        a constant expression.
1195226890Sdim  //     -- it is an aggregate type or has at least one constexpr constructor or
1196226890Sdim  //        constructor template that is not a copy or move constructor, and
1197235633Sdim  //     -- all of its non-static data members and base classes are of literal
1198235633Sdim  //        types
1199226890Sdim  //
1200235633Sdim  // We resolve DR1361 by ignoring the second bullet. We resolve DR1452 by
1201235633Sdim  // treating types with trivial default constructors as literal types.
1202226890Sdim  bool isLiteral() const {
1203226890Sdim    return hasTrivialDestructor() &&
1204235633Sdim           (isAggregate() || hasConstexprNonCopyMoveConstructor() ||
1205235633Sdim            hasTrivialDefaultConstructor()) &&
1206226890Sdim           !hasNonLiteralTypeFieldsOrBases();
1207226890Sdim  }
1208226890Sdim
1209193326Sed  /// \brief If this record is an instantiation of a member class,
1210193326Sed  /// retrieves the member class from which it was instantiated.
1211193326Sed  ///
1212193326Sed  /// This routine will return non-NULL for (non-templated) member
1213193326Sed  /// classes of class templates. For example, given:
1214193326Sed  ///
1215193326Sed  /// \code
1216193326Sed  /// template<typename T>
1217193326Sed  /// struct X {
1218193326Sed  ///   struct A { };
1219193326Sed  /// };
1220193326Sed  /// \endcode
1221193326Sed  ///
1222193326Sed  /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
1223193326Sed  /// whose parent is the class template specialization X<int>. For
1224193326Sed  /// this declaration, getInstantiatedFromMemberClass() will return
1225193326Sed  /// the CXXRecordDecl X<T>::A. When a complete definition of
1226193326Sed  /// X<int>::A is required, it will be instantiated from the
1227193326Sed  /// declaration returned by getInstantiatedFromMemberClass().
1228198092Srdivacky  CXXRecordDecl *getInstantiatedFromMemberClass() const;
1229235633Sdim
1230198092Srdivacky  /// \brief If this class is an instantiation of a member class of a
1231198092Srdivacky  /// class template specialization, retrieves the member specialization
1232198092Srdivacky  /// information.
1233198092Srdivacky  MemberSpecializationInfo *getMemberSpecializationInfo() const;
1234235633Sdim
1235193326Sed  /// \brief Specify that this record is an instantiation of the
1236193326Sed  /// member class RD.
1237198092Srdivacky  void setInstantiationOfMemberClass(CXXRecordDecl *RD,
1238198092Srdivacky                                     TemplateSpecializationKind TSK);
1239193326Sed
1240193326Sed  /// \brief Retrieves the class template that is described by this
1241193326Sed  /// class declaration.
1242193326Sed  ///
1243193326Sed  /// Every class template is represented as a ClassTemplateDecl and a
1244193326Sed  /// CXXRecordDecl. The former contains template properties (such as
1245193326Sed  /// the template parameter lists) while the latter contains the
1246193326Sed  /// actual description of the template's
1247193326Sed  /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
1248193326Sed  /// CXXRecordDecl that from a ClassTemplateDecl, while
1249193326Sed  /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
1250193326Sed  /// a CXXRecordDecl.
1251193326Sed  ClassTemplateDecl *getDescribedClassTemplate() const {
1252193326Sed    return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>();
1253193326Sed  }
1254193326Sed
1255193326Sed  void setDescribedClassTemplate(ClassTemplateDecl *Template) {
1256193326Sed    TemplateOrInstantiation = Template;
1257193326Sed  }
1258193326Sed
1259198092Srdivacky  /// \brief Determine whether this particular class is a specialization or
1260198092Srdivacky  /// instantiation of a class template or member class of a class template,
1261198092Srdivacky  /// and how it was instantiated or specialized.
1262200583Srdivacky  TemplateSpecializationKind getTemplateSpecializationKind() const;
1263235633Sdim
1264198092Srdivacky  /// \brief Set the kind of specialization or template instantiation this is.
1265198092Srdivacky  void setTemplateSpecializationKind(TemplateSpecializationKind TSK);
1266198092Srdivacky
1267193326Sed  /// getDestructor - Returns the destructor decl for this class.
1268210299Sed  CXXDestructorDecl *getDestructor() const;
1269198092Srdivacky
1270195099Sed  /// isLocalClass - If the class is a local class [class.local], returns
1271195099Sed  /// the enclosing function declaration.
1272195099Sed  const FunctionDecl *isLocalClass() const {
1273195099Sed    if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
1274195099Sed      return RD->isLocalClass();
1275198092Srdivacky
1276195099Sed    return dyn_cast<FunctionDecl>(getDeclContext());
1277195099Sed  }
1278198092Srdivacky
1279198092Srdivacky  /// \brief Determine whether this class is derived from the class \p Base.
1280198092Srdivacky  ///
1281198092Srdivacky  /// This routine only determines whether this class is derived from \p Base,
1282198092Srdivacky  /// but does not account for factors that may make a Derived -> Base class
1283198092Srdivacky  /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1284198092Srdivacky  /// base class subobjects.
1285198092Srdivacky  ///
1286198092Srdivacky  /// \param Base the base class we are searching for.
1287198092Srdivacky  ///
1288198092Srdivacky  /// \returns true if this class is derived from Base, false otherwise.
1289218893Sdim  bool isDerivedFrom(const CXXRecordDecl *Base) const;
1290235633Sdim
1291198092Srdivacky  /// \brief Determine whether this class is derived from the type \p Base.
1292198092Srdivacky  ///
1293198092Srdivacky  /// This routine only determines whether this class is derived from \p Base,
1294198092Srdivacky  /// but does not account for factors that may make a Derived -> Base class
1295198092Srdivacky  /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1296198092Srdivacky  /// base class subobjects.
1297198092Srdivacky  ///
1298198092Srdivacky  /// \param Base the base class we are searching for.
1299198092Srdivacky  ///
1300198092Srdivacky  /// \param Paths will contain the paths taken from the current class to the
1301198092Srdivacky  /// given \p Base class.
1302198092Srdivacky  ///
1303198092Srdivacky  /// \returns true if this class is derived from Base, false otherwise.
1304198092Srdivacky  ///
1305235633Sdim  /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than
1306235633Sdim  /// tangling input and output in \p Paths
1307218893Sdim  bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const;
1308200583Srdivacky
1309204643Srdivacky  /// \brief Determine whether this class is virtually derived from
1310204643Srdivacky  /// the class \p Base.
1311204643Srdivacky  ///
1312204643Srdivacky  /// This routine only determines whether this class is virtually
1313204643Srdivacky  /// derived from \p Base, but does not account for factors that may
1314204643Srdivacky  /// make a Derived -> Base class ill-formed, such as
1315204643Srdivacky  /// private/protected inheritance or multiple, ambiguous base class
1316204643Srdivacky  /// subobjects.
1317204643Srdivacky  ///
1318204643Srdivacky  /// \param Base the base class we are searching for.
1319204643Srdivacky  ///
1320204643Srdivacky  /// \returns true if this class is virtually derived from Base,
1321204643Srdivacky  /// false otherwise.
1322204643Srdivacky  bool isVirtuallyDerivedFrom(CXXRecordDecl *Base) const;
1323204643Srdivacky
1324200583Srdivacky  /// \brief Determine whether this class is provably not derived from
1325200583Srdivacky  /// the type \p Base.
1326200583Srdivacky  bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
1327200583Srdivacky
1328200583Srdivacky  /// \brief Function type used by forallBases() as a callback.
1329200583Srdivacky  ///
1330200583Srdivacky  /// \param Base the definition of the base class
1331200583Srdivacky  ///
1332200583Srdivacky  /// \returns true if this base matched the search criteria
1333200583Srdivacky  typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition,
1334200583Srdivacky                                   void *UserData);
1335200583Srdivacky
1336200583Srdivacky  /// \brief Determines if the given callback holds for all the direct
1337200583Srdivacky  /// or indirect base classes of this type.
1338200583Srdivacky  ///
1339200583Srdivacky  /// The class itself does not count as a base class.  This routine
1340200583Srdivacky  /// returns false if the class has non-computable base classes.
1341235633Sdim  ///
1342200583Srdivacky  /// \param AllowShortCircuit if false, forces the callback to be called
1343200583Srdivacky  /// for every base class, even if a dependent or non-matching base was
1344200583Srdivacky  /// found.
1345200583Srdivacky  bool forallBases(ForallBasesCallback *BaseMatches, void *UserData,
1346200583Srdivacky                   bool AllowShortCircuit = true) const;
1347235633Sdim
1348235633Sdim  /// \brief Function type used by lookupInBases() to determine whether a
1349198092Srdivacky  /// specific base class subobject matches the lookup criteria.
1350198092Srdivacky  ///
1351235633Sdim  /// \param Specifier the base-class specifier that describes the inheritance
1352198092Srdivacky  /// from the base class we are trying to match.
1353198092Srdivacky  ///
1354235633Sdim  /// \param Path the current path, from the most-derived class down to the
1355198092Srdivacky  /// base named by the \p Specifier.
1356198092Srdivacky  ///
1357198092Srdivacky  /// \param UserData a single pointer to user-specified data, provided to
1358198092Srdivacky  /// lookupInBases().
1359198092Srdivacky  ///
1360198092Srdivacky  /// \returns true if this base matched the search criteria, false otherwise.
1361199482Srdivacky  typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier,
1362198092Srdivacky                                   CXXBasePath &Path,
1363198092Srdivacky                                   void *UserData);
1364235633Sdim
1365198092Srdivacky  /// \brief Look for entities within the base classes of this C++ class,
1366198092Srdivacky  /// transitively searching all base class subobjects.
1367198092Srdivacky  ///
1368235633Sdim  /// This routine uses the callback function \p BaseMatches to find base
1369198092Srdivacky  /// classes meeting some search criteria, walking all base class subobjects
1370235633Sdim  /// and populating the given \p Paths structure with the paths through the
1371198092Srdivacky  /// inheritance hierarchy that resulted in a match. On a successful search,
1372198092Srdivacky  /// the \p Paths structure can be queried to retrieve the matching paths and
1373198092Srdivacky  /// to determine if there were any ambiguities.
1374198092Srdivacky  ///
1375198092Srdivacky  /// \param BaseMatches callback function used to determine whether a given
1376198092Srdivacky  /// base matches the user-defined search criteria.
1377198092Srdivacky  ///
1378198092Srdivacky  /// \param UserData user data pointer that will be provided to \p BaseMatches.
1379198092Srdivacky  ///
1380198092Srdivacky  /// \param Paths used to record the paths from this class to its base class
1381198092Srdivacky  /// subobjects that match the search criteria.
1382198092Srdivacky  ///
1383198092Srdivacky  /// \returns true if there exists any path from this class to a base class
1384198092Srdivacky  /// subobject that matches the search criteria.
1385198092Srdivacky  bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData,
1386199482Srdivacky                     CXXBasePaths &Paths) const;
1387235633Sdim
1388198092Srdivacky  /// \brief Base-class lookup callback that determines whether the given
1389198092Srdivacky  /// base class specifier refers to a specific class declaration.
1390198092Srdivacky  ///
1391198092Srdivacky  /// This callback can be used with \c lookupInBases() to determine whether
1392198092Srdivacky  /// a given derived class has is a base class subobject of a particular type.
1393198092Srdivacky  /// The user data pointer should refer to the canonical CXXRecordDecl of the
1394198092Srdivacky  /// base class that we are searching for.
1395199482Srdivacky  static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
1396199482Srdivacky                            CXXBasePath &Path, void *BaseRecord);
1397204643Srdivacky
1398204643Srdivacky  /// \brief Base-class lookup callback that determines whether the
1399204643Srdivacky  /// given base class specifier refers to a specific class
1400204643Srdivacky  /// declaration and describes virtual derivation.
1401204643Srdivacky  ///
1402204643Srdivacky  /// This callback can be used with \c lookupInBases() to determine
1403204643Srdivacky  /// whether a given derived class has is a virtual base class
1404204643Srdivacky  /// subobject of a particular type.  The user data pointer should
1405204643Srdivacky  /// refer to the canonical CXXRecordDecl of the base class that we
1406204643Srdivacky  /// are searching for.
1407204643Srdivacky  static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
1408204643Srdivacky                                   CXXBasePath &Path, void *BaseRecord);
1409235633Sdim
1410198092Srdivacky  /// \brief Base-class lookup callback that determines whether there exists
1411198092Srdivacky  /// a tag with the given name.
1412198092Srdivacky  ///
1413198092Srdivacky  /// This callback can be used with \c lookupInBases() to find tag members
1414198092Srdivacky  /// of the given name within a C++ class hierarchy. The user data pointer
1415198092Srdivacky  /// is an opaque \c DeclarationName pointer.
1416199482Srdivacky  static bool FindTagMember(const CXXBaseSpecifier *Specifier,
1417199482Srdivacky                            CXXBasePath &Path, void *Name);
1418198092Srdivacky
1419198092Srdivacky  /// \brief Base-class lookup callback that determines whether there exists
1420198092Srdivacky  /// a member with the given name.
1421198092Srdivacky  ///
1422198092Srdivacky  /// This callback can be used with \c lookupInBases() to find members
1423198092Srdivacky  /// of the given name within a C++ class hierarchy. The user data pointer
1424198092Srdivacky  /// is an opaque \c DeclarationName pointer.
1425199482Srdivacky  static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
1426199482Srdivacky                                 CXXBasePath &Path, void *Name);
1427235633Sdim
1428198092Srdivacky  /// \brief Base-class lookup callback that determines whether there exists
1429198092Srdivacky  /// a member with the given name that can be used in a nested-name-specifier.
1430198092Srdivacky  ///
1431198092Srdivacky  /// This callback can be used with \c lookupInBases() to find membes of
1432198092Srdivacky  /// the given name within a C++ class hierarchy that can occur within
1433198092Srdivacky  /// nested-name-specifiers.
1434199482Srdivacky  static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier,
1435198092Srdivacky                                            CXXBasePath &Path,
1436198092Srdivacky                                            void *UserData);
1437206084Srdivacky
1438206084Srdivacky  /// \brief Retrieve the final overriders for each virtual member
1439206084Srdivacky  /// function in the class hierarchy where this class is the
1440206084Srdivacky  /// most-derived class in the class hierarchy.
1441206084Srdivacky  void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const;
1442206084Srdivacky
1443218893Sdim  /// \brief Get the indirect primary bases for this class.
1444218893Sdim  void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const;
1445218893Sdim
1446193326Sed  /// viewInheritance - Renders and displays an inheritance diagram
1447193326Sed  /// for this C++ class and all of its base classes (transitively) using
1448193326Sed  /// GraphViz.
1449193326Sed  void viewInheritance(ASTContext& Context) const;
1450193326Sed
1451202879Srdivacky  /// MergeAccess - Calculates the access of a decl that is reached
1452202879Srdivacky  /// along a path.
1453202879Srdivacky  static AccessSpecifier MergeAccess(AccessSpecifier PathAccess,
1454202879Srdivacky                                     AccessSpecifier DeclAccess) {
1455202879Srdivacky    assert(DeclAccess != AS_none);
1456202879Srdivacky    if (DeclAccess == AS_private) return AS_none;
1457202879Srdivacky    return (PathAccess > DeclAccess ? PathAccess : DeclAccess);
1458202879Srdivacky  }
1459202879Srdivacky
1460218893Sdim  /// \brief Indicates that the definition of this class is now complete.
1461218893Sdim  virtual void completeDefinition();
1462218893Sdim
1463235633Sdim  /// \brief Indicates that the definition of this class is now complete,
1464218893Sdim  /// and provides a final overrider map to help determine
1465235633Sdim  ///
1466218893Sdim  /// \param FinalOverriders The final overrider map for this class, which can
1467218893Sdim  /// be provided as an optimization for abstract-class checking. If NULL,
1468218893Sdim  /// final overriders will be computed if they are needed to complete the
1469218893Sdim  /// definition.
1470218893Sdim  void completeDefinition(CXXFinalOverriderMap *FinalOverriders);
1471235633Sdim
1472218893Sdim  /// \brief Determine whether this class may end up being abstract, even though
1473218893Sdim  /// it is not yet known to be abstract.
1474218893Sdim  ///
1475218893Sdim  /// \returns true if this class is not known to be abstract but has any
1476218893Sdim  /// base classes that are abstract. In this case, \c completeDefinition()
1477218893Sdim  /// will need to compute final overriders to determine whether the class is
1478218893Sdim  /// actually abstract.
1479218893Sdim  bool mayBeAbstract() const;
1480235633Sdim
1481235633Sdim  /// \brief If this is the closure type of a lambda expression, retrieve the
1482235633Sdim  /// number to be used for name mangling in the Itanium C++ ABI.
1483235633Sdim  ///
1484235633Sdim  /// Zero indicates that this closure type has internal linkage, so the
1485235633Sdim  /// mangling number does not matter, while a non-zero value indicates which
1486235633Sdim  /// lambda expression this is in this particular context.
1487235633Sdim  unsigned getLambdaManglingNumber() const {
1488235633Sdim    assert(isLambda() && "Not a lambda closure type!");
1489235633Sdim    return getLambdaData().ManglingNumber;
1490235633Sdim  }
1491218893Sdim
1492235633Sdim  /// \brief Retrieve the declaration that provides additional context for a
1493235633Sdim  /// lambda, when the normal declaration context is not specific enough.
1494235633Sdim  ///
1495235633Sdim  /// Certain contexts (default arguments of in-class function parameters and
1496235633Sdim  /// the initializers of data members) have separate name mangling rules for
1497235633Sdim  /// lambdas within the Itanium C++ ABI. For these cases, this routine provides
1498235633Sdim  /// the declaration in which the lambda occurs, e.g., the function parameter
1499235633Sdim  /// or the non-static data member. Otherwise, it returns NULL to imply that
1500235633Sdim  /// the declaration context suffices.
1501235633Sdim  Decl *getLambdaContextDecl() const {
1502235633Sdim    assert(isLambda() && "Not a lambda closure type!");
1503235633Sdim    return getLambdaData().ContextDecl;
1504235633Sdim  }
1505235633Sdim
1506235633Sdim  /// \brief Set the mangling number and context declaration for a lambda
1507235633Sdim  /// class.
1508235633Sdim  void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl) {
1509235633Sdim    getLambdaData().ManglingNumber = ManglingNumber;
1510235633Sdim    getLambdaData().ContextDecl = ContextDecl;
1511235633Sdim  }
1512235633Sdim
1513235633Sdim  /// \brief Determine whether this lambda expression was known to be dependent
1514235633Sdim  /// at the time it was created, even if its context does not appear to be
1515235633Sdim  /// dependent.
1516235633Sdim  ///
1517235633Sdim  /// This flag is a workaround for an issue with parsing, where default
1518235633Sdim  /// arguments are parsed before their enclosing function declarations have
1519235633Sdim  /// been created. This means that any lambda expressions within those
1520235633Sdim  /// default arguments will have as their DeclContext the context enclosing
1521235633Sdim  /// the function declaration, which may be non-dependent even when the
1522235633Sdim  /// function declaration itself is dependent. This flag indicates when we
1523235633Sdim  /// know that the lambda is dependent despite that.
1524235633Sdim  bool isDependentLambda() const {
1525235633Sdim    return isLambda() && getLambdaData().Dependent;
1526235633Sdim  }
1527235633Sdim
1528203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1529203955Srdivacky  static bool classofKind(Kind K) {
1530210299Sed    return K >= firstCXXRecord && K <= lastCXXRecord;
1531193326Sed  }
1532193326Sed  static bool classof(const CXXRecordDecl *D) { return true; }
1533198092Srdivacky  static bool classof(const ClassTemplateSpecializationDecl *D) {
1534198092Srdivacky    return true;
1535193326Sed  }
1536210299Sed
1537212904Sdim  friend class ASTDeclReader;
1538212904Sdim  friend class ASTDeclWriter;
1539218893Sdim  friend class ASTReader;
1540218893Sdim  friend class ASTWriter;
1541193326Sed};
1542193326Sed
1543193326Sed/// CXXMethodDecl - Represents a static or instance method of a
1544193326Sed/// struct/union/class.
1545193326Sedclass CXXMethodDecl : public FunctionDecl {
1546235633Sdim  virtual void anchor();
1547193326Sedprotected:
1548221345Sdim  CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation StartLoc,
1549212904Sdim                const DeclarationNameInfo &NameInfo,
1550212904Sdim                QualType T, TypeSourceInfo *TInfo,
1551221345Sdim                bool isStatic, StorageClass SCAsWritten, bool isInline,
1552226890Sdim                bool isConstexpr, SourceLocation EndLocation)
1553221345Sdim    : FunctionDecl(DK, RD, StartLoc, NameInfo, T, TInfo,
1554221345Sdim                   (isStatic ? SC_Static : SC_None),
1555226890Sdim                   SCAsWritten, isInline, isConstexpr) {
1556235633Sdim    if (EndLocation.isValid())
1557235633Sdim      setRangeEnd(EndLocation);
1558235633Sdim  }
1559193326Sed
1560193326Sedpublic:
1561193326Sed  static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1562221345Sdim                               SourceLocation StartLoc,
1563212904Sdim                               const DeclarationNameInfo &NameInfo,
1564212904Sdim                               QualType T, TypeSourceInfo *TInfo,
1565221345Sdim                               bool isStatic,
1566221345Sdim                               StorageClass SCAsWritten,
1567221345Sdim                               bool isInline,
1568226890Sdim                               bool isConstexpr,
1569221345Sdim                               SourceLocation EndLocation);
1570198092Srdivacky
1571235633Sdim  static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1572235633Sdim
1573212904Sdim  bool isStatic() const { return getStorageClass() == SC_Static; }
1574193326Sed  bool isInstance() const { return !isStatic(); }
1575193326Sed
1576198092Srdivacky  bool isVirtual() const {
1577235633Sdim    CXXMethodDecl *CD =
1578198092Srdivacky      cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl());
1579198092Srdivacky
1580198092Srdivacky    if (CD->isVirtualAsWritten())
1581198092Srdivacky      return true;
1582235633Sdim
1583198092Srdivacky    return (CD->begin_overridden_methods() != CD->end_overridden_methods());
1584193326Sed  }
1585206084Srdivacky
1586198092Srdivacky  /// \brief Determine whether this is a usual deallocation function
1587198092Srdivacky  /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded
1588198092Srdivacky  /// delete or delete[] operator with a particular signature.
1589198092Srdivacky  bool isUsualDeallocationFunction() const;
1590235633Sdim
1591207619Srdivacky  /// \brief Determine whether this is a copy-assignment operator, regardless
1592207619Srdivacky  /// of whether it was declared implicitly or explicitly.
1593207619Srdivacky  bool isCopyAssignmentOperator() const;
1594223017Sdim
1595223017Sdim  /// \brief Determine whether this is a move assignment operator.
1596223017Sdim  bool isMoveAssignmentOperator() const;
1597235633Sdim
1598198092Srdivacky  const CXXMethodDecl *getCanonicalDecl() const {
1599198092Srdivacky    return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
1600198092Srdivacky  }
1601198092Srdivacky  CXXMethodDecl *getCanonicalDecl() {
1602198092Srdivacky    return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
1603198092Srdivacky  }
1604223017Sdim
1605223017Sdim  /// isUserProvided - True if it is either an implicit constructor or
1606223017Sdim  /// if it was defaulted or deleted on first declaration.
1607223017Sdim  bool isUserProvided() const {
1608223017Sdim    return !(isDeleted() || getCanonicalDecl()->isDefaulted());
1609223017Sdim  }
1610235633Sdim
1611198092Srdivacky  ///
1612198092Srdivacky  void addOverriddenMethod(const CXXMethodDecl *MD);
1613193326Sed
1614235633Sdim  typedef const CXXMethodDecl *const* method_iterator;
1615198092Srdivacky
1616193326Sed  method_iterator begin_overridden_methods() const;
1617193326Sed  method_iterator end_overridden_methods() const;
1618210299Sed  unsigned size_overridden_methods() const;
1619198092Srdivacky
1620193326Sed  /// getParent - Returns the parent of this method declaration, which
1621193326Sed  /// is the class in which this method is defined.
1622198092Srdivacky  const CXXRecordDecl *getParent() const {
1623198092Srdivacky    return cast<CXXRecordDecl>(FunctionDecl::getParent());
1624193326Sed  }
1625198092Srdivacky
1626193326Sed  /// getParent - Returns the parent of this method declaration, which
1627193326Sed  /// is the class in which this method is defined.
1628198092Srdivacky  CXXRecordDecl *getParent() {
1629193326Sed    return const_cast<CXXRecordDecl *>(
1630193326Sed             cast<CXXRecordDecl>(FunctionDecl::getParent()));
1631193326Sed  }
1632193326Sed
1633193326Sed  /// getThisType - Returns the type of 'this' pointer.
1634193326Sed  /// Should only be called for instance methods.
1635193326Sed  QualType getThisType(ASTContext &C) const;
1636193326Sed
1637193326Sed  unsigned getTypeQualifiers() const {
1638198092Srdivacky    return getType()->getAs<FunctionProtoType>()->getTypeQuals();
1639193326Sed  }
1640193326Sed
1641218893Sdim  /// \brief Retrieve the ref-qualifier associated with this method.
1642218893Sdim  ///
1643218893Sdim  /// In the following example, \c f() has an lvalue ref-qualifier, \c g()
1644218893Sdim  /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier.
1645218893Sdim  /// \code
1646218893Sdim  /// struct X {
1647218893Sdim  ///   void f() &;
1648218893Sdim  ///   void g() &&;
1649218893Sdim  ///   void h();
1650218893Sdim  /// };
1651226890Sdim  /// \endcode
1652218893Sdim  RefQualifierKind getRefQualifier() const {
1653218893Sdim    return getType()->getAs<FunctionProtoType>()->getRefQualifier();
1654218893Sdim  }
1655235633Sdim
1656200583Srdivacky  bool hasInlineBody() const;
1657200583Srdivacky
1658235633Sdim  /// \brief Determine whether this is a lambda closure type's static member
1659235633Sdim  /// function that is used for the result of the lambda's conversion to
1660235633Sdim  /// function pointer (for a lambda with no captures).
1661235633Sdim  ///
1662235633Sdim  /// The function itself, if used, will have a placeholder body that will be
1663235633Sdim  /// supplied by IR generation to either forward to the function call operator
1664235633Sdim  /// or clone the function call operator.
1665235633Sdim  bool isLambdaStaticInvoker() const;
1666235633Sdim
1667193326Sed  // Implement isa/cast/dyncast/etc.
1668203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1669203955Srdivacky  static bool classof(const CXXMethodDecl *D) { return true; }
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()); }
2149193326Sed  static bool classof(const CXXConstructorDecl *D) { return true; }
2150203955Srdivacky  static bool classofKind(Kind K) { return K == CXXConstructor; }
2151235633Sdim
2152212904Sdim  friend class ASTDeclReader;
2153212904Sdim  friend class ASTDeclWriter;
2154193326Sed};
2155193326Sed
2156193326Sed/// CXXDestructorDecl - Represents a C++ destructor within a
2157193326Sed/// class. For example:
2158198092Srdivacky///
2159193326Sed/// @code
2160193326Sed/// class X {
2161193326Sed/// public:
2162193326Sed///   ~X(); // represented by a CXXDestructorDecl.
2163193326Sed/// };
2164193326Sed/// @endcode
2165193326Sedclass CXXDestructorDecl : public CXXMethodDecl {
2166235633Sdim  virtual void anchor();
2167193326Sed  /// ImplicitlyDefined - Whether this destructor was implicitly
2168193326Sed  /// defined by the compiler. When false, the destructor was defined
2169193326Sed  /// by the user. In C++03, this flag will have the same value as
2170193326Sed  /// Implicit. In C++0x, however, a destructor that is
2171193326Sed  /// explicitly defaulted (i.e., defined with " = default") will have
2172193326Sed  /// @c !Implicit && ImplicitlyDefined.
2173193326Sed  bool ImplicitlyDefined : 1;
2174193326Sed
2175199482Srdivacky  FunctionDecl *OperatorDelete;
2176235633Sdim
2177221345Sdim  CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
2178221345Sdim                    const DeclarationNameInfo &NameInfo,
2179218893Sdim                    QualType T, TypeSourceInfo *TInfo,
2180218893Sdim                    bool isInline, bool isImplicitlyDeclared)
2181221345Sdim    : CXXMethodDecl(CXXDestructor, RD, StartLoc, NameInfo, T, TInfo, false,
2182226890Sdim                    SC_None, isInline, /*isConstexpr=*/false, SourceLocation()),
2183199482Srdivacky      ImplicitlyDefined(false), OperatorDelete(0) {
2184193326Sed    setImplicit(isImplicitlyDeclared);
2185193326Sed  }
2186193326Sed
2187193326Sedpublic:
2188193326Sed  static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2189221345Sdim                                   SourceLocation StartLoc,
2190212904Sdim                                   const DeclarationNameInfo &NameInfo,
2191218893Sdim                                   QualType T, TypeSourceInfo* TInfo,
2192218893Sdim                                   bool isInline,
2193193326Sed                                   bool isImplicitlyDeclared);
2194235633Sdim  static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID);
2195193326Sed
2196193326Sed  /// isImplicitlyDefined - Whether this destructor was implicitly
2197193326Sed  /// defined. If false, then this destructor was defined by the
2198193326Sed  /// user. This operation can only be invoked if the destructor has
2199193326Sed  /// already been defined.
2200198092Srdivacky  bool isImplicitlyDefined() const {
2201198092Srdivacky    assert(isThisDeclarationADefinition() &&
2202235633Sdim           "Can only get the implicit-definition flag once the destructor has "
2203235633Sdim           "been defined");
2204198092Srdivacky    return ImplicitlyDefined;
2205193326Sed  }
2206193326Sed
2207193326Sed  /// setImplicitlyDefined - Set whether this destructor was
2208193326Sed  /// implicitly defined or not.
2209198092Srdivacky  void setImplicitlyDefined(bool ID) {
2210198092Srdivacky    assert(isThisDeclarationADefinition() &&
2211235633Sdim           "Can only set the implicit-definition flag once the destructor has "
2212235633Sdim           "been defined");
2213198092Srdivacky    ImplicitlyDefined = ID;
2214193326Sed  }
2215193326Sed
2216199482Srdivacky  void setOperatorDelete(FunctionDecl *OD) { OperatorDelete = OD; }
2217199482Srdivacky  const FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
2218198092Srdivacky
2219193326Sed  // Implement isa/cast/dyncast/etc.
2220203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2221193326Sed  static bool classof(const CXXDestructorDecl *D) { return true; }
2222203955Srdivacky  static bool classofKind(Kind K) { return K == CXXDestructor; }
2223235633Sdim
2224212904Sdim  friend class ASTDeclReader;
2225212904Sdim  friend class ASTDeclWriter;
2226193326Sed};
2227193326Sed
2228193326Sed/// CXXConversionDecl - Represents a C++ conversion function within a
2229193326Sed/// class. For example:
2230198092Srdivacky///
2231193326Sed/// @code
2232193326Sed/// class X {
2233193326Sed/// public:
2234193326Sed///   operator bool();
2235193326Sed/// };
2236193326Sed/// @endcode
2237193326Sedclass CXXConversionDecl : public CXXMethodDecl {
2238235633Sdim  virtual void anchor();
2239235633Sdim  /// IsExplicitSpecified - Whether this conversion function declaration is
2240203955Srdivacky  /// marked "explicit", meaning that it can only be applied when the user
2241193326Sed  /// explicitly wrote a cast. This is a C++0x feature.
2242203955Srdivacky  bool IsExplicitSpecified : 1;
2243193326Sed
2244221345Sdim  CXXConversionDecl(CXXRecordDecl *RD, SourceLocation StartLoc,
2245221345Sdim                    const DeclarationNameInfo &NameInfo,
2246212904Sdim                    QualType T, TypeSourceInfo *TInfo,
2247221345Sdim                    bool isInline, bool isExplicitSpecified,
2248226890Sdim                    bool isConstexpr, SourceLocation EndLocation)
2249221345Sdim    : CXXMethodDecl(CXXConversion, RD, StartLoc, NameInfo, T, TInfo, false,
2250226890Sdim                    SC_None, isInline, isConstexpr, EndLocation),
2251203955Srdivacky      IsExplicitSpecified(isExplicitSpecified) { }
2252193326Sed
2253193326Sedpublic:
2254193326Sed  static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2255221345Sdim                                   SourceLocation StartLoc,
2256212904Sdim                                   const DeclarationNameInfo &NameInfo,
2257200583Srdivacky                                   QualType T, TypeSourceInfo *TInfo,
2258221345Sdim                                   bool isInline, bool isExplicit,
2259226890Sdim                                   bool isConstexpr,
2260221345Sdim                                   SourceLocation EndLocation);
2261235633Sdim  static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2262193326Sed
2263235633Sdim  /// IsExplicitSpecified - Whether this conversion function declaration is
2264203955Srdivacky  /// marked "explicit", meaning that it can only be applied when the user
2265203955Srdivacky  /// explicitly wrote a cast. This is a C++0x feature.
2266203955Srdivacky  bool isExplicitSpecified() const { return IsExplicitSpecified; }
2267203955Srdivacky
2268193326Sed  /// isExplicit - Whether this is an explicit conversion operator
2269193326Sed  /// (C++0x only). Explicit conversion operators are only considered
2270193326Sed  /// when the user has explicitly written a cast.
2271203955Srdivacky  bool isExplicit() const {
2272203955Srdivacky    return cast<CXXConversionDecl>(getFirstDeclaration())
2273203955Srdivacky      ->isExplicitSpecified();
2274203955Srdivacky  }
2275193326Sed
2276193326Sed  /// getConversionType - Returns the type that this conversion
2277193326Sed  /// function is converting to.
2278198092Srdivacky  QualType getConversionType() const {
2279198092Srdivacky    return getType()->getAs<FunctionType>()->getResultType();
2280193326Sed  }
2281193326Sed
2282235633Sdim  /// \brief Determine whether this conversion function is a conversion from
2283235633Sdim  /// a lambda closure type to a block pointer.
2284235633Sdim  bool isLambdaToBlockPointerConversion() const;
2285235633Sdim
2286193326Sed  // Implement isa/cast/dyncast/etc.
2287203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2288193326Sed  static bool classof(const CXXConversionDecl *D) { return true; }
2289203955Srdivacky  static bool classofKind(Kind K) { return K == CXXConversion; }
2290235633Sdim
2291212904Sdim  friend class ASTDeclReader;
2292212904Sdim  friend class ASTDeclWriter;
2293193326Sed};
2294193326Sed
2295193326Sed/// LinkageSpecDecl - This represents a linkage specification.  For example:
2296193326Sed///   extern "C" void foo();
2297193326Sed///
2298193326Sedclass LinkageSpecDecl : public Decl, public DeclContext {
2299235633Sdim  virtual void anchor();
2300193326Sedpublic:
2301193326Sed  /// LanguageIDs - Used to represent the language in a linkage
2302193326Sed  /// specification.  The values are part of the serialization abi for
2303193326Sed  /// ASTs and cannot be changed without altering that abi.  To help
2304193326Sed  /// ensure a stable abi for this, we choose the DW_LANG_ encodings
2305193326Sed  /// from the dwarf standard.
2306208600Srdivacky  enum LanguageIDs {
2307208600Srdivacky    lang_c = /* DW_LANG_C */ 0x0002,
2308208600Srdivacky    lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004
2309208600Srdivacky  };
2310193326Sedprivate:
2311193326Sed  /// Language - The language for this linkage specification.
2312193326Sed  LanguageIDs Language;
2313221345Sdim  /// ExternLoc - The source location for the extern keyword.
2314221345Sdim  SourceLocation ExternLoc;
2315221345Sdim  /// RBraceLoc - The source location for the right brace (if valid).
2316221345Sdim  SourceLocation RBraceLoc;
2317193326Sed
2318221345Sdim  LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
2319221345Sdim                  SourceLocation LangLoc, LanguageIDs lang,
2320221345Sdim                  SourceLocation RBLoc)
2321221345Sdim    : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec),
2322221345Sdim      Language(lang), ExternLoc(ExternLoc), RBraceLoc(RBLoc) { }
2323193326Sed
2324193326Sedpublic:
2325198092Srdivacky  static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
2326221345Sdim                                 SourceLocation ExternLoc,
2327221345Sdim                                 SourceLocation LangLoc, LanguageIDs Lang,
2328221345Sdim                                 SourceLocation RBraceLoc = SourceLocation());
2329235633Sdim  static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2330235633Sdim
2331208600Srdivacky  /// \brief Return the language specified by this linkage specification.
2332193326Sed  LanguageIDs getLanguage() const { return Language; }
2333208600Srdivacky  /// \brief Set the language specified by this linkage specification.
2334208600Srdivacky  void setLanguage(LanguageIDs L) { Language = L; }
2335208600Srdivacky
2336208600Srdivacky  /// \brief Determines whether this linkage specification had braces in
2337208600Srdivacky  /// its syntactic form.
2338221345Sdim  bool hasBraces() const { return RBraceLoc.isValid(); }
2339193326Sed
2340221345Sdim  SourceLocation getExternLoc() const { return ExternLoc; }
2341221345Sdim  SourceLocation getRBraceLoc() const { return RBraceLoc; }
2342221345Sdim  void setExternLoc(SourceLocation L) { ExternLoc = L; }
2343221345Sdim  void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
2344208600Srdivacky
2345235633Sdim  SourceLocation getLocEnd() const LLVM_READONLY {
2346221345Sdim    if (hasBraces())
2347221345Sdim      return getRBraceLoc();
2348221345Sdim    // No braces: get the end location of the (only) declaration in context
2349221345Sdim    // (if present).
2350221345Sdim    return decls_empty() ? getLocation() : decls_begin()->getLocEnd();
2351221345Sdim  }
2352221345Sdim
2353235633Sdim  SourceRange getSourceRange() const LLVM_READONLY {
2354221345Sdim    return SourceRange(ExternLoc, getLocEnd());
2355221345Sdim  }
2356221345Sdim
2357203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2358193326Sed  static bool classof(const LinkageSpecDecl *D) { return true; }
2359203955Srdivacky  static bool classofKind(Kind K) { return K == LinkageSpec; }
2360193326Sed  static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
2361193326Sed    return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
2362193326Sed  }
2363193326Sed  static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
2364193326Sed    return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
2365193326Sed  }
2366193326Sed};
2367193326Sed
2368193326Sed/// UsingDirectiveDecl - Represents C++ using-directive. For example:
2369193326Sed///
2370193326Sed///    using namespace std;
2371193326Sed///
2372193326Sed// NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide
2373235633Sdim// artificial names for all using-directives in order to store
2374193326Sed// them in DeclContext effectively.
2375193326Sedclass UsingDirectiveDecl : public NamedDecl {
2376235633Sdim  virtual void anchor();
2377212904Sdim  /// \brief The location of the "using" keyword.
2378212904Sdim  SourceLocation UsingLoc;
2379235633Sdim
2380193326Sed  /// SourceLocation - Location of 'namespace' token.
2381193326Sed  SourceLocation NamespaceLoc;
2382193326Sed
2383219077Sdim  /// \brief The nested-name-specifier that precedes the namespace.
2384219077Sdim  NestedNameSpecifierLoc QualifierLoc;
2385193326Sed
2386193326Sed  /// NominatedNamespace - Namespace nominated by using-directive.
2387199990Srdivacky  NamedDecl *NominatedNamespace;
2388193326Sed
2389199990Srdivacky  /// Enclosing context containing both using-directive and nominated
2390193326Sed  /// namespace.
2391193326Sed  DeclContext *CommonAncestor;
2392193326Sed
2393193326Sed  /// getUsingDirectiveName - Returns special DeclarationName used by
2394193326Sed  /// using-directives. This is only used by DeclContext for storing
2395193326Sed  /// UsingDirectiveDecls in its lookup structure.
2396193326Sed  static DeclarationName getName() {
2397193326Sed    return DeclarationName::getUsingDirectiveName();
2398193326Sed  }
2399193326Sed
2400212904Sdim  UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc,
2401193326Sed                     SourceLocation NamespcLoc,
2402219077Sdim                     NestedNameSpecifierLoc QualifierLoc,
2403193326Sed                     SourceLocation IdentLoc,
2404199990Srdivacky                     NamedDecl *Nominated,
2405193326Sed                     DeclContext *CommonAncestor)
2406212904Sdim    : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc),
2407219077Sdim      NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc),
2408219077Sdim      NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) { }
2409193326Sed
2410193326Sedpublic:
2411193326Sed  /// \brief Retrieve the nested-name-specifier that qualifies the
2412219077Sdim  /// name of the namespace, with source-location information.
2413219077Sdim  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2414235633Sdim
2415219077Sdim  /// \brief Retrieve the nested-name-specifier that qualifies the
2416193326Sed  /// name of the namespace.
2417235633Sdim  NestedNameSpecifier *getQualifier() const {
2418235633Sdim    return QualifierLoc.getNestedNameSpecifier();
2419219077Sdim  }
2420193326Sed
2421199990Srdivacky  NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
2422199990Srdivacky  const NamedDecl *getNominatedNamespaceAsWritten() const {
2423199990Srdivacky    return NominatedNamespace;
2424199990Srdivacky  }
2425199990Srdivacky
2426193326Sed  /// getNominatedNamespace - Returns namespace nominated by using-directive.
2427199990Srdivacky  NamespaceDecl *getNominatedNamespace();
2428193326Sed
2429193326Sed  const NamespaceDecl *getNominatedNamespace() const {
2430193326Sed    return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
2431193326Sed  }
2432193326Sed
2433208600Srdivacky  /// \brief Returns the common ancestor context of this using-directive and
2434208600Srdivacky  /// its nominated namespace.
2435193326Sed  DeclContext *getCommonAncestor() { return CommonAncestor; }
2436193326Sed  const DeclContext *getCommonAncestor() const { return CommonAncestor; }
2437193326Sed
2438212904Sdim  /// \brief Return the location of the "using" keyword.
2439212904Sdim  SourceLocation getUsingLoc() const { return UsingLoc; }
2440235633Sdim
2441208600Srdivacky  // FIXME: Could omit 'Key' in name.
2442193326Sed  /// getNamespaceKeyLocation - Returns location of namespace keyword.
2443193326Sed  SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
2444193326Sed
2445193326Sed  /// getIdentLocation - Returns location of identifier.
2446212904Sdim  SourceLocation getIdentLocation() const { return getLocation(); }
2447193326Sed
2448193326Sed  static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
2449212904Sdim                                    SourceLocation UsingLoc,
2450193326Sed                                    SourceLocation NamespaceLoc,
2451219077Sdim                                    NestedNameSpecifierLoc QualifierLoc,
2452193326Sed                                    SourceLocation IdentLoc,
2453199990Srdivacky                                    NamedDecl *Nominated,
2454193326Sed                                    DeclContext *CommonAncestor);
2455235633Sdim  static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2456235633Sdim
2457235633Sdim  SourceRange getSourceRange() const LLVM_READONLY {
2458212904Sdim    return SourceRange(UsingLoc, getLocation());
2459212904Sdim  }
2460235633Sdim
2461203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2462193326Sed  static bool classof(const UsingDirectiveDecl *D) { return true; }
2463210299Sed  static bool classofKind(Kind K) { return K == UsingDirective; }
2464193326Sed
2465193326Sed  // Friend for getUsingDirectiveName.
2466193326Sed  friend class DeclContext;
2467235633Sdim
2468212904Sdim  friend class ASTDeclReader;
2469193326Sed};
2470193326Sed
2471193326Sed/// NamespaceAliasDecl - Represents a C++ namespace alias. For example:
2472193326Sed///
2473193326Sed/// @code
2474193326Sed/// namespace Foo = Bar;
2475193326Sed/// @endcode
2476193326Sedclass NamespaceAliasDecl : public NamedDecl {
2477235633Sdim  virtual void anchor();
2478235633Sdim
2479212904Sdim  /// \brief The location of the "namespace" keyword.
2480212904Sdim  SourceLocation NamespaceLoc;
2481193326Sed
2482208600Srdivacky  /// IdentLoc - Location of namespace identifier. Accessed by TargetNameLoc.
2483193326Sed  SourceLocation IdentLoc;
2484235633Sdim
2485219077Sdim  /// \brief The nested-name-specifier that precedes the namespace.
2486219077Sdim  NestedNameSpecifierLoc QualifierLoc;
2487235633Sdim
2488198092Srdivacky  /// Namespace - The Decl that this alias points to. Can either be a
2489193326Sed  /// NamespaceDecl or a NamespaceAliasDecl.
2490193326Sed  NamedDecl *Namespace;
2491198092Srdivacky
2492212904Sdim  NamespaceAliasDecl(DeclContext *DC, SourceLocation NamespaceLoc,
2493198092Srdivacky                     SourceLocation AliasLoc, IdentifierInfo *Alias,
2494219077Sdim                     NestedNameSpecifierLoc QualifierLoc,
2495193326Sed                     SourceLocation IdentLoc, NamedDecl *Namespace)
2496235633Sdim    : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias),
2497219077Sdim      NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc),
2498219077Sdim      QualifierLoc(QualifierLoc), Namespace(Namespace) { }
2499193326Sed
2500212904Sdim  friend class ASTDeclReader;
2501235633Sdim
2502193326Sedpublic:
2503193326Sed  /// \brief Retrieve the nested-name-specifier that qualifies the
2504219077Sdim  /// name of the namespace, with source-location information.
2505219077Sdim  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2506235633Sdim
2507219077Sdim  /// \brief Retrieve the nested-name-specifier that qualifies the
2508193326Sed  /// name of the namespace.
2509235633Sdim  NestedNameSpecifier *getQualifier() const {
2510235633Sdim    return QualifierLoc.getNestedNameSpecifier();
2511219077Sdim  }
2512235633Sdim
2513208600Srdivacky  /// \brief Retrieve the namespace declaration aliased by this directive.
2514193326Sed  NamespaceDecl *getNamespace() {
2515193326Sed    if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
2516193326Sed      return AD->getNamespace();
2517193326Sed
2518193326Sed    return cast<NamespaceDecl>(Namespace);
2519193326Sed  }
2520198092Srdivacky
2521193326Sed  const NamespaceDecl *getNamespace() const {
2522193326Sed    return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
2523193326Sed  }
2524193326Sed
2525203955Srdivacky  /// Returns the location of the alias name, i.e. 'foo' in
2526203955Srdivacky  /// "namespace foo = ns::bar;".
2527212904Sdim  SourceLocation getAliasLoc() const { return getLocation(); }
2528203955Srdivacky
2529203955Srdivacky  /// Returns the location of the 'namespace' keyword.
2530212904Sdim  SourceLocation getNamespaceLoc() const { return NamespaceLoc; }
2531203955Srdivacky
2532203955Srdivacky  /// Returns the location of the identifier in the named namespace.
2533203955Srdivacky  SourceLocation getTargetNameLoc() const { return IdentLoc; }
2534203955Srdivacky
2535193326Sed  /// \brief Retrieve the namespace that this alias refers to, which
2536193326Sed  /// may either be a NamespaceDecl or a NamespaceAliasDecl.
2537193326Sed  NamedDecl *getAliasedNamespace() const { return Namespace; }
2538193326Sed
2539198092Srdivacky  static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
2540235633Sdim                                    SourceLocation NamespaceLoc,
2541212904Sdim                                    SourceLocation AliasLoc,
2542198092Srdivacky                                    IdentifierInfo *Alias,
2543219077Sdim                                    NestedNameSpecifierLoc QualifierLoc,
2544198092Srdivacky                                    SourceLocation IdentLoc,
2545193326Sed                                    NamedDecl *Namespace);
2546198092Srdivacky
2547235633Sdim  static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2548235633Sdim
2549235633Sdim  virtual SourceRange getSourceRange() const LLVM_READONLY {
2550212904Sdim    return SourceRange(NamespaceLoc, IdentLoc);
2551212904Sdim  }
2552235633Sdim
2553203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2554193326Sed  static bool classof(const NamespaceAliasDecl *D) { return true; }
2555210299Sed  static bool classofKind(Kind K) { return K == NamespaceAlias; }
2556193326Sed};
2557194613Sed
2558199482Srdivacky/// UsingShadowDecl - Represents a shadow declaration introduced into
2559199482Srdivacky/// a scope by a (resolved) using declaration.  For example,
2560199482Srdivacky///
2561199482Srdivacky/// namespace A {
2562199482Srdivacky///   void foo();
2563199482Srdivacky/// }
2564199482Srdivacky/// namespace B {
2565199482Srdivacky///   using A::foo(); // <- a UsingDecl
2566199482Srdivacky///                   // Also creates a UsingShadowDecl for A::foo in B
2567199482Srdivacky/// }
2568199482Srdivacky///
2569199482Srdivackyclass UsingShadowDecl : public NamedDecl {
2570235633Sdim  virtual void anchor();
2571235633Sdim
2572199482Srdivacky  /// The referenced declaration.
2573199482Srdivacky  NamedDecl *Underlying;
2574199482Srdivacky
2575218893Sdim  /// \brief The using declaration which introduced this decl or the next using
2576218893Sdim  /// shadow declaration contained in the aforementioned using declaration.
2577218893Sdim  NamedDecl *UsingOrNextShadow;
2578218893Sdim  friend class UsingDecl;
2579199482Srdivacky
2580199482Srdivacky  UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using,
2581199482Srdivacky                  NamedDecl *Target)
2582210299Sed    : NamedDecl(UsingShadow, DC, Loc, DeclarationName()),
2583218893Sdim      Underlying(Target),
2584218893Sdim      UsingOrNextShadow(reinterpret_cast<NamedDecl *>(Using)) {
2585210299Sed    if (Target) {
2586210299Sed      setDeclName(Target->getDeclName());
2587210299Sed      IdentifierNamespace = Target->getIdentifierNamespace();
2588210299Sed    }
2589199482Srdivacky    setImplicit();
2590199482Srdivacky  }
2591199482Srdivacky
2592199482Srdivackypublic:
2593199482Srdivacky  static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
2594199482Srdivacky                                 SourceLocation Loc, UsingDecl *Using,
2595199482Srdivacky                                 NamedDecl *Target) {
2596199482Srdivacky    return new (C) UsingShadowDecl(DC, Loc, Using, Target);
2597199482Srdivacky  }
2598199482Srdivacky
2599235633Sdim  static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2600235633Sdim
2601208600Srdivacky  /// \brief Gets the underlying declaration which has been brought into the
2602199482Srdivacky  /// local scope.
2603208600Srdivacky  NamedDecl *getTargetDecl() const { return Underlying; }
2604199482Srdivacky
2605208600Srdivacky  /// \brief Sets the underlying declaration which has been brought into the
2606208600Srdivacky  /// local scope.
2607210299Sed  void setTargetDecl(NamedDecl* ND) {
2608210299Sed    assert(ND && "Target decl is null!");
2609210299Sed    Underlying = ND;
2610210299Sed    IdentifierNamespace = ND->getIdentifierNamespace();
2611210299Sed  }
2612199482Srdivacky
2613208600Srdivacky  /// \brief Gets the using declaration to which this declaration is tied.
2614218893Sdim  UsingDecl *getUsingDecl() const;
2615208600Srdivacky
2616218893Sdim  /// \brief The next using shadow declaration contained in the shadow decl
2617218893Sdim  /// chain of the using declaration which introduced this decl.
2618218893Sdim  UsingShadowDecl *getNextUsingShadowDecl() const {
2619218893Sdim    return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow);
2620218893Sdim  }
2621208600Srdivacky
2622203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2623199482Srdivacky  static bool classof(const UsingShadowDecl *D) { return true; }
2624203955Srdivacky  static bool classofKind(Kind K) { return K == Decl::UsingShadow; }
2625218893Sdim
2626218893Sdim  friend class ASTDeclReader;
2627218893Sdim  friend class ASTDeclWriter;
2628199482Srdivacky};
2629199482Srdivacky
2630194613Sed/// UsingDecl - Represents a C++ using-declaration. For example:
2631194613Sed///    using someNameSpace::someIdentifier;
2632194613Sedclass UsingDecl : public NamedDecl {
2633235633Sdim  virtual void anchor();
2634235633Sdim
2635194613Sed  /// \brief The source location of the "using" location itself.
2636194613Sed  SourceLocation UsingLocation;
2637198092Srdivacky
2638219077Sdim  /// \brief The nested-name-specifier that precedes the name.
2639219077Sdim  NestedNameSpecifierLoc QualifierLoc;
2640194613Sed
2641212904Sdim  /// DNLoc - Provides source/type location info for the
2642212904Sdim  /// declaration name embedded in the ValueDecl base class.
2643212904Sdim  DeclarationNameLoc DNLoc;
2644212904Sdim
2645218893Sdim  /// \brief The first shadow declaration of the shadow decl chain associated
2646235633Sdim  /// with this using declaration. The bool member of the pair store whether
2647235633Sdim  /// this decl has the 'typename' keyword.
2648235633Sdim  llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow;
2649199482Srdivacky
2650235633Sdim  UsingDecl(DeclContext *DC, SourceLocation UL,
2651219077Sdim            NestedNameSpecifierLoc QualifierLoc,
2652212904Sdim            const DeclarationNameInfo &NameInfo, bool IsTypeNameArg)
2653212904Sdim    : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()),
2654219077Sdim      UsingLocation(UL), QualifierLoc(QualifierLoc),
2655235633Sdim      DNLoc(NameInfo.getInfo()), FirstUsingShadow(0, IsTypeNameArg) {
2656194613Sed  }
2657194613Sed
2658194613Sedpublic:
2659208600Srdivacky  /// \brief Returns the source location of the "using" keyword.
2660212904Sdim  SourceLocation getUsingLocation() const { return UsingLocation; }
2661198092Srdivacky
2662208600Srdivacky  /// \brief Set the source location of the 'using' keyword.
2663208600Srdivacky  void setUsingLocation(SourceLocation L) { UsingLocation = L; }
2664208600Srdivacky
2665219077Sdim  /// \brief Retrieve the nested-name-specifier that qualifies the name,
2666219077Sdim  /// with source-location information.
2667219077Sdim  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2668219077Sdim
2669219077Sdim  /// \brief Retrieve the nested-name-specifier that qualifies the name.
2670235633Sdim  NestedNameSpecifier *getQualifier() const {
2671235633Sdim    return QualifierLoc.getNestedNameSpecifier();
2672195099Sed  }
2673198092Srdivacky
2674212904Sdim  DeclarationNameInfo getNameInfo() const {
2675212904Sdim    return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
2676212904Sdim  }
2677212904Sdim
2678208600Srdivacky  /// \brief Return true if the using declaration has 'typename'.
2679235633Sdim  bool isTypeName() const { return FirstUsingShadow.getInt(); }
2680194613Sed
2681208600Srdivacky  /// \brief Sets whether the using declaration has 'typename'.
2682235633Sdim  void setTypeName(bool TN) { FirstUsingShadow.setInt(TN); }
2683208600Srdivacky
2684218893Sdim  /// \brief Iterates through the using shadow declarations assosiated with
2685218893Sdim  /// this using declaration.
2686218893Sdim  class shadow_iterator {
2687218893Sdim    /// \brief The current using shadow declaration.
2688218893Sdim    UsingShadowDecl *Current;
2689199482Srdivacky
2690218893Sdim  public:
2691218893Sdim    typedef UsingShadowDecl*          value_type;
2692218893Sdim    typedef UsingShadowDecl*          reference;
2693218893Sdim    typedef UsingShadowDecl*          pointer;
2694218893Sdim    typedef std::forward_iterator_tag iterator_category;
2695218893Sdim    typedef std::ptrdiff_t            difference_type;
2696218893Sdim
2697218893Sdim    shadow_iterator() : Current(0) { }
2698218893Sdim    explicit shadow_iterator(UsingShadowDecl *C) : Current(C) { }
2699218893Sdim
2700218893Sdim    reference operator*() const { return Current; }
2701218893Sdim    pointer operator->() const { return Current; }
2702218893Sdim
2703218893Sdim    shadow_iterator& operator++() {
2704218893Sdim      Current = Current->getNextUsingShadowDecl();
2705218893Sdim      return *this;
2706199482Srdivacky    }
2707218893Sdim
2708218893Sdim    shadow_iterator operator++(int) {
2709218893Sdim      shadow_iterator tmp(*this);
2710218893Sdim      ++(*this);
2711218893Sdim      return tmp;
2712199482Srdivacky    }
2713218893Sdim
2714218893Sdim    friend bool operator==(shadow_iterator x, shadow_iterator y) {
2715218893Sdim      return x.Current == y.Current;
2716218893Sdim    }
2717218893Sdim    friend bool operator!=(shadow_iterator x, shadow_iterator y) {
2718218893Sdim      return x.Current != y.Current;
2719218893Sdim    }
2720218893Sdim  };
2721218893Sdim
2722218893Sdim  shadow_iterator shadow_begin() const {
2723235633Sdim    return shadow_iterator(FirstUsingShadow.getPointer());
2724199482Srdivacky  }
2725218893Sdim  shadow_iterator shadow_end() const { return shadow_iterator(); }
2726199482Srdivacky
2727208600Srdivacky  /// \brief Return the number of shadowed declarations associated with this
2728208600Srdivacky  /// using declaration.
2729218893Sdim  unsigned shadow_size() const {
2730218893Sdim    return std::distance(shadow_begin(), shadow_end());
2731208600Srdivacky  }
2732208600Srdivacky
2733218893Sdim  void addShadowDecl(UsingShadowDecl *S);
2734218893Sdim  void removeShadowDecl(UsingShadowDecl *S);
2735218893Sdim
2736194613Sed  static UsingDecl *Create(ASTContext &C, DeclContext *DC,
2737219077Sdim                           SourceLocation UsingL,
2738219077Sdim                           NestedNameSpecifierLoc QualifierLoc,
2739212904Sdim                           const DeclarationNameInfo &NameInfo,
2740212904Sdim                           bool IsTypeNameArg);
2741194613Sed
2742235633Sdim  static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2743235633Sdim
2744235633Sdim  SourceRange getSourceRange() const LLVM_READONLY {
2745212904Sdim    return SourceRange(UsingLocation, getNameInfo().getEndLoc());
2746212904Sdim  }
2747212904Sdim
2748203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2749194613Sed  static bool classof(const UsingDecl *D) { return true; }
2750210299Sed  static bool classofKind(Kind K) { return K == Using; }
2751210299Sed
2752212904Sdim  friend class ASTDeclReader;
2753212904Sdim  friend class ASTDeclWriter;
2754194613Sed};
2755198092Srdivacky
2756199482Srdivacky/// UnresolvedUsingValueDecl - Represents a dependent using
2757199482Srdivacky/// declaration which was not marked with 'typename'.  Unlike
2758199482Srdivacky/// non-dependent using declarations, these *only* bring through
2759199482Srdivacky/// non-types; otherwise they would break two-phase lookup.
2760199482Srdivacky///
2761199482Srdivacky/// template <class T> class A : public Base<T> {
2762199482Srdivacky///   using Base<T>::foo;
2763199482Srdivacky/// };
2764199482Srdivackyclass UnresolvedUsingValueDecl : public ValueDecl {
2765235633Sdim  virtual void anchor();
2766235633Sdim
2767199482Srdivacky  /// \brief The source location of the 'using' keyword
2768199482Srdivacky  SourceLocation UsingLocation;
2769198092Srdivacky
2770219077Sdim  /// \brief The nested-name-specifier that precedes the name.
2771219077Sdim  NestedNameSpecifierLoc QualifierLoc;
2772198092Srdivacky
2773212904Sdim  /// DNLoc - Provides source/type location info for the
2774212904Sdim  /// declaration name embedded in the ValueDecl base class.
2775212904Sdim  DeclarationNameLoc DNLoc;
2776212904Sdim
2777199482Srdivacky  UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
2778235633Sdim                           SourceLocation UsingLoc,
2779219077Sdim                           NestedNameSpecifierLoc QualifierLoc,
2780212904Sdim                           const DeclarationNameInfo &NameInfo)
2781212904Sdim    : ValueDecl(UnresolvedUsingValue, DC,
2782212904Sdim                NameInfo.getLoc(), NameInfo.getName(), Ty),
2783219077Sdim      UsingLocation(UsingLoc), QualifierLoc(QualifierLoc),
2784219077Sdim      DNLoc(NameInfo.getInfo())
2785199482Srdivacky  { }
2786198092Srdivacky
2787199482Srdivackypublic:
2788199482Srdivacky  /// \brief Returns the source location of the 'using' keyword.
2789199482Srdivacky  SourceLocation getUsingLoc() const { return UsingLocation; }
2790199482Srdivacky
2791208600Srdivacky  /// \brief Set the source location of the 'using' keyword.
2792208600Srdivacky  void setUsingLoc(SourceLocation L) { UsingLocation = L; }
2793208600Srdivacky
2794219077Sdim  /// \brief Retrieve the nested-name-specifier that qualifies the name,
2795219077Sdim  /// with source-location information.
2796219077Sdim  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2797219077Sdim
2798219077Sdim  /// \brief Retrieve the nested-name-specifier that qualifies the name.
2799235633Sdim  NestedNameSpecifier *getQualifier() const {
2800235633Sdim    return QualifierLoc.getNestedNameSpecifier();
2801219077Sdim  }
2802235633Sdim
2803212904Sdim  DeclarationNameInfo getNameInfo() const {
2804212904Sdim    return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
2805212904Sdim  }
2806212904Sdim
2807199482Srdivacky  static UnresolvedUsingValueDecl *
2808199482Srdivacky    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
2809235633Sdim           NestedNameSpecifierLoc QualifierLoc,
2810212904Sdim           const DeclarationNameInfo &NameInfo);
2811199482Srdivacky
2812235633Sdim  static UnresolvedUsingValueDecl *
2813235633Sdim  CreateDeserialized(ASTContext &C, unsigned ID);
2814235633Sdim
2815235633Sdim  SourceRange getSourceRange() const LLVM_READONLY {
2816212904Sdim    return SourceRange(UsingLocation, getNameInfo().getEndLoc());
2817212904Sdim  }
2818212904Sdim
2819203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2820199482Srdivacky  static bool classof(const UnresolvedUsingValueDecl *D) { return true; }
2821210299Sed  static bool classofKind(Kind K) { return K == UnresolvedUsingValue; }
2822218893Sdim
2823218893Sdim  friend class ASTDeclReader;
2824218893Sdim  friend class ASTDeclWriter;
2825199482Srdivacky};
2826199482Srdivacky
2827199482Srdivacky/// UnresolvedUsingTypenameDecl - Represents a dependent using
2828199482Srdivacky/// declaration which was marked with 'typename'.
2829199482Srdivacky///
2830199482Srdivacky/// template <class T> class A : public Base<T> {
2831199482Srdivacky///   using typename Base<T>::foo;
2832199482Srdivacky/// };
2833199482Srdivacky///
2834199482Srdivacky/// The type associated with a unresolved using typename decl is
2835199482Srdivacky/// currently always a typename type.
2836199482Srdivackyclass UnresolvedUsingTypenameDecl : public TypeDecl {
2837235633Sdim  virtual void anchor();
2838235633Sdim
2839199482Srdivacky  /// \brief The source location of the 'using' keyword
2840199482Srdivacky  SourceLocation UsingLocation;
2841199482Srdivacky
2842199482Srdivacky  /// \brief The source location of the 'typename' keyword
2843199482Srdivacky  SourceLocation TypenameLocation;
2844199482Srdivacky
2845219077Sdim  /// \brief The nested-name-specifier that precedes the name.
2846219077Sdim  NestedNameSpecifierLoc QualifierLoc;
2847199482Srdivacky
2848199482Srdivacky  UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
2849219077Sdim                              SourceLocation TypenameLoc,
2850219077Sdim                              NestedNameSpecifierLoc QualifierLoc,
2851235633Sdim                              SourceLocation TargetNameLoc,
2852219077Sdim                              IdentifierInfo *TargetName)
2853221345Sdim    : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName,
2854221345Sdim               UsingLoc),
2855221345Sdim      TypenameLocation(TypenameLoc), QualifierLoc(QualifierLoc) { }
2856199482Srdivacky
2857212904Sdim  friend class ASTDeclReader;
2858235633Sdim
2859198092Srdivackypublic:
2860199482Srdivacky  /// \brief Returns the source location of the 'using' keyword.
2861221345Sdim  SourceLocation getUsingLoc() const { return getLocStart(); }
2862198092Srdivacky
2863199482Srdivacky  /// \brief Returns the source location of the 'typename' keyword.
2864199482Srdivacky  SourceLocation getTypenameLoc() const { return TypenameLocation; }
2865198092Srdivacky
2866219077Sdim  /// \brief Retrieve the nested-name-specifier that qualifies the name,
2867219077Sdim  /// with source-location information.
2868219077Sdim  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2869219077Sdim
2870219077Sdim  /// \brief Retrieve the nested-name-specifier that qualifies the name.
2871235633Sdim  NestedNameSpecifier *getQualifier() const {
2872235633Sdim    return QualifierLoc.getNestedNameSpecifier();
2873219077Sdim  }
2874219077Sdim
2875199482Srdivacky  static UnresolvedUsingTypenameDecl *
2876199482Srdivacky    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
2877219077Sdim           SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc,
2878199482Srdivacky           SourceLocation TargetNameLoc, DeclarationName TargetName);
2879198092Srdivacky
2880235633Sdim  static UnresolvedUsingTypenameDecl *
2881235633Sdim  CreateDeserialized(ASTContext &C, unsigned ID);
2882235633Sdim
2883203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2884199482Srdivacky  static bool classof(const UnresolvedUsingTypenameDecl *D) { return true; }
2885210299Sed  static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; }
2886198092Srdivacky};
2887198092Srdivacky
2888193326Sed/// StaticAssertDecl - Represents a C++0x static_assert declaration.
2889193326Sedclass StaticAssertDecl : public Decl {
2890235633Sdim  virtual void anchor();
2891193326Sed  Expr *AssertExpr;
2892193326Sed  StringLiteral *Message;
2893221345Sdim  SourceLocation RParenLoc;
2894193326Sed
2895221345Sdim  StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc,
2896221345Sdim                   Expr *assertexpr, StringLiteral *message,
2897221345Sdim                   SourceLocation RParenLoc)
2898221345Sdim  : Decl(StaticAssert, DC, StaticAssertLoc), AssertExpr(assertexpr),
2899221345Sdim    Message(message), RParenLoc(RParenLoc) { }
2900198092Srdivacky
2901193326Sedpublic:
2902193326Sed  static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
2903221345Sdim                                  SourceLocation StaticAssertLoc,
2904221345Sdim                                  Expr *AssertExpr, StringLiteral *Message,
2905221345Sdim                                  SourceLocation RParenLoc);
2906235633Sdim  static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2907235633Sdim
2908193326Sed  Expr *getAssertExpr() { return AssertExpr; }
2909193326Sed  const Expr *getAssertExpr() const { return AssertExpr; }
2910198092Srdivacky
2911193326Sed  StringLiteral *getMessage() { return Message; }
2912193326Sed  const StringLiteral *getMessage() const { return Message; }
2913198092Srdivacky
2914221345Sdim  SourceLocation getRParenLoc() const { return RParenLoc; }
2915221345Sdim  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2916221345Sdim
2917235633Sdim  SourceRange getSourceRange() const LLVM_READONLY {
2918221345Sdim    return SourceRange(getLocation(), getRParenLoc());
2919221345Sdim  }
2920221345Sdim
2921203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2922193326Sed  static bool classof(StaticAssertDecl *D) { return true; }
2923210299Sed  static bool classofKind(Kind K) { return K == StaticAssert; }
2924212904Sdim
2925212904Sdim  friend class ASTDeclReader;
2926193326Sed};
2927193326Sed
2928193326Sed/// Insertion operator for diagnostics.  This allows sending AccessSpecifier's
2929193326Sed/// into a diagnostic with <<.
2930193326Sedconst DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
2931193326Sed                                    AccessSpecifier AS);
2932198092Srdivacky
2933235633Sdimconst PartialDiagnostic &operator<<(const PartialDiagnostic &DB,
2934235633Sdim                                    AccessSpecifier AS);
2935235633Sdim
2936193326Sed} // end namespace clang
2937193326Sed
2938193326Sed#endif
2939