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