DeclCXX.h revision a8ded8be82f7d5f5fc93c8626cfa9ca9cee4199e
1//===-- DeclCXX.h - Classes for representing C++ declarations -*- C++ -*-=====//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10//  This file defines the C++ Decl subclasses.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_AST_DECLCXX_H
15#define LLVM_CLANG_AST_DECLCXX_H
16
17#include "clang/AST/Decl.h"
18#include "llvm/ADT/SmallVector.h"
19
20namespace clang {
21
22class ClassTemplateDecl;
23class CXXRecordDecl;
24class CXXConstructorDecl;
25class CXXDestructorDecl;
26class CXXConversionDecl;
27class CXXMethodDecl;
28class ClassTemplateSpecializationDecl;
29
30/// \brief Represents any kind of function declaration, whether it is a
31/// concrete function or a function template.
32class AnyFunctionDecl {
33  NamedDecl *Function;
34
35  AnyFunctionDecl(NamedDecl *ND) : Function(ND) { }
36
37public:
38  AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { }
39  AnyFunctionDecl(FunctionTemplateDecl *FTD);
40
41  /// \brief Implicily converts any function or function template into a
42  /// named declaration.
43  operator NamedDecl *() const { return Function; }
44
45  /// \brief Retrieve the underlying function or function template.
46  NamedDecl *get() const { return Function; }
47
48  static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) {
49    return AnyFunctionDecl(ND);
50  }
51};
52
53} // end namespace clang
54
55namespace llvm {
56  /// Implement simplify_type for AnyFunctionDecl, so that we can dyn_cast from
57  /// AnyFunctionDecl to any function or function template declaration.
58  template<> struct simplify_type<const ::clang::AnyFunctionDecl> {
59    typedef ::clang::NamedDecl* SimpleType;
60    static SimpleType getSimplifiedValue(const ::clang::AnyFunctionDecl &Val) {
61      return Val;
62    }
63  };
64  template<> struct simplify_type< ::clang::AnyFunctionDecl>
65  : public simplify_type<const ::clang::AnyFunctionDecl> {};
66
67  // Provide PointerLikeTypeTraits for non-cvr pointers.
68  template<>
69  class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
70  public:
71    static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
72      return F.get();
73    }
74    static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
75      return ::clang::AnyFunctionDecl::getFromNamedDecl(
76                                      static_cast< ::clang::NamedDecl*>(P));
77    }
78
79    enum { NumLowBitsAvailable = 2 };
80  };
81
82} // end namespace llvm
83
84namespace clang {
85
86/// OverloadedFunctionDecl - An instance of this class represents a
87/// set of overloaded functions. All of the functions have the same
88/// name and occur within the same scope.
89///
90/// An OverloadedFunctionDecl has no ownership over the FunctionDecl
91/// nodes it contains. Rather, the FunctionDecls are owned by the
92/// enclosing scope (which also owns the OverloadedFunctionDecl
93/// node). OverloadedFunctionDecl is used primarily to store a set of
94/// overloaded functions for name lookup.
95class OverloadedFunctionDecl : public NamedDecl {
96protected:
97  OverloadedFunctionDecl(DeclContext *DC, DeclarationName N)
98    : NamedDecl(OverloadedFunction, DC, SourceLocation(), N) { }
99
100  /// Functions - the set of overloaded functions contained in this
101  /// overload set.
102  llvm::SmallVector<AnyFunctionDecl, 4> Functions;
103
104  // FIXME: This should go away when we stop using
105  // OverloadedFunctionDecl to store conversions in CXXRecordDecl.
106  friend class CXXRecordDecl;
107
108public:
109  typedef llvm::SmallVector<AnyFunctionDecl, 4>::iterator function_iterator;
110  typedef llvm::SmallVector<AnyFunctionDecl, 4>::const_iterator
111    function_const_iterator;
112
113  static OverloadedFunctionDecl *Create(ASTContext &C, DeclContext *DC,
114                                        DeclarationName N);
115
116  /// \brief Add a new overloaded function or function template to the set
117  /// of overloaded function templates.
118  void addOverload(AnyFunctionDecl F);
119
120  function_iterator function_begin() { return Functions.begin(); }
121  function_iterator function_end() { return Functions.end(); }
122  function_const_iterator function_begin() const { return Functions.begin(); }
123  function_const_iterator function_end() const { return Functions.end(); }
124
125  /// \brief Returns the number of overloaded functions stored in
126  /// this set.
127  unsigned size() const { return Functions.size(); }
128
129  // Implement isa/cast/dyncast/etc.
130  static bool classof(const Decl *D) {
131    return D->getKind() == OverloadedFunction;
132  }
133  static bool classof(const OverloadedFunctionDecl *D) { return true; }
134};
135
136/// \brief Provides uniform iteration syntax for an overload set, function,
137/// or function template.
138class OverloadIterator {
139  /// \brief An overloaded function set, function declaration, or
140  /// function template declaration.
141  NamedDecl *D;
142
143  /// \brief If the declaration is an overloaded function set, this is the
144  /// iterator pointing to the current position within that overloaded
145  /// function set.
146  OverloadedFunctionDecl::function_iterator Iter;
147
148public:
149  typedef AnyFunctionDecl value_type;
150  typedef value_type      reference;
151  typedef NamedDecl      *pointer;
152  typedef int             difference_type;
153  typedef std::forward_iterator_tag iterator_category;
154
155  OverloadIterator() : D(0) { }
156
157  OverloadIterator(FunctionDecl *FD) : D(FD) { }
158  OverloadIterator(FunctionTemplateDecl *FTD)
159    : D(reinterpret_cast<NamedDecl*>(FTD)) { }
160  OverloadIterator(OverloadedFunctionDecl *Ovl)
161    : D(Ovl), Iter(Ovl->function_begin()) { }
162
163  reference operator*() const;
164
165  pointer operator->() const { return (**this).get(); }
166
167  OverloadIterator &operator++();
168
169  OverloadIterator operator++(int) {
170    OverloadIterator Temp(*this);
171    ++(*this);
172    return Temp;
173  }
174
175  bool Equals(const OverloadIterator &Other) const;
176};
177
178inline bool operator==(const OverloadIterator &X, const OverloadIterator &Y) {
179  return X.Equals(Y);
180}
181
182inline bool operator!=(const OverloadIterator &X, const OverloadIterator &Y) {
183  return !(X == Y);
184}
185
186/// CXXBaseSpecifier - A base class of a C++ class.
187///
188/// Each CXXBaseSpecifier represents a single, direct base class (or
189/// struct) of a C++ class (or struct). It specifies the type of that
190/// base class, whether it is a virtual or non-virtual base, and what
191/// level of access (public, protected, private) is used for the
192/// derivation. For example:
193///
194/// @code
195///   class A { };
196///   class B { };
197///   class C : public virtual A, protected B { };
198/// @endcode
199///
200/// In this code, C will have two CXXBaseSpecifiers, one for "public
201/// virtual A" and the other for "protected B".
202class CXXBaseSpecifier {
203  /// Range - The source code range that covers the full base
204  /// specifier, including the "virtual" (if present) and access
205  /// specifier (if present).
206  SourceRange Range;
207
208  /// Virtual - Whether this is a virtual base class or not.
209  bool Virtual : 1;
210
211  /// BaseOfClass - Whether this is the base of a class (true) or of a
212  /// struct (false). This determines the mapping from the access
213  /// specifier as written in the source code to the access specifier
214  /// used for semantic analysis.
215  bool BaseOfClass : 1;
216
217  /// Access - Access specifier as written in the source code (which
218  /// may be AS_none). The actual type of data stored here is an
219  /// AccessSpecifier, but we use "unsigned" here to work around a
220  /// VC++ bug.
221  unsigned Access : 2;
222
223  /// BaseType - The type of the base class. This will be a class or
224  /// struct (or a typedef of such).
225  QualType BaseType;
226
227public:
228  CXXBaseSpecifier() { }
229
230  CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, QualType T)
231    : Range(R), Virtual(V), BaseOfClass(BC), Access(A), BaseType(T) { }
232
233  /// getSourceRange - Retrieves the source range that contains the
234  /// entire base specifier.
235  SourceRange getSourceRange() const { return Range; }
236
237  /// isVirtual - Determines whether the base class is a virtual base
238  /// class (or not).
239  bool isVirtual() const { return Virtual; }
240
241  /// getAccessSpecifier - Returns the access specifier for this base
242  /// specifier. This is the actual base specifier as used for
243  /// semantic analysis, so the result can never be AS_none. To
244  /// retrieve the access specifier as written in the source code, use
245  /// getAccessSpecifierAsWritten().
246  AccessSpecifier getAccessSpecifier() const {
247    if ((AccessSpecifier)Access == AS_none)
248      return BaseOfClass? AS_private : AS_public;
249    else
250      return (AccessSpecifier)Access;
251  }
252
253  /// getAccessSpecifierAsWritten - Retrieves the access specifier as
254  /// written in the source code (which may mean that no access
255  /// specifier was explicitly written). Use getAccessSpecifier() to
256  /// retrieve the access specifier for use in semantic analysis.
257  AccessSpecifier getAccessSpecifierAsWritten() const {
258    return (AccessSpecifier)Access;
259  }
260
261  /// getType - Retrieves the type of the base class. This type will
262  /// always be an unqualified class type.
263  QualType getType() const { return BaseType; }
264};
265
266/// CXXRecordDecl - Represents a C++ struct/union/class.
267/// FIXME: This class will disappear once we've properly taught RecordDecl
268/// to deal with C++-specific things.
269class CXXRecordDecl : public RecordDecl {
270  /// UserDeclaredConstructor - True when this class has a
271  /// user-declared constructor.
272  bool UserDeclaredConstructor : 1;
273
274  /// UserDeclaredCopyConstructor - True when this class has a
275  /// user-declared copy constructor.
276  bool UserDeclaredCopyConstructor : 1;
277
278  /// UserDeclaredCopyAssignment - True when this class has a
279  /// user-declared copy assignment operator.
280  bool UserDeclaredCopyAssignment : 1;
281
282  /// UserDeclaredDestructor - True when this class has a
283  /// user-declared destructor.
284  bool UserDeclaredDestructor : 1;
285
286  /// Aggregate - True when this class is an aggregate.
287  bool Aggregate : 1;
288
289  /// PlainOldData - True when this class is a POD-type.
290  bool PlainOldData : 1;
291
292  /// Polymorphic - True when this class is polymorphic, i.e. has at least one
293  /// virtual member or derives from a polymorphic class.
294  bool Polymorphic : 1;
295
296  /// Abstract - True when this class is abstract, i.e. has at least one
297  /// pure virtual function, (that can come from a base class).
298  bool Abstract : 1;
299
300  /// HasTrivialConstructor - True when this class has a trivial constructor
301  bool HasTrivialConstructor : 1;
302
303  /// HasTrivialDestructor - True when this class has a trivial destructor
304  bool HasTrivialDestructor : 1;
305
306  /// Bases - Base classes of this class.
307  /// FIXME: This is wasted space for a union.
308  CXXBaseSpecifier *Bases;
309
310  /// NumBases - The number of base class specifiers in Bases.
311  unsigned NumBases;
312
313  /// VBases - direct and indirect virtual base classes of this class.
314  CXXBaseSpecifier *VBases;
315
316  /// NumVBases - The number of virtual base class specifiers in VBases.
317  unsigned NumVBases;
318
319  /// Conversions - Overload set containing the conversion functions
320  /// of this C++ class (but not its inherited conversion
321  /// functions). Each of the entries in this overload set is a
322  /// CXXConversionDecl.
323  OverloadedFunctionDecl Conversions;
324
325  /// \brief The template or declaration that this declaration
326  /// describes or was instantiated from, respectively.
327  ///
328  /// For non-templates, this value will be NULL. For record
329  /// declarations that describe a class template, this will be a
330  /// pointer to a ClassTemplateDecl. For member
331  /// classes of class template specializations, this will be the
332  /// RecordDecl from which the member class was instantiated.
333  llvm::PointerUnion<ClassTemplateDecl*, CXXRecordDecl*>
334    TemplateOrInstantiation;
335
336protected:
337  CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
338                SourceLocation L, IdentifierInfo *Id);
339
340  ~CXXRecordDecl();
341
342public:
343  /// base_class_iterator - Iterator that traverses the base classes
344  /// of a clas.
345  typedef CXXBaseSpecifier*       base_class_iterator;
346
347  /// base_class_const_iterator - Iterator that traverses the base
348  /// classes of a clas.
349  typedef const CXXBaseSpecifier* base_class_const_iterator;
350
351  static CXXRecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC,
352                               SourceLocation L, IdentifierInfo *Id,
353                               CXXRecordDecl* PrevDecl=0,
354                               bool DelayTypeCreation = false);
355
356  virtual void Destroy(ASTContext& C);
357
358  /// setBases - Sets the base classes of this struct or class.
359  void setBases(ASTContext &C,
360                CXXBaseSpecifier const * const *Bases, unsigned NumBases);
361
362  /// getNumBases - Retrieves the number of base classes of this
363  /// class.
364  unsigned getNumBases() const { return NumBases; }
365
366  base_class_iterator       bases_begin()       { return Bases; }
367  base_class_const_iterator bases_begin() const { return Bases; }
368  base_class_iterator       bases_end()         { return Bases + NumBases; }
369  base_class_const_iterator bases_end()   const { return Bases + NumBases; }
370
371  /// getNumVBases - Retrieves the number of virtual base classes of this
372  /// class.
373  unsigned getNumVBases() const { return NumVBases; }
374
375  base_class_iterator       vbases_begin()       { return VBases; }
376  base_class_const_iterator vbases_begin() const { return VBases; }
377  base_class_iterator       vbases_end()         { return VBases + NumVBases; }
378  base_class_const_iterator vbases_end()   const { return VBases + NumVBases; }
379
380  /// hasConstCopyConstructor - Determines whether this class has a
381  /// copy constructor that accepts a const-qualified argument.
382  bool hasConstCopyConstructor(ASTContext &Context) const;
383
384  /// getCopyConstructor - Returns the copy constructor for this class
385  CXXConstructorDecl *getCopyConstructor(ASTContext &Context,
386                                         unsigned TypeQuals) const;
387
388  /// hasConstCopyAssignment - Determines whether this class has a
389  /// copy assignment operator that accepts a const-qualified argument.
390  bool hasConstCopyAssignment(ASTContext &Context) const;
391
392  /// addedConstructor - Notify the class that another constructor has
393  /// been added. This routine helps maintain information about the
394  /// class based on which constructors have been added.
395  void addedConstructor(ASTContext &Context, CXXConstructorDecl *ConDecl);
396
397  /// hasUserDeclaredConstructor - Whether this class has any
398  /// user-declared constructors. When true, a default constructor
399  /// will not be implicitly declared.
400  bool hasUserDeclaredConstructor() const { return UserDeclaredConstructor; }
401
402  /// hasUserDeclaredCopyConstructor - Whether this class has a
403  /// user-declared copy constructor. When false, a copy constructor
404  /// will be implicitly declared.
405  bool hasUserDeclaredCopyConstructor() const {
406    return UserDeclaredCopyConstructor;
407  }
408
409  /// addedAssignmentOperator - Notify the class that another assignment
410  /// operator has been added. This routine helps maintain information about the
411   /// class based on which operators have been added.
412  void addedAssignmentOperator(ASTContext &Context, CXXMethodDecl *OpDecl);
413
414  /// hasUserDeclaredCopyAssignment - Whether this class has a
415  /// user-declared copy assignment operator. When false, a copy
416  /// assigment operator will be implicitly declared.
417  bool hasUserDeclaredCopyAssignment() const {
418    return UserDeclaredCopyAssignment;
419  }
420
421  /// hasUserDeclaredDestructor - Whether this class has a
422  /// user-declared destructor. When false, a destructor will be
423  /// implicitly declared.
424  bool hasUserDeclaredDestructor() const { return UserDeclaredDestructor; }
425
426  /// setUserDeclaredDestructor - Set whether this class has a
427  /// user-declared destructor. If not set by the time the class is
428  /// fully defined, a destructor will be implicitly declared.
429  void setUserDeclaredDestructor(bool UCD) {
430    UserDeclaredDestructor = UCD;
431  }
432
433  /// getConversions - Retrieve the overload set containing all of the
434  /// conversion functions in this class.
435  OverloadedFunctionDecl *getConversionFunctions() {
436    return &Conversions;
437  }
438  const OverloadedFunctionDecl *getConversionFunctions() const {
439    return &Conversions;
440  }
441
442  /// addConversionFunction - Add a new conversion function to the
443  /// list of conversion functions.
444  void addConversionFunction(ASTContext &Context, CXXConversionDecl *ConvDecl);
445
446  /// isAggregate - Whether this class is an aggregate (C++
447  /// [dcl.init.aggr]), which is a class with no user-declared
448  /// constructors, no private or protected non-static data members,
449  /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1).
450  bool isAggregate() const { return Aggregate; }
451
452  /// setAggregate - Set whether this class is an aggregate (C++
453  /// [dcl.init.aggr]).
454  void setAggregate(bool Agg) { Aggregate = Agg; }
455
456  /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class
457  /// that is an aggregate that has no non-static non-POD data members, no
458  /// reference data members, no user-defined copy assignment operator and no
459  /// user-defined destructor.
460  bool isPOD() const { return PlainOldData; }
461
462  /// setPOD - Set whether this class is a POD-type (C++ [class]p4).
463  void setPOD(bool POD) { PlainOldData = POD; }
464
465  /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]),
466  /// which means that the class contains or inherits a virtual function.
467  bool isPolymorphic() const { return Polymorphic; }
468
469  /// setPolymorphic - Set whether this class is polymorphic (C++
470  /// [class.virtual]).
471  void setPolymorphic(bool Poly) { Polymorphic = Poly; }
472
473  /// isAbstract - Whether this class is abstract (C++ [class.abstract]),
474  /// which means that the class contains or inherits a pure virtual function.
475  bool isAbstract() const { return Abstract; }
476
477  /// setAbstract - Set whether this class is abstract (C++ [class.abstract])
478  void setAbstract(bool Abs) { Abstract = Abs; }
479
480  // hasTrivialConstructor - Whether this class has a trivial constructor
481  // (C++ [class.ctor]p5)
482  bool hasTrivialConstructor() const { return HasTrivialConstructor; }
483
484  // setHasTrivialConstructor - Set whether this class has a trivial constructor
485  // (C++ [class.ctor]p5)
486  void setHasTrivialConstructor(bool TC) { HasTrivialConstructor = TC; }
487
488  // hasTrivialDestructor - Whether this class has a trivial destructor
489  // (C++ [class.dtor]p3)
490  bool hasTrivialDestructor() const { return HasTrivialDestructor; }
491
492  // setHasTrivialDestructor - Set whether this class has a trivial destructor
493  // (C++ [class.dtor]p3)
494  void setHasTrivialDestructor(bool TC) { HasTrivialDestructor = TC; }
495
496  /// \brief If this record is an instantiation of a member class,
497  /// retrieves the member class from which it was instantiated.
498  ///
499  /// This routine will return non-NULL for (non-templated) member
500  /// classes of class templates. For example, given:
501  ///
502  /// \code
503  /// template<typename T>
504  /// struct X {
505  ///   struct A { };
506  /// };
507  /// \endcode
508  ///
509  /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
510  /// whose parent is the class template specialization X<int>. For
511  /// this declaration, getInstantiatedFromMemberClass() will return
512  /// the CXXRecordDecl X<T>::A. When a complete definition of
513  /// X<int>::A is required, it will be instantiated from the
514  /// declaration returned by getInstantiatedFromMemberClass().
515  CXXRecordDecl *getInstantiatedFromMemberClass() const {
516    return TemplateOrInstantiation.dyn_cast<CXXRecordDecl*>();
517  }
518
519  /// \brief Specify that this record is an instantiation of the
520  /// member class RD.
521  void setInstantiationOfMemberClass(CXXRecordDecl *RD) {
522    TemplateOrInstantiation = RD;
523  }
524
525  /// \brief Retrieves the class template that is described by this
526  /// class declaration.
527  ///
528  /// Every class template is represented as a ClassTemplateDecl and a
529  /// CXXRecordDecl. The former contains template properties (such as
530  /// the template parameter lists) while the latter contains the
531  /// actual description of the template's
532  /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
533  /// CXXRecordDecl that from a ClassTemplateDecl, while
534  /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
535  /// a CXXRecordDecl.
536  ClassTemplateDecl *getDescribedClassTemplate() const {
537    return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>();
538  }
539
540  void setDescribedClassTemplate(ClassTemplateDecl *Template) {
541    TemplateOrInstantiation = Template;
542  }
543
544  /// getDefaultConstructor - Returns the default constructor for this class
545  CXXConstructorDecl *getDefaultConstructor(ASTContext &Context);
546
547  /// getDestructor - Returns the destructor decl for this class.
548  const CXXDestructorDecl *getDestructor(ASTContext &Context);
549
550  /// isLocalClass - If the class is a local class [class.local], returns
551  /// the enclosing function declaration.
552  const FunctionDecl *isLocalClass() const {
553    if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
554      return RD->isLocalClass();
555
556    return dyn_cast<FunctionDecl>(getDeclContext());
557  }
558
559  /// viewInheritance - Renders and displays an inheritance diagram
560  /// for this C++ class and all of its base classes (transitively) using
561  /// GraphViz.
562  void viewInheritance(ASTContext& Context) const;
563
564  static bool classof(const Decl *D) {
565    return D->getKind() == CXXRecord ||
566           D->getKind() == ClassTemplateSpecialization ||
567           D->getKind() == ClassTemplatePartialSpecialization;
568  }
569  static bool classof(const CXXRecordDecl *D) { return true; }
570  static bool classof(const ClassTemplateSpecializationDecl *D) {
571    return true;
572  }
573};
574
575/// CXXMethodDecl - Represents a static or instance method of a
576/// struct/union/class.
577class CXXMethodDecl : public FunctionDecl {
578protected:
579  CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation L,
580                DeclarationName N, QualType T,
581                bool isStatic, bool isInline)
582    : FunctionDecl(DK, RD, L, N, T, (isStatic ? Static : None),
583                   isInline) {}
584
585public:
586  static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
587                              SourceLocation L, DeclarationName N,
588                              QualType T, bool isStatic = false,
589                              bool isInline = false);
590
591  bool isStatic() const { return getStorageClass() == Static; }
592  bool isInstance() const { return !isStatic(); }
593
594  bool isVirtual() const {
595    return isVirtualAsWritten() ||
596      (begin_overridden_methods() != end_overridden_methods());
597  }
598
599  ///
600  void addOverriddenMethod(const CXXMethodDecl *MD);
601
602  typedef const CXXMethodDecl ** method_iterator;
603
604  method_iterator begin_overridden_methods() const;
605  method_iterator end_overridden_methods() const;
606
607  /// getParent - Returns the parent of this method declaration, which
608  /// is the class in which this method is defined.
609  const CXXRecordDecl *getParent() const {
610    return cast<CXXRecordDecl>(FunctionDecl::getParent());
611  }
612
613  /// getParent - Returns the parent of this method declaration, which
614  /// is the class in which this method is defined.
615  CXXRecordDecl *getParent() {
616    return const_cast<CXXRecordDecl *>(
617             cast<CXXRecordDecl>(FunctionDecl::getParent()));
618  }
619
620  /// getThisType - Returns the type of 'this' pointer.
621  /// Should only be called for instance methods.
622  QualType getThisType(ASTContext &C) const;
623
624  unsigned getTypeQualifiers() const {
625    return getType()->getAsFunctionProtoType()->getTypeQuals();
626  }
627
628  // Implement isa/cast/dyncast/etc.
629  static bool classof(const Decl *D) {
630    return D->getKind() >= CXXMethod && D->getKind() <= CXXConversion;
631  }
632  static bool classof(const CXXMethodDecl *D) { return true; }
633};
634
635/// CXXBaseOrMemberInitializer - Represents a C++ base or member
636/// initializer, which is part of a constructor initializer that
637/// initializes one non-static member variable or one base class. For
638/// example, in the following, both 'A(a)' and 'f(3.14159)' are member
639/// initializers:
640///
641/// @code
642/// class A { };
643/// class B : public A {
644///   float f;
645/// public:
646///   B(A& a) : A(a), f(3.14159) { }
647/// };
648/// @endcode
649class CXXBaseOrMemberInitializer {
650  /// BaseOrMember - This points to the entity being initialized,
651  /// which is either a base class (a Type) or a non-static data
652  /// member. When the low bit is 1, it's a base
653  /// class; when the low bit is 0, it's a member.
654  uintptr_t BaseOrMember;
655
656  /// Args - The arguments used to initialize the base or member.
657  Expr **Args;
658  unsigned NumArgs;
659
660  /// IdLoc - Location of the id in ctor-initializer list.
661  SourceLocation IdLoc;
662
663public:
664  /// CXXBaseOrMemberInitializer - Creates a new base-class initializer.
665  explicit
666  CXXBaseOrMemberInitializer(QualType BaseType, Expr **Args, unsigned NumArgs,
667                             SourceLocation L);
668
669  /// CXXBaseOrMemberInitializer - Creates a new member initializer.
670  explicit
671  CXXBaseOrMemberInitializer(FieldDecl *Member, Expr **Args, unsigned NumArgs,
672                             SourceLocation L);
673
674  /// ~CXXBaseOrMemberInitializer - Destroy the base or member initializer.
675  ~CXXBaseOrMemberInitializer();
676
677  /// arg_iterator - Iterates through the member initialization
678  /// arguments.
679  typedef Expr **arg_iterator;
680
681  /// arg_const_iterator - Iterates through the member initialization
682  /// arguments.
683  typedef Expr * const * arg_const_iterator;
684
685  /// getBaseOrMember - get the generic 'member' representing either the field
686  /// or a base class.
687  void* getBaseOrMember() const { return reinterpret_cast<void*>(BaseOrMember); }
688
689  /// isBaseInitializer - Returns true when this initializer is
690  /// initializing a base class.
691  bool isBaseInitializer() const { return (BaseOrMember & 0x1) != 0; }
692
693  /// isMemberInitializer - Returns true when this initializer is
694  /// initializing a non-static data member.
695  bool isMemberInitializer() const { return (BaseOrMember & 0x1) == 0; }
696
697  /// getBaseClass - If this is a base class initializer, returns the
698  /// type used to specify the initializer. The resulting type will be
699  /// a class type or a typedef of a class type. If this is not a base
700  /// class initializer, returns NULL.
701  Type *getBaseClass() {
702    if (isBaseInitializer())
703      return reinterpret_cast<Type*>(BaseOrMember & ~0x01);
704    else
705      return 0;
706  }
707
708  /// getBaseClass - If this is a base class initializer, returns the
709  /// type used to specify the initializer. The resulting type will be
710  /// a class type or a typedef of a class type. If this is not a base
711  /// class initializer, returns NULL.
712  const Type *getBaseClass() const {
713    if (isBaseInitializer())
714      return reinterpret_cast<const Type*>(BaseOrMember & ~0x01);
715    else
716      return 0;
717  }
718
719  /// getMember - If this is a member initializer, returns the
720  /// declaration of the non-static data member being
721  /// initialized. Otherwise, returns NULL.
722  FieldDecl *getMember() {
723    if (isMemberInitializer())
724      return reinterpret_cast<FieldDecl *>(BaseOrMember);
725    else
726      return 0;
727  }
728
729  SourceLocation getSourceLocation() const { return IdLoc; }
730
731  /// begin() - Retrieve an iterator to the first initializer argument.
732  arg_iterator       begin()       { return Args; }
733  /// begin() - Retrieve an iterator to the first initializer argument.
734  arg_const_iterator begin() const { return Args; }
735
736  /// end() - Retrieve an iterator past the last initializer argument.
737  arg_iterator       end()       { return Args + NumArgs; }
738  /// end() - Retrieve an iterator past the last initializer argument.
739  arg_const_iterator end() const { return Args + NumArgs; }
740
741  /// getNumArgs - Determine the number of arguments used to
742  /// initialize the member or base.
743  unsigned getNumArgs() const { return NumArgs; }
744};
745
746/// CXXConstructorDecl - Represents a C++ constructor within a
747/// class. For example:
748///
749/// @code
750/// class X {
751/// public:
752///   explicit X(int); // represented by a CXXConstructorDecl.
753/// };
754/// @endcode
755class CXXConstructorDecl : public CXXMethodDecl {
756  /// Explicit - Whether this constructor is explicit.
757  bool Explicit : 1;
758
759  /// ImplicitlyDefined - Whether this constructor was implicitly
760  /// defined by the compiler. When false, the constructor was defined
761  /// by the user. In C++03, this flag will have the same value as
762  /// Implicit. In C++0x, however, a constructor that is
763  /// explicitly defaulted (i.e., defined with " = default") will have
764  /// @c !Implicit && ImplicitlyDefined.
765  bool ImplicitlyDefined : 1;
766
767  /// Support for base and member initializers.
768  /// BaseOrMemberInitializers - The arguments used to initialize the base
769  /// or member.
770  CXXBaseOrMemberInitializer **BaseOrMemberInitializers;
771  unsigned NumBaseOrMemberInitializers;
772
773  CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation L,
774                     DeclarationName N, QualType T,
775                     bool isExplicit, bool isInline, bool isImplicitlyDeclared)
776    : CXXMethodDecl(CXXConstructor, RD, L, N, T, false, isInline),
777      Explicit(isExplicit), ImplicitlyDefined(false),
778      BaseOrMemberInitializers(0), NumBaseOrMemberInitializers(0) {
779    setImplicit(isImplicitlyDeclared);
780  }
781  virtual void Destroy(ASTContext& C);
782
783public:
784  static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
785                                    SourceLocation L, DeclarationName N,
786                                    QualType T, bool isExplicit,
787                                    bool isInline, bool isImplicitlyDeclared);
788
789  /// isExplicit - Whether this constructor was marked "explicit" or not.
790  bool isExplicit() const { return Explicit; }
791
792  /// isImplicitlyDefined - Whether this constructor was implicitly
793  /// defined. If false, then this constructor was defined by the
794  /// user. This operation can only be invoked if the constructor has
795  /// already been defined.
796  bool isImplicitlyDefined(ASTContext &C) const {
797    assert(isThisDeclarationADefinition() &&
798           "Can only get the implicit-definition flag once the "
799           "constructor has been defined");
800    return ImplicitlyDefined;
801  }
802
803  /// setImplicitlyDefined - Set whether this constructor was
804  /// implicitly defined or not.
805  void setImplicitlyDefined(bool ID) {
806    assert(isThisDeclarationADefinition() &&
807           "Can only set the implicit-definition flag once the constructor "
808           "has been defined");
809    ImplicitlyDefined = ID;
810  }
811
812  /// init_iterator - Iterates through the member/base initializer list.
813  typedef CXXBaseOrMemberInitializer **init_iterator;
814
815  /// init_const_iterator - Iterates through the memberbase initializer list.
816  typedef CXXBaseOrMemberInitializer * const * init_const_iterator;
817
818  /// init_begin() - Retrieve an iterator to the first initializer.
819  init_iterator       init_begin()       { return BaseOrMemberInitializers; }
820  /// begin() - Retrieve an iterator to the first initializer.
821  init_const_iterator init_begin() const { return BaseOrMemberInitializers; }
822
823  /// init_end() - Retrieve an iterator past the last initializer.
824  init_iterator       init_end()       {
825    return BaseOrMemberInitializers + NumBaseOrMemberInitializers;
826  }
827  /// end() - Retrieve an iterator past the last initializer.
828  init_const_iterator init_end() const {
829    return BaseOrMemberInitializers + NumBaseOrMemberInitializers;
830  }
831
832  /// getNumArgs - Determine the number of arguments used to
833  /// initialize the member or base.
834  unsigned getNumBaseOrMemberInitializers() const {
835      return NumBaseOrMemberInitializers;
836  }
837
838  void setBaseOrMemberInitializers(ASTContext &C,
839                                   CXXBaseOrMemberInitializer **Initializers,
840                                   unsigned NumInitializers);
841
842  /// isDefaultConstructor - Whether this constructor is a default
843  /// constructor (C++ [class.ctor]p5), which can be used to
844  /// default-initialize a class of this type.
845  bool isDefaultConstructor() const;
846
847  /// isCopyConstructor - Whether this constructor is a copy
848  /// constructor (C++ [class.copy]p2, which can be used to copy the
849  /// class. @p TypeQuals will be set to the qualifiers on the
850  /// argument type. For example, @p TypeQuals would be set to @c
851  /// QualType::Const for the following copy constructor:
852  ///
853  /// @code
854  /// class X {
855  /// public:
856  ///   X(const X&);
857  /// };
858  /// @endcode
859  bool isCopyConstructor(ASTContext &Context, unsigned &TypeQuals) const;
860
861  /// isCopyConstructor - Whether this constructor is a copy
862  /// constructor (C++ [class.copy]p2, which can be used to copy the
863  /// class.
864  bool isCopyConstructor(ASTContext &Context) const {
865    unsigned TypeQuals = 0;
866    return isCopyConstructor(Context, TypeQuals);
867  }
868
869  /// isConvertingConstructor - Whether this constructor is a
870  /// converting constructor (C++ [class.conv.ctor]), which can be
871  /// used for user-defined conversions.
872  bool isConvertingConstructor() const;
873
874  // Implement isa/cast/dyncast/etc.
875  static bool classof(const Decl *D) {
876    return D->getKind() == CXXConstructor;
877  }
878  static bool classof(const CXXConstructorDecl *D) { return true; }
879};
880
881/// CXXDestructorDecl - Represents a C++ destructor within a
882/// class. For example:
883///
884/// @code
885/// class X {
886/// public:
887///   ~X(); // represented by a CXXDestructorDecl.
888/// };
889/// @endcode
890class CXXDestructorDecl : public CXXMethodDecl {
891  /// ImplicitlyDefined - Whether this destructor was implicitly
892  /// defined by the compiler. When false, the destructor was defined
893  /// by the user. In C++03, this flag will have the same value as
894  /// Implicit. In C++0x, however, a destructor that is
895  /// explicitly defaulted (i.e., defined with " = default") will have
896  /// @c !Implicit && ImplicitlyDefined.
897  bool ImplicitlyDefined : 1;
898
899  /// Support for base and member destruction.
900  /// BaseOrMemberDestructions - The arguments used to destruct the base
901  /// or member.
902  // FIXME. May want to use a new class as CXXBaseOrMemberInitializer has
903  // more info. than is needed. At the least, CXXBaseOrMemberInitializer need
904  // be renamed to something neutral.
905  CXXBaseOrMemberInitializer **BaseOrMemberDestructions;
906  unsigned NumBaseOrMemberDestructions;
907
908  CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation L,
909                    DeclarationName N, QualType T,
910                    bool isInline, bool isImplicitlyDeclared)
911    : CXXMethodDecl(CXXDestructor, RD, L, N, T, false, isInline),
912      ImplicitlyDefined(false),
913      BaseOrMemberDestructions(0), NumBaseOrMemberDestructions(0) {
914    setImplicit(isImplicitlyDeclared);
915  }
916
917public:
918  static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
919                                   SourceLocation L, DeclarationName N,
920                                   QualType T, bool isInline,
921                                   bool isImplicitlyDeclared);
922
923  /// isImplicitlyDefined - Whether this destructor was implicitly
924  /// defined. If false, then this destructor was defined by the
925  /// user. This operation can only be invoked if the destructor has
926  /// already been defined.
927  bool isImplicitlyDefined() const {
928    assert(isThisDeclarationADefinition() &&
929           "Can only get the implicit-definition flag once the destructor has been defined");
930    return ImplicitlyDefined;
931  }
932
933  /// setImplicitlyDefined - Set whether this destructor was
934  /// implicitly defined or not.
935  void setImplicitlyDefined(bool ID) {
936    assert(isThisDeclarationADefinition() &&
937           "Can only set the implicit-definition flag once the destructor has been defined");
938    ImplicitlyDefined = ID;
939  }
940
941  /// destr_iterator - Iterates through the member/base destruction list.
942  typedef CXXBaseOrMemberInitializer **destr_iterator;
943
944  /// destr_const_iterator - Iterates through the member/base destruction list.
945  typedef CXXBaseOrMemberInitializer * const * destr_const_iterator;
946
947  /// destr_begin() - Retrieve an iterator to the first destructed member/base.
948  destr_iterator       destr_begin()       { return BaseOrMemberDestructions; }
949  /// destr_begin() - Retrieve an iterator to the first destructed member/base.
950  destr_const_iterator destr_begin() const { return BaseOrMemberDestructions; }
951
952  /// destr_end() - Retrieve an iterator past the last destructed member/base.
953  destr_iterator       destr_end()       {
954    return BaseOrMemberDestructions + NumBaseOrMemberDestructions;
955  }
956  /// destr_end() - Retrieve an iterator past the last destructed member/base.
957  destr_const_iterator destr_end() const {
958    return BaseOrMemberDestructions + NumBaseOrMemberDestructions;
959  }
960
961  /// getNumArgs - Determine the number of arguments used to
962  /// destruct the member or base.
963  unsigned getNumBaseOrMemberDestructions() const {
964    return NumBaseOrMemberDestructions;
965  }
966
967  void setBaseOrMemberDestructions(ASTContext &C);
968
969  // Implement isa/cast/dyncast/etc.
970  static bool classof(const Decl *D) {
971    return D->getKind() == CXXDestructor;
972  }
973  static bool classof(const CXXDestructorDecl *D) { return true; }
974};
975
976/// CXXConversionDecl - Represents a C++ conversion function within a
977/// class. For example:
978///
979/// @code
980/// class X {
981/// public:
982///   operator bool();
983/// };
984/// @endcode
985class CXXConversionDecl : public CXXMethodDecl {
986  /// Explicit - Whether this conversion function is marked
987  /// "explicit", meaning that it can only be applied when the user
988  /// explicitly wrote a cast. This is a C++0x feature.
989  bool Explicit : 1;
990
991  CXXConversionDecl(CXXRecordDecl *RD, SourceLocation L,
992                    DeclarationName N, QualType T,
993                    bool isInline, bool isExplicit)
994    : CXXMethodDecl(CXXConversion, RD, L, N, T, false, isInline),
995      Explicit(isExplicit) { }
996
997public:
998  static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
999                                   SourceLocation L, DeclarationName N,
1000                                   QualType T, bool isInline,
1001                                   bool isExplicit);
1002
1003  /// isExplicit - Whether this is an explicit conversion operator
1004  /// (C++0x only). Explicit conversion operators are only considered
1005  /// when the user has explicitly written a cast.
1006  bool isExplicit() const { return Explicit; }
1007
1008  /// getConversionType - Returns the type that this conversion
1009  /// function is converting to.
1010  QualType getConversionType() const {
1011    return getType()->getAsFunctionType()->getResultType();
1012  }
1013
1014  // Implement isa/cast/dyncast/etc.
1015  static bool classof(const Decl *D) {
1016    return D->getKind() == CXXConversion;
1017  }
1018  static bool classof(const CXXConversionDecl *D) { return true; }
1019};
1020
1021/// LinkageSpecDecl - This represents a linkage specification.  For example:
1022///   extern "C" void foo();
1023///
1024class LinkageSpecDecl : public Decl, public DeclContext {
1025public:
1026  /// LanguageIDs - Used to represent the language in a linkage
1027  /// specification.  The values are part of the serialization abi for
1028  /// ASTs and cannot be changed without altering that abi.  To help
1029  /// ensure a stable abi for this, we choose the DW_LANG_ encodings
1030  /// from the dwarf standard.
1031  enum LanguageIDs { lang_c = /* DW_LANG_C */ 0x0002,
1032  lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004 };
1033private:
1034  /// Language - The language for this linkage specification.
1035  LanguageIDs Language;
1036
1037  /// HadBraces - Whether this linkage specification had curly braces or not.
1038  bool HadBraces : 1;
1039
1040  LinkageSpecDecl(DeclContext *DC, SourceLocation L, LanguageIDs lang,
1041                  bool Braces)
1042    : Decl(LinkageSpec, DC, L),
1043      DeclContext(LinkageSpec), Language(lang), HadBraces(Braces) { }
1044
1045public:
1046  static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
1047                                 SourceLocation L, LanguageIDs Lang,
1048                                 bool Braces);
1049
1050  LanguageIDs getLanguage() const { return Language; }
1051
1052  /// hasBraces - Determines whether this linkage specification had
1053  /// braces in its syntactic form.
1054  bool hasBraces() const { return HadBraces; }
1055
1056  static bool classof(const Decl *D) {
1057    return D->getKind() == LinkageSpec;
1058  }
1059  static bool classof(const LinkageSpecDecl *D) { return true; }
1060  static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
1061    return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
1062  }
1063  static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
1064    return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
1065  }
1066};
1067
1068/// UsingDirectiveDecl - Represents C++ using-directive. For example:
1069///
1070///    using namespace std;
1071///
1072// NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide
1073// artificial name, for all using-directives in order to store
1074// them in DeclContext effectively.
1075class UsingDirectiveDecl : public NamedDecl {
1076
1077  /// SourceLocation - Location of 'namespace' token.
1078  SourceLocation NamespaceLoc;
1079
1080  /// \brief The source range that covers the nested-name-specifier
1081  /// preceding the namespace name.
1082  SourceRange QualifierRange;
1083
1084  /// \brief The nested-name-specifier that precedes the namespace
1085  /// name, if any.
1086  NestedNameSpecifier *Qualifier;
1087
1088  /// IdentLoc - Location of nominated namespace-name identifier.
1089  // FIXME: We don't store location of scope specifier.
1090  SourceLocation IdentLoc;
1091
1092  /// NominatedNamespace - Namespace nominated by using-directive.
1093  NamespaceDecl *NominatedNamespace;
1094
1095  /// Enclosing context containing both using-directive and nomintated
1096  /// namespace.
1097  DeclContext *CommonAncestor;
1098
1099  /// getUsingDirectiveName - Returns special DeclarationName used by
1100  /// using-directives. This is only used by DeclContext for storing
1101  /// UsingDirectiveDecls in its lookup structure.
1102  static DeclarationName getName() {
1103    return DeclarationName::getUsingDirectiveName();
1104  }
1105
1106  UsingDirectiveDecl(DeclContext *DC, SourceLocation L,
1107                     SourceLocation NamespcLoc,
1108                     SourceRange QualifierRange,
1109                     NestedNameSpecifier *Qualifier,
1110                     SourceLocation IdentLoc,
1111                     NamespaceDecl *Nominated,
1112                     DeclContext *CommonAncestor)
1113    : NamedDecl(Decl::UsingDirective, DC, L, getName()),
1114      NamespaceLoc(NamespcLoc), QualifierRange(QualifierRange),
1115      Qualifier(Qualifier), IdentLoc(IdentLoc),
1116      NominatedNamespace(Nominated? Nominated->getOriginalNamespace() : 0),
1117      CommonAncestor(CommonAncestor) {
1118  }
1119
1120public:
1121  /// \brief Retrieve the source range of the nested-name-specifier
1122  /// that qualifiers the namespace name.
1123  SourceRange getQualifierRange() const { return QualifierRange; }
1124
1125  /// \brief Retrieve the nested-name-specifier that qualifies the
1126  /// name of the namespace.
1127  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1128
1129  /// getNominatedNamespace - Returns namespace nominated by using-directive.
1130  NamespaceDecl *getNominatedNamespace() { return NominatedNamespace; }
1131
1132  const NamespaceDecl *getNominatedNamespace() const {
1133    return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
1134  }
1135
1136  /// getCommonAncestor - returns common ancestor context of using-directive,
1137  /// and nominated by it namespace.
1138  DeclContext *getCommonAncestor() { return CommonAncestor; }
1139  const DeclContext *getCommonAncestor() const { return CommonAncestor; }
1140
1141  /// getNamespaceKeyLocation - Returns location of namespace keyword.
1142  SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
1143
1144  /// getIdentLocation - Returns location of identifier.
1145  SourceLocation getIdentLocation() const { return IdentLoc; }
1146
1147  static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
1148                                    SourceLocation L,
1149                                    SourceLocation NamespaceLoc,
1150                                    SourceRange QualifierRange,
1151                                    NestedNameSpecifier *Qualifier,
1152                                    SourceLocation IdentLoc,
1153                                    NamespaceDecl *Nominated,
1154                                    DeclContext *CommonAncestor);
1155
1156  static bool classof(const Decl *D) {
1157    return D->getKind() == Decl::UsingDirective;
1158  }
1159  static bool classof(const UsingDirectiveDecl *D) { return true; }
1160
1161  // Friend for getUsingDirectiveName.
1162  friend class DeclContext;
1163};
1164
1165/// NamespaceAliasDecl - Represents a C++ namespace alias. For example:
1166///
1167/// @code
1168/// namespace Foo = Bar;
1169/// @endcode
1170class NamespaceAliasDecl : public NamedDecl {
1171  SourceLocation AliasLoc;
1172
1173  /// \brief The source range that covers the nested-name-specifier
1174  /// preceding the namespace name.
1175  SourceRange QualifierRange;
1176
1177  /// \brief The nested-name-specifier that precedes the namespace
1178  /// name, if any.
1179  NestedNameSpecifier *Qualifier;
1180
1181  /// IdentLoc - Location of namespace identifier.
1182  SourceLocation IdentLoc;
1183
1184  /// Namespace - The Decl that this alias points to. Can either be a
1185  /// NamespaceDecl or a NamespaceAliasDecl.
1186  NamedDecl *Namespace;
1187
1188  NamespaceAliasDecl(DeclContext *DC, SourceLocation L,
1189                     SourceLocation AliasLoc, IdentifierInfo *Alias,
1190                     SourceRange QualifierRange,
1191                     NestedNameSpecifier *Qualifier,
1192                     SourceLocation IdentLoc, NamedDecl *Namespace)
1193    : NamedDecl(Decl::NamespaceAlias, DC, L, Alias), AliasLoc(AliasLoc),
1194      QualifierRange(QualifierRange), Qualifier(Qualifier),
1195      IdentLoc(IdentLoc), Namespace(Namespace) { }
1196
1197public:
1198  /// \brief Retrieve the source range of the nested-name-specifier
1199  /// that qualifiers the namespace name.
1200  SourceRange getQualifierRange() const { return QualifierRange; }
1201
1202  /// \brief Retrieve the nested-name-specifier that qualifies the
1203  /// name of the namespace.
1204  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1205
1206  NamespaceDecl *getNamespace() {
1207    if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
1208      return AD->getNamespace();
1209
1210    return cast<NamespaceDecl>(Namespace);
1211  }
1212
1213  const NamespaceDecl *getNamespace() const {
1214    return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
1215  }
1216
1217  /// \brief Retrieve the namespace that this alias refers to, which
1218  /// may either be a NamespaceDecl or a NamespaceAliasDecl.
1219  NamedDecl *getAliasedNamespace() const { return Namespace; }
1220
1221  static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
1222                                    SourceLocation L, SourceLocation AliasLoc,
1223                                    IdentifierInfo *Alias,
1224                                    SourceRange QualifierRange,
1225                                    NestedNameSpecifier *Qualifier,
1226                                    SourceLocation IdentLoc,
1227                                    NamedDecl *Namespace);
1228
1229  static bool classof(const Decl *D) {
1230    return D->getKind() == Decl::NamespaceAlias;
1231  }
1232  static bool classof(const NamespaceAliasDecl *D) { return true; }
1233};
1234
1235/// UsingDecl - Represents a C++ using-declaration. For example:
1236///    using someNameSpace::someIdentifier;
1237class UsingDecl : public NamedDecl {
1238
1239  /// \brief The source range that covers the nested-name-specifier
1240  /// preceding the declaration name.
1241  SourceRange NestedNameRange;
1242  /// \brief The source location of the target declaration name.
1243  SourceLocation TargetNameLocation;
1244  /// \brief The source location of the "using" location itself.
1245  SourceLocation UsingLocation;
1246  /// \brief Target declaration.
1247  NamedDecl* TargetDecl;
1248  /// \brief Target declaration.
1249  NestedNameSpecifier* TargetNestedNameDecl;
1250
1251  // Had 'typename' keyword.
1252  bool IsTypeName;
1253
1254  UsingDecl(DeclContext *DC, SourceLocation L, SourceRange NNR,
1255            SourceLocation TargetNL, SourceLocation UL, NamedDecl* Target,
1256            NestedNameSpecifier* TargetNNS, bool IsTypeNameArg)
1257    : NamedDecl(Decl::Using, DC, L, Target->getDeclName()),
1258      NestedNameRange(NNR), TargetNameLocation(TargetNL),
1259      UsingLocation(UL), TargetDecl(Target),
1260      TargetNestedNameDecl(TargetNNS), IsTypeName(IsTypeNameArg) {
1261    this->IdentifierNamespace = TargetDecl->getIdentifierNamespace();
1262  }
1263
1264public:
1265  /// \brief Returns the source range that covers the nested-name-specifier
1266  /// preceding the namespace name.
1267  SourceRange getNestedNameRange() { return NestedNameRange; }
1268
1269  /// \brief Returns the source location of the target declaration name.
1270  SourceLocation getTargetNameLocation() { return TargetNameLocation; }
1271
1272  /// \brief Returns the source location of the "using" location itself.
1273  SourceLocation getUsingLocation() { return UsingLocation; }
1274
1275  /// \brief getTargetDecl - Returns target specified by using-decl.
1276  NamedDecl *getTargetDecl() { return TargetDecl; }
1277  const NamedDecl *getTargetDecl() const { return TargetDecl; }
1278
1279  /// \brief Get target nested name declaration.
1280  NestedNameSpecifier* getTargetNestedNameDecl() {
1281    return TargetNestedNameDecl;
1282  }
1283
1284  /// isTypeName - Return true if using decl had 'typename'.
1285  bool isTypeName() const { return IsTypeName; }
1286
1287  static UsingDecl *Create(ASTContext &C, DeclContext *DC,
1288      SourceLocation L, SourceRange NNR, SourceLocation TargetNL,
1289      SourceLocation UL, NamedDecl* Target,
1290      NestedNameSpecifier* TargetNNS, bool IsTypeNameArg);
1291
1292  static bool classof(const Decl *D) {
1293    return D->getKind() == Decl::Using;
1294  }
1295  static bool classof(const UsingDecl *D) { return true; }
1296};
1297
1298/// StaticAssertDecl - Represents a C++0x static_assert declaration.
1299class StaticAssertDecl : public Decl {
1300  Expr *AssertExpr;
1301  StringLiteral *Message;
1302
1303  StaticAssertDecl(DeclContext *DC, SourceLocation L,
1304                   Expr *assertexpr, StringLiteral *message)
1305  : Decl(StaticAssert, DC, L), AssertExpr(assertexpr), Message(message) { }
1306
1307public:
1308  static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
1309                                  SourceLocation L, Expr *AssertExpr,
1310                                  StringLiteral *Message);
1311
1312  Expr *getAssertExpr() { return AssertExpr; }
1313  const Expr *getAssertExpr() const { return AssertExpr; }
1314
1315  StringLiteral *getMessage() { return Message; }
1316  const StringLiteral *getMessage() const { return Message; }
1317
1318  virtual ~StaticAssertDecl();
1319  virtual void Destroy(ASTContext& C);
1320
1321  static bool classof(const Decl *D) {
1322    return D->getKind() == Decl::StaticAssert;
1323  }
1324  static bool classof(StaticAssertDecl *D) { return true; }
1325};
1326
1327/// Insertion operator for diagnostics.  This allows sending AccessSpecifier's
1328/// into a diagnostic with <<.
1329const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
1330                                    AccessSpecifier AS);
1331
1332} // end namespace clang
1333
1334#endif
1335