DeclCXX.h revision 205219
1193326Sed//===-- DeclCXX.h - Classes for representing C++ declarations -*- C++ -*-=====//
2193326Sed//
3193326Sed//                     The LLVM Compiler Infrastructure
4193326Sed//
5193326Sed// This file is distributed under the University of Illinois Open Source
6193326Sed// License. See LICENSE.TXT for details.
7193326Sed//
8193326Sed//===----------------------------------------------------------------------===//
9193326Sed//
10205219Srdivacky//  This file defines the C++ Decl subclasses, other than those for
11205219Srdivacky//  templates (in DeclTemplate.h) and friends (in DeclFriend.h).
12193326Sed//
13193326Sed//===----------------------------------------------------------------------===//
14193326Sed
15193326Sed#ifndef LLVM_CLANG_AST_DECLCXX_H
16193326Sed#define LLVM_CLANG_AST_DECLCXX_H
17193326Sed
18198092Srdivacky#include "clang/AST/Expr.h"
19193326Sed#include "clang/AST/Decl.h"
20202879Srdivacky#include "clang/AST/UnresolvedSet.h"
21193326Sed#include "llvm/ADT/SmallVector.h"
22198092Srdivacky#include "llvm/ADT/SmallPtrSet.h"
23193326Sed
24193326Sednamespace clang {
25193326Sed
26193326Sedclass ClassTemplateDecl;
27198092Srdivackyclass ClassTemplateSpecializationDecl;
28198092Srdivackyclass CXXBasePath;
29198092Srdivackyclass CXXBasePaths;
30193326Sedclass CXXConstructorDecl;
31198092Srdivackyclass CXXConversionDecl;
32193326Sedclass CXXDestructorDecl;
33193326Sedclass CXXMethodDecl;
34198092Srdivackyclass CXXRecordDecl;
35198092Srdivackyclass CXXMemberLookupCriteria;
36205219Srdivackyclass FriendDecl;
37198092Srdivacky
38198092Srdivacky/// \brief Represents any kind of function declaration, whether it is a
39195099Sed/// concrete function or a function template.
40195099Sedclass AnyFunctionDecl {
41195099Sed  NamedDecl *Function;
42198092Srdivacky
43195341Sed  AnyFunctionDecl(NamedDecl *ND) : Function(ND) { }
44198092Srdivacky
45195099Sedpublic:
46195099Sed  AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { }
47195099Sed  AnyFunctionDecl(FunctionTemplateDecl *FTD);
48198092Srdivacky
49198092Srdivacky  /// \brief Implicily converts any function or function template into a
50195099Sed  /// named declaration.
51195099Sed  operator NamedDecl *() const { return Function; }
52198092Srdivacky
53195099Sed  /// \brief Retrieve the underlying function or function template.
54195099Sed  NamedDecl *get() const { return Function; }
55198092Srdivacky
56198092Srdivacky  static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) {
57195341Sed    return AnyFunctionDecl(ND);
58195341Sed  }
59195099Sed};
60198092Srdivacky
61195099Sed} // end namespace clang
62195099Sed
63195099Sednamespace llvm {
64198092Srdivacky  /// Implement simplify_type for AnyFunctionDecl, so that we can dyn_cast from
65195099Sed  /// AnyFunctionDecl to any function or function template declaration.
66195099Sed  template<> struct simplify_type<const ::clang::AnyFunctionDecl> {
67195099Sed    typedef ::clang::NamedDecl* SimpleType;
68195099Sed    static SimpleType getSimplifiedValue(const ::clang::AnyFunctionDecl &Val) {
69195099Sed      return Val;
70195099Sed    }
71195099Sed  };
72195099Sed  template<> struct simplify_type< ::clang::AnyFunctionDecl>
73195099Sed  : public simplify_type<const ::clang::AnyFunctionDecl> {};
74198092Srdivacky
75195341Sed  // Provide PointerLikeTypeTraits for non-cvr pointers.
76195341Sed  template<>
77195341Sed  class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
78195341Sed  public:
79195341Sed    static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
80198092Srdivacky      return F.get();
81195341Sed    }
82195341Sed    static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
83195341Sed      return ::clang::AnyFunctionDecl::getFromNamedDecl(
84195341Sed                                      static_cast< ::clang::NamedDecl*>(P));
85195341Sed    }
86198092Srdivacky
87195341Sed    enum { NumLowBitsAvailable = 2 };
88195341Sed  };
89198092Srdivacky
90195099Sed} // end namespace llvm
91195099Sed
92195099Sednamespace clang {
93198092Srdivacky
94193326Sed/// CXXBaseSpecifier - A base class of a C++ class.
95193326Sed///
96193326Sed/// Each CXXBaseSpecifier represents a single, direct base class (or
97193326Sed/// struct) of a C++ class (or struct). It specifies the type of that
98193326Sed/// base class, whether it is a virtual or non-virtual base, and what
99193326Sed/// level of access (public, protected, private) is used for the
100193326Sed/// derivation. For example:
101193326Sed///
102193326Sed/// @code
103193326Sed///   class A { };
104193326Sed///   class B { };
105193326Sed///   class C : public virtual A, protected B { };
106193326Sed/// @endcode
107193326Sed///
108193326Sed/// In this code, C will have two CXXBaseSpecifiers, one for "public
109193326Sed/// virtual A" and the other for "protected B".
110193326Sedclass CXXBaseSpecifier {
111193326Sed  /// Range - The source code range that covers the full base
112193326Sed  /// specifier, including the "virtual" (if present) and access
113193326Sed  /// specifier (if present).
114200583Srdivacky  // FIXME: Move over to a TypeLoc!
115193326Sed  SourceRange Range;
116193326Sed
117193326Sed  /// Virtual - Whether this is a virtual base class or not.
118193326Sed  bool Virtual : 1;
119193326Sed
120193326Sed  /// BaseOfClass - Whether this is the base of a class (true) or of a
121193326Sed  /// struct (false). This determines the mapping from the access
122193326Sed  /// specifier as written in the source code to the access specifier
123193326Sed  /// used for semantic analysis.
124198092Srdivacky  bool BaseOfClass : 1;
125193326Sed
126193326Sed  /// Access - Access specifier as written in the source code (which
127193326Sed  /// may be AS_none). The actual type of data stored here is an
128193326Sed  /// AccessSpecifier, but we use "unsigned" here to work around a
129193326Sed  /// VC++ bug.
130193326Sed  unsigned Access : 2;
131193326Sed
132193326Sed  /// BaseType - The type of the base class. This will be a class or
133193326Sed  /// struct (or a typedef of such).
134193326Sed  QualType BaseType;
135198092Srdivacky
136193326Sedpublic:
137193326Sed  CXXBaseSpecifier() { }
138193326Sed
139193326Sed  CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, QualType T)
140193326Sed    : Range(R), Virtual(V), BaseOfClass(BC), Access(A), BaseType(T) { }
141193326Sed
142193326Sed  /// getSourceRange - Retrieves the source range that contains the
143193326Sed  /// entire base specifier.
144193326Sed  SourceRange getSourceRange() const { return Range; }
145198092Srdivacky
146193326Sed  /// isVirtual - Determines whether the base class is a virtual base
147193326Sed  /// class (or not).
148193326Sed  bool isVirtual() const { return Virtual; }
149193326Sed
150203955Srdivacky  /// \brief Determine whether this base class if a base of a class declared
151203955Srdivacky  /// with the 'class' keyword (vs. one declared with the 'struct' keyword).
152203955Srdivacky  bool isBaseOfClass() const { return BaseOfClass; }
153203955Srdivacky
154193326Sed  /// getAccessSpecifier - Returns the access specifier for this base
155193326Sed  /// specifier. This is the actual base specifier as used for
156193326Sed  /// semantic analysis, so the result can never be AS_none. To
157193326Sed  /// retrieve the access specifier as written in the source code, use
158193326Sed  /// getAccessSpecifierAsWritten().
159198092Srdivacky  AccessSpecifier getAccessSpecifier() const {
160193326Sed    if ((AccessSpecifier)Access == AS_none)
161193326Sed      return BaseOfClass? AS_private : AS_public;
162193326Sed    else
163198092Srdivacky      return (AccessSpecifier)Access;
164193326Sed  }
165193326Sed
166193326Sed  /// getAccessSpecifierAsWritten - Retrieves the access specifier as
167193326Sed  /// written in the source code (which may mean that no access
168193326Sed  /// specifier was explicitly written). Use getAccessSpecifier() to
169193326Sed  /// retrieve the access specifier for use in semantic analysis.
170193326Sed  AccessSpecifier getAccessSpecifierAsWritten() const {
171193326Sed    return (AccessSpecifier)Access;
172193326Sed  }
173193326Sed
174193326Sed  /// getType - Retrieves the type of the base class. This type will
175193326Sed  /// always be an unqualified class type.
176193326Sed  QualType getType() const { return BaseType; }
177193326Sed};
178193326Sed
179193326Sed/// CXXRecordDecl - Represents a C++ struct/union/class.
180193326Sed/// FIXME: This class will disappear once we've properly taught RecordDecl
181193326Sed/// to deal with C++-specific things.
182193326Sedclass CXXRecordDecl : public RecordDecl {
183193326Sed
184203955Srdivacky  friend void TagDecl::startDefinition();
185193326Sed
186203955Srdivacky  struct DefinitionData {
187203955Srdivacky    DefinitionData(CXXRecordDecl *D);
188193326Sed
189203955Srdivacky    /// UserDeclaredConstructor - True when this class has a
190203955Srdivacky    /// user-declared constructor.
191203955Srdivacky    bool UserDeclaredConstructor : 1;
192193326Sed
193203955Srdivacky    /// UserDeclaredCopyConstructor - True when this class has a
194203955Srdivacky    /// user-declared copy constructor.
195203955Srdivacky    bool UserDeclaredCopyConstructor : 1;
196193326Sed
197203955Srdivacky    /// UserDeclaredCopyAssignment - True when this class has a
198203955Srdivacky    /// user-declared copy assignment operator.
199203955Srdivacky    bool UserDeclaredCopyAssignment : 1;
200193326Sed
201203955Srdivacky    /// UserDeclaredDestructor - True when this class has a
202203955Srdivacky    /// user-declared destructor.
203203955Srdivacky    bool UserDeclaredDestructor : 1;
204198092Srdivacky
205203955Srdivacky    /// Aggregate - True when this class is an aggregate.
206203955Srdivacky    bool Aggregate : 1;
207193326Sed
208203955Srdivacky    /// PlainOldData - True when this class is a POD-type.
209203955Srdivacky    bool PlainOldData : 1;
210198092Srdivacky
211203955Srdivacky    /// Empty - true when this class is empty for traits purposes,
212203955Srdivacky    /// i.e. has no data members other than 0-width bit-fields, has no
213203955Srdivacky    /// virtual function/base, and doesn't inherit from a non-empty
214203955Srdivacky    /// class. Doesn't take union-ness into account.
215203955Srdivacky    bool Empty : 1;
216198092Srdivacky
217203955Srdivacky    /// Polymorphic - True when this class is polymorphic, i.e. has at
218203955Srdivacky    /// least one virtual member or derives from a polymorphic class.
219203955Srdivacky    bool Polymorphic : 1;
220198092Srdivacky
221203955Srdivacky    /// Abstract - True when this class is abstract, i.e. has at least
222203955Srdivacky    /// one pure virtual function, (that can come from a base class).
223203955Srdivacky    bool Abstract : 1;
224198092Srdivacky
225203955Srdivacky    /// HasTrivialConstructor - True when this class has a trivial constructor.
226203955Srdivacky    ///
227203955Srdivacky    /// C++ [class.ctor]p5.  A constructor is trivial if it is an
228203955Srdivacky    /// implicitly-declared default constructor and if:
229203955Srdivacky    /// * its class has no virtual functions and no virtual base classes, and
230203955Srdivacky    /// * all the direct base classes of its class have trivial constructors, and
231203955Srdivacky    /// * for all the nonstatic data members of its class that are of class type
232203955Srdivacky    ///   (or array thereof), each such class has a trivial constructor.
233203955Srdivacky    bool HasTrivialConstructor : 1;
234198092Srdivacky
235203955Srdivacky    /// HasTrivialCopyConstructor - True when this class has a trivial copy
236203955Srdivacky    /// constructor.
237203955Srdivacky    ///
238203955Srdivacky    /// C++ [class.copy]p6.  A copy constructor for class X is trivial
239203955Srdivacky    /// if it is implicitly declared and if
240203955Srdivacky    /// * class X has no virtual functions and no virtual base classes, and
241203955Srdivacky    /// * each direct base class of X has a trivial copy constructor, and
242203955Srdivacky    /// * for all the nonstatic data members of X that are of class type (or
243203955Srdivacky    ///   array thereof), each such class type has a trivial copy constructor;
244203955Srdivacky    /// otherwise the copy constructor is non-trivial.
245203955Srdivacky    bool HasTrivialCopyConstructor : 1;
246203955Srdivacky
247203955Srdivacky    /// HasTrivialCopyAssignment - True when this class has a trivial copy
248203955Srdivacky    /// assignment operator.
249203955Srdivacky    ///
250203955Srdivacky    /// C++ [class.copy]p11.  A copy assignment operator for class X is
251203955Srdivacky    /// trivial if it is implicitly declared and if
252203955Srdivacky    /// * class X has no virtual functions and no virtual base classes, and
253203955Srdivacky    /// * each direct base class of X has a trivial copy assignment operator, and
254203955Srdivacky    /// * for all the nonstatic data members of X that are of class type (or
255203955Srdivacky    ///   array thereof), each such class type has a trivial copy assignment
256203955Srdivacky    ///   operator;
257203955Srdivacky    /// otherwise the copy assignment operator is non-trivial.
258203955Srdivacky    bool HasTrivialCopyAssignment : 1;
259203955Srdivacky
260203955Srdivacky    /// HasTrivialDestructor - True when this class has a trivial destructor.
261203955Srdivacky    ///
262203955Srdivacky    /// C++ [class.dtor]p3.  A destructor is trivial if it is an
263203955Srdivacky    /// implicitly-declared destructor and if:
264203955Srdivacky    /// * all of the direct base classes of its class have trivial destructors
265203955Srdivacky    ///   and
266203955Srdivacky    /// * for all of the non-static data members of its class that are of class
267203955Srdivacky    ///   type (or array thereof), each such class has a trivial destructor.
268203955Srdivacky    bool HasTrivialDestructor : 1;
269203955Srdivacky
270203955Srdivacky    /// ComputedVisibleConversions - True when visible conversion functions are
271203955Srdivacky    /// already computed and are available.
272203955Srdivacky    bool ComputedVisibleConversions : 1;
273193326Sed
274203955Srdivacky    /// Bases - Base classes of this class.
275203955Srdivacky    /// FIXME: This is wasted space for a union.
276203955Srdivacky    CXXBaseSpecifier *Bases;
277193326Sed
278203955Srdivacky    /// NumBases - The number of base class specifiers in Bases.
279203955Srdivacky    unsigned NumBases;
280193326Sed
281203955Srdivacky    /// VBases - direct and indirect virtual base classes of this class.
282203955Srdivacky    CXXBaseSpecifier *VBases;
283198092Srdivacky
284203955Srdivacky    /// NumVBases - The number of virtual base class specifiers in VBases.
285203955Srdivacky    unsigned NumVBases;
286198092Srdivacky
287203955Srdivacky    /// Conversions - Overload set containing the conversion functions
288203955Srdivacky    /// of this C++ class (but not its inherited conversion
289203955Srdivacky    /// functions). Each of the entries in this overload set is a
290203955Srdivacky    /// CXXConversionDecl.
291203955Srdivacky    UnresolvedSet<4> Conversions;
292193326Sed
293203955Srdivacky    /// VisibleConversions - Overload set containing the conversion
294203955Srdivacky    /// functions of this C++ class and all those inherited conversion
295203955Srdivacky    /// functions that are visible in this class. Each of the entries
296203955Srdivacky    /// in this overload set is a CXXConversionDecl or a
297203955Srdivacky    /// FunctionTemplateDecl.
298203955Srdivacky    UnresolvedSet<4> VisibleConversions;
299203955Srdivacky
300203955Srdivacky    /// Definition - The declaration which defines this record.
301203955Srdivacky    CXXRecordDecl *Definition;
302203955Srdivacky
303205219Srdivacky    /// FirstFriend - The first friend declaration in this class, or
304205219Srdivacky    /// null if there aren't any.  This is actually currently stored
305205219Srdivacky    /// in reverse order.
306205219Srdivacky    FriendDecl *FirstFriend;
307205219Srdivacky
308203955Srdivacky  } *DefinitionData;
309203955Srdivacky
310203955Srdivacky  struct DefinitionData &data() {
311203955Srdivacky    assert(DefinitionData && "queried property of class with no definition");
312203955Srdivacky    return *DefinitionData;
313203955Srdivacky  }
314203955Srdivacky
315203955Srdivacky  const struct DefinitionData &data() const {
316203955Srdivacky    assert(DefinitionData && "queried property of class with no definition");
317203955Srdivacky    return *DefinitionData;
318203955Srdivacky  }
319198092Srdivacky
320193326Sed  /// \brief The template or declaration that this declaration
321193326Sed  /// describes or was instantiated from, respectively.
322198092Srdivacky  ///
323193326Sed  /// For non-templates, this value will be NULL. For record
324193326Sed  /// declarations that describe a class template, this will be a
325193326Sed  /// pointer to a ClassTemplateDecl. For member
326193326Sed  /// classes of class template specializations, this will be the
327198092Srdivacky  /// MemberSpecializationInfo referring to the member class that was
328198092Srdivacky  /// instantiated or specialized.
329198092Srdivacky  llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*>
330193326Sed    TemplateOrInstantiation;
331198092Srdivacky
332193326Sedprotected:
333193326Sed  CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
334198092Srdivacky                SourceLocation L, IdentifierInfo *Id,
335198092Srdivacky                CXXRecordDecl *PrevDecl,
336198092Srdivacky                SourceLocation TKL = SourceLocation());
337193326Sed
338193326Sed  ~CXXRecordDecl();
339193326Sed
340193326Sedpublic:
341193326Sed  /// base_class_iterator - Iterator that traverses the base classes
342198092Srdivacky  /// of a class.
343193326Sed  typedef CXXBaseSpecifier*       base_class_iterator;
344193326Sed
345193326Sed  /// base_class_const_iterator - Iterator that traverses the base
346198092Srdivacky  /// classes of a class.
347193326Sed  typedef const CXXBaseSpecifier* base_class_const_iterator;
348193326Sed
349198092Srdivacky  /// reverse_base_class_iterator = Iterator that traverses the base classes
350198092Srdivacky  /// of a class in reverse order.
351198092Srdivacky  typedef std::reverse_iterator<base_class_iterator>
352198092Srdivacky    reverse_base_class_iterator;
353198092Srdivacky
354198092Srdivacky  /// reverse_base_class_iterator = Iterator that traverses the base classes
355198092Srdivacky  /// of a class in reverse order.
356198092Srdivacky  typedef std::reverse_iterator<base_class_const_iterator>
357198092Srdivacky    reverse_base_class_const_iterator;
358198092Srdivacky
359198092Srdivacky  virtual CXXRecordDecl *getCanonicalDecl() {
360198092Srdivacky    return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
361198092Srdivacky  }
362199482Srdivacky  virtual const CXXRecordDecl *getCanonicalDecl() const {
363199482Srdivacky    return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
364199482Srdivacky  }
365198092Srdivacky
366203955Srdivacky  CXXRecordDecl *getDefinition() const {
367203955Srdivacky    if (!DefinitionData) return 0;
368203955Srdivacky    return data().Definition;
369203955Srdivacky  }
370203955Srdivacky
371203955Srdivacky  bool hasDefinition() const { return DefinitionData != 0; }
372203955Srdivacky
373193326Sed  static CXXRecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC,
374193326Sed                               SourceLocation L, IdentifierInfo *Id,
375198092Srdivacky                               SourceLocation TKL = SourceLocation(),
376193326Sed                               CXXRecordDecl* PrevDecl=0,
377193326Sed                               bool DelayTypeCreation = false);
378198092Srdivacky
379195341Sed  virtual void Destroy(ASTContext& C);
380198092Srdivacky
381198092Srdivacky  bool isDynamicClass() const {
382203955Srdivacky    return data().Polymorphic || data().NumVBases != 0;
383198092Srdivacky  }
384198092Srdivacky
385193326Sed  /// setBases - Sets the base classes of this struct or class.
386203955Srdivacky  void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
387193326Sed
388193326Sed  /// getNumBases - Retrieves the number of base classes of this
389193326Sed  /// class.
390203955Srdivacky  unsigned getNumBases() const { return data().NumBases; }
391193326Sed
392203955Srdivacky  base_class_iterator bases_begin() { return data().Bases; }
393203955Srdivacky  base_class_const_iterator bases_begin() const { return data().Bases; }
394203955Srdivacky  base_class_iterator bases_end() { return bases_begin() + data().NumBases; }
395203955Srdivacky  base_class_const_iterator bases_end() const {
396203955Srdivacky    return bases_begin() + data().NumBases;
397203955Srdivacky  }
398198092Srdivacky  reverse_base_class_iterator       bases_rbegin() {
399198092Srdivacky    return reverse_base_class_iterator(bases_end());
400198092Srdivacky  }
401198092Srdivacky  reverse_base_class_const_iterator bases_rbegin() const {
402198092Srdivacky    return reverse_base_class_const_iterator(bases_end());
403198092Srdivacky  }
404198092Srdivacky  reverse_base_class_iterator bases_rend() {
405198092Srdivacky    return reverse_base_class_iterator(bases_begin());
406198092Srdivacky  }
407198092Srdivacky  reverse_base_class_const_iterator bases_rend() const {
408198092Srdivacky    return reverse_base_class_const_iterator(bases_begin());
409198092Srdivacky  }
410193326Sed
411198092Srdivacky  /// getNumVBases - Retrieves the number of virtual base classes of this
412198092Srdivacky  /// class.
413203955Srdivacky  unsigned getNumVBases() const { return data().NumVBases; }
414198092Srdivacky
415203955Srdivacky  base_class_iterator vbases_begin() { return data().VBases; }
416203955Srdivacky  base_class_const_iterator vbases_begin() const { return data().VBases; }
417203955Srdivacky  base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; }
418203955Srdivacky  base_class_const_iterator vbases_end() const {
419203955Srdivacky    return vbases_begin() + data().NumVBases;
420203955Srdivacky  }
421198092Srdivacky  reverse_base_class_iterator vbases_rbegin() {
422198092Srdivacky    return reverse_base_class_iterator(vbases_end());
423198092Srdivacky  }
424198092Srdivacky  reverse_base_class_const_iterator vbases_rbegin() const {
425198092Srdivacky    return reverse_base_class_const_iterator(vbases_end());
426198092Srdivacky  }
427198092Srdivacky  reverse_base_class_iterator vbases_rend() {
428198092Srdivacky    return reverse_base_class_iterator(vbases_begin());
429198092Srdivacky  }
430198092Srdivacky  reverse_base_class_const_iterator vbases_rend() const {
431198092Srdivacky    return reverse_base_class_const_iterator(vbases_begin());
432198092Srdivacky }
433198092Srdivacky
434202379Srdivacky  /// \brief Determine whether this class has any dependent base classes.
435202379Srdivacky  bool hasAnyDependentBases() const;
436202379Srdivacky
437198092Srdivacky  /// Iterator access to method members.  The method iterator visits
438198092Srdivacky  /// all method members of the class, including non-instance methods,
439198092Srdivacky  /// special methods, etc.
440198092Srdivacky  typedef specific_decl_iterator<CXXMethodDecl> method_iterator;
441198092Srdivacky
442198092Srdivacky  /// method_begin - Method begin iterator.  Iterates in the order the methods
443198092Srdivacky  /// were declared.
444198092Srdivacky  method_iterator method_begin() const {
445198092Srdivacky    return method_iterator(decls_begin());
446198092Srdivacky  }
447198092Srdivacky  /// method_end - Method end iterator.
448198092Srdivacky  method_iterator method_end() const {
449198092Srdivacky    return method_iterator(decls_end());
450198092Srdivacky  }
451198092Srdivacky
452198092Srdivacky  /// Iterator access to constructor members.
453198092Srdivacky  typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator;
454198092Srdivacky
455198092Srdivacky  ctor_iterator ctor_begin() const {
456198092Srdivacky    return ctor_iterator(decls_begin());
457198092Srdivacky  }
458198092Srdivacky  ctor_iterator ctor_end() const {
459198092Srdivacky    return ctor_iterator(decls_end());
460198092Srdivacky  }
461198092Srdivacky
462205219Srdivacky  /// An iterator over friend declarations.  All of these are defined
463205219Srdivacky  /// in DeclFriend.h.
464205219Srdivacky  class friend_iterator;
465205219Srdivacky  friend_iterator friend_begin() const;
466205219Srdivacky  friend_iterator friend_end() const;
467205219Srdivacky  void pushFriendDecl(FriendDecl *FD);
468205219Srdivacky
469193326Sed  /// hasConstCopyConstructor - Determines whether this class has a
470193326Sed  /// copy constructor that accepts a const-qualified argument.
471193326Sed  bool hasConstCopyConstructor(ASTContext &Context) const;
472193326Sed
473194711Sed  /// getCopyConstructor - Returns the copy constructor for this class
474198092Srdivacky  CXXConstructorDecl *getCopyConstructor(ASTContext &Context,
475194711Sed                                         unsigned TypeQuals) const;
476194711Sed
477193326Sed  /// hasConstCopyAssignment - Determines whether this class has a
478193326Sed  /// copy assignment operator that accepts a const-qualified argument.
479198092Srdivacky  /// It returns its decl in MD if found.
480198092Srdivacky  bool hasConstCopyAssignment(ASTContext &Context,
481198092Srdivacky                              const CXXMethodDecl *&MD) const;
482193326Sed
483193326Sed  /// addedConstructor - Notify the class that another constructor has
484193326Sed  /// been added. This routine helps maintain information about the
485193326Sed  /// class based on which constructors have been added.
486193326Sed  void addedConstructor(ASTContext &Context, CXXConstructorDecl *ConDecl);
487193326Sed
488193326Sed  /// hasUserDeclaredConstructor - Whether this class has any
489193326Sed  /// user-declared constructors. When true, a default constructor
490193326Sed  /// will not be implicitly declared.
491198092Srdivacky  bool hasUserDeclaredConstructor() const {
492203955Srdivacky    return data().UserDeclaredConstructor;
493198092Srdivacky  }
494193326Sed
495193326Sed  /// hasUserDeclaredCopyConstructor - Whether this class has a
496193326Sed  /// user-declared copy constructor. When false, a copy constructor
497193326Sed  /// will be implicitly declared.
498193326Sed  bool hasUserDeclaredCopyConstructor() const {
499203955Srdivacky    return data().UserDeclaredCopyConstructor;
500193326Sed  }
501193326Sed
502193326Sed  /// addedAssignmentOperator - Notify the class that another assignment
503193326Sed  /// operator has been added. This routine helps maintain information about the
504193326Sed   /// class based on which operators have been added.
505193326Sed  void addedAssignmentOperator(ASTContext &Context, CXXMethodDecl *OpDecl);
506193326Sed
507193326Sed  /// hasUserDeclaredCopyAssignment - Whether this class has a
508193326Sed  /// user-declared copy assignment operator. When false, a copy
509193326Sed  /// assigment operator will be implicitly declared.
510193326Sed  bool hasUserDeclaredCopyAssignment() const {
511203955Srdivacky    return data().UserDeclaredCopyAssignment;
512193326Sed  }
513193326Sed
514193326Sed  /// hasUserDeclaredDestructor - Whether this class has a
515193326Sed  /// user-declared destructor. When false, a destructor will be
516193326Sed  /// implicitly declared.
517203955Srdivacky  bool hasUserDeclaredDestructor() const {
518203955Srdivacky    return data().UserDeclaredDestructor;
519203955Srdivacky  }
520193326Sed
521193326Sed  /// setUserDeclaredDestructor - Set whether this class has a
522193326Sed  /// user-declared destructor. If not set by the time the class is
523193326Sed  /// fully defined, a destructor will be implicitly declared.
524198092Srdivacky  void setUserDeclaredDestructor(bool UCD) {
525203955Srdivacky    data().UserDeclaredDestructor = UCD;
526193326Sed  }
527193326Sed
528193326Sed  /// getConversions - Retrieve the overload set containing all of the
529193326Sed  /// conversion functions in this class.
530202879Srdivacky  UnresolvedSetImpl *getConversionFunctions() {
531203955Srdivacky    return &data().Conversions;
532193326Sed  }
533202879Srdivacky  const UnresolvedSetImpl *getConversionFunctions() const {
534203955Srdivacky    return &data().Conversions;
535193326Sed  }
536193326Sed
537202879Srdivacky  typedef UnresolvedSetImpl::iterator conversion_iterator;
538203955Srdivacky  conversion_iterator conversion_begin() const {
539203955Srdivacky    return getConversionFunctions()->begin();
540203955Srdivacky  }
541203955Srdivacky  conversion_iterator conversion_end() const {
542203955Srdivacky    return getConversionFunctions()->end();
543203955Srdivacky  }
544199990Srdivacky
545199990Srdivacky  /// Replaces a conversion function with a new declaration.
546199990Srdivacky  ///
547199990Srdivacky  /// Returns true if the old conversion was found.
548199990Srdivacky  bool replaceConversion(const NamedDecl* Old, NamedDecl *New) {
549203955Srdivacky    return getConversionFunctions()->replace(Old, New);
550199990Srdivacky  }
551199990Srdivacky
552198092Srdivacky  /// getVisibleConversionFunctions - get all conversion functions visible
553198092Srdivacky  /// in current class; including conversion function templates.
554202879Srdivacky  const UnresolvedSetImpl *getVisibleConversionFunctions();
555199990Srdivacky
556193326Sed  /// addConversionFunction - Add a new conversion function to the
557193326Sed  /// list of conversion functions.
558198092Srdivacky  void addConversionFunction(CXXConversionDecl *ConvDecl);
559193326Sed
560198092Srdivacky  /// \brief Add a new conversion function template to the list of conversion
561198092Srdivacky  /// functions.
562198092Srdivacky  void addConversionFunction(FunctionTemplateDecl *ConvDecl);
563198092Srdivacky
564193326Sed  /// isAggregate - Whether this class is an aggregate (C++
565193326Sed  /// [dcl.init.aggr]), which is a class with no user-declared
566193326Sed  /// constructors, no private or protected non-static data members,
567193326Sed  /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1).
568203955Srdivacky  bool isAggregate() const { return data().Aggregate; }
569193326Sed
570193326Sed  /// setAggregate - Set whether this class is an aggregate (C++
571193326Sed  /// [dcl.init.aggr]).
572203955Srdivacky  void setAggregate(bool Agg) { data().Aggregate = Agg; }
573193326Sed
574200583Srdivacky  /// setMethodAsVirtual - Make input method virtual and set the necesssary
575200583Srdivacky  /// special function bits and other bits accordingly.
576200583Srdivacky  void setMethodAsVirtual(FunctionDecl *Method);
577200583Srdivacky
578193326Sed  /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class
579193326Sed  /// that is an aggregate that has no non-static non-POD data members, no
580193326Sed  /// reference data members, no user-defined copy assignment operator and no
581193326Sed  /// user-defined destructor.
582203955Srdivacky  bool isPOD() const { return data().PlainOldData; }
583193326Sed
584193326Sed  /// setPOD - Set whether this class is a POD-type (C++ [class]p4).
585203955Srdivacky  void setPOD(bool POD) { data().PlainOldData = POD; }
586193326Sed
587198092Srdivacky  /// isEmpty - Whether this class is empty (C++0x [meta.unary.prop]), which
588198092Srdivacky  /// means it has a virtual function, virtual base, data member (other than
589198092Srdivacky  /// 0-width bit-field) or inherits from a non-empty class. Does NOT include
590198092Srdivacky  /// a check for union-ness.
591203955Srdivacky  bool isEmpty() const { return data().Empty; }
592198092Srdivacky
593198092Srdivacky  /// Set whether this class is empty (C++0x [meta.unary.prop])
594203955Srdivacky  void setEmpty(bool Emp) { data().Empty = Emp; }
595198092Srdivacky
596193326Sed  /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]),
597193326Sed  /// which means that the class contains or inherits a virtual function.
598203955Srdivacky  bool isPolymorphic() const { return data().Polymorphic; }
599193326Sed
600193326Sed  /// setPolymorphic - Set whether this class is polymorphic (C++
601193326Sed  /// [class.virtual]).
602203955Srdivacky  void setPolymorphic(bool Poly) { data().Polymorphic = Poly; }
603193326Sed
604193326Sed  /// isAbstract - Whether this class is abstract (C++ [class.abstract]),
605193326Sed  /// which means that the class contains or inherits a pure virtual function.
606203955Srdivacky  bool isAbstract() const { return data().Abstract; }
607198092Srdivacky
608193326Sed  /// setAbstract - Set whether this class is abstract (C++ [class.abstract])
609203955Srdivacky  void setAbstract(bool Abs) { data().Abstract = Abs; }
610198092Srdivacky
611193326Sed  // hasTrivialConstructor - Whether this class has a trivial constructor
612193326Sed  // (C++ [class.ctor]p5)
613203955Srdivacky  bool hasTrivialConstructor() const { return data().HasTrivialConstructor; }
614198092Srdivacky
615193326Sed  // setHasTrivialConstructor - Set whether this class has a trivial constructor
616193326Sed  // (C++ [class.ctor]p5)
617203955Srdivacky  void setHasTrivialConstructor(bool TC) { data().HasTrivialConstructor = TC; }
618198092Srdivacky
619198092Srdivacky  // hasTrivialCopyConstructor - Whether this class has a trivial copy
620198092Srdivacky  // constructor (C++ [class.copy]p6)
621203955Srdivacky  bool hasTrivialCopyConstructor() const {
622203955Srdivacky    return data().HasTrivialCopyConstructor;
623203955Srdivacky  }
624198092Srdivacky
625198092Srdivacky  // setHasTrivialCopyConstructor - Set whether this class has a trivial
626198092Srdivacky  // copy constructor (C++ [class.copy]p6)
627203955Srdivacky  void setHasTrivialCopyConstructor(bool TC) {
628203955Srdivacky    data().HasTrivialCopyConstructor = TC;
629203955Srdivacky  }
630198092Srdivacky
631198092Srdivacky  // hasTrivialCopyAssignment - Whether this class has a trivial copy
632198092Srdivacky  // assignment operator (C++ [class.copy]p11)
633203955Srdivacky  bool hasTrivialCopyAssignment() const {
634203955Srdivacky    return data().HasTrivialCopyAssignment;
635203955Srdivacky  }
636198092Srdivacky
637198092Srdivacky  // setHasTrivialCopyAssignment - Set whether this class has a
638198092Srdivacky  // trivial copy assignment operator (C++ [class.copy]p11)
639203955Srdivacky  void setHasTrivialCopyAssignment(bool TC) {
640203955Srdivacky    data().HasTrivialCopyAssignment = TC;
641203955Srdivacky  }
642198092Srdivacky
643193326Sed  // hasTrivialDestructor - Whether this class has a trivial destructor
644193326Sed  // (C++ [class.dtor]p3)
645203955Srdivacky  bool hasTrivialDestructor() const { return data().HasTrivialDestructor; }
646198092Srdivacky
647193326Sed  // setHasTrivialDestructor - Set whether this class has a trivial destructor
648193326Sed  // (C++ [class.dtor]p3)
649203955Srdivacky  void setHasTrivialDestructor(bool TC) { data().HasTrivialDestructor = TC; }
650198092Srdivacky
651193326Sed  /// \brief If this record is an instantiation of a member class,
652193326Sed  /// retrieves the member class from which it was instantiated.
653193326Sed  ///
654193326Sed  /// This routine will return non-NULL for (non-templated) member
655193326Sed  /// classes of class templates. For example, given:
656193326Sed  ///
657193326Sed  /// \code
658193326Sed  /// template<typename T>
659193326Sed  /// struct X {
660193326Sed  ///   struct A { };
661193326Sed  /// };
662193326Sed  /// \endcode
663193326Sed  ///
664193326Sed  /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
665193326Sed  /// whose parent is the class template specialization X<int>. For
666193326Sed  /// this declaration, getInstantiatedFromMemberClass() will return
667193326Sed  /// the CXXRecordDecl X<T>::A. When a complete definition of
668193326Sed  /// X<int>::A is required, it will be instantiated from the
669193326Sed  /// declaration returned by getInstantiatedFromMemberClass().
670198092Srdivacky  CXXRecordDecl *getInstantiatedFromMemberClass() const;
671198092Srdivacky
672198092Srdivacky  /// \brief If this class is an instantiation of a member class of a
673198092Srdivacky  /// class template specialization, retrieves the member specialization
674198092Srdivacky  /// information.
675198092Srdivacky  MemberSpecializationInfo *getMemberSpecializationInfo() const;
676198092Srdivacky
677193326Sed  /// \brief Specify that this record is an instantiation of the
678193326Sed  /// member class RD.
679198092Srdivacky  void setInstantiationOfMemberClass(CXXRecordDecl *RD,
680198092Srdivacky                                     TemplateSpecializationKind TSK);
681193326Sed
682193326Sed  /// \brief Retrieves the class template that is described by this
683193326Sed  /// class declaration.
684193326Sed  ///
685193326Sed  /// Every class template is represented as a ClassTemplateDecl and a
686193326Sed  /// CXXRecordDecl. The former contains template properties (such as
687193326Sed  /// the template parameter lists) while the latter contains the
688193326Sed  /// actual description of the template's
689193326Sed  /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
690193326Sed  /// CXXRecordDecl that from a ClassTemplateDecl, while
691193326Sed  /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
692193326Sed  /// a CXXRecordDecl.
693193326Sed  ClassTemplateDecl *getDescribedClassTemplate() const {
694193326Sed    return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>();
695193326Sed  }
696193326Sed
697193326Sed  void setDescribedClassTemplate(ClassTemplateDecl *Template) {
698193326Sed    TemplateOrInstantiation = Template;
699193326Sed  }
700193326Sed
701198092Srdivacky  /// \brief Determine whether this particular class is a specialization or
702198092Srdivacky  /// instantiation of a class template or member class of a class template,
703198092Srdivacky  /// and how it was instantiated or specialized.
704200583Srdivacky  TemplateSpecializationKind getTemplateSpecializationKind() const;
705198092Srdivacky
706198092Srdivacky  /// \brief Set the kind of specialization or template instantiation this is.
707198092Srdivacky  void setTemplateSpecializationKind(TemplateSpecializationKind TSK);
708198092Srdivacky
709194613Sed  /// getDefaultConstructor - Returns the default constructor for this class
710194613Sed  CXXConstructorDecl *getDefaultConstructor(ASTContext &Context);
711198092Srdivacky
712193326Sed  /// getDestructor - Returns the destructor decl for this class.
713204643Srdivacky  CXXDestructorDecl *getDestructor(ASTContext &Context) const;
714198092Srdivacky
715195099Sed  /// isLocalClass - If the class is a local class [class.local], returns
716195099Sed  /// the enclosing function declaration.
717195099Sed  const FunctionDecl *isLocalClass() const {
718195099Sed    if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
719195099Sed      return RD->isLocalClass();
720198092Srdivacky
721195099Sed    return dyn_cast<FunctionDecl>(getDeclContext());
722195099Sed  }
723198092Srdivacky
724198092Srdivacky  /// \brief Determine whether this class is derived from the class \p Base.
725198092Srdivacky  ///
726198092Srdivacky  /// This routine only determines whether this class is derived from \p Base,
727198092Srdivacky  /// but does not account for factors that may make a Derived -> Base class
728198092Srdivacky  /// ill-formed, such as private/protected inheritance or multiple, ambiguous
729198092Srdivacky  /// base class subobjects.
730198092Srdivacky  ///
731198092Srdivacky  /// \param Base the base class we are searching for.
732198092Srdivacky  ///
733198092Srdivacky  /// \returns true if this class is derived from Base, false otherwise.
734199482Srdivacky  bool isDerivedFrom(CXXRecordDecl *Base) const;
735195099Sed
736198092Srdivacky  /// \brief Determine whether this class is derived from the type \p Base.
737198092Srdivacky  ///
738198092Srdivacky  /// This routine only determines whether this class is derived from \p Base,
739198092Srdivacky  /// but does not account for factors that may make a Derived -> Base class
740198092Srdivacky  /// ill-formed, such as private/protected inheritance or multiple, ambiguous
741198092Srdivacky  /// base class subobjects.
742198092Srdivacky  ///
743198092Srdivacky  /// \param Base the base class we are searching for.
744198092Srdivacky  ///
745198092Srdivacky  /// \param Paths will contain the paths taken from the current class to the
746198092Srdivacky  /// given \p Base class.
747198092Srdivacky  ///
748198092Srdivacky  /// \returns true if this class is derived from Base, false otherwise.
749198092Srdivacky  ///
750198092Srdivacky  /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than
751198092Srdivacky  /// tangling input and output in \p Paths
752199482Srdivacky  bool isDerivedFrom(CXXRecordDecl *Base, CXXBasePaths &Paths) const;
753200583Srdivacky
754204643Srdivacky  /// \brief Determine whether this class is virtually derived from
755204643Srdivacky  /// the class \p Base.
756204643Srdivacky  ///
757204643Srdivacky  /// This routine only determines whether this class is virtually
758204643Srdivacky  /// derived from \p Base, but does not account for factors that may
759204643Srdivacky  /// make a Derived -> Base class ill-formed, such as
760204643Srdivacky  /// private/protected inheritance or multiple, ambiguous base class
761204643Srdivacky  /// subobjects.
762204643Srdivacky  ///
763204643Srdivacky  /// \param Base the base class we are searching for.
764204643Srdivacky  ///
765204643Srdivacky  /// \returns true if this class is virtually derived from Base,
766204643Srdivacky  /// false otherwise.
767204643Srdivacky  bool isVirtuallyDerivedFrom(CXXRecordDecl *Base) const;
768204643Srdivacky
769200583Srdivacky  /// \brief Determine whether this class is provably not derived from
770200583Srdivacky  /// the type \p Base.
771200583Srdivacky  bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
772200583Srdivacky
773200583Srdivacky  /// \brief Function type used by forallBases() as a callback.
774200583Srdivacky  ///
775200583Srdivacky  /// \param Base the definition of the base class
776200583Srdivacky  ///
777200583Srdivacky  /// \returns true if this base matched the search criteria
778200583Srdivacky  typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition,
779200583Srdivacky                                   void *UserData);
780200583Srdivacky
781200583Srdivacky  /// \brief Determines if the given callback holds for all the direct
782200583Srdivacky  /// or indirect base classes of this type.
783200583Srdivacky  ///
784200583Srdivacky  /// The class itself does not count as a base class.  This routine
785200583Srdivacky  /// returns false if the class has non-computable base classes.
786200583Srdivacky  ///
787200583Srdivacky  /// \param AllowShortCircuit if false, forces the callback to be called
788200583Srdivacky  /// for every base class, even if a dependent or non-matching base was
789200583Srdivacky  /// found.
790200583Srdivacky  bool forallBases(ForallBasesCallback *BaseMatches, void *UserData,
791200583Srdivacky                   bool AllowShortCircuit = true) const;
792198092Srdivacky
793198092Srdivacky  /// \brief Function type used by lookupInBases() to determine whether a
794198092Srdivacky  /// specific base class subobject matches the lookup criteria.
795198092Srdivacky  ///
796198092Srdivacky  /// \param Specifier the base-class specifier that describes the inheritance
797198092Srdivacky  /// from the base class we are trying to match.
798198092Srdivacky  ///
799198092Srdivacky  /// \param Path the current path, from the most-derived class down to the
800198092Srdivacky  /// base named by the \p Specifier.
801198092Srdivacky  ///
802198092Srdivacky  /// \param UserData a single pointer to user-specified data, provided to
803198092Srdivacky  /// lookupInBases().
804198092Srdivacky  ///
805198092Srdivacky  /// \returns true if this base matched the search criteria, false otherwise.
806199482Srdivacky  typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier,
807198092Srdivacky                                   CXXBasePath &Path,
808198092Srdivacky                                   void *UserData);
809198092Srdivacky
810198092Srdivacky  /// \brief Look for entities within the base classes of this C++ class,
811198092Srdivacky  /// transitively searching all base class subobjects.
812198092Srdivacky  ///
813198092Srdivacky  /// This routine uses the callback function \p BaseMatches to find base
814198092Srdivacky  /// classes meeting some search criteria, walking all base class subobjects
815198092Srdivacky  /// and populating the given \p Paths structure with the paths through the
816198092Srdivacky  /// inheritance hierarchy that resulted in a match. On a successful search,
817198092Srdivacky  /// the \p Paths structure can be queried to retrieve the matching paths and
818198092Srdivacky  /// to determine if there were any ambiguities.
819198092Srdivacky  ///
820198092Srdivacky  /// \param BaseMatches callback function used to determine whether a given
821198092Srdivacky  /// base matches the user-defined search criteria.
822198092Srdivacky  ///
823198092Srdivacky  /// \param UserData user data pointer that will be provided to \p BaseMatches.
824198092Srdivacky  ///
825198092Srdivacky  /// \param Paths used to record the paths from this class to its base class
826198092Srdivacky  /// subobjects that match the search criteria.
827198092Srdivacky  ///
828198092Srdivacky  /// \returns true if there exists any path from this class to a base class
829198092Srdivacky  /// subobject that matches the search criteria.
830198092Srdivacky  bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData,
831199482Srdivacky                     CXXBasePaths &Paths) const;
832198092Srdivacky
833198092Srdivacky  /// \brief Base-class lookup callback that determines whether the given
834198092Srdivacky  /// base class specifier refers to a specific class declaration.
835198092Srdivacky  ///
836198092Srdivacky  /// This callback can be used with \c lookupInBases() to determine whether
837198092Srdivacky  /// a given derived class has is a base class subobject of a particular type.
838198092Srdivacky  /// The user data pointer should refer to the canonical CXXRecordDecl of the
839198092Srdivacky  /// base class that we are searching for.
840199482Srdivacky  static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
841199482Srdivacky                            CXXBasePath &Path, void *BaseRecord);
842204643Srdivacky
843204643Srdivacky  /// \brief Base-class lookup callback that determines whether the
844204643Srdivacky  /// given base class specifier refers to a specific class
845204643Srdivacky  /// declaration and describes virtual derivation.
846204643Srdivacky  ///
847204643Srdivacky  /// This callback can be used with \c lookupInBases() to determine
848204643Srdivacky  /// whether a given derived class has is a virtual base class
849204643Srdivacky  /// subobject of a particular type.  The user data pointer should
850204643Srdivacky  /// refer to the canonical CXXRecordDecl of the base class that we
851204643Srdivacky  /// are searching for.
852204643Srdivacky  static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
853204643Srdivacky                                   CXXBasePath &Path, void *BaseRecord);
854198092Srdivacky
855198092Srdivacky  /// \brief Base-class lookup callback that determines whether there exists
856198092Srdivacky  /// a tag with the given name.
857198092Srdivacky  ///
858198092Srdivacky  /// This callback can be used with \c lookupInBases() to find tag members
859198092Srdivacky  /// of the given name within a C++ class hierarchy. The user data pointer
860198092Srdivacky  /// is an opaque \c DeclarationName pointer.
861199482Srdivacky  static bool FindTagMember(const CXXBaseSpecifier *Specifier,
862199482Srdivacky                            CXXBasePath &Path, void *Name);
863198092Srdivacky
864198092Srdivacky  /// \brief Base-class lookup callback that determines whether there exists
865198092Srdivacky  /// a member with the given name.
866198092Srdivacky  ///
867198092Srdivacky  /// This callback can be used with \c lookupInBases() to find members
868198092Srdivacky  /// of the given name within a C++ class hierarchy. The user data pointer
869198092Srdivacky  /// is an opaque \c DeclarationName pointer.
870199482Srdivacky  static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
871199482Srdivacky                                 CXXBasePath &Path, void *Name);
872198092Srdivacky
873198092Srdivacky  /// \brief Base-class lookup callback that determines whether there exists
874198092Srdivacky  /// a member with the given name that can be used in a nested-name-specifier.
875198092Srdivacky  ///
876198092Srdivacky  /// This callback can be used with \c lookupInBases() to find membes of
877198092Srdivacky  /// the given name within a C++ class hierarchy that can occur within
878198092Srdivacky  /// nested-name-specifiers.
879199482Srdivacky  static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier,
880198092Srdivacky                                            CXXBasePath &Path,
881198092Srdivacky                                            void *UserData);
882198092Srdivacky
883193326Sed  /// viewInheritance - Renders and displays an inheritance diagram
884193326Sed  /// for this C++ class and all of its base classes (transitively) using
885193326Sed  /// GraphViz.
886193326Sed  void viewInheritance(ASTContext& Context) const;
887193326Sed
888202879Srdivacky  /// MergeAccess - Calculates the access of a decl that is reached
889202879Srdivacky  /// along a path.
890202879Srdivacky  static AccessSpecifier MergeAccess(AccessSpecifier PathAccess,
891202879Srdivacky                                     AccessSpecifier DeclAccess) {
892202879Srdivacky    assert(DeclAccess != AS_none);
893202879Srdivacky    if (DeclAccess == AS_private) return AS_none;
894202879Srdivacky    return (PathAccess > DeclAccess ? PathAccess : DeclAccess);
895202879Srdivacky  }
896202879Srdivacky
897203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
898203955Srdivacky  static bool classofKind(Kind K) {
899203955Srdivacky    return K == CXXRecord ||
900203955Srdivacky           K == ClassTemplateSpecialization ||
901203955Srdivacky           K == ClassTemplatePartialSpecialization;
902193326Sed  }
903193326Sed  static bool classof(const CXXRecordDecl *D) { return true; }
904198092Srdivacky  static bool classof(const ClassTemplateSpecializationDecl *D) {
905198092Srdivacky    return true;
906193326Sed  }
907193326Sed};
908193326Sed
909193326Sed/// CXXMethodDecl - Represents a static or instance method of a
910193326Sed/// struct/union/class.
911193326Sedclass CXXMethodDecl : public FunctionDecl {
912193326Sedprotected:
913193326Sed  CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation L,
914200583Srdivacky                DeclarationName N, QualType T, TypeSourceInfo *TInfo,
915193326Sed                bool isStatic, bool isInline)
916200583Srdivacky    : FunctionDecl(DK, RD, L, N, T, TInfo, (isStatic ? Static : None),
917193326Sed                   isInline) {}
918193326Sed
919193326Sedpublic:
920193326Sed  static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
921193326Sed                              SourceLocation L, DeclarationName N,
922200583Srdivacky                              QualType T, TypeSourceInfo *TInfo,
923198092Srdivacky                              bool isStatic = false,
924193326Sed                              bool isInline = false);
925198092Srdivacky
926193326Sed  bool isStatic() const { return getStorageClass() == Static; }
927193326Sed  bool isInstance() const { return !isStatic(); }
928193326Sed
929198092Srdivacky  bool isVirtual() const {
930198092Srdivacky    CXXMethodDecl *CD =
931198092Srdivacky      cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl());
932198092Srdivacky
933198092Srdivacky    if (CD->isVirtualAsWritten())
934198092Srdivacky      return true;
935198092Srdivacky
936198092Srdivacky    return (CD->begin_overridden_methods() != CD->end_overridden_methods());
937193326Sed  }
938198092Srdivacky
939198092Srdivacky  /// \brief Determine whether this is a usual deallocation function
940198092Srdivacky  /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded
941198092Srdivacky  /// delete or delete[] operator with a particular signature.
942198092Srdivacky  bool isUsualDeallocationFunction() const;
943198092Srdivacky
944198092Srdivacky  const CXXMethodDecl *getCanonicalDecl() const {
945198092Srdivacky    return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
946198092Srdivacky  }
947198092Srdivacky  CXXMethodDecl *getCanonicalDecl() {
948198092Srdivacky    return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
949198092Srdivacky  }
950198092Srdivacky
951198092Srdivacky  ///
952198092Srdivacky  void addOverriddenMethod(const CXXMethodDecl *MD);
953193326Sed
954193326Sed  typedef const CXXMethodDecl ** method_iterator;
955198092Srdivacky
956193326Sed  method_iterator begin_overridden_methods() const;
957193326Sed  method_iterator end_overridden_methods() const;
958198092Srdivacky
959193326Sed  /// getParent - Returns the parent of this method declaration, which
960193326Sed  /// is the class in which this method is defined.
961198092Srdivacky  const CXXRecordDecl *getParent() const {
962198092Srdivacky    return cast<CXXRecordDecl>(FunctionDecl::getParent());
963193326Sed  }
964198092Srdivacky
965193326Sed  /// getParent - Returns the parent of this method declaration, which
966193326Sed  /// is the class in which this method is defined.
967198092Srdivacky  CXXRecordDecl *getParent() {
968193326Sed    return const_cast<CXXRecordDecl *>(
969193326Sed             cast<CXXRecordDecl>(FunctionDecl::getParent()));
970193326Sed  }
971193326Sed
972193326Sed  /// getThisType - Returns the type of 'this' pointer.
973193326Sed  /// Should only be called for instance methods.
974193326Sed  QualType getThisType(ASTContext &C) const;
975193326Sed
976193326Sed  unsigned getTypeQualifiers() const {
977198092Srdivacky    return getType()->getAs<FunctionProtoType>()->getTypeQuals();
978193326Sed  }
979193326Sed
980200583Srdivacky  bool hasInlineBody() const;
981200583Srdivacky
982193326Sed  // Implement isa/cast/dyncast/etc.
983203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
984203955Srdivacky  static bool classof(const CXXMethodDecl *D) { return true; }
985203955Srdivacky  static bool classofKind(Kind K) {
986203955Srdivacky    return K >= CXXMethod && K <= CXXConversion;
987193326Sed  }
988193326Sed};
989193326Sed
990193326Sed/// CXXBaseOrMemberInitializer - Represents a C++ base or member
991193326Sed/// initializer, which is part of a constructor initializer that
992193326Sed/// initializes one non-static member variable or one base class. For
993193326Sed/// example, in the following, both 'A(a)' and 'f(3.14159)' are member
994193326Sed/// initializers:
995193326Sed///
996193326Sed/// @code
997193326Sed/// class A { };
998193326Sed/// class B : public A {
999193326Sed///   float f;
1000193326Sed/// public:
1001193326Sed///   B(A& a) : A(a), f(3.14159) { }
1002193326Sed/// };
1003194613Sed/// @endcode
1004193326Sedclass CXXBaseOrMemberInitializer {
1005200583Srdivacky  /// \brief Either the base class name (stored as a TypeSourceInfo*) or the
1006200583Srdivacky  /// field being initialized.
1007200583Srdivacky  llvm::PointerUnion<TypeSourceInfo *, FieldDecl *> BaseOrMember;
1008200583Srdivacky
1009200583Srdivacky  /// \brief The source location for the field name.
1010200583Srdivacky  SourceLocation MemberLocation;
1011200583Srdivacky
1012203955Srdivacky  /// \brief The argument used to initialize the base or member, which may
1013203955Srdivacky  /// end up constructing an object (when multiple arguments are involved).
1014203955Srdivacky  Stmt *Init;
1015198092Srdivacky
1016198092Srdivacky  /// \brief Stores either the constructor to call to initialize this base or
1017198092Srdivacky  /// member (a CXXConstructorDecl pointer), or stores the anonymous union of
1018198092Srdivacky  /// which the initialized value is a member.
1019198092Srdivacky  ///
1020198092Srdivacky  /// When the value is a FieldDecl pointer, 'BaseOrMember' is class's
1021198092Srdivacky  /// anonymous union data member, this field holds the FieldDecl for the
1022198092Srdivacky  /// member of the anonymous union being initialized.
1023198092Srdivacky  /// @code
1024198092Srdivacky  /// struct X {
1025198092Srdivacky  ///   X() : au_i1(123) {}
1026198092Srdivacky  ///   union {
1027198092Srdivacky  ///     int au_i1;
1028198092Srdivacky  ///     float au_f1;
1029198092Srdivacky  ///   };
1030198092Srdivacky  /// };
1031198092Srdivacky  /// @endcode
1032198092Srdivacky  /// In above example, BaseOrMember holds the field decl. for anonymous union
1033198092Srdivacky  /// and AnonUnionMember holds field decl for au_i1.
1034203955Srdivacky  FieldDecl *AnonUnionMember;
1035198092Srdivacky
1036200583Srdivacky  /// LParenLoc - Location of the left paren of the ctor-initializer.
1037200583Srdivacky  SourceLocation LParenLoc;
1038193326Sed
1039198092Srdivacky  /// RParenLoc - Location of the right paren of the ctor-initializer.
1040198092Srdivacky  SourceLocation RParenLoc;
1041198092Srdivacky
1042193326Sedpublic:
1043193326Sed  /// CXXBaseOrMemberInitializer - Creates a new base-class initializer.
1044198092Srdivacky  explicit
1045200583Srdivacky  CXXBaseOrMemberInitializer(ASTContext &Context,
1046203955Srdivacky                             TypeSourceInfo *TInfo,
1047200583Srdivacky                             SourceLocation L,
1048203955Srdivacky                             Expr *Init,
1049200583Srdivacky                             SourceLocation R);
1050193326Sed
1051193326Sed  /// CXXBaseOrMemberInitializer - Creates a new member initializer.
1052198092Srdivacky  explicit
1053200583Srdivacky  CXXBaseOrMemberInitializer(ASTContext &Context,
1054200583Srdivacky                             FieldDecl *Member, SourceLocation MemberLoc,
1055203955Srdivacky                             SourceLocation L,
1056203955Srdivacky                             Expr *Init,
1057200583Srdivacky                             SourceLocation R);
1058193326Sed
1059200583Srdivacky  /// \brief Destroy the base or member initializer.
1060200583Srdivacky  void Destroy(ASTContext &Context);
1061193326Sed
1062193326Sed  /// isBaseInitializer - Returns true when this initializer is
1063193326Sed  /// initializing a base class.
1064200583Srdivacky  bool isBaseInitializer() const { return BaseOrMember.is<TypeSourceInfo*>(); }
1065193326Sed
1066193326Sed  /// isMemberInitializer - Returns true when this initializer is
1067193326Sed  /// initializing a non-static data member.
1068200583Srdivacky  bool isMemberInitializer() const { return BaseOrMember.is<FieldDecl*>(); }
1069193326Sed
1070200583Srdivacky  /// If this is a base class initializer, returns the type of the
1071200583Srdivacky  /// base class with location information. Otherwise, returns an NULL
1072200583Srdivacky  /// type location.
1073200583Srdivacky  TypeLoc getBaseClassLoc() const;
1074193326Sed
1075200583Srdivacky  /// If this is a base class initializer, returns the type of the base class.
1076200583Srdivacky  /// Otherwise, returns NULL.
1077200583Srdivacky  const Type *getBaseClass() const;
1078200583Srdivacky  Type *getBaseClass();
1079200583Srdivacky
1080200583Srdivacky  /// \brief Returns the declarator information for a base class initializer.
1081200583Srdivacky  TypeSourceInfo *getBaseClassInfo() const {
1082200583Srdivacky    return BaseOrMember.dyn_cast<TypeSourceInfo *>();
1083193326Sed  }
1084200583Srdivacky
1085193326Sed  /// getMember - If this is a member initializer, returns the
1086193326Sed  /// declaration of the non-static data member being
1087193326Sed  /// initialized. Otherwise, returns NULL.
1088198092Srdivacky  FieldDecl *getMember() {
1089193326Sed    if (isMemberInitializer())
1090200583Srdivacky      return BaseOrMember.get<FieldDecl*>();
1091193326Sed    else
1092193326Sed      return 0;
1093193326Sed  }
1094193326Sed
1095200583Srdivacky  SourceLocation getMemberLocation() const {
1096200583Srdivacky    return MemberLocation;
1097198092Srdivacky  }
1098198092Srdivacky
1099200583Srdivacky  void setMember(FieldDecl *Member) {
1100200583Srdivacky    assert(isMemberInitializer());
1101200583Srdivacky    BaseOrMember = Member;
1102200583Srdivacky  }
1103200583Srdivacky
1104200583Srdivacky  /// \brief Determine the source location of the initializer.
1105200583Srdivacky  SourceLocation getSourceLocation() const;
1106200583Srdivacky
1107200583Srdivacky  /// \brief Determine the source range covering the entire initializer.
1108200583Srdivacky  SourceRange getSourceRange() const;
1109200583Srdivacky
1110198092Srdivacky  FieldDecl *getAnonUnionMember() const {
1111203955Srdivacky    return AnonUnionMember;
1112198092Srdivacky  }
1113198092Srdivacky  void setAnonUnionMember(FieldDecl *anonMember) {
1114203955Srdivacky    AnonUnionMember = anonMember;
1115198092Srdivacky  }
1116198092Srdivacky
1117200583Srdivacky  SourceLocation getLParenLoc() const { return LParenLoc; }
1118198092Srdivacky  SourceLocation getRParenLoc() const { return RParenLoc; }
1119193326Sed
1120203955Srdivacky  Expr *getInit() { return static_cast<Expr *>(Init); }
1121193326Sed};
1122193326Sed
1123193326Sed/// CXXConstructorDecl - Represents a C++ constructor within a
1124193326Sed/// class. For example:
1125198092Srdivacky///
1126193326Sed/// @code
1127193326Sed/// class X {
1128193326Sed/// public:
1129193326Sed///   explicit X(int); // represented by a CXXConstructorDecl.
1130193326Sed/// };
1131193326Sed/// @endcode
1132193326Sedclass CXXConstructorDecl : public CXXMethodDecl {
1133203955Srdivacky  /// IsExplicitSpecified - Whether this constructor declaration has the
1134203955Srdivacky  /// 'explicit' keyword specified.
1135203955Srdivacky  bool IsExplicitSpecified : 1;
1136193326Sed
1137193326Sed  /// ImplicitlyDefined - Whether this constructor was implicitly
1138193326Sed  /// defined by the compiler. When false, the constructor was defined
1139193326Sed  /// by the user. In C++03, this flag will have the same value as
1140193326Sed  /// Implicit. In C++0x, however, a constructor that is
1141193326Sed  /// explicitly defaulted (i.e., defined with " = default") will have
1142193326Sed  /// @c !Implicit && ImplicitlyDefined.
1143193326Sed  bool ImplicitlyDefined : 1;
1144198092Srdivacky
1145195341Sed  /// Support for base and member initializers.
1146198092Srdivacky  /// BaseOrMemberInitializers - The arguments used to initialize the base
1147195341Sed  /// or member.
1148195341Sed  CXXBaseOrMemberInitializer **BaseOrMemberInitializers;
1149195341Sed  unsigned NumBaseOrMemberInitializers;
1150198092Srdivacky
1151193326Sed  CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation L,
1152200583Srdivacky                     DeclarationName N, QualType T, TypeSourceInfo *TInfo,
1153203955Srdivacky                     bool isExplicitSpecified, bool isInline,
1154203955Srdivacky                     bool isImplicitlyDeclared)
1155200583Srdivacky    : CXXMethodDecl(CXXConstructor, RD, L, N, T, TInfo, false, isInline),
1156203955Srdivacky      IsExplicitSpecified(isExplicitSpecified), ImplicitlyDefined(false),
1157198092Srdivacky      BaseOrMemberInitializers(0), NumBaseOrMemberInitializers(0) {
1158193326Sed    setImplicit(isImplicitlyDeclared);
1159193326Sed  }
1160195341Sed  virtual void Destroy(ASTContext& C);
1161198092Srdivacky
1162193326Sedpublic:
1163193326Sed  static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1164193326Sed                                    SourceLocation L, DeclarationName N,
1165200583Srdivacky                                    QualType T, TypeSourceInfo *TInfo,
1166198092Srdivacky                                    bool isExplicit,
1167193326Sed                                    bool isInline, bool isImplicitlyDeclared);
1168193326Sed
1169203955Srdivacky  /// isExplicitSpecified - Whether this constructor declaration has the
1170203955Srdivacky  /// 'explicit' keyword specified.
1171203955Srdivacky  bool isExplicitSpecified() const { return IsExplicitSpecified; }
1172203955Srdivacky
1173198092Srdivacky  /// isExplicit - Whether this constructor was marked "explicit" or not.
1174203955Srdivacky  bool isExplicit() const {
1175203955Srdivacky    return cast<CXXConstructorDecl>(getFirstDeclaration())
1176203955Srdivacky      ->isExplicitSpecified();
1177203955Srdivacky  }
1178193326Sed
1179193326Sed  /// isImplicitlyDefined - Whether this constructor was implicitly
1180193326Sed  /// defined. If false, then this constructor was defined by the
1181193326Sed  /// user. This operation can only be invoked if the constructor has
1182193326Sed  /// already been defined.
1183198092Srdivacky  bool isImplicitlyDefined(ASTContext &C) const {
1184198092Srdivacky    assert(isThisDeclarationADefinition() &&
1185195341Sed           "Can only get the implicit-definition flag once the "
1186195341Sed           "constructor has been defined");
1187198092Srdivacky    return ImplicitlyDefined;
1188193326Sed  }
1189193326Sed
1190193326Sed  /// setImplicitlyDefined - Set whether this constructor was
1191193326Sed  /// implicitly defined or not.
1192198092Srdivacky  void setImplicitlyDefined(bool ID) {
1193198092Srdivacky    assert(isThisDeclarationADefinition() &&
1194195341Sed           "Can only set the implicit-definition flag once the constructor "
1195195341Sed           "has been defined");
1196198092Srdivacky    ImplicitlyDefined = ID;
1197193326Sed  }
1198198092Srdivacky
1199195341Sed  /// init_iterator - Iterates through the member/base initializer list.
1200195341Sed  typedef CXXBaseOrMemberInitializer **init_iterator;
1201198092Srdivacky
1202195341Sed  /// init_const_iterator - Iterates through the memberbase initializer list.
1203195341Sed  typedef CXXBaseOrMemberInitializer * const * init_const_iterator;
1204198092Srdivacky
1205198092Srdivacky  /// init_begin() - Retrieve an iterator to the first initializer.
1206198092Srdivacky  init_iterator       init_begin()       { return BaseOrMemberInitializers; }
1207195341Sed  /// begin() - Retrieve an iterator to the first initializer.
1208198092Srdivacky  init_const_iterator init_begin() const { return BaseOrMemberInitializers; }
1209198092Srdivacky
1210198092Srdivacky  /// init_end() - Retrieve an iterator past the last initializer.
1211198092Srdivacky  init_iterator       init_end()       {
1212198092Srdivacky    return BaseOrMemberInitializers + NumBaseOrMemberInitializers;
1213195341Sed  }
1214195341Sed  /// end() - Retrieve an iterator past the last initializer.
1215198092Srdivacky  init_const_iterator init_end() const {
1216198092Srdivacky    return BaseOrMemberInitializers + NumBaseOrMemberInitializers;
1217195341Sed  }
1218198092Srdivacky
1219195341Sed  /// getNumArgs - Determine the number of arguments used to
1220195341Sed  /// initialize the member or base.
1221198092Srdivacky  unsigned getNumBaseOrMemberInitializers() const {
1222198092Srdivacky      return NumBaseOrMemberInitializers;
1223195341Sed  }
1224198092Srdivacky
1225198092Srdivacky  void setNumBaseOrMemberInitializers(unsigned numBaseOrMemberInitializers) {
1226198092Srdivacky    NumBaseOrMemberInitializers = numBaseOrMemberInitializers;
1227198092Srdivacky  }
1228198092Srdivacky
1229198092Srdivacky  void setBaseOrMemberInitializers(CXXBaseOrMemberInitializer ** initializers) {
1230198092Srdivacky    BaseOrMemberInitializers = initializers;
1231198092Srdivacky  }
1232193326Sed  /// isDefaultConstructor - Whether this constructor is a default
1233193326Sed  /// constructor (C++ [class.ctor]p5), which can be used to
1234193326Sed  /// default-initialize a class of this type.
1235193326Sed  bool isDefaultConstructor() const;
1236193326Sed
1237193326Sed  /// isCopyConstructor - Whether this constructor is a copy
1238193326Sed  /// constructor (C++ [class.copy]p2, which can be used to copy the
1239193326Sed  /// class. @p TypeQuals will be set to the qualifiers on the
1240193326Sed  /// argument type. For example, @p TypeQuals would be set to @c
1241193326Sed  /// QualType::Const for the following copy constructor:
1242193326Sed  ///
1243193326Sed  /// @code
1244193326Sed  /// class X {
1245193326Sed  /// public:
1246193326Sed  ///   X(const X&);
1247193326Sed  /// };
1248193326Sed  /// @endcode
1249201361Srdivacky  bool isCopyConstructor(unsigned &TypeQuals) const;
1250193326Sed
1251193326Sed  /// isCopyConstructor - Whether this constructor is a copy
1252193326Sed  /// constructor (C++ [class.copy]p2, which can be used to copy the
1253193326Sed  /// class.
1254201361Srdivacky  bool isCopyConstructor() const {
1255193326Sed    unsigned TypeQuals = 0;
1256201361Srdivacky    return isCopyConstructor(TypeQuals);
1257193326Sed  }
1258193326Sed
1259193326Sed  /// isConvertingConstructor - Whether this constructor is a
1260193326Sed  /// converting constructor (C++ [class.conv.ctor]), which can be
1261193326Sed  /// used for user-defined conversions.
1262198092Srdivacky  bool isConvertingConstructor(bool AllowExplicit) const;
1263193326Sed
1264199482Srdivacky  /// \brief Determine whether this is a member template specialization that
1265199482Srdivacky  /// looks like a copy constructor. Such constructors are never used to copy
1266199482Srdivacky  /// an object.
1267199482Srdivacky  bool isCopyConstructorLikeSpecialization() const;
1268199482Srdivacky
1269193326Sed  // Implement isa/cast/dyncast/etc.
1270203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1271193326Sed  static bool classof(const CXXConstructorDecl *D) { return true; }
1272203955Srdivacky  static bool classofKind(Kind K) { return K == CXXConstructor; }
1273193326Sed};
1274193326Sed
1275193326Sed/// CXXDestructorDecl - Represents a C++ destructor within a
1276193326Sed/// class. For example:
1277198092Srdivacky///
1278193326Sed/// @code
1279193326Sed/// class X {
1280193326Sed/// public:
1281193326Sed///   ~X(); // represented by a CXXDestructorDecl.
1282193326Sed/// };
1283193326Sed/// @endcode
1284193326Sedclass CXXDestructorDecl : public CXXMethodDecl {
1285193326Sed  /// ImplicitlyDefined - Whether this destructor was implicitly
1286193326Sed  /// defined by the compiler. When false, the destructor was defined
1287193326Sed  /// by the user. In C++03, this flag will have the same value as
1288193326Sed  /// Implicit. In C++0x, however, a destructor that is
1289193326Sed  /// explicitly defaulted (i.e., defined with " = default") will have
1290193326Sed  /// @c !Implicit && ImplicitlyDefined.
1291193326Sed  bool ImplicitlyDefined : 1;
1292193326Sed
1293199482Srdivacky  FunctionDecl *OperatorDelete;
1294199482Srdivacky
1295193326Sed  CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation L,
1296193326Sed                    DeclarationName N, QualType T,
1297193326Sed                    bool isInline, bool isImplicitlyDeclared)
1298200583Srdivacky    : CXXMethodDecl(CXXDestructor, RD, L, N, T, /*TInfo=*/0, false, isInline),
1299199482Srdivacky      ImplicitlyDefined(false), OperatorDelete(0) {
1300193326Sed    setImplicit(isImplicitlyDeclared);
1301193326Sed  }
1302193326Sed
1303193326Sedpublic:
1304193326Sed  static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1305193326Sed                                   SourceLocation L, DeclarationName N,
1306198092Srdivacky                                   QualType T, bool isInline,
1307193326Sed                                   bool isImplicitlyDeclared);
1308193326Sed
1309193326Sed  /// isImplicitlyDefined - Whether this destructor was implicitly
1310193326Sed  /// defined. If false, then this destructor was defined by the
1311193326Sed  /// user. This operation can only be invoked if the destructor has
1312193326Sed  /// already been defined.
1313198092Srdivacky  bool isImplicitlyDefined() const {
1314198092Srdivacky    assert(isThisDeclarationADefinition() &&
1315193326Sed           "Can only get the implicit-definition flag once the destructor has been defined");
1316198092Srdivacky    return ImplicitlyDefined;
1317193326Sed  }
1318193326Sed
1319193326Sed  /// setImplicitlyDefined - Set whether this destructor was
1320193326Sed  /// implicitly defined or not.
1321198092Srdivacky  void setImplicitlyDefined(bool ID) {
1322198092Srdivacky    assert(isThisDeclarationADefinition() &&
1323193326Sed           "Can only set the implicit-definition flag once the destructor has been defined");
1324198092Srdivacky    ImplicitlyDefined = ID;
1325193326Sed  }
1326193326Sed
1327199482Srdivacky  void setOperatorDelete(FunctionDecl *OD) { OperatorDelete = OD; }
1328199482Srdivacky  const FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1329198092Srdivacky
1330193326Sed  // Implement isa/cast/dyncast/etc.
1331203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1332193326Sed  static bool classof(const CXXDestructorDecl *D) { return true; }
1333203955Srdivacky  static bool classofKind(Kind K) { return K == CXXDestructor; }
1334193326Sed};
1335193326Sed
1336193326Sed/// CXXConversionDecl - Represents a C++ conversion function within a
1337193326Sed/// class. For example:
1338198092Srdivacky///
1339193326Sed/// @code
1340193326Sed/// class X {
1341193326Sed/// public:
1342193326Sed///   operator bool();
1343193326Sed/// };
1344193326Sed/// @endcode
1345193326Sedclass CXXConversionDecl : public CXXMethodDecl {
1346203955Srdivacky  /// IsExplicitSpecified - Whether this conversion function declaration is
1347203955Srdivacky  /// marked "explicit", meaning that it can only be applied when the user
1348193326Sed  /// explicitly wrote a cast. This is a C++0x feature.
1349203955Srdivacky  bool IsExplicitSpecified : 1;
1350193326Sed
1351193326Sed  CXXConversionDecl(CXXRecordDecl *RD, SourceLocation L,
1352200583Srdivacky                    DeclarationName N, QualType T, TypeSourceInfo *TInfo,
1353203955Srdivacky                    bool isInline, bool isExplicitSpecified)
1354200583Srdivacky    : CXXMethodDecl(CXXConversion, RD, L, N, T, TInfo, false, isInline),
1355203955Srdivacky      IsExplicitSpecified(isExplicitSpecified) { }
1356193326Sed
1357193326Sedpublic:
1358193326Sed  static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1359193326Sed                                   SourceLocation L, DeclarationName N,
1360200583Srdivacky                                   QualType T, TypeSourceInfo *TInfo,
1361198092Srdivacky                                   bool isInline, bool isExplicit);
1362193326Sed
1363203955Srdivacky  /// IsExplicitSpecified - Whether this conversion function declaration is
1364203955Srdivacky  /// marked "explicit", meaning that it can only be applied when the user
1365203955Srdivacky  /// explicitly wrote a cast. This is a C++0x feature.
1366203955Srdivacky  bool isExplicitSpecified() const { return IsExplicitSpecified; }
1367203955Srdivacky
1368193326Sed  /// isExplicit - Whether this is an explicit conversion operator
1369193326Sed  /// (C++0x only). Explicit conversion operators are only considered
1370193326Sed  /// when the user has explicitly written a cast.
1371203955Srdivacky  bool isExplicit() const {
1372203955Srdivacky    return cast<CXXConversionDecl>(getFirstDeclaration())
1373203955Srdivacky      ->isExplicitSpecified();
1374203955Srdivacky  }
1375193326Sed
1376193326Sed  /// getConversionType - Returns the type that this conversion
1377193326Sed  /// function is converting to.
1378198092Srdivacky  QualType getConversionType() const {
1379198092Srdivacky    return getType()->getAs<FunctionType>()->getResultType();
1380193326Sed  }
1381193326Sed
1382193326Sed  // Implement isa/cast/dyncast/etc.
1383203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1384193326Sed  static bool classof(const CXXConversionDecl *D) { return true; }
1385203955Srdivacky  static bool classofKind(Kind K) { return K == CXXConversion; }
1386193326Sed};
1387193326Sed
1388193326Sed/// LinkageSpecDecl - This represents a linkage specification.  For example:
1389193326Sed///   extern "C" void foo();
1390193326Sed///
1391193326Sedclass LinkageSpecDecl : public Decl, public DeclContext {
1392193326Sedpublic:
1393193326Sed  /// LanguageIDs - Used to represent the language in a linkage
1394193326Sed  /// specification.  The values are part of the serialization abi for
1395193326Sed  /// ASTs and cannot be changed without altering that abi.  To help
1396193326Sed  /// ensure a stable abi for this, we choose the DW_LANG_ encodings
1397193326Sed  /// from the dwarf standard.
1398193326Sed  enum LanguageIDs { lang_c = /* DW_LANG_C */ 0x0002,
1399193326Sed  lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004 };
1400193326Sedprivate:
1401193326Sed  /// Language - The language for this linkage specification.
1402193326Sed  LanguageIDs Language;
1403193326Sed
1404193326Sed  /// HadBraces - Whether this linkage specification had curly braces or not.
1405193326Sed  bool HadBraces : 1;
1406193326Sed
1407198092Srdivacky  LinkageSpecDecl(DeclContext *DC, SourceLocation L, LanguageIDs lang,
1408193326Sed                  bool Braces)
1409198092Srdivacky    : Decl(LinkageSpec, DC, L),
1410193326Sed      DeclContext(LinkageSpec), Language(lang), HadBraces(Braces) { }
1411193326Sed
1412193326Sedpublic:
1413198092Srdivacky  static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
1414198092Srdivacky                                 SourceLocation L, LanguageIDs Lang,
1415193326Sed                                 bool Braces);
1416193326Sed
1417193326Sed  LanguageIDs getLanguage() const { return Language; }
1418193326Sed
1419193326Sed  /// hasBraces - Determines whether this linkage specification had
1420193326Sed  /// braces in its syntactic form.
1421193326Sed  bool hasBraces() const { return HadBraces; }
1422193326Sed
1423203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1424193326Sed  static bool classof(const LinkageSpecDecl *D) { return true; }
1425203955Srdivacky  static bool classofKind(Kind K) { return K == LinkageSpec; }
1426193326Sed  static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
1427193326Sed    return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
1428193326Sed  }
1429193326Sed  static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
1430193326Sed    return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
1431193326Sed  }
1432193326Sed};
1433193326Sed
1434193326Sed/// UsingDirectiveDecl - Represents C++ using-directive. For example:
1435193326Sed///
1436193326Sed///    using namespace std;
1437193326Sed///
1438193326Sed// NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide
1439193326Sed// artificial name, for all using-directives in order to store
1440193326Sed// them in DeclContext effectively.
1441193326Sedclass UsingDirectiveDecl : public NamedDecl {
1442193326Sed
1443193326Sed  /// SourceLocation - Location of 'namespace' token.
1444193326Sed  SourceLocation NamespaceLoc;
1445193326Sed
1446193326Sed  /// \brief The source range that covers the nested-name-specifier
1447193326Sed  /// preceding the namespace name.
1448193326Sed  SourceRange QualifierRange;
1449193326Sed
1450193326Sed  /// \brief The nested-name-specifier that precedes the namespace
1451193326Sed  /// name, if any.
1452193326Sed  NestedNameSpecifier *Qualifier;
1453193326Sed
1454193326Sed  /// IdentLoc - Location of nominated namespace-name identifier.
1455193326Sed  // FIXME: We don't store location of scope specifier.
1456193326Sed  SourceLocation IdentLoc;
1457193326Sed
1458193326Sed  /// NominatedNamespace - Namespace nominated by using-directive.
1459199990Srdivacky  NamedDecl *NominatedNamespace;
1460193326Sed
1461199990Srdivacky  /// Enclosing context containing both using-directive and nominated
1462193326Sed  /// namespace.
1463193326Sed  DeclContext *CommonAncestor;
1464193326Sed
1465193326Sed  /// getUsingDirectiveName - Returns special DeclarationName used by
1466193326Sed  /// using-directives. This is only used by DeclContext for storing
1467193326Sed  /// UsingDirectiveDecls in its lookup structure.
1468193326Sed  static DeclarationName getName() {
1469193326Sed    return DeclarationName::getUsingDirectiveName();
1470193326Sed  }
1471193326Sed
1472193326Sed  UsingDirectiveDecl(DeclContext *DC, SourceLocation L,
1473193326Sed                     SourceLocation NamespcLoc,
1474193326Sed                     SourceRange QualifierRange,
1475193326Sed                     NestedNameSpecifier *Qualifier,
1476193326Sed                     SourceLocation IdentLoc,
1477199990Srdivacky                     NamedDecl *Nominated,
1478193326Sed                     DeclContext *CommonAncestor)
1479193326Sed    : NamedDecl(Decl::UsingDirective, DC, L, getName()),
1480198092Srdivacky      NamespaceLoc(NamespcLoc), QualifierRange(QualifierRange),
1481198092Srdivacky      Qualifier(Qualifier), IdentLoc(IdentLoc),
1482199990Srdivacky      NominatedNamespace(Nominated),
1483193326Sed      CommonAncestor(CommonAncestor) {
1484193326Sed  }
1485193326Sed
1486193326Sedpublic:
1487193326Sed  /// \brief Retrieve the source range of the nested-name-specifier
1488193326Sed  /// that qualifiers the namespace name.
1489193326Sed  SourceRange getQualifierRange() const { return QualifierRange; }
1490193326Sed
1491193326Sed  /// \brief Retrieve the nested-name-specifier that qualifies the
1492193326Sed  /// name of the namespace.
1493193326Sed  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1494193326Sed
1495199990Srdivacky  NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
1496199990Srdivacky  const NamedDecl *getNominatedNamespaceAsWritten() const {
1497199990Srdivacky    return NominatedNamespace;
1498199990Srdivacky  }
1499199990Srdivacky
1500193326Sed  /// getNominatedNamespace - Returns namespace nominated by using-directive.
1501199990Srdivacky  NamespaceDecl *getNominatedNamespace();
1502193326Sed
1503193326Sed  const NamespaceDecl *getNominatedNamespace() const {
1504193326Sed    return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
1505193326Sed  }
1506193326Sed
1507193326Sed  /// getCommonAncestor - returns common ancestor context of using-directive,
1508193326Sed  /// and nominated by it namespace.
1509193326Sed  DeclContext *getCommonAncestor() { return CommonAncestor; }
1510193326Sed  const DeclContext *getCommonAncestor() const { return CommonAncestor; }
1511193326Sed
1512193326Sed  /// getNamespaceKeyLocation - Returns location of namespace keyword.
1513193326Sed  SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
1514193326Sed
1515193326Sed  /// getIdentLocation - Returns location of identifier.
1516193326Sed  SourceLocation getIdentLocation() const { return IdentLoc; }
1517193326Sed
1518193326Sed  static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
1519193326Sed                                    SourceLocation L,
1520193326Sed                                    SourceLocation NamespaceLoc,
1521193326Sed                                    SourceRange QualifierRange,
1522193326Sed                                    NestedNameSpecifier *Qualifier,
1523193326Sed                                    SourceLocation IdentLoc,
1524199990Srdivacky                                    NamedDecl *Nominated,
1525193326Sed                                    DeclContext *CommonAncestor);
1526193326Sed
1527203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1528193326Sed  static bool classof(const UsingDirectiveDecl *D) { return true; }
1529203955Srdivacky  static bool classofKind(Kind K) { return K == Decl::UsingDirective; }
1530193326Sed
1531193326Sed  // Friend for getUsingDirectiveName.
1532193326Sed  friend class DeclContext;
1533193326Sed};
1534193326Sed
1535193326Sed/// NamespaceAliasDecl - Represents a C++ namespace alias. For example:
1536193326Sed///
1537193326Sed/// @code
1538193326Sed/// namespace Foo = Bar;
1539193326Sed/// @endcode
1540193326Sedclass NamespaceAliasDecl : public NamedDecl {
1541193326Sed  SourceLocation AliasLoc;
1542193326Sed
1543193326Sed  /// \brief The source range that covers the nested-name-specifier
1544193326Sed  /// preceding the namespace name.
1545193326Sed  SourceRange QualifierRange;
1546193326Sed
1547193326Sed  /// \brief The nested-name-specifier that precedes the namespace
1548193326Sed  /// name, if any.
1549193326Sed  NestedNameSpecifier *Qualifier;
1550198092Srdivacky
1551193326Sed  /// IdentLoc - Location of namespace identifier.
1552193326Sed  SourceLocation IdentLoc;
1553198092Srdivacky
1554198092Srdivacky  /// Namespace - The Decl that this alias points to. Can either be a
1555193326Sed  /// NamespaceDecl or a NamespaceAliasDecl.
1556193326Sed  NamedDecl *Namespace;
1557198092Srdivacky
1558198092Srdivacky  NamespaceAliasDecl(DeclContext *DC, SourceLocation L,
1559198092Srdivacky                     SourceLocation AliasLoc, IdentifierInfo *Alias,
1560193326Sed                     SourceRange QualifierRange,
1561193326Sed                     NestedNameSpecifier *Qualifier,
1562193326Sed                     SourceLocation IdentLoc, NamedDecl *Namespace)
1563198092Srdivacky    : NamedDecl(Decl::NamespaceAlias, DC, L, Alias), AliasLoc(AliasLoc),
1564193326Sed      QualifierRange(QualifierRange), Qualifier(Qualifier),
1565193326Sed      IdentLoc(IdentLoc), Namespace(Namespace) { }
1566193326Sed
1567193326Sedpublic:
1568193326Sed  /// \brief Retrieve the source range of the nested-name-specifier
1569193326Sed  /// that qualifiers the namespace name.
1570193326Sed  SourceRange getQualifierRange() const { return QualifierRange; }
1571193326Sed
1572193326Sed  /// \brief Retrieve the nested-name-specifier that qualifies the
1573193326Sed  /// name of the namespace.
1574193326Sed  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1575193326Sed
1576193326Sed  NamespaceDecl *getNamespace() {
1577193326Sed    if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
1578193326Sed      return AD->getNamespace();
1579193326Sed
1580193326Sed    return cast<NamespaceDecl>(Namespace);
1581193326Sed  }
1582198092Srdivacky
1583193326Sed  const NamespaceDecl *getNamespace() const {
1584193326Sed    return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
1585193326Sed  }
1586193326Sed
1587203955Srdivacky  /// Returns the location of the alias name, i.e. 'foo' in
1588203955Srdivacky  /// "namespace foo = ns::bar;".
1589203955Srdivacky  SourceLocation getAliasLoc() const { return AliasLoc; }
1590203955Srdivacky
1591203955Srdivacky  /// Returns the location of the 'namespace' keyword.
1592203955Srdivacky  SourceLocation getNamespaceLoc() const { return getLocation(); }
1593203955Srdivacky
1594203955Srdivacky  /// Returns the location of the identifier in the named namespace.
1595203955Srdivacky  SourceLocation getTargetNameLoc() const { return IdentLoc; }
1596203955Srdivacky
1597193326Sed  /// \brief Retrieve the namespace that this alias refers to, which
1598193326Sed  /// may either be a NamespaceDecl or a NamespaceAliasDecl.
1599193326Sed  NamedDecl *getAliasedNamespace() const { return Namespace; }
1600193326Sed
1601198092Srdivacky  static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
1602198092Srdivacky                                    SourceLocation L, SourceLocation AliasLoc,
1603198092Srdivacky                                    IdentifierInfo *Alias,
1604193326Sed                                    SourceRange QualifierRange,
1605193326Sed                                    NestedNameSpecifier *Qualifier,
1606198092Srdivacky                                    SourceLocation IdentLoc,
1607193326Sed                                    NamedDecl *Namespace);
1608198092Srdivacky
1609203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1610193326Sed  static bool classof(const NamespaceAliasDecl *D) { return true; }
1611203955Srdivacky  static bool classofKind(Kind K) { return K == Decl::NamespaceAlias; }
1612193326Sed};
1613194613Sed
1614199482Srdivacky/// UsingShadowDecl - Represents a shadow declaration introduced into
1615199482Srdivacky/// a scope by a (resolved) using declaration.  For example,
1616199482Srdivacky///
1617199482Srdivacky/// namespace A {
1618199482Srdivacky///   void foo();
1619199482Srdivacky/// }
1620199482Srdivacky/// namespace B {
1621199482Srdivacky///   using A::foo(); // <- a UsingDecl
1622199482Srdivacky///                   // Also creates a UsingShadowDecl for A::foo in B
1623199482Srdivacky/// }
1624199482Srdivacky///
1625199482Srdivackyclass UsingShadowDecl : public NamedDecl {
1626199482Srdivacky  /// The referenced declaration.
1627199482Srdivacky  NamedDecl *Underlying;
1628199482Srdivacky
1629199482Srdivacky  /// The using declaration which introduced this decl.
1630199482Srdivacky  UsingDecl *Using;
1631199482Srdivacky
1632199482Srdivacky  UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using,
1633199482Srdivacky                  NamedDecl *Target)
1634199482Srdivacky    : NamedDecl(UsingShadow, DC, Loc, Target->getDeclName()),
1635199482Srdivacky      Underlying(Target), Using(Using) {
1636199482Srdivacky    IdentifierNamespace = Target->getIdentifierNamespace();
1637199482Srdivacky    setImplicit();
1638199482Srdivacky  }
1639199482Srdivacky
1640199482Srdivackypublic:
1641199482Srdivacky  static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
1642199482Srdivacky                                 SourceLocation Loc, UsingDecl *Using,
1643199482Srdivacky                                 NamedDecl *Target) {
1644199482Srdivacky    return new (C) UsingShadowDecl(DC, Loc, Using, Target);
1645199482Srdivacky  }
1646199482Srdivacky
1647199482Srdivacky  /// Gets the underlying declaration which has been brought into the
1648199482Srdivacky  /// local scope.
1649199482Srdivacky  NamedDecl *getTargetDecl() const {
1650199482Srdivacky    return Underlying;
1651199482Srdivacky  }
1652199482Srdivacky
1653199482Srdivacky  /// Gets the using declaration to which this declaration is tied.
1654199482Srdivacky  UsingDecl *getUsingDecl() const {
1655199482Srdivacky    return Using;
1656199482Srdivacky  }
1657199482Srdivacky
1658203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1659199482Srdivacky  static bool classof(const UsingShadowDecl *D) { return true; }
1660203955Srdivacky  static bool classofKind(Kind K) { return K == Decl::UsingShadow; }
1661199482Srdivacky};
1662199482Srdivacky
1663194613Sed/// UsingDecl - Represents a C++ using-declaration. For example:
1664194613Sed///    using someNameSpace::someIdentifier;
1665194613Sedclass UsingDecl : public NamedDecl {
1666194613Sed  /// \brief The source range that covers the nested-name-specifier
1667194613Sed  /// preceding the declaration name.
1668194613Sed  SourceRange NestedNameRange;
1669198092Srdivacky
1670194613Sed  /// \brief The source location of the "using" location itself.
1671194613Sed  SourceLocation UsingLocation;
1672198092Srdivacky
1673198092Srdivacky  /// \brief Target nested name specifier.
1674199482Srdivacky  NestedNameSpecifier* TargetNestedName;
1675194613Sed
1676199482Srdivacky  /// \brief The collection of shadow declarations associated with
1677199482Srdivacky  /// this using declaration.  This set can change as a class is
1678199482Srdivacky  /// processed.
1679199482Srdivacky  llvm::SmallPtrSet<UsingShadowDecl*, 8> Shadows;
1680199482Srdivacky
1681198092Srdivacky  // \brief Has 'typename' keyword.
1682194613Sed  bool IsTypeName;
1683194613Sed
1684194613Sed  UsingDecl(DeclContext *DC, SourceLocation L, SourceRange NNR,
1685199482Srdivacky            SourceLocation UL, NestedNameSpecifier* TargetNNS,
1686199482Srdivacky            DeclarationName Name, bool IsTypeNameArg)
1687199482Srdivacky    : NamedDecl(Decl::Using, DC, L, Name),
1688199482Srdivacky      NestedNameRange(NNR), UsingLocation(UL), TargetNestedName(TargetNNS),
1689199482Srdivacky      IsTypeName(IsTypeNameArg) {
1690194613Sed  }
1691194613Sed
1692194613Sedpublic:
1693194613Sed  /// \brief Returns the source range that covers the nested-name-specifier
1694194613Sed  /// preceding the namespace name.
1695195099Sed  SourceRange getNestedNameRange() { return NestedNameRange; }
1696198092Srdivacky
1697194613Sed  /// \brief Returns the source location of the "using" location itself.
1698195099Sed  SourceLocation getUsingLocation() { return UsingLocation; }
1699198092Srdivacky
1700194613Sed  /// \brief Get target nested name declaration.
1701198092Srdivacky  NestedNameSpecifier* getTargetNestedNameDecl() {
1702199482Srdivacky    return TargetNestedName;
1703195099Sed  }
1704198092Srdivacky
1705198092Srdivacky  /// isTypeName - Return true if using decl has 'typename'.
1706195099Sed  bool isTypeName() const { return IsTypeName; }
1707194613Sed
1708199482Srdivacky  typedef llvm::SmallPtrSet<UsingShadowDecl*,8>::const_iterator shadow_iterator;
1709199482Srdivacky  shadow_iterator shadow_begin() const { return Shadows.begin(); }
1710199482Srdivacky  shadow_iterator shadow_end() const { return Shadows.end(); }
1711199482Srdivacky
1712199482Srdivacky  void addShadowDecl(UsingShadowDecl *S) {
1713199482Srdivacky    assert(S->getUsingDecl() == this);
1714199482Srdivacky    if (!Shadows.insert(S)) {
1715199482Srdivacky      assert(false && "declaration already in set");
1716199482Srdivacky    }
1717199482Srdivacky  }
1718199482Srdivacky  void removeShadowDecl(UsingShadowDecl *S) {
1719199482Srdivacky    assert(S->getUsingDecl() == this);
1720199482Srdivacky    if (!Shadows.erase(S)) {
1721199482Srdivacky      assert(false && "declaration not in set");
1722199482Srdivacky    }
1723199482Srdivacky  }
1724199482Srdivacky
1725194613Sed  static UsingDecl *Create(ASTContext &C, DeclContext *DC,
1726199482Srdivacky      SourceLocation IdentL, SourceRange NNR, SourceLocation UsingL,
1727199482Srdivacky      NestedNameSpecifier* TargetNNS, DeclarationName Name, bool IsTypeNameArg);
1728194613Sed
1729203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1730194613Sed  static bool classof(const UsingDecl *D) { return true; }
1731203955Srdivacky  static bool classofKind(Kind K) { return K == Decl::Using; }
1732194613Sed};
1733198092Srdivacky
1734199482Srdivacky/// UnresolvedUsingValueDecl - Represents a dependent using
1735199482Srdivacky/// declaration which was not marked with 'typename'.  Unlike
1736199482Srdivacky/// non-dependent using declarations, these *only* bring through
1737199482Srdivacky/// non-types; otherwise they would break two-phase lookup.
1738199482Srdivacky///
1739199482Srdivacky/// template <class T> class A : public Base<T> {
1740199482Srdivacky///   using Base<T>::foo;
1741199482Srdivacky/// };
1742199482Srdivackyclass UnresolvedUsingValueDecl : public ValueDecl {
1743198092Srdivacky  /// \brief The source range that covers the nested-name-specifier
1744198092Srdivacky  /// preceding the declaration name.
1745198092Srdivacky  SourceRange TargetNestedNameRange;
1746198092Srdivacky
1747199482Srdivacky  /// \brief The source location of the 'using' keyword
1748199482Srdivacky  SourceLocation UsingLocation;
1749198092Srdivacky
1750198092Srdivacky  NestedNameSpecifier *TargetNestedNameSpecifier;
1751198092Srdivacky
1752199482Srdivacky  UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
1753199482Srdivacky                           SourceLocation UsingLoc, SourceRange TargetNNR,
1754199482Srdivacky                           NestedNameSpecifier *TargetNNS,
1755199482Srdivacky                           SourceLocation TargetNameLoc,
1756199482Srdivacky                           DeclarationName TargetName)
1757199482Srdivacky    : ValueDecl(Decl::UnresolvedUsingValue, DC, TargetNameLoc, TargetName, Ty),
1758199482Srdivacky    TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc),
1759199482Srdivacky    TargetNestedNameSpecifier(TargetNNS)
1760199482Srdivacky  { }
1761198092Srdivacky
1762199482Srdivackypublic:
1763199482Srdivacky  /// \brief Returns the source range that covers the nested-name-specifier
1764199482Srdivacky  /// preceding the namespace name.
1765199482Srdivacky  SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; }
1766198092Srdivacky
1767199482Srdivacky  /// \brief Get target nested name declaration.
1768199482Srdivacky  NestedNameSpecifier* getTargetNestedNameSpecifier() {
1769199482Srdivacky    return TargetNestedNameSpecifier;
1770199482Srdivacky  }
1771198092Srdivacky
1772199482Srdivacky  /// \brief Returns the source location of the 'using' keyword.
1773199482Srdivacky  SourceLocation getUsingLoc() const { return UsingLocation; }
1774199482Srdivacky
1775199482Srdivacky  static UnresolvedUsingValueDecl *
1776199482Srdivacky    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
1777199482Srdivacky           SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
1778199482Srdivacky           SourceLocation TargetNameLoc, DeclarationName TargetName);
1779199482Srdivacky
1780203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1781199482Srdivacky  static bool classof(const UnresolvedUsingValueDecl *D) { return true; }
1782203955Srdivacky  static bool classofKind(Kind K) { return K == Decl::UnresolvedUsingValue; }
1783199482Srdivacky};
1784199482Srdivacky
1785199482Srdivacky/// UnresolvedUsingTypenameDecl - Represents a dependent using
1786199482Srdivacky/// declaration which was marked with 'typename'.
1787199482Srdivacky///
1788199482Srdivacky/// template <class T> class A : public Base<T> {
1789199482Srdivacky///   using typename Base<T>::foo;
1790199482Srdivacky/// };
1791199482Srdivacky///
1792199482Srdivacky/// The type associated with a unresolved using typename decl is
1793199482Srdivacky/// currently always a typename type.
1794199482Srdivackyclass UnresolvedUsingTypenameDecl : public TypeDecl {
1795199482Srdivacky  /// \brief The source range that covers the nested-name-specifier
1796199482Srdivacky  /// preceding the declaration name.
1797199482Srdivacky  SourceRange TargetNestedNameRange;
1798199482Srdivacky
1799199482Srdivacky  /// \brief The source location of the 'using' keyword
1800199482Srdivacky  SourceLocation UsingLocation;
1801199482Srdivacky
1802199482Srdivacky  /// \brief The source location of the 'typename' keyword
1803199482Srdivacky  SourceLocation TypenameLocation;
1804199482Srdivacky
1805199482Srdivacky  NestedNameSpecifier *TargetNestedNameSpecifier;
1806199482Srdivacky
1807199482Srdivacky  UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
1808199482Srdivacky                    SourceLocation TypenameLoc,
1809199482Srdivacky                    SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
1810199482Srdivacky                    SourceLocation TargetNameLoc, IdentifierInfo *TargetName)
1811199482Srdivacky  : TypeDecl(Decl::UnresolvedUsingTypename, DC, TargetNameLoc, TargetName),
1812199482Srdivacky    TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc),
1813199482Srdivacky    TypenameLocation(TypenameLoc), TargetNestedNameSpecifier(TargetNNS)
1814199482Srdivacky  { }
1815199482Srdivacky
1816198092Srdivackypublic:
1817198092Srdivacky  /// \brief Returns the source range that covers the nested-name-specifier
1818198092Srdivacky  /// preceding the namespace name.
1819198092Srdivacky  SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; }
1820198092Srdivacky
1821198092Srdivacky  /// \brief Get target nested name declaration.
1822198092Srdivacky  NestedNameSpecifier* getTargetNestedNameSpecifier() {
1823198092Srdivacky    return TargetNestedNameSpecifier;
1824198092Srdivacky  }
1825198092Srdivacky
1826199482Srdivacky  /// \brief Returns the source location of the 'using' keyword.
1827199482Srdivacky  SourceLocation getUsingLoc() const { return UsingLocation; }
1828198092Srdivacky
1829199482Srdivacky  /// \brief Returns the source location of the 'typename' keyword.
1830199482Srdivacky  SourceLocation getTypenameLoc() const { return TypenameLocation; }
1831198092Srdivacky
1832199482Srdivacky  static UnresolvedUsingTypenameDecl *
1833199482Srdivacky    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
1834199482Srdivacky           SourceLocation TypenameLoc,
1835199482Srdivacky           SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
1836199482Srdivacky           SourceLocation TargetNameLoc, DeclarationName TargetName);
1837198092Srdivacky
1838203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1839199482Srdivacky  static bool classof(const UnresolvedUsingTypenameDecl *D) { return true; }
1840203955Srdivacky  static bool classofKind(Kind K) { return K == Decl::UnresolvedUsingTypename; }
1841198092Srdivacky};
1842198092Srdivacky
1843193326Sed/// StaticAssertDecl - Represents a C++0x static_assert declaration.
1844193326Sedclass StaticAssertDecl : public Decl {
1845193326Sed  Expr *AssertExpr;
1846193326Sed  StringLiteral *Message;
1847193326Sed
1848198092Srdivacky  StaticAssertDecl(DeclContext *DC, SourceLocation L,
1849193326Sed                   Expr *assertexpr, StringLiteral *message)
1850193326Sed  : Decl(StaticAssert, DC, L), AssertExpr(assertexpr), Message(message) { }
1851198092Srdivacky
1852193326Sedpublic:
1853193326Sed  static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
1854193326Sed                                  SourceLocation L, Expr *AssertExpr,
1855193326Sed                                  StringLiteral *Message);
1856198092Srdivacky
1857193326Sed  Expr *getAssertExpr() { return AssertExpr; }
1858193326Sed  const Expr *getAssertExpr() const { return AssertExpr; }
1859198092Srdivacky
1860193326Sed  StringLiteral *getMessage() { return Message; }
1861193326Sed  const StringLiteral *getMessage() const { return Message; }
1862198092Srdivacky
1863193326Sed  virtual ~StaticAssertDecl();
1864193326Sed  virtual void Destroy(ASTContext& C);
1865193326Sed
1866203955Srdivacky  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1867193326Sed  static bool classof(StaticAssertDecl *D) { return true; }
1868203955Srdivacky  static bool classofKind(Kind K) { return K == Decl::StaticAssert; }
1869193326Sed};
1870193326Sed
1871193326Sed/// Insertion operator for diagnostics.  This allows sending AccessSpecifier's
1872193326Sed/// into a diagnostic with <<.
1873193326Sedconst DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
1874193326Sed                                    AccessSpecifier AS);
1875198092Srdivacky
1876193326Sed} // end namespace clang
1877193326Sed
1878193326Sed#endif
1879