DeclCXX.h revision 195099
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//
10193326Sed//  This file defines the C++ Decl subclasses.
11193326Sed//
12193326Sed//===----------------------------------------------------------------------===//
13193326Sed
14193326Sed#ifndef LLVM_CLANG_AST_DECLCXX_H
15193326Sed#define LLVM_CLANG_AST_DECLCXX_H
16193326Sed
17193326Sed#include "clang/AST/Decl.h"
18193326Sed#include "llvm/ADT/SmallVector.h"
19193326Sed
20193326Sednamespace clang {
21193326Sed
22193326Sedclass ClassTemplateDecl;
23193326Sedclass CXXRecordDecl;
24193326Sedclass CXXConstructorDecl;
25193326Sedclass CXXDestructorDecl;
26193326Sedclass CXXConversionDecl;
27193326Sedclass CXXMethodDecl;
28193326Sedclass ClassTemplateSpecializationDecl;
29193326Sed
30195099Sed/// \brief Represents any kind of function declaration, whether it is a
31195099Sed/// concrete function or a function template.
32195099Sedclass AnyFunctionDecl {
33195099Sed  NamedDecl *Function;
34195099Sed
35195099Sedpublic:
36195099Sed  AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { }
37195099Sed  AnyFunctionDecl(FunctionTemplateDecl *FTD);
38195099Sed
39195099Sed  /// \brief Implicily converts any function or function template into a
40195099Sed  /// named declaration.
41195099Sed  operator NamedDecl *() const { return Function; }
42195099Sed
43195099Sed  /// \brief Retrieve the underlying function or function template.
44195099Sed  NamedDecl *get() const { return Function; }
45195099Sed};
46195099Sed
47195099Sed} // end namespace clang
48195099Sed
49195099Sednamespace llvm {
50195099Sed  /// Implement simplify_type for AnyFunctionDecl, so that we can dyn_cast from
51195099Sed  /// AnyFunctionDecl to any function or function template declaration.
52195099Sed  template<> struct simplify_type<const ::clang::AnyFunctionDecl> {
53195099Sed    typedef ::clang::NamedDecl* SimpleType;
54195099Sed    static SimpleType getSimplifiedValue(const ::clang::AnyFunctionDecl &Val) {
55195099Sed      return Val;
56195099Sed    }
57195099Sed  };
58195099Sed  template<> struct simplify_type< ::clang::AnyFunctionDecl>
59195099Sed  : public simplify_type<const ::clang::AnyFunctionDecl> {};
60195099Sed} // end namespace llvm
61195099Sed
62195099Sednamespace clang {
63195099Sed
64193326Sed/// OverloadedFunctionDecl - An instance of this class represents a
65193326Sed/// set of overloaded functions. All of the functions have the same
66193326Sed/// name and occur within the same scope.
67193326Sed///
68193326Sed/// An OverloadedFunctionDecl has no ownership over the FunctionDecl
69193326Sed/// nodes it contains. Rather, the FunctionDecls are owned by the
70193326Sed/// enclosing scope (which also owns the OverloadedFunctionDecl
71193326Sed/// node). OverloadedFunctionDecl is used primarily to store a set of
72193326Sed/// overloaded functions for name lookup.
73193326Sedclass OverloadedFunctionDecl : public NamedDecl {
74193326Sedprotected:
75193326Sed  OverloadedFunctionDecl(DeclContext *DC, DeclarationName N)
76193326Sed    : NamedDecl(OverloadedFunction, DC, SourceLocation(), N) { }
77193326Sed
78193326Sed  /// Functions - the set of overloaded functions contained in this
79193326Sed  /// overload set.
80195099Sed  llvm::SmallVector<AnyFunctionDecl, 4> Functions;
81193326Sed
82193326Sed  // FIXME: This should go away when we stop using
83193326Sed  // OverloadedFunctionDecl to store conversions in CXXRecordDecl.
84193326Sed  friend class CXXRecordDecl;
85193326Sed
86193326Sedpublic:
87195099Sed  typedef llvm::SmallVector<AnyFunctionDecl, 4>::iterator function_iterator;
88195099Sed  typedef llvm::SmallVector<AnyFunctionDecl, 4>::const_iterator
89193326Sed    function_const_iterator;
90193326Sed
91193326Sed  static OverloadedFunctionDecl *Create(ASTContext &C, DeclContext *DC,
92193326Sed                                        DeclarationName N);
93193326Sed
94193326Sed  /// addOverload - Add an overloaded function FD to this set of
95193326Sed  /// overloaded functions.
96193326Sed  void addOverload(FunctionDecl *FD) {
97193326Sed    assert((FD->getDeclName() == getDeclName() ||
98193326Sed            isa<CXXConversionDecl>(FD) || isa<CXXConstructorDecl>(FD)) &&
99193326Sed           "Overloaded functions must have the same name");
100193326Sed    Functions.push_back(FD);
101193326Sed
102193326Sed    // An overloaded function declaration always has the location of
103193326Sed    // the most-recently-added function declaration.
104193326Sed    if (FD->getLocation().isValid())
105193326Sed      this->setLocation(FD->getLocation());
106193326Sed  }
107193326Sed
108195099Sed  /// addOverload - Add an overloaded function template FTD to this set of
109195099Sed  /// overloaded functions.
110195099Sed  void addOverload(FunctionTemplateDecl *FTD);
111195099Sed
112193326Sed  function_iterator function_begin() { return Functions.begin(); }
113193326Sed  function_iterator function_end() { return Functions.end(); }
114193326Sed  function_const_iterator function_begin() const { return Functions.begin(); }
115193326Sed  function_const_iterator function_end() const { return Functions.end(); }
116193326Sed
117195099Sed  /// \brief Returns the number of overloaded functions stored in
118193326Sed  /// this set.
119195099Sed  unsigned size() const { return Functions.size(); }
120193326Sed
121193326Sed  // Implement isa/cast/dyncast/etc.
122193326Sed  static bool classof(const Decl *D) {
123193326Sed    return D->getKind() == OverloadedFunction;
124193326Sed  }
125193326Sed  static bool classof(const OverloadedFunctionDecl *D) { return true; }
126193326Sed};
127193326Sed
128193326Sed/// CXXBaseSpecifier - A base class of a C++ class.
129193326Sed///
130193326Sed/// Each CXXBaseSpecifier represents a single, direct base class (or
131193326Sed/// struct) of a C++ class (or struct). It specifies the type of that
132193326Sed/// base class, whether it is a virtual or non-virtual base, and what
133193326Sed/// level of access (public, protected, private) is used for the
134193326Sed/// derivation. For example:
135193326Sed///
136193326Sed/// @code
137193326Sed///   class A { };
138193326Sed///   class B { };
139193326Sed///   class C : public virtual A, protected B { };
140193326Sed/// @endcode
141193326Sed///
142193326Sed/// In this code, C will have two CXXBaseSpecifiers, one for "public
143193326Sed/// virtual A" and the other for "protected B".
144193326Sedclass CXXBaseSpecifier {
145193326Sed  /// Range - The source code range that covers the full base
146193326Sed  /// specifier, including the "virtual" (if present) and access
147193326Sed  /// specifier (if present).
148193326Sed  SourceRange Range;
149193326Sed
150193326Sed  /// Virtual - Whether this is a virtual base class or not.
151193326Sed  bool Virtual : 1;
152193326Sed
153193326Sed  /// BaseOfClass - Whether this is the base of a class (true) or of a
154193326Sed  /// struct (false). This determines the mapping from the access
155193326Sed  /// specifier as written in the source code to the access specifier
156193326Sed  /// used for semantic analysis.
157193326Sed  bool BaseOfClass : 1;
158193326Sed
159193326Sed  /// Access - Access specifier as written in the source code (which
160193326Sed  /// may be AS_none). The actual type of data stored here is an
161193326Sed  /// AccessSpecifier, but we use "unsigned" here to work around a
162193326Sed  /// VC++ bug.
163193326Sed  unsigned Access : 2;
164193326Sed
165193326Sed  /// BaseType - The type of the base class. This will be a class or
166193326Sed  /// struct (or a typedef of such).
167193326Sed  QualType BaseType;
168193326Sed
169193326Sedpublic:
170193326Sed  CXXBaseSpecifier() { }
171193326Sed
172193326Sed  CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, QualType T)
173193326Sed    : Range(R), Virtual(V), BaseOfClass(BC), Access(A), BaseType(T) { }
174193326Sed
175193326Sed  /// getSourceRange - Retrieves the source range that contains the
176193326Sed  /// entire base specifier.
177193326Sed  SourceRange getSourceRange() const { return Range; }
178193326Sed
179193326Sed  /// isVirtual - Determines whether the base class is a virtual base
180193326Sed  /// class (or not).
181193326Sed  bool isVirtual() const { return Virtual; }
182193326Sed
183193326Sed  /// getAccessSpecifier - Returns the access specifier for this base
184193326Sed  /// specifier. This is the actual base specifier as used for
185193326Sed  /// semantic analysis, so the result can never be AS_none. To
186193326Sed  /// retrieve the access specifier as written in the source code, use
187193326Sed  /// getAccessSpecifierAsWritten().
188193326Sed  AccessSpecifier getAccessSpecifier() const {
189193326Sed    if ((AccessSpecifier)Access == AS_none)
190193326Sed      return BaseOfClass? AS_private : AS_public;
191193326Sed    else
192193326Sed      return (AccessSpecifier)Access;
193193326Sed  }
194193326Sed
195193326Sed  /// getAccessSpecifierAsWritten - Retrieves the access specifier as
196193326Sed  /// written in the source code (which may mean that no access
197193326Sed  /// specifier was explicitly written). Use getAccessSpecifier() to
198193326Sed  /// retrieve the access specifier for use in semantic analysis.
199193326Sed  AccessSpecifier getAccessSpecifierAsWritten() const {
200193326Sed    return (AccessSpecifier)Access;
201193326Sed  }
202193326Sed
203193326Sed  /// getType - Retrieves the type of the base class. This type will
204193326Sed  /// always be an unqualified class type.
205193326Sed  QualType getType() const { return BaseType; }
206193326Sed};
207193326Sed
208193326Sed/// CXXRecordDecl - Represents a C++ struct/union/class.
209193326Sed/// FIXME: This class will disappear once we've properly taught RecordDecl
210193326Sed/// to deal with C++-specific things.
211193326Sedclass CXXRecordDecl : public RecordDecl {
212193326Sed  /// UserDeclaredConstructor - True when this class has a
213193326Sed  /// user-declared constructor.
214193326Sed  bool UserDeclaredConstructor : 1;
215193326Sed
216193326Sed  /// UserDeclaredCopyConstructor - True when this class has a
217193326Sed  /// user-declared copy constructor.
218193326Sed  bool UserDeclaredCopyConstructor : 1;
219193326Sed
220193326Sed  /// UserDeclaredCopyAssignment - True when this class has a
221193326Sed  /// user-declared copy assignment operator.
222193326Sed  bool UserDeclaredCopyAssignment : 1;
223193326Sed
224193326Sed  /// UserDeclaredDestructor - True when this class has a
225193326Sed  /// user-declared destructor.
226193326Sed  bool UserDeclaredDestructor : 1;
227193326Sed
228193326Sed  /// Aggregate - True when this class is an aggregate.
229193326Sed  bool Aggregate : 1;
230193326Sed
231193326Sed  /// PlainOldData - True when this class is a POD-type.
232193326Sed  bool PlainOldData : 1;
233193326Sed
234193326Sed  /// Polymorphic - True when this class is polymorphic, i.e. has at least one
235193326Sed  /// virtual member or derives from a polymorphic class.
236193326Sed  bool Polymorphic : 1;
237193326Sed
238193326Sed  /// Abstract - True when this class is abstract, i.e. has at least one
239193326Sed  /// pure virtual function, (that can come from a base class).
240193326Sed  bool Abstract : 1;
241193326Sed
242193326Sed  /// HasTrivialConstructor - True when this class has a trivial constructor
243193326Sed  bool HasTrivialConstructor : 1;
244193326Sed
245193326Sed  /// HasTrivialDestructor - True when this class has a trivial destructor
246193326Sed  bool HasTrivialDestructor : 1;
247193326Sed
248193326Sed  /// Bases - Base classes of this class.
249193326Sed  /// FIXME: This is wasted space for a union.
250193326Sed  CXXBaseSpecifier *Bases;
251193326Sed
252193326Sed  /// NumBases - The number of base class specifiers in Bases.
253193326Sed  unsigned NumBases;
254193326Sed
255193326Sed  /// Conversions - Overload set containing the conversion functions
256193326Sed  /// of this C++ class (but not its inherited conversion
257193326Sed  /// functions). Each of the entries in this overload set is a
258193326Sed  /// CXXConversionDecl.
259193326Sed  OverloadedFunctionDecl Conversions;
260193326Sed
261193326Sed  /// \brief The template or declaration that this declaration
262193326Sed  /// describes or was instantiated from, respectively.
263193326Sed  ///
264193326Sed  /// For non-templates, this value will be NULL. For record
265193326Sed  /// declarations that describe a class template, this will be a
266193326Sed  /// pointer to a ClassTemplateDecl. For member
267193326Sed  /// classes of class template specializations, this will be the
268193326Sed  /// RecordDecl from which the member class was instantiated.
269193326Sed  llvm::PointerUnion<ClassTemplateDecl*, CXXRecordDecl*>
270193326Sed    TemplateOrInstantiation;
271193326Sed
272193326Sedprotected:
273193326Sed  CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
274193326Sed                SourceLocation L, IdentifierInfo *Id);
275193326Sed
276193326Sed  ~CXXRecordDecl();
277193326Sed
278193326Sedpublic:
279193326Sed  /// base_class_iterator - Iterator that traverses the base classes
280193326Sed  /// of a clas.
281193326Sed  typedef CXXBaseSpecifier*       base_class_iterator;
282193326Sed
283193326Sed  /// base_class_const_iterator - Iterator that traverses the base
284193326Sed  /// classes of a clas.
285193326Sed  typedef const CXXBaseSpecifier* base_class_const_iterator;
286193326Sed
287193326Sed  static CXXRecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC,
288193326Sed                               SourceLocation L, IdentifierInfo *Id,
289193326Sed                               CXXRecordDecl* PrevDecl=0,
290193326Sed                               bool DelayTypeCreation = false);
291193326Sed
292193326Sed  /// setBases - Sets the base classes of this struct or class.
293193326Sed  void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
294193326Sed
295193326Sed  /// getNumBases - Retrieves the number of base classes of this
296193326Sed  /// class.
297193326Sed  unsigned getNumBases() const { return NumBases; }
298193326Sed
299193326Sed  base_class_iterator       bases_begin()       { return Bases; }
300193326Sed  base_class_const_iterator bases_begin() const { return Bases; }
301193326Sed  base_class_iterator       bases_end()         { return Bases + NumBases; }
302193326Sed  base_class_const_iterator bases_end()   const { return Bases + NumBases; }
303193326Sed
304193326Sed  /// hasConstCopyConstructor - Determines whether this class has a
305193326Sed  /// copy constructor that accepts a const-qualified argument.
306193326Sed  bool hasConstCopyConstructor(ASTContext &Context) const;
307193326Sed
308194711Sed  /// getCopyConstructor - Returns the copy constructor for this class
309194711Sed  CXXConstructorDecl *getCopyConstructor(ASTContext &Context,
310194711Sed                                         unsigned TypeQuals) const;
311194711Sed
312193326Sed  /// hasConstCopyAssignment - Determines whether this class has a
313193326Sed  /// copy assignment operator that accepts a const-qualified argument.
314193326Sed  bool hasConstCopyAssignment(ASTContext &Context) const;
315193326Sed
316193326Sed  /// addedConstructor - Notify the class that another constructor has
317193326Sed  /// been added. This routine helps maintain information about the
318193326Sed  /// class based on which constructors have been added.
319193326Sed  void addedConstructor(ASTContext &Context, CXXConstructorDecl *ConDecl);
320193326Sed
321193326Sed  /// hasUserDeclaredConstructor - Whether this class has any
322193326Sed  /// user-declared constructors. When true, a default constructor
323193326Sed  /// will not be implicitly declared.
324193326Sed  bool hasUserDeclaredConstructor() const { return UserDeclaredConstructor; }
325193326Sed
326193326Sed  /// hasUserDeclaredCopyConstructor - Whether this class has a
327193326Sed  /// user-declared copy constructor. When false, a copy constructor
328193326Sed  /// will be implicitly declared.
329193326Sed  bool hasUserDeclaredCopyConstructor() const {
330193326Sed    return UserDeclaredCopyConstructor;
331193326Sed  }
332193326Sed
333193326Sed  /// addedAssignmentOperator - Notify the class that another assignment
334193326Sed  /// operator has been added. This routine helps maintain information about the
335193326Sed   /// class based on which operators have been added.
336193326Sed  void addedAssignmentOperator(ASTContext &Context, CXXMethodDecl *OpDecl);
337193326Sed
338193326Sed  /// hasUserDeclaredCopyAssignment - Whether this class has a
339193326Sed  /// user-declared copy assignment operator. When false, a copy
340193326Sed  /// assigment operator will be implicitly declared.
341193326Sed  bool hasUserDeclaredCopyAssignment() const {
342193326Sed    return UserDeclaredCopyAssignment;
343193326Sed  }
344193326Sed
345193326Sed  /// hasUserDeclaredDestructor - Whether this class has a
346193326Sed  /// user-declared destructor. When false, a destructor will be
347193326Sed  /// implicitly declared.
348193326Sed  bool hasUserDeclaredDestructor() const { return UserDeclaredDestructor; }
349193326Sed
350193326Sed  /// setUserDeclaredDestructor - Set whether this class has a
351193326Sed  /// user-declared destructor. If not set by the time the class is
352193326Sed  /// fully defined, a destructor will be implicitly declared.
353193326Sed  void setUserDeclaredDestructor(bool UCD) {
354193326Sed    UserDeclaredDestructor = UCD;
355193326Sed  }
356193326Sed
357193326Sed  /// getConversions - Retrieve the overload set containing all of the
358193326Sed  /// conversion functions in this class.
359193326Sed  OverloadedFunctionDecl *getConversionFunctions() {
360193326Sed    return &Conversions;
361193326Sed  }
362193326Sed  const OverloadedFunctionDecl *getConversionFunctions() const {
363193326Sed    return &Conversions;
364193326Sed  }
365193326Sed
366193326Sed  /// addConversionFunction - Add a new conversion function to the
367193326Sed  /// list of conversion functions.
368193326Sed  void addConversionFunction(ASTContext &Context, CXXConversionDecl *ConvDecl);
369193326Sed
370193326Sed  /// isAggregate - Whether this class is an aggregate (C++
371193326Sed  /// [dcl.init.aggr]), which is a class with no user-declared
372193326Sed  /// constructors, no private or protected non-static data members,
373193326Sed  /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1).
374193326Sed  bool isAggregate() const { return Aggregate; }
375193326Sed
376193326Sed  /// setAggregate - Set whether this class is an aggregate (C++
377193326Sed  /// [dcl.init.aggr]).
378193326Sed  void setAggregate(bool Agg) { Aggregate = Agg; }
379193326Sed
380193326Sed  /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class
381193326Sed  /// that is an aggregate that has no non-static non-POD data members, no
382193326Sed  /// reference data members, no user-defined copy assignment operator and no
383193326Sed  /// user-defined destructor.
384193326Sed  bool isPOD() const { return PlainOldData; }
385193326Sed
386193326Sed  /// setPOD - Set whether this class is a POD-type (C++ [class]p4).
387193326Sed  void setPOD(bool POD) { PlainOldData = POD; }
388193326Sed
389193326Sed  /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]),
390193326Sed  /// which means that the class contains or inherits a virtual function.
391193326Sed  bool isPolymorphic() const { return Polymorphic; }
392193326Sed
393193326Sed  /// setPolymorphic - Set whether this class is polymorphic (C++
394193326Sed  /// [class.virtual]).
395193326Sed  void setPolymorphic(bool Poly) { Polymorphic = Poly; }
396193326Sed
397193326Sed  /// isAbstract - Whether this class is abstract (C++ [class.abstract]),
398193326Sed  /// which means that the class contains or inherits a pure virtual function.
399193326Sed  bool isAbstract() const { return Abstract; }
400193326Sed
401193326Sed  /// setAbstract - Set whether this class is abstract (C++ [class.abstract])
402193326Sed  void setAbstract(bool Abs) { Abstract = Abs; }
403193326Sed
404193326Sed  // hasTrivialConstructor - Whether this class has a trivial constructor
405193326Sed  // (C++ [class.ctor]p5)
406193326Sed  bool hasTrivialConstructor() const { return HasTrivialConstructor; }
407193326Sed
408193326Sed  // setHasTrivialConstructor - Set whether this class has a trivial constructor
409193326Sed  // (C++ [class.ctor]p5)
410193326Sed  void setHasTrivialConstructor(bool TC) { HasTrivialConstructor = TC; }
411193326Sed
412193326Sed  // hasTrivialDestructor - Whether this class has a trivial destructor
413193326Sed  // (C++ [class.dtor]p3)
414193326Sed  bool hasTrivialDestructor() const { return HasTrivialDestructor; }
415193326Sed
416193326Sed  // setHasTrivialDestructor - Set whether this class has a trivial destructor
417193326Sed  // (C++ [class.dtor]p3)
418193326Sed  void setHasTrivialDestructor(bool TC) { HasTrivialDestructor = TC; }
419193326Sed
420193326Sed  /// \brief If this record is an instantiation of a member class,
421193326Sed  /// retrieves the member class from which it was instantiated.
422193326Sed  ///
423193326Sed  /// This routine will return non-NULL for (non-templated) member
424193326Sed  /// classes of class templates. For example, given:
425193326Sed  ///
426193326Sed  /// \code
427193326Sed  /// template<typename T>
428193326Sed  /// struct X {
429193326Sed  ///   struct A { };
430193326Sed  /// };
431193326Sed  /// \endcode
432193326Sed  ///
433193326Sed  /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
434193326Sed  /// whose parent is the class template specialization X<int>. For
435193326Sed  /// this declaration, getInstantiatedFromMemberClass() will return
436193326Sed  /// the CXXRecordDecl X<T>::A. When a complete definition of
437193326Sed  /// X<int>::A is required, it will be instantiated from the
438193326Sed  /// declaration returned by getInstantiatedFromMemberClass().
439193326Sed  CXXRecordDecl *getInstantiatedFromMemberClass() const {
440193326Sed    return TemplateOrInstantiation.dyn_cast<CXXRecordDecl*>();
441193326Sed  }
442193326Sed
443193326Sed  /// \brief Specify that this record is an instantiation of the
444193326Sed  /// member class RD.
445193326Sed  void setInstantiationOfMemberClass(CXXRecordDecl *RD) {
446193326Sed    TemplateOrInstantiation = RD;
447193326Sed  }
448193326Sed
449193326Sed  /// \brief Retrieves the class template that is described by this
450193326Sed  /// class declaration.
451193326Sed  ///
452193326Sed  /// Every class template is represented as a ClassTemplateDecl and a
453193326Sed  /// CXXRecordDecl. The former contains template properties (such as
454193326Sed  /// the template parameter lists) while the latter contains the
455193326Sed  /// actual description of the template's
456193326Sed  /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
457193326Sed  /// CXXRecordDecl that from a ClassTemplateDecl, while
458193326Sed  /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
459193326Sed  /// a CXXRecordDecl.
460193326Sed  ClassTemplateDecl *getDescribedClassTemplate() const {
461193326Sed    return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>();
462193326Sed  }
463193326Sed
464193326Sed  void setDescribedClassTemplate(ClassTemplateDecl *Template) {
465193326Sed    TemplateOrInstantiation = Template;
466193326Sed  }
467193326Sed
468194613Sed  /// getDefaultConstructor - Returns the default constructor for this class
469194613Sed  CXXConstructorDecl *getDefaultConstructor(ASTContext &Context);
470194613Sed
471193326Sed  /// getDestructor - Returns the destructor decl for this class.
472193326Sed  const CXXDestructorDecl *getDestructor(ASTContext &Context);
473193326Sed
474195099Sed  /// isLocalClass - If the class is a local class [class.local], returns
475195099Sed  /// the enclosing function declaration.
476195099Sed  const FunctionDecl *isLocalClass() const {
477195099Sed    if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
478195099Sed      return RD->isLocalClass();
479195099Sed
480195099Sed    return dyn_cast<FunctionDecl>(getDeclContext());
481195099Sed  }
482195099Sed
483193326Sed  /// viewInheritance - Renders and displays an inheritance diagram
484193326Sed  /// for this C++ class and all of its base classes (transitively) using
485193326Sed  /// GraphViz.
486193326Sed  void viewInheritance(ASTContext& Context) const;
487193326Sed
488193326Sed  static bool classof(const Decl *D) {
489193326Sed    return D->getKind() == CXXRecord ||
490193326Sed           D->getKind() == ClassTemplateSpecialization ||
491193326Sed           D->getKind() == ClassTemplatePartialSpecialization;
492193326Sed  }
493193326Sed  static bool classof(const CXXRecordDecl *D) { return true; }
494193326Sed  static bool classof(const ClassTemplateSpecializationDecl *D) {
495193326Sed    return true;
496193326Sed  }
497193326Sed};
498193326Sed
499193326Sed/// CXXMethodDecl - Represents a static or instance method of a
500193326Sed/// struct/union/class.
501193326Sedclass CXXMethodDecl : public FunctionDecl {
502193326Sedprotected:
503193326Sed  CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation L,
504193326Sed                DeclarationName N, QualType T,
505193326Sed                bool isStatic, bool isInline)
506193326Sed    : FunctionDecl(DK, RD, L, N, T, (isStatic ? Static : None),
507193326Sed                   isInline) {}
508193326Sed
509193326Sedpublic:
510193326Sed  static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
511193326Sed                              SourceLocation L, DeclarationName N,
512193326Sed                              QualType T, bool isStatic = false,
513193326Sed                              bool isInline = false);
514193326Sed
515193326Sed  bool isStatic() const { return getStorageClass() == Static; }
516193326Sed  bool isInstance() const { return !isStatic(); }
517193326Sed
518193326Sed  bool isVirtual() const {
519193326Sed    return isVirtualAsWritten() ||
520193326Sed      (begin_overridden_methods() != end_overridden_methods());
521193326Sed  }
522193326Sed
523193326Sed  ///
524193326Sed  void addOverriddenMethod(const CXXMethodDecl *MD);
525193326Sed
526193326Sed  typedef const CXXMethodDecl ** method_iterator;
527193326Sed
528193326Sed  method_iterator begin_overridden_methods() const;
529193326Sed  method_iterator end_overridden_methods() const;
530193326Sed
531193326Sed  /// getParent - Returns the parent of this method declaration, which
532193326Sed  /// is the class in which this method is defined.
533193326Sed  const CXXRecordDecl *getParent() const {
534193326Sed    return cast<CXXRecordDecl>(FunctionDecl::getParent());
535193326Sed  }
536193326Sed
537193326Sed  /// getParent - Returns the parent of this method declaration, which
538193326Sed  /// is the class in which this method is defined.
539193326Sed  CXXRecordDecl *getParent() {
540193326Sed    return const_cast<CXXRecordDecl *>(
541193326Sed             cast<CXXRecordDecl>(FunctionDecl::getParent()));
542193326Sed  }
543193326Sed
544193326Sed  /// getThisType - Returns the type of 'this' pointer.
545193326Sed  /// Should only be called for instance methods.
546193326Sed  QualType getThisType(ASTContext &C) const;
547193326Sed
548193326Sed  unsigned getTypeQualifiers() const {
549193326Sed    return getType()->getAsFunctionProtoType()->getTypeQuals();
550193326Sed  }
551193326Sed
552193326Sed  // Implement isa/cast/dyncast/etc.
553193326Sed  static bool classof(const Decl *D) {
554193326Sed    return D->getKind() >= CXXMethod && D->getKind() <= CXXConversion;
555193326Sed  }
556193326Sed  static bool classof(const CXXMethodDecl *D) { return true; }
557193326Sed};
558193326Sed
559193326Sed/// CXXBaseOrMemberInitializer - Represents a C++ base or member
560193326Sed/// initializer, which is part of a constructor initializer that
561193326Sed/// initializes one non-static member variable or one base class. For
562193326Sed/// example, in the following, both 'A(a)' and 'f(3.14159)' are member
563193326Sed/// initializers:
564193326Sed///
565193326Sed/// @code
566193326Sed/// class A { };
567193326Sed/// class B : public A {
568193326Sed///   float f;
569193326Sed/// public:
570193326Sed///   B(A& a) : A(a), f(3.14159) { }
571193326Sed/// };
572194613Sed/// @endcode
573193326Sedclass CXXBaseOrMemberInitializer {
574193326Sed  /// BaseOrMember - This points to the entity being initialized,
575193326Sed  /// which is either a base class (a Type) or a non-static data
576193326Sed  /// member. When the low bit is 1, it's a base
577193326Sed  /// class; when the low bit is 0, it's a member.
578193326Sed  uintptr_t BaseOrMember;
579193326Sed
580193326Sed  /// Args - The arguments used to initialize the base or member.
581193326Sed  Expr **Args;
582193326Sed  unsigned NumArgs;
583193326Sed
584193326Sedpublic:
585193326Sed  /// CXXBaseOrMemberInitializer - Creates a new base-class initializer.
586193326Sed  explicit
587193326Sed  CXXBaseOrMemberInitializer(QualType BaseType, Expr **Args, unsigned NumArgs);
588193326Sed
589193326Sed  /// CXXBaseOrMemberInitializer - Creates a new member initializer.
590193326Sed  explicit
591193326Sed  CXXBaseOrMemberInitializer(FieldDecl *Member, Expr **Args, unsigned NumArgs);
592193326Sed
593193326Sed  /// ~CXXBaseOrMemberInitializer - Destroy the base or member initializer.
594193326Sed  ~CXXBaseOrMemberInitializer();
595193326Sed
596193326Sed  /// arg_iterator - Iterates through the member initialization
597193326Sed  /// arguments.
598193326Sed  typedef Expr **arg_iterator;
599193326Sed
600193326Sed  /// arg_const_iterator - Iterates through the member initialization
601193326Sed  /// arguments.
602193326Sed  typedef Expr * const * arg_const_iterator;
603193326Sed
604193326Sed  /// isBaseInitializer - Returns true when this initializer is
605193326Sed  /// initializing a base class.
606193326Sed  bool isBaseInitializer() const { return (BaseOrMember & 0x1) != 0; }
607193326Sed
608193326Sed  /// isMemberInitializer - Returns true when this initializer is
609193326Sed  /// initializing a non-static data member.
610193326Sed  bool isMemberInitializer() const { return (BaseOrMember & 0x1) == 0; }
611193326Sed
612193326Sed  /// getBaseClass - If this is a base class initializer, returns the
613193326Sed  /// type used to specify the initializer. The resulting type will be
614193326Sed  /// a class type or a typedef of a class type. If this is not a base
615193326Sed  /// class initializer, returns NULL.
616193326Sed  Type *getBaseClass() {
617193326Sed    if (isBaseInitializer())
618193326Sed      return reinterpret_cast<Type*>(BaseOrMember & ~0x01);
619193326Sed    else
620193326Sed      return 0;
621193326Sed  }
622193326Sed
623193326Sed  /// getBaseClass - If this is a base class initializer, returns the
624193326Sed  /// type used to specify the initializer. The resulting type will be
625193326Sed  /// a class type or a typedef of a class type. If this is not a base
626193326Sed  /// class initializer, returns NULL.
627193326Sed  const Type *getBaseClass() const {
628193326Sed    if (isBaseInitializer())
629193326Sed      return reinterpret_cast<const Type*>(BaseOrMember & ~0x01);
630193326Sed    else
631193326Sed      return 0;
632193326Sed  }
633193326Sed
634193326Sed  /// getMember - If this is a member initializer, returns the
635193326Sed  /// declaration of the non-static data member being
636193326Sed  /// initialized. Otherwise, returns NULL.
637193326Sed  FieldDecl *getMember() {
638193326Sed    if (isMemberInitializer())
639193326Sed      return reinterpret_cast<FieldDecl *>(BaseOrMember);
640193326Sed    else
641193326Sed      return 0;
642193326Sed  }
643193326Sed
644193326Sed  /// begin() - Retrieve an iterator to the first initializer argument.
645193326Sed  arg_iterator       begin()       { return Args; }
646193326Sed  /// begin() - Retrieve an iterator to the first initializer argument.
647193326Sed  arg_const_iterator begin() const { return Args; }
648193326Sed
649193326Sed  /// end() - Retrieve an iterator past the last initializer argument.
650193326Sed  arg_iterator       end()       { return Args + NumArgs; }
651193326Sed  /// end() - Retrieve an iterator past the last initializer argument.
652193326Sed  arg_const_iterator end() const { return Args + NumArgs; }
653193326Sed
654193326Sed  /// getNumArgs - Determine the number of arguments used to
655193326Sed  /// initialize the member or base.
656193326Sed  unsigned getNumArgs() const { return NumArgs; }
657193326Sed};
658193326Sed
659193326Sed/// CXXConstructorDecl - Represents a C++ constructor within a
660193326Sed/// class. For example:
661193326Sed///
662193326Sed/// @code
663193326Sed/// class X {
664193326Sed/// public:
665193326Sed///   explicit X(int); // represented by a CXXConstructorDecl.
666193326Sed/// };
667193326Sed/// @endcode
668193326Sedclass CXXConstructorDecl : public CXXMethodDecl {
669193326Sed  /// Explicit - Whether this constructor is explicit.
670193326Sed  bool Explicit : 1;
671193326Sed
672193326Sed  /// ImplicitlyDefined - Whether this constructor was implicitly
673193326Sed  /// defined by the compiler. When false, the constructor was defined
674193326Sed  /// by the user. In C++03, this flag will have the same value as
675193326Sed  /// Implicit. In C++0x, however, a constructor that is
676193326Sed  /// explicitly defaulted (i.e., defined with " = default") will have
677193326Sed  /// @c !Implicit && ImplicitlyDefined.
678193326Sed  bool ImplicitlyDefined : 1;
679194613Sed
680193326Sed  /// FIXME: Add support for base and member initializers.
681193326Sed
682193326Sed  CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation L,
683193326Sed                     DeclarationName N, QualType T,
684193326Sed                     bool isExplicit, bool isInline, bool isImplicitlyDeclared)
685193326Sed    : CXXMethodDecl(CXXConstructor, RD, L, N, T, false, isInline),
686194711Sed      Explicit(isExplicit), ImplicitlyDefined(false) {
687193326Sed    setImplicit(isImplicitlyDeclared);
688193326Sed  }
689193326Sed
690193326Sedpublic:
691193326Sed  static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
692193326Sed                                    SourceLocation L, DeclarationName N,
693193326Sed                                    QualType T, bool isExplicit,
694193326Sed                                    bool isInline, bool isImplicitlyDeclared);
695193326Sed
696193326Sed  /// isExplicit - Whether this constructor was marked "explicit" or not.
697193326Sed  bool isExplicit() const { return Explicit; }
698193326Sed
699193326Sed  /// isImplicitlyDefined - Whether this constructor was implicitly
700193326Sed  /// defined. If false, then this constructor was defined by the
701193326Sed  /// user. This operation can only be invoked if the constructor has
702193326Sed  /// already been defined.
703193326Sed  bool isImplicitlyDefined(ASTContext &C) const {
704193326Sed    assert(isThisDeclarationADefinition() &&
705193326Sed           "Can only get the implicit-definition flag once the constructor has been defined");
706193326Sed    return ImplicitlyDefined;
707193326Sed  }
708193326Sed
709193326Sed  /// setImplicitlyDefined - Set whether this constructor was
710193326Sed  /// implicitly defined or not.
711193326Sed  void setImplicitlyDefined(bool ID) {
712193326Sed    assert(isThisDeclarationADefinition() &&
713193326Sed           "Can only set the implicit-definition flag once the constructor has been defined");
714193326Sed    ImplicitlyDefined = ID;
715193326Sed  }
716194613Sed
717193326Sed  /// isDefaultConstructor - Whether this constructor is a default
718193326Sed  /// constructor (C++ [class.ctor]p5), which can be used to
719193326Sed  /// default-initialize a class of this type.
720193326Sed  bool isDefaultConstructor() const;
721193326Sed
722193326Sed  /// isCopyConstructor - Whether this constructor is a copy
723193326Sed  /// constructor (C++ [class.copy]p2, which can be used to copy the
724193326Sed  /// class. @p TypeQuals will be set to the qualifiers on the
725193326Sed  /// argument type. For example, @p TypeQuals would be set to @c
726193326Sed  /// QualType::Const for the following copy constructor:
727193326Sed  ///
728193326Sed  /// @code
729193326Sed  /// class X {
730193326Sed  /// public:
731193326Sed  ///   X(const X&);
732193326Sed  /// };
733193326Sed  /// @endcode
734193326Sed  bool isCopyConstructor(ASTContext &Context, unsigned &TypeQuals) const;
735193326Sed
736193326Sed  /// isCopyConstructor - Whether this constructor is a copy
737193326Sed  /// constructor (C++ [class.copy]p2, which can be used to copy the
738193326Sed  /// class.
739193326Sed  bool isCopyConstructor(ASTContext &Context) const {
740193326Sed    unsigned TypeQuals = 0;
741193326Sed    return isCopyConstructor(Context, TypeQuals);
742193326Sed  }
743193326Sed
744193326Sed  /// isConvertingConstructor - Whether this constructor is a
745193326Sed  /// converting constructor (C++ [class.conv.ctor]), which can be
746193326Sed  /// used for user-defined conversions.
747193326Sed  bool isConvertingConstructor() const;
748193326Sed
749193326Sed  // Implement isa/cast/dyncast/etc.
750193326Sed  static bool classof(const Decl *D) {
751193326Sed    return D->getKind() == CXXConstructor;
752193326Sed  }
753193326Sed  static bool classof(const CXXConstructorDecl *D) { return true; }
754193326Sed};
755193326Sed
756193326Sed/// CXXDestructorDecl - Represents a C++ destructor within a
757193326Sed/// class. For example:
758193326Sed///
759193326Sed/// @code
760193326Sed/// class X {
761193326Sed/// public:
762193326Sed///   ~X(); // represented by a CXXDestructorDecl.
763193326Sed/// };
764193326Sed/// @endcode
765193326Sedclass CXXDestructorDecl : public CXXMethodDecl {
766193326Sed  /// ImplicitlyDefined - Whether this destructor was implicitly
767193326Sed  /// defined by the compiler. When false, the destructor was defined
768193326Sed  /// by the user. In C++03, this flag will have the same value as
769193326Sed  /// Implicit. In C++0x, however, a destructor that is
770193326Sed  /// explicitly defaulted (i.e., defined with " = default") will have
771193326Sed  /// @c !Implicit && ImplicitlyDefined.
772193326Sed  bool ImplicitlyDefined : 1;
773193326Sed
774193326Sed  CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation L,
775193326Sed                    DeclarationName N, QualType T,
776193326Sed                    bool isInline, bool isImplicitlyDeclared)
777193326Sed    : CXXMethodDecl(CXXDestructor, RD, L, N, T, false, isInline),
778193326Sed      ImplicitlyDefined(false) {
779193326Sed    setImplicit(isImplicitlyDeclared);
780193326Sed  }
781193326Sed
782193326Sedpublic:
783193326Sed  static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
784193326Sed                                   SourceLocation L, DeclarationName N,
785193326Sed                                   QualType T, bool isInline,
786193326Sed                                   bool isImplicitlyDeclared);
787193326Sed
788193326Sed  /// isImplicitlyDefined - Whether this destructor was implicitly
789193326Sed  /// defined. If false, then this destructor was defined by the
790193326Sed  /// user. This operation can only be invoked if the destructor has
791193326Sed  /// already been defined.
792193326Sed  bool isImplicitlyDefined() const {
793193326Sed    assert(isThisDeclarationADefinition() &&
794193326Sed           "Can only get the implicit-definition flag once the destructor has been defined");
795193326Sed    return ImplicitlyDefined;
796193326Sed  }
797193326Sed
798193326Sed  /// setImplicitlyDefined - Set whether this destructor was
799193326Sed  /// implicitly defined or not.
800193326Sed  void setImplicitlyDefined(bool ID) {
801193326Sed    assert(isThisDeclarationADefinition() &&
802193326Sed           "Can only set the implicit-definition flag once the destructor has been defined");
803193326Sed    ImplicitlyDefined = ID;
804193326Sed  }
805193326Sed
806193326Sed  // Implement isa/cast/dyncast/etc.
807193326Sed  static bool classof(const Decl *D) {
808193326Sed    return D->getKind() == CXXDestructor;
809193326Sed  }
810193326Sed  static bool classof(const CXXDestructorDecl *D) { return true; }
811193326Sed};
812193326Sed
813193326Sed/// CXXConversionDecl - Represents a C++ conversion function within a
814193326Sed/// class. For example:
815193326Sed///
816193326Sed/// @code
817193326Sed/// class X {
818193326Sed/// public:
819193326Sed///   operator bool();
820193326Sed/// };
821193326Sed/// @endcode
822193326Sedclass CXXConversionDecl : public CXXMethodDecl {
823193326Sed  /// Explicit - Whether this conversion function is marked
824193326Sed  /// "explicit", meaning that it can only be applied when the user
825193326Sed  /// explicitly wrote a cast. This is a C++0x feature.
826193326Sed  bool Explicit : 1;
827193326Sed
828193326Sed  CXXConversionDecl(CXXRecordDecl *RD, SourceLocation L,
829193326Sed                    DeclarationName N, QualType T,
830193326Sed                    bool isInline, bool isExplicit)
831193326Sed    : CXXMethodDecl(CXXConversion, RD, L, N, T, false, isInline),
832193326Sed      Explicit(isExplicit) { }
833193326Sed
834193326Sedpublic:
835193326Sed  static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
836193326Sed                                   SourceLocation L, DeclarationName N,
837193326Sed                                   QualType T, bool isInline,
838193326Sed                                   bool isExplicit);
839193326Sed
840193326Sed  /// isExplicit - Whether this is an explicit conversion operator
841193326Sed  /// (C++0x only). Explicit conversion operators are only considered
842193326Sed  /// when the user has explicitly written a cast.
843193326Sed  bool isExplicit() const { return Explicit; }
844193326Sed
845193326Sed  /// getConversionType - Returns the type that this conversion
846193326Sed  /// function is converting to.
847193326Sed  QualType getConversionType() const {
848193326Sed    return getType()->getAsFunctionType()->getResultType();
849193326Sed  }
850193326Sed
851193326Sed  // Implement isa/cast/dyncast/etc.
852193326Sed  static bool classof(const Decl *D) {
853193326Sed    return D->getKind() == CXXConversion;
854193326Sed  }
855193326Sed  static bool classof(const CXXConversionDecl *D) { return true; }
856193326Sed};
857193326Sed
858193326Sed/// LinkageSpecDecl - This represents a linkage specification.  For example:
859193326Sed///   extern "C" void foo();
860193326Sed///
861193326Sedclass LinkageSpecDecl : public Decl, public DeclContext {
862193326Sedpublic:
863193326Sed  /// LanguageIDs - Used to represent the language in a linkage
864193326Sed  /// specification.  The values are part of the serialization abi for
865193326Sed  /// ASTs and cannot be changed without altering that abi.  To help
866193326Sed  /// ensure a stable abi for this, we choose the DW_LANG_ encodings
867193326Sed  /// from the dwarf standard.
868193326Sed  enum LanguageIDs { lang_c = /* DW_LANG_C */ 0x0002,
869193326Sed  lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004 };
870193326Sedprivate:
871193326Sed  /// Language - The language for this linkage specification.
872193326Sed  LanguageIDs Language;
873193326Sed
874193326Sed  /// HadBraces - Whether this linkage specification had curly braces or not.
875193326Sed  bool HadBraces : 1;
876193326Sed
877193326Sed  LinkageSpecDecl(DeclContext *DC, SourceLocation L, LanguageIDs lang,
878193326Sed                  bool Braces)
879193326Sed    : Decl(LinkageSpec, DC, L),
880193326Sed      DeclContext(LinkageSpec), Language(lang), HadBraces(Braces) { }
881193326Sed
882193326Sedpublic:
883193326Sed  static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
884193326Sed                                 SourceLocation L, LanguageIDs Lang,
885193326Sed                                 bool Braces);
886193326Sed
887193326Sed  LanguageIDs getLanguage() const { return Language; }
888193326Sed
889193326Sed  /// hasBraces - Determines whether this linkage specification had
890193326Sed  /// braces in its syntactic form.
891193326Sed  bool hasBraces() const { return HadBraces; }
892193326Sed
893193326Sed  static bool classof(const Decl *D) {
894193326Sed    return D->getKind() == LinkageSpec;
895193326Sed  }
896193326Sed  static bool classof(const LinkageSpecDecl *D) { return true; }
897193326Sed  static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
898193326Sed    return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
899193326Sed  }
900193326Sed  static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
901193326Sed    return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
902193326Sed  }
903193326Sed};
904193326Sed
905193326Sed/// UsingDirectiveDecl - Represents C++ using-directive. For example:
906193326Sed///
907193326Sed///    using namespace std;
908193326Sed///
909193326Sed// NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide
910193326Sed// artificial name, for all using-directives in order to store
911193326Sed// them in DeclContext effectively.
912193326Sedclass UsingDirectiveDecl : public NamedDecl {
913193326Sed
914193326Sed  /// SourceLocation - Location of 'namespace' token.
915193326Sed  SourceLocation NamespaceLoc;
916193326Sed
917193326Sed  /// \brief The source range that covers the nested-name-specifier
918193326Sed  /// preceding the namespace name.
919193326Sed  SourceRange QualifierRange;
920193326Sed
921193326Sed  /// \brief The nested-name-specifier that precedes the namespace
922193326Sed  /// name, if any.
923193326Sed  NestedNameSpecifier *Qualifier;
924193326Sed
925193326Sed  /// IdentLoc - Location of nominated namespace-name identifier.
926193326Sed  // FIXME: We don't store location of scope specifier.
927193326Sed  SourceLocation IdentLoc;
928193326Sed
929193326Sed  /// NominatedNamespace - Namespace nominated by using-directive.
930193326Sed  NamespaceDecl *NominatedNamespace;
931193326Sed
932193326Sed  /// Enclosing context containing both using-directive and nomintated
933193326Sed  /// namespace.
934193326Sed  DeclContext *CommonAncestor;
935193326Sed
936193326Sed  /// getUsingDirectiveName - Returns special DeclarationName used by
937193326Sed  /// using-directives. This is only used by DeclContext for storing
938193326Sed  /// UsingDirectiveDecls in its lookup structure.
939193326Sed  static DeclarationName getName() {
940193326Sed    return DeclarationName::getUsingDirectiveName();
941193326Sed  }
942193326Sed
943193326Sed  UsingDirectiveDecl(DeclContext *DC, SourceLocation L,
944193326Sed                     SourceLocation NamespcLoc,
945193326Sed                     SourceRange QualifierRange,
946193326Sed                     NestedNameSpecifier *Qualifier,
947193326Sed                     SourceLocation IdentLoc,
948193326Sed                     NamespaceDecl *Nominated,
949193326Sed                     DeclContext *CommonAncestor)
950193326Sed    : NamedDecl(Decl::UsingDirective, DC, L, getName()),
951193326Sed      NamespaceLoc(NamespcLoc), QualifierRange(QualifierRange),
952193326Sed      Qualifier(Qualifier), IdentLoc(IdentLoc),
953193326Sed      NominatedNamespace(Nominated? Nominated->getOriginalNamespace() : 0),
954193326Sed      CommonAncestor(CommonAncestor) {
955193326Sed  }
956193326Sed
957193326Sedpublic:
958193326Sed  /// \brief Retrieve the source range of the nested-name-specifier
959193326Sed  /// that qualifiers the namespace name.
960193326Sed  SourceRange getQualifierRange() const { return QualifierRange; }
961193326Sed
962193326Sed  /// \brief Retrieve the nested-name-specifier that qualifies the
963193326Sed  /// name of the namespace.
964193326Sed  NestedNameSpecifier *getQualifier() const { return Qualifier; }
965193326Sed
966193326Sed  /// getNominatedNamespace - Returns namespace nominated by using-directive.
967193326Sed  NamespaceDecl *getNominatedNamespace() { return NominatedNamespace; }
968193326Sed
969193326Sed  const NamespaceDecl *getNominatedNamespace() const {
970193326Sed    return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
971193326Sed  }
972193326Sed
973193326Sed  /// getCommonAncestor - returns common ancestor context of using-directive,
974193326Sed  /// and nominated by it namespace.
975193326Sed  DeclContext *getCommonAncestor() { return CommonAncestor; }
976193326Sed  const DeclContext *getCommonAncestor() const { return CommonAncestor; }
977193326Sed
978193326Sed  /// getNamespaceKeyLocation - Returns location of namespace keyword.
979193326Sed  SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
980193326Sed
981193326Sed  /// getIdentLocation - Returns location of identifier.
982193326Sed  SourceLocation getIdentLocation() const { return IdentLoc; }
983193326Sed
984193326Sed  static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
985193326Sed                                    SourceLocation L,
986193326Sed                                    SourceLocation NamespaceLoc,
987193326Sed                                    SourceRange QualifierRange,
988193326Sed                                    NestedNameSpecifier *Qualifier,
989193326Sed                                    SourceLocation IdentLoc,
990193326Sed                                    NamespaceDecl *Nominated,
991193326Sed                                    DeclContext *CommonAncestor);
992193326Sed
993193326Sed  static bool classof(const Decl *D) {
994193326Sed    return D->getKind() == Decl::UsingDirective;
995193326Sed  }
996193326Sed  static bool classof(const UsingDirectiveDecl *D) { return true; }
997193326Sed
998193326Sed  // Friend for getUsingDirectiveName.
999193326Sed  friend class DeclContext;
1000193326Sed};
1001193326Sed
1002193326Sed/// NamespaceAliasDecl - Represents a C++ namespace alias. For example:
1003193326Sed///
1004193326Sed/// @code
1005193326Sed/// namespace Foo = Bar;
1006193326Sed/// @endcode
1007193326Sedclass NamespaceAliasDecl : public NamedDecl {
1008193326Sed  SourceLocation AliasLoc;
1009193326Sed
1010193326Sed  /// \brief The source range that covers the nested-name-specifier
1011193326Sed  /// preceding the namespace name.
1012193326Sed  SourceRange QualifierRange;
1013193326Sed
1014193326Sed  /// \brief The nested-name-specifier that precedes the namespace
1015193326Sed  /// name, if any.
1016193326Sed  NestedNameSpecifier *Qualifier;
1017193326Sed
1018193326Sed  /// IdentLoc - Location of namespace identifier.
1019193326Sed  SourceLocation IdentLoc;
1020193326Sed
1021193326Sed  /// Namespace - The Decl that this alias points to. Can either be a
1022193326Sed  /// NamespaceDecl or a NamespaceAliasDecl.
1023193326Sed  NamedDecl *Namespace;
1024193326Sed
1025193326Sed  NamespaceAliasDecl(DeclContext *DC, SourceLocation L,
1026193326Sed                     SourceLocation AliasLoc, IdentifierInfo *Alias,
1027193326Sed                     SourceRange QualifierRange,
1028193326Sed                     NestedNameSpecifier *Qualifier,
1029193326Sed                     SourceLocation IdentLoc, NamedDecl *Namespace)
1030193326Sed    : NamedDecl(Decl::NamespaceAlias, DC, L, Alias), AliasLoc(AliasLoc),
1031193326Sed      QualifierRange(QualifierRange), Qualifier(Qualifier),
1032193326Sed      IdentLoc(IdentLoc), Namespace(Namespace) { }
1033193326Sed
1034193326Sedpublic:
1035193326Sed  /// \brief Retrieve the source range of the nested-name-specifier
1036193326Sed  /// that qualifiers the namespace name.
1037193326Sed  SourceRange getQualifierRange() const { return QualifierRange; }
1038193326Sed
1039193326Sed  /// \brief Retrieve the nested-name-specifier that qualifies the
1040193326Sed  /// name of the namespace.
1041193326Sed  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1042193326Sed
1043193326Sed  NamespaceDecl *getNamespace() {
1044193326Sed    if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
1045193326Sed      return AD->getNamespace();
1046193326Sed
1047193326Sed    return cast<NamespaceDecl>(Namespace);
1048193326Sed  }
1049193326Sed
1050193326Sed  const NamespaceDecl *getNamespace() const {
1051193326Sed    return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
1052193326Sed  }
1053193326Sed
1054193326Sed  /// \brief Retrieve the namespace that this alias refers to, which
1055193326Sed  /// may either be a NamespaceDecl or a NamespaceAliasDecl.
1056193326Sed  NamedDecl *getAliasedNamespace() const { return Namespace; }
1057193326Sed
1058193326Sed  static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
1059193326Sed                                    SourceLocation L, SourceLocation AliasLoc,
1060193326Sed                                    IdentifierInfo *Alias,
1061193326Sed                                    SourceRange QualifierRange,
1062193326Sed                                    NestedNameSpecifier *Qualifier,
1063193326Sed                                    SourceLocation IdentLoc,
1064193326Sed                                    NamedDecl *Namespace);
1065193326Sed
1066193326Sed  static bool classof(const Decl *D) {
1067193326Sed    return D->getKind() == Decl::NamespaceAlias;
1068193326Sed  }
1069193326Sed  static bool classof(const NamespaceAliasDecl *D) { return true; }
1070193326Sed};
1071194613Sed
1072194613Sed/// UsingDecl - Represents a C++ using-declaration. For example:
1073194613Sed///    using someNameSpace::someIdentifier;
1074194613Sedclass UsingDecl : public NamedDecl {
1075194613Sed
1076194613Sed  /// \brief The source range that covers the nested-name-specifier
1077194613Sed  /// preceding the declaration name.
1078194613Sed  SourceRange NestedNameRange;
1079194613Sed  /// \brief The source location of the target declaration name.
1080194613Sed  SourceLocation TargetNameLocation;
1081194613Sed  /// \brief The source location of the "using" location itself.
1082194613Sed  SourceLocation UsingLocation;
1083194613Sed  /// \brief Target declaration.
1084194613Sed  NamedDecl* TargetDecl;
1085194613Sed  /// \brief Target declaration.
1086194613Sed  NestedNameSpecifier* TargetNestedNameDecl;
1087194613Sed
1088194613Sed  // Had 'typename' keyword.
1089194613Sed  bool IsTypeName;
1090194613Sed
1091194613Sed  UsingDecl(DeclContext *DC, SourceLocation L, SourceRange NNR,
1092194613Sed            SourceLocation TargetNL, SourceLocation UL, NamedDecl* Target,
1093194613Sed            NestedNameSpecifier* TargetNNS, bool IsTypeNameArg)
1094194613Sed    : NamedDecl(Decl::Using, DC, L, Target->getDeclName()),
1095194613Sed      NestedNameRange(NNR), TargetNameLocation(TargetNL),
1096194613Sed      UsingLocation(UL), TargetDecl(Target),
1097194613Sed      TargetNestedNameDecl(TargetNNS), IsTypeName(IsTypeNameArg) {
1098194613Sed    this->IdentifierNamespace = TargetDecl->getIdentifierNamespace();
1099194613Sed  }
1100194613Sed
1101194613Sedpublic:
1102194613Sed  /// \brief Returns the source range that covers the nested-name-specifier
1103194613Sed  /// preceding the namespace name.
1104195099Sed  SourceRange getNestedNameRange() { return NestedNameRange; }
1105195099Sed
1106194613Sed  /// \brief Returns the source location of the target declaration name.
1107195099Sed  SourceLocation getTargetNameLocation() { return TargetNameLocation; }
1108195099Sed
1109194613Sed  /// \brief Returns the source location of the "using" location itself.
1110195099Sed  SourceLocation getUsingLocation() { return UsingLocation; }
1111195099Sed
1112194613Sed  /// \brief getTargetDecl - Returns target specified by using-decl.
1113195099Sed  NamedDecl *getTargetDecl() { return TargetDecl; }
1114195099Sed  const NamedDecl *getTargetDecl() const { return TargetDecl; }
1115195099Sed
1116194613Sed  /// \brief Get target nested name declaration.
1117195099Sed  NestedNameSpecifier* getTargetNestedNameDecl() {
1118195099Sed    return TargetNestedNameDecl;
1119195099Sed  }
1120195099Sed
1121194613Sed  /// isTypeName - Return true if using decl had 'typename'.
1122195099Sed  bool isTypeName() const { return IsTypeName; }
1123194613Sed
1124194613Sed  static UsingDecl *Create(ASTContext &C, DeclContext *DC,
1125194613Sed      SourceLocation L, SourceRange NNR, SourceLocation TargetNL,
1126194613Sed      SourceLocation UL, NamedDecl* Target,
1127194613Sed      NestedNameSpecifier* TargetNNS, bool IsTypeNameArg);
1128194613Sed
1129194613Sed  static bool classof(const Decl *D) {
1130194613Sed    return D->getKind() == Decl::Using;
1131194613Sed  }
1132194613Sed  static bool classof(const UsingDecl *D) { return true; }
1133194613Sed};
1134193326Sed
1135193326Sed/// StaticAssertDecl - Represents a C++0x static_assert declaration.
1136193326Sedclass StaticAssertDecl : public Decl {
1137193326Sed  Expr *AssertExpr;
1138193326Sed  StringLiteral *Message;
1139193326Sed
1140193326Sed  StaticAssertDecl(DeclContext *DC, SourceLocation L,
1141193326Sed                   Expr *assertexpr, StringLiteral *message)
1142193326Sed  : Decl(StaticAssert, DC, L), AssertExpr(assertexpr), Message(message) { }
1143193326Sed
1144193326Sedpublic:
1145193326Sed  static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
1146193326Sed                                  SourceLocation L, Expr *AssertExpr,
1147193326Sed                                  StringLiteral *Message);
1148193326Sed
1149193326Sed  Expr *getAssertExpr() { return AssertExpr; }
1150193326Sed  const Expr *getAssertExpr() const { return AssertExpr; }
1151193326Sed
1152193326Sed  StringLiteral *getMessage() { return Message; }
1153193326Sed  const StringLiteral *getMessage() const { return Message; }
1154193326Sed
1155193326Sed  virtual ~StaticAssertDecl();
1156193326Sed  virtual void Destroy(ASTContext& C);
1157193326Sed
1158193326Sed  static bool classof(const Decl *D) {
1159193326Sed    return D->getKind() == Decl::StaticAssert;
1160193326Sed  }
1161193326Sed  static bool classof(StaticAssertDecl *D) { return true; }
1162193326Sed};
1163193326Sed
1164193326Sed/// Insertion operator for diagnostics.  This allows sending AccessSpecifier's
1165193326Sed/// into a diagnostic with <<.
1166193326Sedconst DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
1167193326Sed                                    AccessSpecifier AS);
1168193326Sed
1169193326Sed} // end namespace clang
1170193326Sed
1171193326Sed#endif
1172