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