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