DeclCXX.h revision 206084
1133819Stjr//===-- DeclCXX.h - Classes for representing C++ declarations -*- C++ -*-=====//
2133819Stjr//
3133819Stjr//                     The LLVM Compiler Infrastructure
4133819Stjr//
5133819Stjr// This file is distributed under the University of Illinois Open Source
6156843Snetchild// License. See LICENSE.TXT for details.
7133819Stjr//
8133819Stjr//===----------------------------------------------------------------------===//
9133819Stjr//
10133819Stjr//  This file defines the C++ Decl subclasses, other than those for
11133819Stjr//  templates (in DeclTemplate.h) and friends (in DeclFriend.h).
12133819Stjr//
13133819Stjr//===----------------------------------------------------------------------===//
14133819Stjr
15133819Stjr#ifndef LLVM_CLANG_AST_DECLCXX_H
16133819Stjr#define LLVM_CLANG_AST_DECLCXX_H
17133819Stjr
18133819Stjr#include "clang/AST/Expr.h"
19133819Stjr#include "clang/AST/Decl.h"
20133819Stjr#include "clang/AST/UnresolvedSet.h"
21133819Stjr#include "llvm/ADT/SmallVector.h"
22133819Stjr#include "llvm/ADT/SmallPtrSet.h"
23133819Stjr
24133819Stjrnamespace clang {
25133819Stjr
26133819Stjrclass ClassTemplateDecl;
27133819Stjrclass ClassTemplateSpecializationDecl;
28133819Stjrclass CXXBasePath;
29133819Stjrclass CXXBasePaths;
30133819Stjrclass CXXConstructorDecl;
31133819Stjrclass CXXConversionDecl;
32133819Stjrclass CXXDestructorDecl;
33133819Stjrclass CXXMethodDecl;
34133819Stjrclass CXXRecordDecl;
35143198Ssobomaxclass CXXMemberLookupCriteria;
36133819Stjrclass CXXFinalOverriderMap;
37133819Stjrclass FriendDecl;
38133819Stjr
39133819Stjr/// \brief Represents any kind of function declaration, whether it is a
40133819Stjr/// concrete function or a function template.
41133819Stjrclass AnyFunctionDecl {
42133819Stjr  NamedDecl *Function;
43133819Stjr
44133819Stjr  AnyFunctionDecl(NamedDecl *ND) : Function(ND) { }
45133819Stjr
46133819Stjrpublic:
47133819Stjr  AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { }
48133819Stjr  AnyFunctionDecl(FunctionTemplateDecl *FTD);
49133819Stjr
50133819Stjr  /// \brief Implicily converts any function or function template into a
51133819Stjr  /// named declaration.
52133819Stjr  operator NamedDecl *() const { return Function; }
53133819Stjr
54133819Stjr  /// \brief Retrieve the underlying function or function template.
55133819Stjr  NamedDecl *get() const { return Function; }
56133819Stjr
57133819Stjr  static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) {
58133819Stjr    return AnyFunctionDecl(ND);
59133819Stjr  }
60133819Stjr};
61133819Stjr
62133819Stjr} // end namespace clang
63133819Stjr
64133819Stjrnamespace llvm {
65133819Stjr  /// Implement simplify_type for AnyFunctionDecl, so that we can dyn_cast from
66133819Stjr  /// AnyFunctionDecl to any function or function template declaration.
67133819Stjr  template<> struct simplify_type<const ::clang::AnyFunctionDecl> {
68133819Stjr    typedef ::clang::NamedDecl* SimpleType;
69133819Stjr    static SimpleType getSimplifiedValue(const ::clang::AnyFunctionDecl &Val) {
70133819Stjr      return Val;
71133819Stjr    }
72133819Stjr  };
73133819Stjr  template<> struct simplify_type< ::clang::AnyFunctionDecl>
74133819Stjr  : public simplify_type<const ::clang::AnyFunctionDecl> {};
75133819Stjr
76133819Stjr  // Provide PointerLikeTypeTraits for non-cvr pointers.
77133819Stjr  template<>
78133819Stjr  class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
79133819Stjr  public:
80133819Stjr    static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
81133819Stjr      return F.get();
82133819Stjr    }
83133819Stjr    static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
84133819Stjr      return ::clang::AnyFunctionDecl::getFromNamedDecl(
85133819Stjr                                      static_cast< ::clang::NamedDecl*>(P));
86133819Stjr    }
87133819Stjr
88133819Stjr    enum { NumLowBitsAvailable = 2 };
89133819Stjr  };
90133819Stjr
91133819Stjr} // end namespace llvm
92133819Stjr
93133819Stjrnamespace clang {
94133819Stjr
95133819Stjr/// CXXBaseSpecifier - A base class of a C++ class.
96133819Stjr///
97133819Stjr/// Each CXXBaseSpecifier represents a single, direct base class (or
98133819Stjr/// struct) of a C++ class (or struct). It specifies the type of that
99133819Stjr/// base class, whether it is a virtual or non-virtual base, and what
100133819Stjr/// level of access (public, protected, private) is used for the
101133819Stjr/// derivation. For example:
102133819Stjr///
103133819Stjr/// @code
104133819Stjr///   class A { };
105133819Stjr///   class B { };
106133819Stjr///   class C : public virtual A, protected B { };
107133819Stjr/// @endcode
108133819Stjr///
109133819Stjr/// In this code, C will have two CXXBaseSpecifiers, one for "public
110133819Stjr/// virtual A" and the other for "protected B".
111133819Stjrclass CXXBaseSpecifier {
112133819Stjr  /// Range - The source code range that covers the full base
113133819Stjr  /// specifier, including the "virtual" (if present) and access
114133819Stjr  /// specifier (if present).
115133819Stjr  // FIXME: Move over to a TypeLoc!
116133819Stjr  SourceRange Range;
117133819Stjr
118133819Stjr  /// Virtual - Whether this is a virtual base class or not.
119133819Stjr  bool Virtual : 1;
120133819Stjr
121133819Stjr  /// BaseOfClass - Whether this is the base of a class (true) or of a
122133819Stjr  /// struct (false). This determines the mapping from the access
123133819Stjr  /// specifier as written in the source code to the access specifier
124133819Stjr  /// used for semantic analysis.
125133819Stjr  bool BaseOfClass : 1;
126133819Stjr
127133819Stjr  /// Access - Access specifier as written in the source code (which
128133819Stjr  /// may be AS_none). The actual type of data stored here is an
129133819Stjr  /// AccessSpecifier, but we use "unsigned" here to work around a
130133819Stjr  /// VC++ bug.
131133819Stjr  unsigned Access : 2;
132133819Stjr
133133819Stjr  /// BaseType - The type of the base class. This will be a class or
134133819Stjr  /// struct (or a typedef of such).
135133819Stjr  QualType BaseType;
136133819Stjr
137133819Stjrpublic:
138133819Stjr  CXXBaseSpecifier() { }
139133819Stjr
140133819Stjr  CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, QualType T)
141133819Stjr    : Range(R), Virtual(V), BaseOfClass(BC), Access(A), BaseType(T) { }
142133819Stjr
143133819Stjr  /// getSourceRange - Retrieves the source range that contains the
144133819Stjr  /// entire base specifier.
145133819Stjr  SourceRange getSourceRange() const { return Range; }
146133819Stjr
147133819Stjr  /// isVirtual - Determines whether the base class is a virtual base
148133819Stjr  /// class (or not).
149133819Stjr  bool isVirtual() const { return Virtual; }
150133819Stjr
151133819Stjr  /// \brief Determine whether this base class if a base of a class declared
152133819Stjr  /// with the 'class' keyword (vs. one declared with the 'struct' keyword).
153133819Stjr  bool isBaseOfClass() const { return BaseOfClass; }
154133819Stjr
155133819Stjr  /// getAccessSpecifier - Returns the access specifier for this base
156133819Stjr  /// specifier. This is the actual base specifier as used for
157133819Stjr  /// semantic analysis, so the result can never be AS_none. To
158133819Stjr  /// retrieve the access specifier as written in the source code, use
159133819Stjr  /// getAccessSpecifierAsWritten().
160133819Stjr  AccessSpecifier getAccessSpecifier() const {
161133819Stjr    if ((AccessSpecifier)Access == AS_none)
162133819Stjr      return BaseOfClass? AS_private : AS_public;
163133819Stjr    else
164133819Stjr      return (AccessSpecifier)Access;
165133819Stjr  }
166133819Stjr
167133819Stjr  /// getAccessSpecifierAsWritten - Retrieves the access specifier as
168133819Stjr  /// written in the source code (which may mean that no access
169133819Stjr  /// specifier was explicitly written). Use getAccessSpecifier() to
170133819Stjr  /// retrieve the access specifier for use in semantic analysis.
171133819Stjr  AccessSpecifier getAccessSpecifierAsWritten() const {
172133819Stjr    return (AccessSpecifier)Access;
173133819Stjr  }
174133819Stjr
175133819Stjr  /// getType - Retrieves the type of the base class. This type will
176133819Stjr  /// always be an unqualified class type.
177133819Stjr  QualType getType() const { return BaseType; }
178133819Stjr};
179133819Stjr
180133819Stjr/// CXXRecordDecl - Represents a C++ struct/union/class.
181133819Stjr/// FIXME: This class will disappear once we've properly taught RecordDecl
182133819Stjr/// to deal with C++-specific things.
183133819Stjrclass CXXRecordDecl : public RecordDecl {
184133819Stjr
185133819Stjr  friend void TagDecl::startDefinition();
186133819Stjr
187133819Stjr  struct DefinitionData {
188133819Stjr    DefinitionData(CXXRecordDecl *D);
189133819Stjr
190133819Stjr    /// UserDeclaredConstructor - True when this class has a
191133819Stjr    /// user-declared constructor.
192133819Stjr    bool UserDeclaredConstructor : 1;
193133819Stjr
194133819Stjr    /// UserDeclaredCopyConstructor - True when this class has a
195133819Stjr    /// user-declared copy constructor.
196133819Stjr    bool UserDeclaredCopyConstructor : 1;
197133819Stjr
198133819Stjr    /// UserDeclaredCopyAssignment - True when this class has a
199133819Stjr    /// user-declared copy assignment operator.
200133819Stjr    bool UserDeclaredCopyAssignment : 1;
201133819Stjr
202133819Stjr    /// UserDeclaredDestructor - True when this class has a
203133819Stjr    /// user-declared destructor.
204133819Stjr    bool UserDeclaredDestructor : 1;
205133819Stjr
206133819Stjr    /// Aggregate - True when this class is an aggregate.
207133819Stjr    bool Aggregate : 1;
208133819Stjr
209133819Stjr    /// PlainOldData - True when this class is a POD-type.
210133819Stjr    bool PlainOldData : 1;
211133819Stjr
212133819Stjr    /// Empty - true when this class is empty for traits purposes,
213133819Stjr    /// i.e. has no data members other than 0-width bit-fields, has no
214133819Stjr    /// virtual function/base, and doesn't inherit from a non-empty
215133819Stjr    /// class. Doesn't take union-ness into account.
216133819Stjr    bool Empty : 1;
217133819Stjr
218133819Stjr    /// Polymorphic - True when this class is polymorphic, i.e. has at
219133819Stjr    /// least one virtual member or derives from a polymorphic class.
220133819Stjr    bool Polymorphic : 1;
221133819Stjr
222133819Stjr    /// Abstract - True when this class is abstract, i.e. has at least
223156843Snetchild    /// one pure virtual function, (that can come from a base class).
224156843Snetchild    bool Abstract : 1;
225156843Snetchild
226156843Snetchild    /// HasTrivialConstructor - True when this class has a trivial constructor.
227133819Stjr    ///
228133819Stjr    /// C++ [class.ctor]p5.  A constructor is trivial if it is an
229133819Stjr    /// implicitly-declared default constructor and if:
230133819Stjr    /// * its class has no virtual functions and no virtual base classes, and
231133819Stjr    /// * all the direct base classes of its class have trivial constructors, and
232133819Stjr    /// * for all the nonstatic data members of its class that are of class type
233133819Stjr    ///   (or array thereof), each such class has a trivial constructor.
234133819Stjr    bool HasTrivialConstructor : 1;
235133819Stjr
236133819Stjr    /// HasTrivialCopyConstructor - True when this class has a trivial copy
237133819Stjr    /// constructor.
238133819Stjr    ///
239133819Stjr    /// C++ [class.copy]p6.  A copy constructor for class X is trivial
240133819Stjr    /// if it is implicitly declared and if
241133819Stjr    /// * class X has no virtual functions and no virtual base classes, and
242133819Stjr    /// * each direct base class of X has a trivial copy constructor, and
243133819Stjr    /// * for all the nonstatic data members of X that are of class type (or
244133819Stjr    ///   array thereof), each such class type has a trivial copy constructor;
245133819Stjr    /// otherwise the copy constructor is non-trivial.
246133819Stjr    bool HasTrivialCopyConstructor : 1;
247133819Stjr
248133819Stjr    /// HasTrivialCopyAssignment - True when this class has a trivial copy
249133819Stjr    /// assignment operator.
250133819Stjr    ///
251133819Stjr    /// C++ [class.copy]p11.  A copy assignment operator for class X is
252133819Stjr    /// trivial if it is implicitly declared and if
253133819Stjr    /// * class X has no virtual functions and no virtual base classes, and
254133819Stjr    /// * each direct base class of X has a trivial copy assignment operator, and
255133819Stjr    /// * for all the nonstatic data members of X that are of class type (or
256133819Stjr    ///   array thereof), each such class type has a trivial copy assignment
257133819Stjr    ///   operator;
258133819Stjr    /// otherwise the copy assignment operator is non-trivial.
259133819Stjr    bool HasTrivialCopyAssignment : 1;
260133819Stjr
261133819Stjr    /// HasTrivialDestructor - True when this class has a trivial destructor.
262156843Snetchild    ///
263156843Snetchild    /// C++ [class.dtor]p3.  A destructor is trivial if it is an
264156843Snetchild    /// implicitly-declared destructor and if:
265156843Snetchild    /// * all of the direct base classes of its class have trivial destructors
266133819Stjr    ///   and
267133819Stjr    /// * for all of the non-static data members of its class that are of class
268133819Stjr    ///   type (or array thereof), each such class has a trivial destructor.
269133819Stjr    bool HasTrivialDestructor : 1;
270133819Stjr
271133819Stjr    /// ComputedVisibleConversions - True when visible conversion functions are
272133819Stjr    /// already computed and are available.
273133819Stjr    bool ComputedVisibleConversions : 1;
274133819Stjr
275133819Stjr    /// Bases - Base classes of this class.
276133819Stjr    /// FIXME: This is wasted space for a union.
277133819Stjr    CXXBaseSpecifier *Bases;
278133819Stjr
279133819Stjr    /// NumBases - The number of base class specifiers in Bases.
280133819Stjr    unsigned NumBases;
281133819Stjr
282133819Stjr    /// VBases - direct and indirect virtual base classes of this class.
283133819Stjr    CXXBaseSpecifier *VBases;
284133819Stjr
285133819Stjr    /// NumVBases - The number of virtual base class specifiers in VBases.
286133819Stjr    unsigned NumVBases;
287133819Stjr
288133819Stjr    /// Conversions - Overload set containing the conversion functions
289156843Snetchild    /// of this C++ class (but not its inherited conversion
290156843Snetchild    /// functions). Each of the entries in this overload set is a
291156843Snetchild    /// CXXConversionDecl.
292156843Snetchild    UnresolvedSet<4> Conversions;
293147142Ssobomax
294147142Ssobomax    /// VisibleConversions - Overload set containing the conversion
295147142Ssobomax    /// functions of this C++ class and all those inherited conversion
296147142Ssobomax    /// functions that are visible in this class. Each of the entries
297133819Stjr    /// in this overload set is a CXXConversionDecl or a
298133819Stjr    /// FunctionTemplateDecl.
299133819Stjr    UnresolvedSet<4> VisibleConversions;
300133819Stjr
301133819Stjr    /// Definition - The declaration which defines this record.
302133819Stjr    CXXRecordDecl *Definition;
303133819Stjr
304133819Stjr    /// FirstFriend - The first friend declaration in this class, or
305133819Stjr    /// null if there aren't any.  This is actually currently stored
306133819Stjr    /// in reverse order.
307133819Stjr    FriendDecl *FirstFriend;
308133819Stjr
309133819Stjr  } *DefinitionData;
310133819Stjr
311133819Stjr  struct DefinitionData &data() {
312133819Stjr    assert(DefinitionData && "queried property of class with no definition");
313133819Stjr    return *DefinitionData;
314133819Stjr  }
315133819Stjr
316133819Stjr  const struct DefinitionData &data() const {
317133819Stjr    assert(DefinitionData && "queried property of class with no definition");
318133819Stjr    return *DefinitionData;
319133819Stjr  }
320133819Stjr
321133819Stjr  /// \brief The template or declaration that this declaration
322133819Stjr  /// describes or was instantiated from, respectively.
323133819Stjr  ///
324133819Stjr  /// For non-templates, this value will be NULL. For record
325133819Stjr  /// declarations that describe a class template, this will be a
326133819Stjr  /// pointer to a ClassTemplateDecl. For member
327133819Stjr  /// classes of class template specializations, this will be the
328133819Stjr  /// MemberSpecializationInfo referring to the member class that was
329133819Stjr  /// instantiated or specialized.
330133819Stjr  llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*>
331133819Stjr    TemplateOrInstantiation;
332133819Stjr
333133819Stjr#ifndef NDEBUG
334133819Stjr  void CheckConversionFunction(NamedDecl *D);
335133819Stjr#endif
336133819Stjr
337133819Stjrprotected:
338133819Stjr  CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
339133819Stjr                SourceLocation L, IdentifierInfo *Id,
340133819Stjr                CXXRecordDecl *PrevDecl,
341133819Stjr                SourceLocation TKL = SourceLocation());
342133819Stjr
343133819Stjr  ~CXXRecordDecl();
344133819Stjr
345133819Stjrpublic:
346133819Stjr  /// base_class_iterator - Iterator that traverses the base classes
347133819Stjr  /// of a class.
348133819Stjr  typedef CXXBaseSpecifier*       base_class_iterator;
349133819Stjr
350133819Stjr  /// base_class_const_iterator - Iterator that traverses the base
351133819Stjr  /// classes of a class.
352133819Stjr  typedef const CXXBaseSpecifier* base_class_const_iterator;
353133819Stjr
354133819Stjr  /// reverse_base_class_iterator = Iterator that traverses the base classes
355133819Stjr  /// of a class in reverse order.
356133819Stjr  typedef std::reverse_iterator<base_class_iterator>
357133819Stjr    reverse_base_class_iterator;
358133819Stjr
359133819Stjr  /// reverse_base_class_iterator = Iterator that traverses the base classes
360133819Stjr  /// of a class in reverse order.
361133819Stjr  typedef std::reverse_iterator<base_class_const_iterator>
362133819Stjr    reverse_base_class_const_iterator;
363133819Stjr
364133819Stjr  virtual CXXRecordDecl *getCanonicalDecl() {
365133819Stjr    return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
366133819Stjr  }
367133819Stjr  virtual const CXXRecordDecl *getCanonicalDecl() const {
368133819Stjr    return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
369133819Stjr  }
370133819Stjr
371133819Stjr  CXXRecordDecl *getDefinition() const {
372133819Stjr    if (!DefinitionData) return 0;
373133819Stjr    return data().Definition;
374133819Stjr  }
375133819Stjr
376133819Stjr  bool hasDefinition() const { return DefinitionData != 0; }
377133819Stjr
378133819Stjr  static CXXRecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC,
379133819Stjr                               SourceLocation L, IdentifierInfo *Id,
380133819Stjr                               SourceLocation TKL = SourceLocation(),
381133819Stjr                               CXXRecordDecl* PrevDecl=0,
382133819Stjr                               bool DelayTypeCreation = false);
383133819Stjr
384133819Stjr  virtual void Destroy(ASTContext& C);
385133819Stjr
386133819Stjr  bool isDynamicClass() const {
387133819Stjr    return data().Polymorphic || data().NumVBases != 0;
388133819Stjr  }
389133819Stjr
390133819Stjr  /// setBases - Sets the base classes of this struct or class.
391133819Stjr  void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
392133819Stjr
393133819Stjr  /// getNumBases - Retrieves the number of base classes of this
394133819Stjr  /// class.
395133819Stjr  unsigned getNumBases() const { return data().NumBases; }
396133819Stjr
397133819Stjr  base_class_iterator bases_begin() { return data().Bases; }
398133819Stjr  base_class_const_iterator bases_begin() const { return data().Bases; }
399133819Stjr  base_class_iterator bases_end() { return bases_begin() + data().NumBases; }
400133819Stjr  base_class_const_iterator bases_end() const {
401133819Stjr    return bases_begin() + data().NumBases;
402133819Stjr  }
403133819Stjr  reverse_base_class_iterator       bases_rbegin() {
404133819Stjr    return reverse_base_class_iterator(bases_end());
405133819Stjr  }
406133819Stjr  reverse_base_class_const_iterator bases_rbegin() const {
407133819Stjr    return reverse_base_class_const_iterator(bases_end());
408133819Stjr  }
409133819Stjr  reverse_base_class_iterator bases_rend() {
410133819Stjr    return reverse_base_class_iterator(bases_begin());
411133819Stjr  }
412133819Stjr  reverse_base_class_const_iterator bases_rend() const {
413133819Stjr    return reverse_base_class_const_iterator(bases_begin());
414133819Stjr  }
415133819Stjr
416133819Stjr  /// getNumVBases - Retrieves the number of virtual base classes of this
417133819Stjr  /// class.
418133819Stjr  unsigned getNumVBases() const { return data().NumVBases; }
419133819Stjr
420133819Stjr  base_class_iterator vbases_begin() { return data().VBases; }
421133819Stjr  base_class_const_iterator vbases_begin() const { return data().VBases; }
422133819Stjr  base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; }
423133819Stjr  base_class_const_iterator vbases_end() const {
424133819Stjr    return vbases_begin() + data().NumVBases;
425133819Stjr  }
426133819Stjr  reverse_base_class_iterator vbases_rbegin() {
427133819Stjr    return reverse_base_class_iterator(vbases_end());
428133819Stjr  }
429133819Stjr  reverse_base_class_const_iterator vbases_rbegin() const {
430133819Stjr    return reverse_base_class_const_iterator(vbases_end());
431133819Stjr  }
432133819Stjr  reverse_base_class_iterator vbases_rend() {
433133819Stjr    return reverse_base_class_iterator(vbases_begin());
434133819Stjr  }
435133819Stjr  reverse_base_class_const_iterator vbases_rend() const {
436133819Stjr    return reverse_base_class_const_iterator(vbases_begin());
437133819Stjr }
438133819Stjr
439133819Stjr  /// \brief Determine whether this class has any dependent base classes.
440133819Stjr  bool hasAnyDependentBases() const;
441133819Stjr
442133819Stjr  /// Iterator access to method members.  The method iterator visits
443133819Stjr  /// all method members of the class, including non-instance methods,
444133819Stjr  /// special methods, etc.
445133819Stjr  typedef specific_decl_iterator<CXXMethodDecl> method_iterator;
446133819Stjr
447133819Stjr  /// method_begin - Method begin iterator.  Iterates in the order the methods
448133819Stjr  /// were declared.
449133819Stjr  method_iterator method_begin() const {
450133819Stjr    return method_iterator(decls_begin());
451133819Stjr  }
452133819Stjr  /// method_end - Method end iterator.
453133819Stjr  method_iterator method_end() const {
454133819Stjr    return method_iterator(decls_end());
455133819Stjr  }
456133819Stjr
457133819Stjr  /// Iterator access to constructor members.
458133819Stjr  typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator;
459133819Stjr
460133819Stjr  ctor_iterator ctor_begin() const {
461133819Stjr    return ctor_iterator(decls_begin());
462133819Stjr  }
463133819Stjr  ctor_iterator ctor_end() const {
464133819Stjr    return ctor_iterator(decls_end());
465133819Stjr  }
466133819Stjr
467133819Stjr  /// An iterator over friend declarations.  All of these are defined
468133819Stjr  /// in DeclFriend.h.
469133819Stjr  class friend_iterator;
470133819Stjr  friend_iterator friend_begin() const;
471133819Stjr  friend_iterator friend_end() const;
472133819Stjr  void pushFriendDecl(FriendDecl *FD);
473133819Stjr
474133819Stjr  /// hasConstCopyConstructor - Determines whether this class has a
475133819Stjr  /// copy constructor that accepts a const-qualified argument.
476133819Stjr  bool hasConstCopyConstructor(ASTContext &Context) const;
477133819Stjr
478133819Stjr  /// getCopyConstructor - Returns the copy constructor for this class
479133819Stjr  CXXConstructorDecl *getCopyConstructor(ASTContext &Context,
480133819Stjr                                         unsigned TypeQuals) const;
481133819Stjr
482133819Stjr  /// hasConstCopyAssignment - Determines whether this class has a
483133819Stjr  /// copy assignment operator that accepts a const-qualified argument.
484133819Stjr  /// It returns its decl in MD if found.
485133819Stjr  bool hasConstCopyAssignment(ASTContext &Context,
486133819Stjr                              const CXXMethodDecl *&MD) const;
487133819Stjr
488133819Stjr  /// addedConstructor - Notify the class that another constructor has
489133819Stjr  /// been added. This routine helps maintain information about the
490133819Stjr  /// class based on which constructors have been added.
491133819Stjr  void addedConstructor(ASTContext &Context, CXXConstructorDecl *ConDecl);
492133819Stjr
493133819Stjr  /// hasUserDeclaredConstructor - Whether this class has any
494133819Stjr  /// user-declared constructors. When true, a default constructor
495133819Stjr  /// will not be implicitly declared.
496133819Stjr  bool hasUserDeclaredConstructor() const {
497133819Stjr    return data().UserDeclaredConstructor;
498133819Stjr  }
499133819Stjr
500133819Stjr  /// hasUserDeclaredCopyConstructor - Whether this class has a
501133819Stjr  /// user-declared copy constructor. When false, a copy constructor
502133819Stjr  /// will be implicitly declared.
503133819Stjr  bool hasUserDeclaredCopyConstructor() const {
504133819Stjr    return data().UserDeclaredCopyConstructor;
505133819Stjr  }
506133819Stjr
507133819Stjr  /// addedAssignmentOperator - Notify the class that another assignment
508133819Stjr  /// operator has been added. This routine helps maintain information about the
509133819Stjr   /// class based on which operators have been added.
510133819Stjr  void addedAssignmentOperator(ASTContext &Context, CXXMethodDecl *OpDecl);
511133819Stjr
512133819Stjr  /// hasUserDeclaredCopyAssignment - Whether this class has a
513133819Stjr  /// user-declared copy assignment operator. When false, a copy
514133819Stjr  /// assigment operator will be implicitly declared.
515133819Stjr  bool hasUserDeclaredCopyAssignment() const {
516133819Stjr    return data().UserDeclaredCopyAssignment;
517133819Stjr  }
518133819Stjr
519133819Stjr  /// hasUserDeclaredDestructor - Whether this class has a
520133819Stjr  /// user-declared destructor. When false, a destructor will be
521133819Stjr  /// implicitly declared.
522133819Stjr  bool hasUserDeclaredDestructor() const {
523133819Stjr    return data().UserDeclaredDestructor;
524133819Stjr  }
525133819Stjr
526133819Stjr  /// setUserDeclaredDestructor - Set whether this class has a
527133819Stjr  /// user-declared destructor. If not set by the time the class is
528133819Stjr  /// fully defined, a destructor will be implicitly declared.
529133819Stjr  void setUserDeclaredDestructor(bool UCD) {
530133819Stjr    data().UserDeclaredDestructor = UCD;
531133819Stjr  }
532133819Stjr
533133819Stjr  /// getConversions - Retrieve the overload set containing all of the
534133819Stjr  /// conversion functions in this class.
535133819Stjr  UnresolvedSetImpl *getConversionFunctions() {
536133819Stjr    return &data().Conversions;
537133819Stjr  }
538133819Stjr  const UnresolvedSetImpl *getConversionFunctions() const {
539133819Stjr    return &data().Conversions;
540133819Stjr  }
541133819Stjr
542133819Stjr  typedef UnresolvedSetImpl::iterator conversion_iterator;
543133819Stjr  conversion_iterator conversion_begin() const {
544133819Stjr    return getConversionFunctions()->begin();
545133819Stjr  }
546133819Stjr  conversion_iterator conversion_end() const {
547133819Stjr    return getConversionFunctions()->end();
548133819Stjr  }
549133819Stjr
550133819Stjr  /// Replaces a conversion function with a new declaration.
551133819Stjr  ///
552133819Stjr  /// Returns true if the old conversion was found.
553133819Stjr  bool replaceConversion(const NamedDecl* Old, NamedDecl *New) {
554133819Stjr    return getConversionFunctions()->replace(Old, New);
555133819Stjr  }
556133819Stjr
557133819Stjr  /// Removes a conversion function from this class.  The conversion
558133819Stjr  /// function must currently be a member of this class.  Furthermore,
559133819Stjr  /// this class must currently be in the process of being defined.
560133819Stjr  void removeConversion(const NamedDecl *Old);
561133819Stjr
562133819Stjr  /// getVisibleConversionFunctions - get all conversion functions visible
563133819Stjr  /// in current class; including conversion function templates.
564133819Stjr  const UnresolvedSetImpl *getVisibleConversionFunctions();
565133819Stjr
566133819Stjr  /// addConversionFunction - Registers a conversion function which
567133819Stjr  /// this class declares directly.
568133819Stjr  void addConversionFunction(NamedDecl *Decl) {
569133819Stjr#ifndef NDEBUG
570133819Stjr    CheckConversionFunction(Decl);
571133819Stjr#endif
572133819Stjr
573133819Stjr    // We intentionally don't use the decl's access here because it
574133819Stjr    // hasn't been set yet.  That's really just a misdesign in Sema.
575133819Stjr    data().Conversions.addDecl(Decl);
576133819Stjr  }
577133819Stjr
578133819Stjr  /// isAggregate - Whether this class is an aggregate (C++
579133819Stjr  /// [dcl.init.aggr]), which is a class with no user-declared
580133819Stjr  /// constructors, no private or protected non-static data members,
581133819Stjr  /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1).
582133819Stjr  bool isAggregate() const { return data().Aggregate; }
583133819Stjr
584133819Stjr  /// setAggregate - Set whether this class is an aggregate (C++
585133819Stjr  /// [dcl.init.aggr]).
586133819Stjr  void setAggregate(bool Agg) { data().Aggregate = Agg; }
587133819Stjr
588133819Stjr  /// setMethodAsVirtual - Make input method virtual and set the necesssary
589133819Stjr  /// special function bits and other bits accordingly.
590133819Stjr  void setMethodAsVirtual(FunctionDecl *Method);
591133819Stjr
592133819Stjr  /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class
593133819Stjr  /// that is an aggregate that has no non-static non-POD data members, no
594133819Stjr  /// reference data members, no user-defined copy assignment operator and no
595133819Stjr  /// user-defined destructor.
596133819Stjr  bool isPOD() const { return data().PlainOldData; }
597133819Stjr
598133819Stjr  /// setPOD - Set whether this class is a POD-type (C++ [class]p4).
599133819Stjr  void setPOD(bool POD) { data().PlainOldData = POD; }
600133819Stjr
601133819Stjr  /// isEmpty - Whether this class is empty (C++0x [meta.unary.prop]), which
602133819Stjr  /// means it has a virtual function, virtual base, data member (other than
603133819Stjr  /// 0-width bit-field) or inherits from a non-empty class. Does NOT include
604133819Stjr  /// a check for union-ness.
605133819Stjr  bool isEmpty() const { return data().Empty; }
606133819Stjr
607133819Stjr  /// Set whether this class is empty (C++0x [meta.unary.prop])
608133819Stjr  void setEmpty(bool Emp) { data().Empty = Emp; }
609133819Stjr
610133819Stjr  /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]),
611133819Stjr  /// which means that the class contains or inherits a virtual function.
612133819Stjr  bool isPolymorphic() const { return data().Polymorphic; }
613133819Stjr
614133819Stjr  /// setPolymorphic - Set whether this class is polymorphic (C++
615133819Stjr  /// [class.virtual]).
616133819Stjr  void setPolymorphic(bool Poly) { data().Polymorphic = Poly; }
617133819Stjr
618133819Stjr  /// isAbstract - Whether this class is abstract (C++ [class.abstract]),
619133819Stjr  /// which means that the class contains or inherits a pure virtual function.
620133819Stjr  bool isAbstract() const { return data().Abstract; }
621133819Stjr
622133819Stjr  /// setAbstract - Set whether this class is abstract (C++ [class.abstract])
623133819Stjr  void setAbstract(bool Abs) { data().Abstract = Abs; }
624133819Stjr
625133819Stjr  // hasTrivialConstructor - Whether this class has a trivial constructor
626133819Stjr  // (C++ [class.ctor]p5)
627133819Stjr  bool hasTrivialConstructor() const { return data().HasTrivialConstructor; }
628133819Stjr
629133819Stjr  // setHasTrivialConstructor - Set whether this class has a trivial constructor
630133819Stjr  // (C++ [class.ctor]p5)
631133819Stjr  void setHasTrivialConstructor(bool TC) { data().HasTrivialConstructor = TC; }
632133819Stjr
633133819Stjr  // hasTrivialCopyConstructor - Whether this class has a trivial copy
634133819Stjr  // constructor (C++ [class.copy]p6)
635133819Stjr  bool hasTrivialCopyConstructor() const {
636133819Stjr    return data().HasTrivialCopyConstructor;
637133819Stjr  }
638133819Stjr
639133819Stjr  // setHasTrivialCopyConstructor - Set whether this class has a trivial
640133819Stjr  // copy constructor (C++ [class.copy]p6)
641133819Stjr  void setHasTrivialCopyConstructor(bool TC) {
642133819Stjr    data().HasTrivialCopyConstructor = TC;
643133819Stjr  }
644133819Stjr
645133819Stjr  // hasTrivialCopyAssignment - Whether this class has a trivial copy
646133819Stjr  // assignment operator (C++ [class.copy]p11)
647133819Stjr  bool hasTrivialCopyAssignment() const {
648133819Stjr    return data().HasTrivialCopyAssignment;
649133819Stjr  }
650133819Stjr
651133819Stjr  // setHasTrivialCopyAssignment - Set whether this class has a
652133819Stjr  // trivial copy assignment operator (C++ [class.copy]p11)
653133819Stjr  void setHasTrivialCopyAssignment(bool TC) {
654133819Stjr    data().HasTrivialCopyAssignment = TC;
655133819Stjr  }
656133819Stjr
657133819Stjr  // hasTrivialDestructor - Whether this class has a trivial destructor
658133819Stjr  // (C++ [class.dtor]p3)
659133819Stjr  bool hasTrivialDestructor() const { return data().HasTrivialDestructor; }
660133819Stjr
661133819Stjr  // setHasTrivialDestructor - Set whether this class has a trivial destructor
662133819Stjr  // (C++ [class.dtor]p3)
663133819Stjr  void setHasTrivialDestructor(bool TC) { data().HasTrivialDestructor = TC; }
664133819Stjr
665133819Stjr  /// \brief If this record is an instantiation of a member class,
666133819Stjr  /// retrieves the member class from which it was instantiated.
667133819Stjr  ///
668133819Stjr  /// This routine will return non-NULL for (non-templated) member
669133819Stjr  /// classes of class templates. For example, given:
670133819Stjr  ///
671133819Stjr  /// \code
672133819Stjr  /// template<typename T>
673133819Stjr  /// struct X {
674133819Stjr  ///   struct A { };
675133819Stjr  /// };
676133819Stjr  /// \endcode
677133819Stjr  ///
678133819Stjr  /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
679133819Stjr  /// whose parent is the class template specialization X<int>. For
680133819Stjr  /// this declaration, getInstantiatedFromMemberClass() will return
681133819Stjr  /// the CXXRecordDecl X<T>::A. When a complete definition of
682133819Stjr  /// X<int>::A is required, it will be instantiated from the
683133819Stjr  /// declaration returned by getInstantiatedFromMemberClass().
684133819Stjr  CXXRecordDecl *getInstantiatedFromMemberClass() const;
685133819Stjr
686133819Stjr  /// \brief If this class is an instantiation of a member class of a
687133819Stjr  /// class template specialization, retrieves the member specialization
688133819Stjr  /// information.
689133819Stjr  MemberSpecializationInfo *getMemberSpecializationInfo() const;
690133819Stjr
691133819Stjr  /// \brief Specify that this record is an instantiation of the
692133819Stjr  /// member class RD.
693133819Stjr  void setInstantiationOfMemberClass(CXXRecordDecl *RD,
694133819Stjr                                     TemplateSpecializationKind TSK);
695133819Stjr
696133819Stjr  /// \brief Retrieves the class template that is described by this
697133819Stjr  /// class declaration.
698133819Stjr  ///
699133819Stjr  /// Every class template is represented as a ClassTemplateDecl and a
700133819Stjr  /// CXXRecordDecl. The former contains template properties (such as
701133819Stjr  /// the template parameter lists) while the latter contains the
702133819Stjr  /// actual description of the template's
703133819Stjr  /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
704133819Stjr  /// CXXRecordDecl that from a ClassTemplateDecl, while
705143198Ssobomax  /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
706133819Stjr  /// a CXXRecordDecl.
707133819Stjr  ClassTemplateDecl *getDescribedClassTemplate() const {
708133819Stjr    return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>();
709133819Stjr  }
710133819Stjr
711133819Stjr  void setDescribedClassTemplate(ClassTemplateDecl *Template) {
712133819Stjr    TemplateOrInstantiation = Template;
713133819Stjr  }
714133819Stjr
715133819Stjr  /// \brief Determine whether this particular class is a specialization or
716133819Stjr  /// instantiation of a class template or member class of a class template,
717133819Stjr  /// and how it was instantiated or specialized.
718133819Stjr  TemplateSpecializationKind getTemplateSpecializationKind() const;
719133819Stjr
720133819Stjr  /// \brief Set the kind of specialization or template instantiation this is.
721133819Stjr  void setTemplateSpecializationKind(TemplateSpecializationKind TSK);
722133819Stjr
723133819Stjr  /// getDefaultConstructor - Returns the default constructor for this class
724133819Stjr  CXXConstructorDecl *getDefaultConstructor(ASTContext &Context);
725133819Stjr
726133819Stjr  /// getDestructor - Returns the destructor decl for this class.
727133819Stjr  CXXDestructorDecl *getDestructor(ASTContext &Context) const;
728133819Stjr
729133819Stjr  /// isLocalClass - If the class is a local class [class.local], returns
730133819Stjr  /// the enclosing function declaration.
731133819Stjr  const FunctionDecl *isLocalClass() const {
732133819Stjr    if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
733133819Stjr      return RD->isLocalClass();
734133819Stjr
735133819Stjr    return dyn_cast<FunctionDecl>(getDeclContext());
736133819Stjr  }
737133819Stjr
738133819Stjr  /// \brief Determine whether this class is derived from the class \p Base.
739133819Stjr  ///
740133819Stjr  /// This routine only determines whether this class is derived from \p Base,
741133819Stjr  /// but does not account for factors that may make a Derived -> Base class
742133819Stjr  /// ill-formed, such as private/protected inheritance or multiple, ambiguous
743133819Stjr  /// base class subobjects.
744133819Stjr  ///
745133819Stjr  /// \param Base the base class we are searching for.
746133819Stjr  ///
747133819Stjr  /// \returns true if this class is derived from Base, false otherwise.
748133819Stjr  bool isDerivedFrom(CXXRecordDecl *Base) const;
749133819Stjr
750133819Stjr  /// \brief Determine whether this class is derived from the type \p Base.
751133819Stjr  ///
752133819Stjr  /// This routine only determines whether this class is derived from \p Base,
753133819Stjr  /// but does not account for factors that may make a Derived -> Base class
754133819Stjr  /// ill-formed, such as private/protected inheritance or multiple, ambiguous
755156843Snetchild  /// base class subobjects.
756133819Stjr  ///
757133819Stjr  /// \param Base the base class we are searching for.
758133819Stjr  ///
759133819Stjr  /// \param Paths will contain the paths taken from the current class to the
760133819Stjr  /// given \p Base class.
761133819Stjr  ///
762133819Stjr  /// \returns true if this class is derived from Base, false otherwise.
763133819Stjr  ///
764133819Stjr  /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than
765156843Snetchild  /// tangling input and output in \p Paths
766133819Stjr  bool isDerivedFrom(CXXRecordDecl *Base, CXXBasePaths &Paths) const;
767133819Stjr
768133819Stjr  /// \brief Determine whether this class is virtually derived from
769133819Stjr  /// the class \p Base.
770133819Stjr  ///
771156843Snetchild  /// This routine only determines whether this class is virtually
772147142Ssobomax  /// derived from \p Base, but does not account for factors that may
773133819Stjr  /// make a Derived -> Base class ill-formed, such as
774133819Stjr  /// private/protected inheritance or multiple, ambiguous base class
775133819Stjr  /// subobjects.
776133819Stjr  ///
777133819Stjr  /// \param Base the base class we are searching for.
778133819Stjr  ///
779133819Stjr  /// \returns true if this class is virtually derived from Base,
780133819Stjr  /// false otherwise.
781133819Stjr  bool isVirtuallyDerivedFrom(CXXRecordDecl *Base) const;
782133819Stjr
783133819Stjr  /// \brief Determine whether this class is provably not derived from
784133819Stjr  /// the type \p Base.
785133819Stjr  bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
786133819Stjr
787133819Stjr  /// \brief Function type used by forallBases() as a callback.
788133819Stjr  ///
789133819Stjr  /// \param Base the definition of the base class
790133819Stjr  ///
791133819Stjr  /// \returns true if this base matched the search criteria
792133819Stjr  typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition,
793133819Stjr                                   void *UserData);
794133819Stjr
795133819Stjr  /// \brief Determines if the given callback holds for all the direct
796133819Stjr  /// or indirect base classes of this type.
797133819Stjr  ///
798133819Stjr  /// The class itself does not count as a base class.  This routine
799133819Stjr  /// returns false if the class has non-computable base classes.
800133819Stjr  ///
801133819Stjr  /// \param AllowShortCircuit if false, forces the callback to be called
802133819Stjr  /// for every base class, even if a dependent or non-matching base was
803133819Stjr  /// found.
804133819Stjr  bool forallBases(ForallBasesCallback *BaseMatches, void *UserData,
805133819Stjr                   bool AllowShortCircuit = true) const;
806133819Stjr
807133819Stjr  /// \brief Function type used by lookupInBases() to determine whether a
808133819Stjr  /// specific base class subobject matches the lookup criteria.
809133819Stjr  ///
810133819Stjr  /// \param Specifier the base-class specifier that describes the inheritance
811133819Stjr  /// from the base class we are trying to match.
812133819Stjr  ///
813133819Stjr  /// \param Path the current path, from the most-derived class down to the
814133819Stjr  /// base named by the \p Specifier.
815133819Stjr  ///
816133819Stjr  /// \param UserData a single pointer to user-specified data, provided to
817133819Stjr  /// lookupInBases().
818133819Stjr  ///
819133819Stjr  /// \returns true if this base matched the search criteria, false otherwise.
820133819Stjr  typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier,
821133819Stjr                                   CXXBasePath &Path,
822133819Stjr                                   void *UserData);
823133819Stjr
824133819Stjr  /// \brief Look for entities within the base classes of this C++ class,
825133819Stjr  /// transitively searching all base class subobjects.
826133819Stjr  ///
827133819Stjr  /// This routine uses the callback function \p BaseMatches to find base
828133819Stjr  /// classes meeting some search criteria, walking all base class subobjects
829133819Stjr  /// and populating the given \p Paths structure with the paths through the
830133819Stjr  /// inheritance hierarchy that resulted in a match. On a successful search,
831133819Stjr  /// the \p Paths structure can be queried to retrieve the matching paths and
832133819Stjr  /// to determine if there were any ambiguities.
833133819Stjr  ///
834133819Stjr  /// \param BaseMatches callback function used to determine whether a given
835133819Stjr  /// base matches the user-defined search criteria.
836133819Stjr  ///
837133819Stjr  /// \param UserData user data pointer that will be provided to \p BaseMatches.
838133819Stjr  ///
839133819Stjr  /// \param Paths used to record the paths from this class to its base class
840133819Stjr  /// subobjects that match the search criteria.
841133819Stjr  ///
842133819Stjr  /// \returns true if there exists any path from this class to a base class
843133819Stjr  /// subobject that matches the search criteria.
844133819Stjr  bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData,
845133819Stjr                     CXXBasePaths &Paths) const;
846133819Stjr
847133819Stjr  /// \brief Base-class lookup callback that determines whether the given
848133819Stjr  /// base class specifier refers to a specific class declaration.
849133819Stjr  ///
850133819Stjr  /// This callback can be used with \c lookupInBases() to determine whether
851133819Stjr  /// a given derived class has is a base class subobject of a particular type.
852133819Stjr  /// The user data pointer should refer to the canonical CXXRecordDecl of the
853133819Stjr  /// base class that we are searching for.
854133819Stjr  static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
855133819Stjr                            CXXBasePath &Path, void *BaseRecord);
856133819Stjr
857133819Stjr  /// \brief Base-class lookup callback that determines whether the
858133819Stjr  /// given base class specifier refers to a specific class
859133819Stjr  /// declaration and describes virtual derivation.
860133819Stjr  ///
861133819Stjr  /// This callback can be used with \c lookupInBases() to determine
862133819Stjr  /// whether a given derived class has is a virtual base class
863133819Stjr  /// subobject of a particular type.  The user data pointer should
864133819Stjr  /// refer to the canonical CXXRecordDecl of the base class that we
865133819Stjr  /// are searching for.
866133819Stjr  static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
867133819Stjr                                   CXXBasePath &Path, void *BaseRecord);
868133819Stjr
869133819Stjr  /// \brief Base-class lookup callback that determines whether there exists
870133819Stjr  /// a tag with the given name.
871133819Stjr  ///
872133819Stjr  /// This callback can be used with \c lookupInBases() to find tag members
873133819Stjr  /// of the given name within a C++ class hierarchy. The user data pointer
874133819Stjr  /// is an opaque \c DeclarationName pointer.
875133819Stjr  static bool FindTagMember(const CXXBaseSpecifier *Specifier,
876133819Stjr                            CXXBasePath &Path, void *Name);
877133819Stjr
878143198Ssobomax  /// \brief Base-class lookup callback that determines whether there exists
879133819Stjr  /// a member with the given name.
880133819Stjr  ///
881133819Stjr  /// This callback can be used with \c lookupInBases() to find members
882133819Stjr  /// of the given name within a C++ class hierarchy. The user data pointer
883133819Stjr  /// is an opaque \c DeclarationName pointer.
884133819Stjr  static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
885143198Ssobomax                                 CXXBasePath &Path, void *Name);
886133819Stjr
887133819Stjr  /// \brief Base-class lookup callback that determines whether there exists
888133819Stjr  /// a member with the given name that can be used in a nested-name-specifier.
889133819Stjr  ///
890133819Stjr  /// This callback can be used with \c lookupInBases() to find membes of
891133819Stjr  /// the given name within a C++ class hierarchy that can occur within
892133819Stjr  /// nested-name-specifiers.
893133819Stjr  static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier,
894                                            CXXBasePath &Path,
895                                            void *UserData);
896
897  /// \brief Retrieve the final overriders for each virtual member
898  /// function in the class hierarchy where this class is the
899  /// most-derived class in the class hierarchy.
900  void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const;
901
902  /// viewInheritance - Renders and displays an inheritance diagram
903  /// for this C++ class and all of its base classes (transitively) using
904  /// GraphViz.
905  void viewInheritance(ASTContext& Context) const;
906
907  /// MergeAccess - Calculates the access of a decl that is reached
908  /// along a path.
909  static AccessSpecifier MergeAccess(AccessSpecifier PathAccess,
910                                     AccessSpecifier DeclAccess) {
911    assert(DeclAccess != AS_none);
912    if (DeclAccess == AS_private) return AS_none;
913    return (PathAccess > DeclAccess ? PathAccess : DeclAccess);
914  }
915
916  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
917  static bool classofKind(Kind K) {
918    return K == CXXRecord ||
919           K == ClassTemplateSpecialization ||
920           K == ClassTemplatePartialSpecialization;
921  }
922  static bool classof(const CXXRecordDecl *D) { return true; }
923  static bool classof(const ClassTemplateSpecializationDecl *D) {
924    return true;
925  }
926};
927
928/// CXXMethodDecl - Represents a static or instance method of a
929/// struct/union/class.
930class CXXMethodDecl : public FunctionDecl {
931protected:
932  CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation L,
933                DeclarationName N, QualType T, TypeSourceInfo *TInfo,
934                bool isStatic, bool isInline)
935    : FunctionDecl(DK, RD, L, N, T, TInfo, (isStatic ? Static : None),
936                   isInline) {}
937
938public:
939  static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
940                              SourceLocation L, DeclarationName N,
941                              QualType T, TypeSourceInfo *TInfo,
942                              bool isStatic = false,
943                              bool isInline = false);
944
945  bool isStatic() const { return getStorageClass() == Static; }
946  bool isInstance() const { return !isStatic(); }
947
948  bool isVirtual() const {
949    CXXMethodDecl *CD =
950      cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl());
951
952    if (CD->isVirtualAsWritten())
953      return true;
954
955    return (CD->begin_overridden_methods() != CD->end_overridden_methods());
956  }
957
958  /// \brief Determine whether this is a usual deallocation function
959  /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded
960  /// delete or delete[] operator with a particular signature.
961  bool isUsualDeallocationFunction() const;
962
963  const CXXMethodDecl *getCanonicalDecl() const {
964    return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
965  }
966  CXXMethodDecl *getCanonicalDecl() {
967    return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
968  }
969
970  ///
971  void addOverriddenMethod(const CXXMethodDecl *MD);
972
973  typedef const CXXMethodDecl ** method_iterator;
974
975  method_iterator begin_overridden_methods() const;
976  method_iterator end_overridden_methods() const;
977
978  /// getParent - Returns the parent of this method declaration, which
979  /// is the class in which this method is defined.
980  const CXXRecordDecl *getParent() const {
981    return cast<CXXRecordDecl>(FunctionDecl::getParent());
982  }
983
984  /// getParent - Returns the parent of this method declaration, which
985  /// is the class in which this method is defined.
986  CXXRecordDecl *getParent() {
987    return const_cast<CXXRecordDecl *>(
988             cast<CXXRecordDecl>(FunctionDecl::getParent()));
989  }
990
991  /// getThisType - Returns the type of 'this' pointer.
992  /// Should only be called for instance methods.
993  QualType getThisType(ASTContext &C) const;
994
995  unsigned getTypeQualifiers() const {
996    return getType()->getAs<FunctionProtoType>()->getTypeQuals();
997  }
998
999  bool hasInlineBody() const;
1000
1001  // Implement isa/cast/dyncast/etc.
1002  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1003  static bool classof(const CXXMethodDecl *D) { return true; }
1004  static bool classofKind(Kind K) {
1005    return K >= CXXMethod && K <= CXXConversion;
1006  }
1007};
1008
1009/// CXXBaseOrMemberInitializer - Represents a C++ base or member
1010/// initializer, which is part of a constructor initializer that
1011/// initializes one non-static member variable or one base class. For
1012/// example, in the following, both 'A(a)' and 'f(3.14159)' are member
1013/// initializers:
1014///
1015/// @code
1016/// class A { };
1017/// class B : public A {
1018///   float f;
1019/// public:
1020///   B(A& a) : A(a), f(3.14159) { }
1021/// };
1022/// @endcode
1023class CXXBaseOrMemberInitializer {
1024  /// \brief Either the base class name (stored as a TypeSourceInfo*) or the
1025  /// field being initialized.
1026  llvm::PointerUnion<TypeSourceInfo *, FieldDecl *> BaseOrMember;
1027
1028  /// \brief The source location for the field name.
1029  SourceLocation MemberLocation;
1030
1031  /// \brief The argument used to initialize the base or member, which may
1032  /// end up constructing an object (when multiple arguments are involved).
1033  Stmt *Init;
1034
1035  /// \brief Stores either the constructor to call to initialize this base or
1036  /// member (a CXXConstructorDecl pointer), or stores the anonymous union of
1037  /// which the initialized value is a member.
1038  ///
1039  /// When the value is a FieldDecl pointer, 'BaseOrMember' is class's
1040  /// anonymous union data member, this field holds the FieldDecl for the
1041  /// member of the anonymous union being initialized.
1042  /// @code
1043  /// struct X {
1044  ///   X() : au_i1(123) {}
1045  ///   union {
1046  ///     int au_i1;
1047  ///     float au_f1;
1048  ///   };
1049  /// };
1050  /// @endcode
1051  /// In above example, BaseOrMember holds the field decl. for anonymous union
1052  /// and AnonUnionMember holds field decl for au_i1.
1053  FieldDecl *AnonUnionMember;
1054
1055  /// LParenLoc - Location of the left paren of the ctor-initializer.
1056  SourceLocation LParenLoc;
1057
1058  /// RParenLoc - Location of the right paren of the ctor-initializer.
1059  SourceLocation RParenLoc;
1060
1061public:
1062  /// CXXBaseOrMemberInitializer - Creates a new base-class initializer.
1063  explicit
1064  CXXBaseOrMemberInitializer(ASTContext &Context,
1065                             TypeSourceInfo *TInfo,
1066                             SourceLocation L,
1067                             Expr *Init,
1068                             SourceLocation R);
1069
1070  /// CXXBaseOrMemberInitializer - Creates a new member initializer.
1071  explicit
1072  CXXBaseOrMemberInitializer(ASTContext &Context,
1073                             FieldDecl *Member, SourceLocation MemberLoc,
1074                             SourceLocation L,
1075                             Expr *Init,
1076                             SourceLocation R);
1077
1078  /// \brief Destroy the base or member initializer.
1079  void Destroy(ASTContext &Context);
1080
1081  /// isBaseInitializer - Returns true when this initializer is
1082  /// initializing a base class.
1083  bool isBaseInitializer() const { return BaseOrMember.is<TypeSourceInfo*>(); }
1084
1085  /// isMemberInitializer - Returns true when this initializer is
1086  /// initializing a non-static data member.
1087  bool isMemberInitializer() const { return BaseOrMember.is<FieldDecl*>(); }
1088
1089  /// If this is a base class initializer, returns the type of the
1090  /// base class with location information. Otherwise, returns an NULL
1091  /// type location.
1092  TypeLoc getBaseClassLoc() const;
1093
1094  /// If this is a base class initializer, returns the type of the base class.
1095  /// Otherwise, returns NULL.
1096  const Type *getBaseClass() const;
1097  Type *getBaseClass();
1098
1099  /// \brief Returns the declarator information for a base class initializer.
1100  TypeSourceInfo *getBaseClassInfo() const {
1101    return BaseOrMember.dyn_cast<TypeSourceInfo *>();
1102  }
1103
1104  /// getMember - If this is a member initializer, returns the
1105  /// declaration of the non-static data member being
1106  /// initialized. Otherwise, returns NULL.
1107  FieldDecl *getMember() {
1108    if (isMemberInitializer())
1109      return BaseOrMember.get<FieldDecl*>();
1110    else
1111      return 0;
1112  }
1113
1114  SourceLocation getMemberLocation() const {
1115    return MemberLocation;
1116  }
1117
1118  void setMember(FieldDecl *Member) {
1119    assert(isMemberInitializer());
1120    BaseOrMember = Member;
1121  }
1122
1123  /// \brief Determine the source location of the initializer.
1124  SourceLocation getSourceLocation() const;
1125
1126  /// \brief Determine the source range covering the entire initializer.
1127  SourceRange getSourceRange() const;
1128
1129  FieldDecl *getAnonUnionMember() const {
1130    return AnonUnionMember;
1131  }
1132  void setAnonUnionMember(FieldDecl *anonMember) {
1133    AnonUnionMember = anonMember;
1134  }
1135
1136  SourceLocation getLParenLoc() const { return LParenLoc; }
1137  SourceLocation getRParenLoc() const { return RParenLoc; }
1138
1139  Expr *getInit() { return static_cast<Expr *>(Init); }
1140};
1141
1142/// CXXConstructorDecl - Represents a C++ constructor within a
1143/// class. For example:
1144///
1145/// @code
1146/// class X {
1147/// public:
1148///   explicit X(int); // represented by a CXXConstructorDecl.
1149/// };
1150/// @endcode
1151class CXXConstructorDecl : public CXXMethodDecl {
1152  /// IsExplicitSpecified - Whether this constructor declaration has the
1153  /// 'explicit' keyword specified.
1154  bool IsExplicitSpecified : 1;
1155
1156  /// ImplicitlyDefined - Whether this constructor was implicitly
1157  /// defined by the compiler. When false, the constructor was defined
1158  /// by the user. In C++03, this flag will have the same value as
1159  /// Implicit. In C++0x, however, a constructor that is
1160  /// explicitly defaulted (i.e., defined with " = default") will have
1161  /// @c !Implicit && ImplicitlyDefined.
1162  bool ImplicitlyDefined : 1;
1163
1164  /// Support for base and member initializers.
1165  /// BaseOrMemberInitializers - The arguments used to initialize the base
1166  /// or member.
1167  CXXBaseOrMemberInitializer **BaseOrMemberInitializers;
1168  unsigned NumBaseOrMemberInitializers;
1169
1170  CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation L,
1171                     DeclarationName N, QualType T, TypeSourceInfo *TInfo,
1172                     bool isExplicitSpecified, bool isInline,
1173                     bool isImplicitlyDeclared)
1174    : CXXMethodDecl(CXXConstructor, RD, L, N, T, TInfo, false, isInline),
1175      IsExplicitSpecified(isExplicitSpecified), ImplicitlyDefined(false),
1176      BaseOrMemberInitializers(0), NumBaseOrMemberInitializers(0) {
1177    setImplicit(isImplicitlyDeclared);
1178  }
1179  virtual void Destroy(ASTContext& C);
1180
1181public:
1182  static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1183                                    SourceLocation L, DeclarationName N,
1184                                    QualType T, TypeSourceInfo *TInfo,
1185                                    bool isExplicit,
1186                                    bool isInline, bool isImplicitlyDeclared);
1187
1188  /// isExplicitSpecified - Whether this constructor declaration has the
1189  /// 'explicit' keyword specified.
1190  bool isExplicitSpecified() const { return IsExplicitSpecified; }
1191
1192  /// isExplicit - Whether this constructor was marked "explicit" or not.
1193  bool isExplicit() const {
1194    return cast<CXXConstructorDecl>(getFirstDeclaration())
1195      ->isExplicitSpecified();
1196  }
1197
1198  /// isImplicitlyDefined - Whether this constructor was implicitly
1199  /// defined. If false, then this constructor was defined by the
1200  /// user. This operation can only be invoked if the constructor has
1201  /// already been defined.
1202  bool isImplicitlyDefined(ASTContext &C) const {
1203    assert(isThisDeclarationADefinition() &&
1204           "Can only get the implicit-definition flag once the "
1205           "constructor has been defined");
1206    return ImplicitlyDefined;
1207  }
1208
1209  /// setImplicitlyDefined - Set whether this constructor was
1210  /// implicitly defined or not.
1211  void setImplicitlyDefined(bool ID) {
1212    assert(isThisDeclarationADefinition() &&
1213           "Can only set the implicit-definition flag once the constructor "
1214           "has been defined");
1215    ImplicitlyDefined = ID;
1216  }
1217
1218  /// init_iterator - Iterates through the member/base initializer list.
1219  typedef CXXBaseOrMemberInitializer **init_iterator;
1220
1221  /// init_const_iterator - Iterates through the memberbase initializer list.
1222  typedef CXXBaseOrMemberInitializer * const * init_const_iterator;
1223
1224  /// init_begin() - Retrieve an iterator to the first initializer.
1225  init_iterator       init_begin()       { return BaseOrMemberInitializers; }
1226  /// begin() - Retrieve an iterator to the first initializer.
1227  init_const_iterator init_begin() const { return BaseOrMemberInitializers; }
1228
1229  /// init_end() - Retrieve an iterator past the last initializer.
1230  init_iterator       init_end()       {
1231    return BaseOrMemberInitializers + NumBaseOrMemberInitializers;
1232  }
1233  /// end() - Retrieve an iterator past the last initializer.
1234  init_const_iterator init_end() const {
1235    return BaseOrMemberInitializers + NumBaseOrMemberInitializers;
1236  }
1237
1238  /// getNumArgs - Determine the number of arguments used to
1239  /// initialize the member or base.
1240  unsigned getNumBaseOrMemberInitializers() const {
1241      return NumBaseOrMemberInitializers;
1242  }
1243
1244  void setNumBaseOrMemberInitializers(unsigned numBaseOrMemberInitializers) {
1245    NumBaseOrMemberInitializers = numBaseOrMemberInitializers;
1246  }
1247
1248  void setBaseOrMemberInitializers(CXXBaseOrMemberInitializer ** initializers) {
1249    BaseOrMemberInitializers = initializers;
1250  }
1251  /// isDefaultConstructor - Whether this constructor is a default
1252  /// constructor (C++ [class.ctor]p5), which can be used to
1253  /// default-initialize a class of this type.
1254  bool isDefaultConstructor() const;
1255
1256  /// isCopyConstructor - Whether this constructor is a copy
1257  /// constructor (C++ [class.copy]p2, which can be used to copy the
1258  /// class. @p TypeQuals will be set to the qualifiers on the
1259  /// argument type. For example, @p TypeQuals would be set to @c
1260  /// QualType::Const for the following copy constructor:
1261  ///
1262  /// @code
1263  /// class X {
1264  /// public:
1265  ///   X(const X&);
1266  /// };
1267  /// @endcode
1268  bool isCopyConstructor(unsigned &TypeQuals) const;
1269
1270  /// isCopyConstructor - Whether this constructor is a copy
1271  /// constructor (C++ [class.copy]p2, which can be used to copy the
1272  /// class.
1273  bool isCopyConstructor() const {
1274    unsigned TypeQuals = 0;
1275    return isCopyConstructor(TypeQuals);
1276  }
1277
1278  /// isConvertingConstructor - Whether this constructor is a
1279  /// converting constructor (C++ [class.conv.ctor]), which can be
1280  /// used for user-defined conversions.
1281  bool isConvertingConstructor(bool AllowExplicit) const;
1282
1283  /// \brief Determine whether this is a member template specialization that
1284  /// looks like a copy constructor. Such constructors are never used to copy
1285  /// an object.
1286  bool isCopyConstructorLikeSpecialization() const;
1287
1288  // Implement isa/cast/dyncast/etc.
1289  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1290  static bool classof(const CXXConstructorDecl *D) { return true; }
1291  static bool classofKind(Kind K) { return K == CXXConstructor; }
1292};
1293
1294/// CXXDestructorDecl - Represents a C++ destructor within a
1295/// class. For example:
1296///
1297/// @code
1298/// class X {
1299/// public:
1300///   ~X(); // represented by a CXXDestructorDecl.
1301/// };
1302/// @endcode
1303class CXXDestructorDecl : public CXXMethodDecl {
1304  /// ImplicitlyDefined - Whether this destructor was implicitly
1305  /// defined by the compiler. When false, the destructor was defined
1306  /// by the user. In C++03, this flag will have the same value as
1307  /// Implicit. In C++0x, however, a destructor that is
1308  /// explicitly defaulted (i.e., defined with " = default") will have
1309  /// @c !Implicit && ImplicitlyDefined.
1310  bool ImplicitlyDefined : 1;
1311
1312  FunctionDecl *OperatorDelete;
1313
1314  CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation L,
1315                    DeclarationName N, QualType T,
1316                    bool isInline, bool isImplicitlyDeclared)
1317    : CXXMethodDecl(CXXDestructor, RD, L, N, T, /*TInfo=*/0, false, isInline),
1318      ImplicitlyDefined(false), OperatorDelete(0) {
1319    setImplicit(isImplicitlyDeclared);
1320  }
1321
1322public:
1323  static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1324                                   SourceLocation L, DeclarationName N,
1325                                   QualType T, bool isInline,
1326                                   bool isImplicitlyDeclared);
1327
1328  /// isImplicitlyDefined - Whether this destructor was implicitly
1329  /// defined. If false, then this destructor was defined by the
1330  /// user. This operation can only be invoked if the destructor has
1331  /// already been defined.
1332  bool isImplicitlyDefined() const {
1333    assert(isThisDeclarationADefinition() &&
1334           "Can only get the implicit-definition flag once the destructor has been defined");
1335    return ImplicitlyDefined;
1336  }
1337
1338  /// setImplicitlyDefined - Set whether this destructor was
1339  /// implicitly defined or not.
1340  void setImplicitlyDefined(bool ID) {
1341    assert(isThisDeclarationADefinition() &&
1342           "Can only set the implicit-definition flag once the destructor has been defined");
1343    ImplicitlyDefined = ID;
1344  }
1345
1346  void setOperatorDelete(FunctionDecl *OD) { OperatorDelete = OD; }
1347  const FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1348
1349  // Implement isa/cast/dyncast/etc.
1350  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1351  static bool classof(const CXXDestructorDecl *D) { return true; }
1352  static bool classofKind(Kind K) { return K == CXXDestructor; }
1353};
1354
1355/// CXXConversionDecl - Represents a C++ conversion function within a
1356/// class. For example:
1357///
1358/// @code
1359/// class X {
1360/// public:
1361///   operator bool();
1362/// };
1363/// @endcode
1364class CXXConversionDecl : public CXXMethodDecl {
1365  /// IsExplicitSpecified - Whether this conversion function declaration is
1366  /// marked "explicit", meaning that it can only be applied when the user
1367  /// explicitly wrote a cast. This is a C++0x feature.
1368  bool IsExplicitSpecified : 1;
1369
1370  CXXConversionDecl(CXXRecordDecl *RD, SourceLocation L,
1371                    DeclarationName N, QualType T, TypeSourceInfo *TInfo,
1372                    bool isInline, bool isExplicitSpecified)
1373    : CXXMethodDecl(CXXConversion, RD, L, N, T, TInfo, false, isInline),
1374      IsExplicitSpecified(isExplicitSpecified) { }
1375
1376public:
1377  static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1378                                   SourceLocation L, DeclarationName N,
1379                                   QualType T, TypeSourceInfo *TInfo,
1380                                   bool isInline, bool isExplicit);
1381
1382  /// IsExplicitSpecified - Whether this conversion function declaration is
1383  /// marked "explicit", meaning that it can only be applied when the user
1384  /// explicitly wrote a cast. This is a C++0x feature.
1385  bool isExplicitSpecified() const { return IsExplicitSpecified; }
1386
1387  /// isExplicit - Whether this is an explicit conversion operator
1388  /// (C++0x only). Explicit conversion operators are only considered
1389  /// when the user has explicitly written a cast.
1390  bool isExplicit() const {
1391    return cast<CXXConversionDecl>(getFirstDeclaration())
1392      ->isExplicitSpecified();
1393  }
1394
1395  /// getConversionType - Returns the type that this conversion
1396  /// function is converting to.
1397  QualType getConversionType() const {
1398    return getType()->getAs<FunctionType>()->getResultType();
1399  }
1400
1401  // Implement isa/cast/dyncast/etc.
1402  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1403  static bool classof(const CXXConversionDecl *D) { return true; }
1404  static bool classofKind(Kind K) { return K == CXXConversion; }
1405};
1406
1407/// LinkageSpecDecl - This represents a linkage specification.  For example:
1408///   extern "C" void foo();
1409///
1410class LinkageSpecDecl : public Decl, public DeclContext {
1411public:
1412  /// LanguageIDs - Used to represent the language in a linkage
1413  /// specification.  The values are part of the serialization abi for
1414  /// ASTs and cannot be changed without altering that abi.  To help
1415  /// ensure a stable abi for this, we choose the DW_LANG_ encodings
1416  /// from the dwarf standard.
1417  enum LanguageIDs { lang_c = /* DW_LANG_C */ 0x0002,
1418  lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004 };
1419private:
1420  /// Language - The language for this linkage specification.
1421  LanguageIDs Language;
1422
1423  /// HadBraces - Whether this linkage specification had curly braces or not.
1424  bool HadBraces : 1;
1425
1426  LinkageSpecDecl(DeclContext *DC, SourceLocation L, LanguageIDs lang,
1427                  bool Braces)
1428    : Decl(LinkageSpec, DC, L),
1429      DeclContext(LinkageSpec), Language(lang), HadBraces(Braces) { }
1430
1431public:
1432  static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
1433                                 SourceLocation L, LanguageIDs Lang,
1434                                 bool Braces);
1435
1436  LanguageIDs getLanguage() const { return Language; }
1437
1438  /// hasBraces - Determines whether this linkage specification had
1439  /// braces in its syntactic form.
1440  bool hasBraces() const { return HadBraces; }
1441
1442  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1443  static bool classof(const LinkageSpecDecl *D) { return true; }
1444  static bool classofKind(Kind K) { return K == LinkageSpec; }
1445  static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
1446    return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
1447  }
1448  static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
1449    return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
1450  }
1451};
1452
1453/// UsingDirectiveDecl - Represents C++ using-directive. For example:
1454///
1455///    using namespace std;
1456///
1457// NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide
1458// artificial name, for all using-directives in order to store
1459// them in DeclContext effectively.
1460class UsingDirectiveDecl : public NamedDecl {
1461
1462  /// SourceLocation - Location of 'namespace' token.
1463  SourceLocation NamespaceLoc;
1464
1465  /// \brief The source range that covers the nested-name-specifier
1466  /// preceding the namespace name.
1467  SourceRange QualifierRange;
1468
1469  /// \brief The nested-name-specifier that precedes the namespace
1470  /// name, if any.
1471  NestedNameSpecifier *Qualifier;
1472
1473  /// IdentLoc - Location of nominated namespace-name identifier.
1474  // FIXME: We don't store location of scope specifier.
1475  SourceLocation IdentLoc;
1476
1477  /// NominatedNamespace - Namespace nominated by using-directive.
1478  NamedDecl *NominatedNamespace;
1479
1480  /// Enclosing context containing both using-directive and nominated
1481  /// namespace.
1482  DeclContext *CommonAncestor;
1483
1484  /// getUsingDirectiveName - Returns special DeclarationName used by
1485  /// using-directives. This is only used by DeclContext for storing
1486  /// UsingDirectiveDecls in its lookup structure.
1487  static DeclarationName getName() {
1488    return DeclarationName::getUsingDirectiveName();
1489  }
1490
1491  UsingDirectiveDecl(DeclContext *DC, SourceLocation L,
1492                     SourceLocation NamespcLoc,
1493                     SourceRange QualifierRange,
1494                     NestedNameSpecifier *Qualifier,
1495                     SourceLocation IdentLoc,
1496                     NamedDecl *Nominated,
1497                     DeclContext *CommonAncestor)
1498    : NamedDecl(Decl::UsingDirective, DC, L, getName()),
1499      NamespaceLoc(NamespcLoc), QualifierRange(QualifierRange),
1500      Qualifier(Qualifier), IdentLoc(IdentLoc),
1501      NominatedNamespace(Nominated),
1502      CommonAncestor(CommonAncestor) {
1503  }
1504
1505public:
1506  /// \brief Retrieve the source range of the nested-name-specifier
1507  /// that qualifiers the namespace name.
1508  SourceRange getQualifierRange() const { return QualifierRange; }
1509
1510  /// \brief Retrieve the nested-name-specifier that qualifies the
1511  /// name of the namespace.
1512  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1513
1514  NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
1515  const NamedDecl *getNominatedNamespaceAsWritten() const {
1516    return NominatedNamespace;
1517  }
1518
1519  /// getNominatedNamespace - Returns namespace nominated by using-directive.
1520  NamespaceDecl *getNominatedNamespace();
1521
1522  const NamespaceDecl *getNominatedNamespace() const {
1523    return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
1524  }
1525
1526  /// getCommonAncestor - returns common ancestor context of using-directive,
1527  /// and nominated by it namespace.
1528  DeclContext *getCommonAncestor() { return CommonAncestor; }
1529  const DeclContext *getCommonAncestor() const { return CommonAncestor; }
1530
1531  /// getNamespaceKeyLocation - Returns location of namespace keyword.
1532  SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
1533
1534  /// getIdentLocation - Returns location of identifier.
1535  SourceLocation getIdentLocation() const { return IdentLoc; }
1536
1537  static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
1538                                    SourceLocation L,
1539                                    SourceLocation NamespaceLoc,
1540                                    SourceRange QualifierRange,
1541                                    NestedNameSpecifier *Qualifier,
1542                                    SourceLocation IdentLoc,
1543                                    NamedDecl *Nominated,
1544                                    DeclContext *CommonAncestor);
1545
1546  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1547  static bool classof(const UsingDirectiveDecl *D) { return true; }
1548  static bool classofKind(Kind K) { return K == Decl::UsingDirective; }
1549
1550  // Friend for getUsingDirectiveName.
1551  friend class DeclContext;
1552};
1553
1554/// NamespaceAliasDecl - Represents a C++ namespace alias. For example:
1555///
1556/// @code
1557/// namespace Foo = Bar;
1558/// @endcode
1559class NamespaceAliasDecl : public NamedDecl {
1560  SourceLocation AliasLoc;
1561
1562  /// \brief The source range that covers the nested-name-specifier
1563  /// preceding the namespace name.
1564  SourceRange QualifierRange;
1565
1566  /// \brief The nested-name-specifier that precedes the namespace
1567  /// name, if any.
1568  NestedNameSpecifier *Qualifier;
1569
1570  /// IdentLoc - Location of namespace identifier.
1571  SourceLocation IdentLoc;
1572
1573  /// Namespace - The Decl that this alias points to. Can either be a
1574  /// NamespaceDecl or a NamespaceAliasDecl.
1575  NamedDecl *Namespace;
1576
1577  NamespaceAliasDecl(DeclContext *DC, SourceLocation L,
1578                     SourceLocation AliasLoc, IdentifierInfo *Alias,
1579                     SourceRange QualifierRange,
1580                     NestedNameSpecifier *Qualifier,
1581                     SourceLocation IdentLoc, NamedDecl *Namespace)
1582    : NamedDecl(Decl::NamespaceAlias, DC, L, Alias), AliasLoc(AliasLoc),
1583      QualifierRange(QualifierRange), Qualifier(Qualifier),
1584      IdentLoc(IdentLoc), Namespace(Namespace) { }
1585
1586public:
1587  /// \brief Retrieve the source range of the nested-name-specifier
1588  /// that qualifiers the namespace name.
1589  SourceRange getQualifierRange() const { return QualifierRange; }
1590
1591  /// \brief Retrieve the nested-name-specifier that qualifies the
1592  /// name of the namespace.
1593  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1594
1595  NamespaceDecl *getNamespace() {
1596    if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
1597      return AD->getNamespace();
1598
1599    return cast<NamespaceDecl>(Namespace);
1600  }
1601
1602  const NamespaceDecl *getNamespace() const {
1603    return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
1604  }
1605
1606  /// Returns the location of the alias name, i.e. 'foo' in
1607  /// "namespace foo = ns::bar;".
1608  SourceLocation getAliasLoc() const { return AliasLoc; }
1609
1610  /// Returns the location of the 'namespace' keyword.
1611  SourceLocation getNamespaceLoc() const { return getLocation(); }
1612
1613  /// Returns the location of the identifier in the named namespace.
1614  SourceLocation getTargetNameLoc() const { return IdentLoc; }
1615
1616  /// \brief Retrieve the namespace that this alias refers to, which
1617  /// may either be a NamespaceDecl or a NamespaceAliasDecl.
1618  NamedDecl *getAliasedNamespace() const { return Namespace; }
1619
1620  static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
1621                                    SourceLocation L, SourceLocation AliasLoc,
1622                                    IdentifierInfo *Alias,
1623                                    SourceRange QualifierRange,
1624                                    NestedNameSpecifier *Qualifier,
1625                                    SourceLocation IdentLoc,
1626                                    NamedDecl *Namespace);
1627
1628  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1629  static bool classof(const NamespaceAliasDecl *D) { return true; }
1630  static bool classofKind(Kind K) { return K == Decl::NamespaceAlias; }
1631};
1632
1633/// UsingShadowDecl - Represents a shadow declaration introduced into
1634/// a scope by a (resolved) using declaration.  For example,
1635///
1636/// namespace A {
1637///   void foo();
1638/// }
1639/// namespace B {
1640///   using A::foo(); // <- a UsingDecl
1641///                   // Also creates a UsingShadowDecl for A::foo in B
1642/// }
1643///
1644class UsingShadowDecl : public NamedDecl {
1645  /// The referenced declaration.
1646  NamedDecl *Underlying;
1647
1648  /// The using declaration which introduced this decl.
1649  UsingDecl *Using;
1650
1651  UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using,
1652                  NamedDecl *Target)
1653    : NamedDecl(UsingShadow, DC, Loc, Target->getDeclName()),
1654      Underlying(Target), Using(Using) {
1655    IdentifierNamespace = Target->getIdentifierNamespace();
1656    setImplicit();
1657  }
1658
1659public:
1660  static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
1661                                 SourceLocation Loc, UsingDecl *Using,
1662                                 NamedDecl *Target) {
1663    return new (C) UsingShadowDecl(DC, Loc, Using, Target);
1664  }
1665
1666  /// Gets the underlying declaration which has been brought into the
1667  /// local scope.
1668  NamedDecl *getTargetDecl() const {
1669    return Underlying;
1670  }
1671
1672  /// Gets the using declaration to which this declaration is tied.
1673  UsingDecl *getUsingDecl() const {
1674    return Using;
1675  }
1676
1677  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1678  static bool classof(const UsingShadowDecl *D) { return true; }
1679  static bool classofKind(Kind K) { return K == Decl::UsingShadow; }
1680};
1681
1682/// UsingDecl - Represents a C++ using-declaration. For example:
1683///    using someNameSpace::someIdentifier;
1684class UsingDecl : public NamedDecl {
1685  /// \brief The source range that covers the nested-name-specifier
1686  /// preceding the declaration name.
1687  SourceRange NestedNameRange;
1688
1689  /// \brief The source location of the "using" location itself.
1690  SourceLocation UsingLocation;
1691
1692  /// \brief Target nested name specifier.
1693  NestedNameSpecifier* TargetNestedName;
1694
1695  /// \brief The collection of shadow declarations associated with
1696  /// this using declaration.  This set can change as a class is
1697  /// processed.
1698  llvm::SmallPtrSet<UsingShadowDecl*, 8> Shadows;
1699
1700  // \brief Has 'typename' keyword.
1701  bool IsTypeName;
1702
1703  UsingDecl(DeclContext *DC, SourceLocation L, SourceRange NNR,
1704            SourceLocation UL, NestedNameSpecifier* TargetNNS,
1705            DeclarationName Name, bool IsTypeNameArg)
1706    : NamedDecl(Decl::Using, DC, L, Name),
1707      NestedNameRange(NNR), UsingLocation(UL), TargetNestedName(TargetNNS),
1708      IsTypeName(IsTypeNameArg) {
1709  }
1710
1711public:
1712  /// \brief Returns the source range that covers the nested-name-specifier
1713  /// preceding the namespace name.
1714  SourceRange getNestedNameRange() { return NestedNameRange; }
1715
1716  /// \brief Returns the source location of the "using" location itself.
1717  SourceLocation getUsingLocation() { return UsingLocation; }
1718
1719  /// \brief Get target nested name declaration.
1720  NestedNameSpecifier* getTargetNestedNameDecl() {
1721    return TargetNestedName;
1722  }
1723
1724  /// isTypeName - Return true if using decl has 'typename'.
1725  bool isTypeName() const { return IsTypeName; }
1726
1727  typedef llvm::SmallPtrSet<UsingShadowDecl*,8>::const_iterator shadow_iterator;
1728  shadow_iterator shadow_begin() const { return Shadows.begin(); }
1729  shadow_iterator shadow_end() const { return Shadows.end(); }
1730
1731  void addShadowDecl(UsingShadowDecl *S) {
1732    assert(S->getUsingDecl() == this);
1733    if (!Shadows.insert(S)) {
1734      assert(false && "declaration already in set");
1735    }
1736  }
1737  void removeShadowDecl(UsingShadowDecl *S) {
1738    assert(S->getUsingDecl() == this);
1739    if (!Shadows.erase(S)) {
1740      assert(false && "declaration not in set");
1741    }
1742  }
1743
1744  static UsingDecl *Create(ASTContext &C, DeclContext *DC,
1745      SourceLocation IdentL, SourceRange NNR, SourceLocation UsingL,
1746      NestedNameSpecifier* TargetNNS, DeclarationName Name, bool IsTypeNameArg);
1747
1748  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1749  static bool classof(const UsingDecl *D) { return true; }
1750  static bool classofKind(Kind K) { return K == Decl::Using; }
1751};
1752
1753/// UnresolvedUsingValueDecl - Represents a dependent using
1754/// declaration which was not marked with 'typename'.  Unlike
1755/// non-dependent using declarations, these *only* bring through
1756/// non-types; otherwise they would break two-phase lookup.
1757///
1758/// template <class T> class A : public Base<T> {
1759///   using Base<T>::foo;
1760/// };
1761class UnresolvedUsingValueDecl : public ValueDecl {
1762  /// \brief The source range that covers the nested-name-specifier
1763  /// preceding the declaration name.
1764  SourceRange TargetNestedNameRange;
1765
1766  /// \brief The source location of the 'using' keyword
1767  SourceLocation UsingLocation;
1768
1769  NestedNameSpecifier *TargetNestedNameSpecifier;
1770
1771  UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
1772                           SourceLocation UsingLoc, SourceRange TargetNNR,
1773                           NestedNameSpecifier *TargetNNS,
1774                           SourceLocation TargetNameLoc,
1775                           DeclarationName TargetName)
1776    : ValueDecl(Decl::UnresolvedUsingValue, DC, TargetNameLoc, TargetName, Ty),
1777    TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc),
1778    TargetNestedNameSpecifier(TargetNNS)
1779  { }
1780
1781public:
1782  /// \brief Returns the source range that covers the nested-name-specifier
1783  /// preceding the namespace name.
1784  SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; }
1785
1786  /// \brief Get target nested name declaration.
1787  NestedNameSpecifier* getTargetNestedNameSpecifier() {
1788    return TargetNestedNameSpecifier;
1789  }
1790
1791  /// \brief Returns the source location of the 'using' keyword.
1792  SourceLocation getUsingLoc() const { return UsingLocation; }
1793
1794  static UnresolvedUsingValueDecl *
1795    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
1796           SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
1797           SourceLocation TargetNameLoc, DeclarationName TargetName);
1798
1799  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1800  static bool classof(const UnresolvedUsingValueDecl *D) { return true; }
1801  static bool classofKind(Kind K) { return K == Decl::UnresolvedUsingValue; }
1802};
1803
1804/// UnresolvedUsingTypenameDecl - Represents a dependent using
1805/// declaration which was marked with 'typename'.
1806///
1807/// template <class T> class A : public Base<T> {
1808///   using typename Base<T>::foo;
1809/// };
1810///
1811/// The type associated with a unresolved using typename decl is
1812/// currently always a typename type.
1813class UnresolvedUsingTypenameDecl : public TypeDecl {
1814  /// \brief The source range that covers the nested-name-specifier
1815  /// preceding the declaration name.
1816  SourceRange TargetNestedNameRange;
1817
1818  /// \brief The source location of the 'using' keyword
1819  SourceLocation UsingLocation;
1820
1821  /// \brief The source location of the 'typename' keyword
1822  SourceLocation TypenameLocation;
1823
1824  NestedNameSpecifier *TargetNestedNameSpecifier;
1825
1826  UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
1827                    SourceLocation TypenameLoc,
1828                    SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
1829                    SourceLocation TargetNameLoc, IdentifierInfo *TargetName)
1830  : TypeDecl(Decl::UnresolvedUsingTypename, DC, TargetNameLoc, TargetName),
1831    TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc),
1832    TypenameLocation(TypenameLoc), TargetNestedNameSpecifier(TargetNNS)
1833  { }
1834
1835public:
1836  /// \brief Returns the source range that covers the nested-name-specifier
1837  /// preceding the namespace name.
1838  SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; }
1839
1840  /// \brief Get target nested name declaration.
1841  NestedNameSpecifier* getTargetNestedNameSpecifier() {
1842    return TargetNestedNameSpecifier;
1843  }
1844
1845  /// \brief Returns the source location of the 'using' keyword.
1846  SourceLocation getUsingLoc() const { return UsingLocation; }
1847
1848  /// \brief Returns the source location of the 'typename' keyword.
1849  SourceLocation getTypenameLoc() const { return TypenameLocation; }
1850
1851  static UnresolvedUsingTypenameDecl *
1852    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
1853           SourceLocation TypenameLoc,
1854           SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
1855           SourceLocation TargetNameLoc, DeclarationName TargetName);
1856
1857  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1858  static bool classof(const UnresolvedUsingTypenameDecl *D) { return true; }
1859  static bool classofKind(Kind K) { return K == Decl::UnresolvedUsingTypename; }
1860};
1861
1862/// StaticAssertDecl - Represents a C++0x static_assert declaration.
1863class StaticAssertDecl : public Decl {
1864  Expr *AssertExpr;
1865  StringLiteral *Message;
1866
1867  StaticAssertDecl(DeclContext *DC, SourceLocation L,
1868                   Expr *assertexpr, StringLiteral *message)
1869  : Decl(StaticAssert, DC, L), AssertExpr(assertexpr), Message(message) { }
1870
1871public:
1872  static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
1873                                  SourceLocation L, Expr *AssertExpr,
1874                                  StringLiteral *Message);
1875
1876  Expr *getAssertExpr() { return AssertExpr; }
1877  const Expr *getAssertExpr() const { return AssertExpr; }
1878
1879  StringLiteral *getMessage() { return Message; }
1880  const StringLiteral *getMessage() const { return Message; }
1881
1882  virtual ~StaticAssertDecl();
1883  virtual void Destroy(ASTContext& C);
1884
1885  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1886  static bool classof(StaticAssertDecl *D) { return true; }
1887  static bool classofKind(Kind K) { return K == Decl::StaticAssert; }
1888};
1889
1890/// Insertion operator for diagnostics.  This allows sending AccessSpecifier's
1891/// into a diagnostic with <<.
1892const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
1893                                    AccessSpecifier AS);
1894
1895} // end namespace clang
1896
1897#endif
1898