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