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