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