DeclCXX.h revision 560de45ccbf21c5e4dbeef3fc49f932e499cc181
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    setImplicit(isImplicitlyDeclared);
914  }
915
916public:
917  static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
918                                   SourceLocation L, DeclarationName N,
919                                   QualType T, bool isInline,
920                                   bool isImplicitlyDeclared);
921
922  /// isImplicitlyDefined - Whether this destructor was implicitly
923  /// defined. If false, then this destructor was defined by the
924  /// user. This operation can only be invoked if the destructor has
925  /// already been defined.
926  bool isImplicitlyDefined() const {
927    assert(isThisDeclarationADefinition() &&
928           "Can only get the implicit-definition flag once the destructor has been defined");
929    return ImplicitlyDefined;
930  }
931
932  /// setImplicitlyDefined - Set whether this destructor was
933  /// implicitly defined or not.
934  void setImplicitlyDefined(bool ID) {
935    assert(isThisDeclarationADefinition() &&
936           "Can only set the implicit-definition flag once the destructor has been defined");
937    ImplicitlyDefined = ID;
938  }
939
940  /// destr_iterator - Iterates through the member/base destruction list.
941  typedef CXXBaseOrMemberInitializer **destr_iterator;
942
943  /// destr_const_iterator - Iterates through the member/base destruction list.
944  typedef CXXBaseOrMemberInitializer * const * destr_const_iterator;
945
946  /// destr_begin() - Retrieve an iterator to the first destructed member/base.
947  destr_iterator       destr_begin()       { return BaseOrMemberDestructions; }
948  /// destr_begin() - Retrieve an iterator to the first destructed member/base.
949  destr_const_iterator destr_begin() const { return BaseOrMemberDestructions; }
950
951  /// destr_end() - Retrieve an iterator past the last destructed member/base.
952  destr_iterator       destr_end()       {
953    return BaseOrMemberDestructions + NumBaseOrMemberDestructions;
954  }
955  /// destr_end() - Retrieve an iterator past the last destructed member/base.
956  destr_const_iterator destr_end() const {
957    return BaseOrMemberDestructions + NumBaseOrMemberDestructions;
958  }
959
960  /// getNumArgs - Determine the number of arguments used to
961  /// destruct the member or base.
962  unsigned getNumBaseOrMemberDestructions() const {
963    return NumBaseOrMemberDestructions;
964  }
965
966  void setBaseOrMemberDestructions(ASTContext &C);
967
968  // Implement isa/cast/dyncast/etc.
969  static bool classof(const Decl *D) {
970    return D->getKind() == CXXDestructor;
971  }
972  static bool classof(const CXXDestructorDecl *D) { return true; }
973};
974
975/// CXXConversionDecl - Represents a C++ conversion function within a
976/// class. For example:
977///
978/// @code
979/// class X {
980/// public:
981///   operator bool();
982/// };
983/// @endcode
984class CXXConversionDecl : public CXXMethodDecl {
985  /// Explicit - Whether this conversion function is marked
986  /// "explicit", meaning that it can only be applied when the user
987  /// explicitly wrote a cast. This is a C++0x feature.
988  bool Explicit : 1;
989
990  CXXConversionDecl(CXXRecordDecl *RD, SourceLocation L,
991                    DeclarationName N, QualType T,
992                    bool isInline, bool isExplicit)
993    : CXXMethodDecl(CXXConversion, RD, L, N, T, false, isInline),
994      Explicit(isExplicit) { }
995
996public:
997  static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
998                                   SourceLocation L, DeclarationName N,
999                                   QualType T, bool isInline,
1000                                   bool isExplicit);
1001
1002  /// isExplicit - Whether this is an explicit conversion operator
1003  /// (C++0x only). Explicit conversion operators are only considered
1004  /// when the user has explicitly written a cast.
1005  bool isExplicit() const { return Explicit; }
1006
1007  /// getConversionType - Returns the type that this conversion
1008  /// function is converting to.
1009  QualType getConversionType() const {
1010    return getType()->getAsFunctionType()->getResultType();
1011  }
1012
1013  // Implement isa/cast/dyncast/etc.
1014  static bool classof(const Decl *D) {
1015    return D->getKind() == CXXConversion;
1016  }
1017  static bool classof(const CXXConversionDecl *D) { return true; }
1018};
1019
1020/// LinkageSpecDecl - This represents a linkage specification.  For example:
1021///   extern "C" void foo();
1022///
1023class LinkageSpecDecl : public Decl, public DeclContext {
1024public:
1025  /// LanguageIDs - Used to represent the language in a linkage
1026  /// specification.  The values are part of the serialization abi for
1027  /// ASTs and cannot be changed without altering that abi.  To help
1028  /// ensure a stable abi for this, we choose the DW_LANG_ encodings
1029  /// from the dwarf standard.
1030  enum LanguageIDs { lang_c = /* DW_LANG_C */ 0x0002,
1031  lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004 };
1032private:
1033  /// Language - The language for this linkage specification.
1034  LanguageIDs Language;
1035
1036  /// HadBraces - Whether this linkage specification had curly braces or not.
1037  bool HadBraces : 1;
1038
1039  LinkageSpecDecl(DeclContext *DC, SourceLocation L, LanguageIDs lang,
1040                  bool Braces)
1041    : Decl(LinkageSpec, DC, L),
1042      DeclContext(LinkageSpec), Language(lang), HadBraces(Braces) { }
1043
1044public:
1045  static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
1046                                 SourceLocation L, LanguageIDs Lang,
1047                                 bool Braces);
1048
1049  LanguageIDs getLanguage() const { return Language; }
1050
1051  /// hasBraces - Determines whether this linkage specification had
1052  /// braces in its syntactic form.
1053  bool hasBraces() const { return HadBraces; }
1054
1055  static bool classof(const Decl *D) {
1056    return D->getKind() == LinkageSpec;
1057  }
1058  static bool classof(const LinkageSpecDecl *D) { return true; }
1059  static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
1060    return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
1061  }
1062  static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
1063    return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
1064  }
1065};
1066
1067/// UsingDirectiveDecl - Represents C++ using-directive. For example:
1068///
1069///    using namespace std;
1070///
1071// NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide
1072// artificial name, for all using-directives in order to store
1073// them in DeclContext effectively.
1074class UsingDirectiveDecl : public NamedDecl {
1075
1076  /// SourceLocation - Location of 'namespace' token.
1077  SourceLocation NamespaceLoc;
1078
1079  /// \brief The source range that covers the nested-name-specifier
1080  /// preceding the namespace name.
1081  SourceRange QualifierRange;
1082
1083  /// \brief The nested-name-specifier that precedes the namespace
1084  /// name, if any.
1085  NestedNameSpecifier *Qualifier;
1086
1087  /// IdentLoc - Location of nominated namespace-name identifier.
1088  // FIXME: We don't store location of scope specifier.
1089  SourceLocation IdentLoc;
1090
1091  /// NominatedNamespace - Namespace nominated by using-directive.
1092  NamespaceDecl *NominatedNamespace;
1093
1094  /// Enclosing context containing both using-directive and nomintated
1095  /// namespace.
1096  DeclContext *CommonAncestor;
1097
1098  /// getUsingDirectiveName - Returns special DeclarationName used by
1099  /// using-directives. This is only used by DeclContext for storing
1100  /// UsingDirectiveDecls in its lookup structure.
1101  static DeclarationName getName() {
1102    return DeclarationName::getUsingDirectiveName();
1103  }
1104
1105  UsingDirectiveDecl(DeclContext *DC, SourceLocation L,
1106                     SourceLocation NamespcLoc,
1107                     SourceRange QualifierRange,
1108                     NestedNameSpecifier *Qualifier,
1109                     SourceLocation IdentLoc,
1110                     NamespaceDecl *Nominated,
1111                     DeclContext *CommonAncestor)
1112    : NamedDecl(Decl::UsingDirective, DC, L, getName()),
1113      NamespaceLoc(NamespcLoc), QualifierRange(QualifierRange),
1114      Qualifier(Qualifier), IdentLoc(IdentLoc),
1115      NominatedNamespace(Nominated? Nominated->getOriginalNamespace() : 0),
1116      CommonAncestor(CommonAncestor) {
1117  }
1118
1119public:
1120  /// \brief Retrieve the source range of the nested-name-specifier
1121  /// that qualifiers the namespace name.
1122  SourceRange getQualifierRange() const { return QualifierRange; }
1123
1124  /// \brief Retrieve the nested-name-specifier that qualifies the
1125  /// name of the namespace.
1126  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1127
1128  /// getNominatedNamespace - Returns namespace nominated by using-directive.
1129  NamespaceDecl *getNominatedNamespace() { return NominatedNamespace; }
1130
1131  const NamespaceDecl *getNominatedNamespace() const {
1132    return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
1133  }
1134
1135  /// getCommonAncestor - returns common ancestor context of using-directive,
1136  /// and nominated by it namespace.
1137  DeclContext *getCommonAncestor() { return CommonAncestor; }
1138  const DeclContext *getCommonAncestor() const { return CommonAncestor; }
1139
1140  /// getNamespaceKeyLocation - Returns location of namespace keyword.
1141  SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
1142
1143  /// getIdentLocation - Returns location of identifier.
1144  SourceLocation getIdentLocation() const { return IdentLoc; }
1145
1146  static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
1147                                    SourceLocation L,
1148                                    SourceLocation NamespaceLoc,
1149                                    SourceRange QualifierRange,
1150                                    NestedNameSpecifier *Qualifier,
1151                                    SourceLocation IdentLoc,
1152                                    NamespaceDecl *Nominated,
1153                                    DeclContext *CommonAncestor);
1154
1155  static bool classof(const Decl *D) {
1156    return D->getKind() == Decl::UsingDirective;
1157  }
1158  static bool classof(const UsingDirectiveDecl *D) { return true; }
1159
1160  // Friend for getUsingDirectiveName.
1161  friend class DeclContext;
1162};
1163
1164/// NamespaceAliasDecl - Represents a C++ namespace alias. For example:
1165///
1166/// @code
1167/// namespace Foo = Bar;
1168/// @endcode
1169class NamespaceAliasDecl : public NamedDecl {
1170  SourceLocation AliasLoc;
1171
1172  /// \brief The source range that covers the nested-name-specifier
1173  /// preceding the namespace name.
1174  SourceRange QualifierRange;
1175
1176  /// \brief The nested-name-specifier that precedes the namespace
1177  /// name, if any.
1178  NestedNameSpecifier *Qualifier;
1179
1180  /// IdentLoc - Location of namespace identifier.
1181  SourceLocation IdentLoc;
1182
1183  /// Namespace - The Decl that this alias points to. Can either be a
1184  /// NamespaceDecl or a NamespaceAliasDecl.
1185  NamedDecl *Namespace;
1186
1187  NamespaceAliasDecl(DeclContext *DC, SourceLocation L,
1188                     SourceLocation AliasLoc, IdentifierInfo *Alias,
1189                     SourceRange QualifierRange,
1190                     NestedNameSpecifier *Qualifier,
1191                     SourceLocation IdentLoc, NamedDecl *Namespace)
1192    : NamedDecl(Decl::NamespaceAlias, DC, L, Alias), AliasLoc(AliasLoc),
1193      QualifierRange(QualifierRange), Qualifier(Qualifier),
1194      IdentLoc(IdentLoc), Namespace(Namespace) { }
1195
1196public:
1197  /// \brief Retrieve the source range of the nested-name-specifier
1198  /// that qualifiers the namespace name.
1199  SourceRange getQualifierRange() const { return QualifierRange; }
1200
1201  /// \brief Retrieve the nested-name-specifier that qualifies the
1202  /// name of the namespace.
1203  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1204
1205  NamespaceDecl *getNamespace() {
1206    if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
1207      return AD->getNamespace();
1208
1209    return cast<NamespaceDecl>(Namespace);
1210  }
1211
1212  const NamespaceDecl *getNamespace() const {
1213    return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
1214  }
1215
1216  /// \brief Retrieve the namespace that this alias refers to, which
1217  /// may either be a NamespaceDecl or a NamespaceAliasDecl.
1218  NamedDecl *getAliasedNamespace() const { return Namespace; }
1219
1220  static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
1221                                    SourceLocation L, SourceLocation AliasLoc,
1222                                    IdentifierInfo *Alias,
1223                                    SourceRange QualifierRange,
1224                                    NestedNameSpecifier *Qualifier,
1225                                    SourceLocation IdentLoc,
1226                                    NamedDecl *Namespace);
1227
1228  static bool classof(const Decl *D) {
1229    return D->getKind() == Decl::NamespaceAlias;
1230  }
1231  static bool classof(const NamespaceAliasDecl *D) { return true; }
1232};
1233
1234/// UsingDecl - Represents a C++ using-declaration. For example:
1235///    using someNameSpace::someIdentifier;
1236class UsingDecl : public NamedDecl {
1237
1238  /// \brief The source range that covers the nested-name-specifier
1239  /// preceding the declaration name.
1240  SourceRange NestedNameRange;
1241  /// \brief The source location of the target declaration name.
1242  SourceLocation TargetNameLocation;
1243  /// \brief The source location of the "using" location itself.
1244  SourceLocation UsingLocation;
1245  /// \brief Target declaration.
1246  NamedDecl* TargetDecl;
1247  /// \brief Target declaration.
1248  NestedNameSpecifier* TargetNestedNameDecl;
1249
1250  // Had 'typename' keyword.
1251  bool IsTypeName;
1252
1253  UsingDecl(DeclContext *DC, SourceLocation L, SourceRange NNR,
1254            SourceLocation TargetNL, SourceLocation UL, NamedDecl* Target,
1255            NestedNameSpecifier* TargetNNS, bool IsTypeNameArg)
1256    : NamedDecl(Decl::Using, DC, L, Target->getDeclName()),
1257      NestedNameRange(NNR), TargetNameLocation(TargetNL),
1258      UsingLocation(UL), TargetDecl(Target),
1259      TargetNestedNameDecl(TargetNNS), IsTypeName(IsTypeNameArg) {
1260    this->IdentifierNamespace = TargetDecl->getIdentifierNamespace();
1261  }
1262
1263public:
1264  /// \brief Returns the source range that covers the nested-name-specifier
1265  /// preceding the namespace name.
1266  SourceRange getNestedNameRange() { return NestedNameRange; }
1267
1268  /// \brief Returns the source location of the target declaration name.
1269  SourceLocation getTargetNameLocation() { return TargetNameLocation; }
1270
1271  /// \brief Returns the source location of the "using" location itself.
1272  SourceLocation getUsingLocation() { return UsingLocation; }
1273
1274  /// \brief getTargetDecl - Returns target specified by using-decl.
1275  NamedDecl *getTargetDecl() { return TargetDecl; }
1276  const NamedDecl *getTargetDecl() const { return TargetDecl; }
1277
1278  /// \brief Get target nested name declaration.
1279  NestedNameSpecifier* getTargetNestedNameDecl() {
1280    return TargetNestedNameDecl;
1281  }
1282
1283  /// isTypeName - Return true if using decl had 'typename'.
1284  bool isTypeName() const { return IsTypeName; }
1285
1286  static UsingDecl *Create(ASTContext &C, DeclContext *DC,
1287      SourceLocation L, SourceRange NNR, SourceLocation TargetNL,
1288      SourceLocation UL, NamedDecl* Target,
1289      NestedNameSpecifier* TargetNNS, bool IsTypeNameArg);
1290
1291  static bool classof(const Decl *D) {
1292    return D->getKind() == Decl::Using;
1293  }
1294  static bool classof(const UsingDecl *D) { return true; }
1295};
1296
1297/// StaticAssertDecl - Represents a C++0x static_assert declaration.
1298class StaticAssertDecl : public Decl {
1299  Expr *AssertExpr;
1300  StringLiteral *Message;
1301
1302  StaticAssertDecl(DeclContext *DC, SourceLocation L,
1303                   Expr *assertexpr, StringLiteral *message)
1304  : Decl(StaticAssert, DC, L), AssertExpr(assertexpr), Message(message) { }
1305
1306public:
1307  static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
1308                                  SourceLocation L, Expr *AssertExpr,
1309                                  StringLiteral *Message);
1310
1311  Expr *getAssertExpr() { return AssertExpr; }
1312  const Expr *getAssertExpr() const { return AssertExpr; }
1313
1314  StringLiteral *getMessage() { return Message; }
1315  const StringLiteral *getMessage() const { return Message; }
1316
1317  virtual ~StaticAssertDecl();
1318  virtual void Destroy(ASTContext& C);
1319
1320  static bool classof(const Decl *D) {
1321    return D->getKind() == Decl::StaticAssert;
1322  }
1323  static bool classof(StaticAssertDecl *D) { return true; }
1324};
1325
1326/// Insertion operator for diagnostics.  This allows sending AccessSpecifier's
1327/// into a diagnostic with <<.
1328const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
1329                                    AccessSpecifier AS);
1330
1331} // end namespace clang
1332
1333#endif
1334