DeclCXX.h revision 741dd9a7e1d63e4e385b657e4ce11c5d96d44f72
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                SourceLocation TKL = SourceLocation());
340
341  ~CXXRecordDecl();
342
343public:
344  /// base_class_iterator - Iterator that traverses the base classes
345  /// of a clas.
346  typedef CXXBaseSpecifier*       base_class_iterator;
347
348  /// base_class_const_iterator - Iterator that traverses the base
349  /// classes of a clas.
350  typedef const CXXBaseSpecifier* base_class_const_iterator;
351
352  static CXXRecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC,
353                               SourceLocation L, IdentifierInfo *Id,
354                               SourceLocation TKL = SourceLocation(),
355                               CXXRecordDecl* PrevDecl=0,
356                               bool DelayTypeCreation = false);
357
358  virtual void Destroy(ASTContext& C);
359
360  /// setBases - Sets the base classes of this struct or class.
361  void setBases(ASTContext &C,
362                CXXBaseSpecifier const * const *Bases, unsigned NumBases);
363
364  /// getNumBases - Retrieves the number of base classes of this
365  /// class.
366  unsigned getNumBases() const { return NumBases; }
367
368  base_class_iterator       bases_begin()       { return Bases; }
369  base_class_const_iterator bases_begin() const { return Bases; }
370  base_class_iterator       bases_end()         { return Bases + NumBases; }
371  base_class_const_iterator bases_end()   const { return Bases + NumBases; }
372
373  /// getNumVBases - Retrieves the number of virtual base classes of this
374  /// class.
375  unsigned getNumVBases() const { return NumVBases; }
376
377  base_class_iterator       vbases_begin()       { return VBases; }
378  base_class_const_iterator vbases_begin() const { return VBases; }
379  base_class_iterator       vbases_end()         { return VBases + NumVBases; }
380  base_class_const_iterator vbases_end()   const { return VBases + NumVBases; }
381
382  /// hasConstCopyConstructor - Determines whether this class has a
383  /// copy constructor that accepts a const-qualified argument.
384  bool hasConstCopyConstructor(ASTContext &Context) const;
385
386  /// getCopyConstructor - Returns the copy constructor for this class
387  CXXConstructorDecl *getCopyConstructor(ASTContext &Context,
388                                         unsigned TypeQuals) const;
389
390  /// hasConstCopyAssignment - Determines whether this class has a
391  /// copy assignment operator that accepts a const-qualified argument.
392  bool hasConstCopyAssignment(ASTContext &Context) const;
393
394  /// addedConstructor - Notify the class that another constructor has
395  /// been added. This routine helps maintain information about the
396  /// class based on which constructors have been added.
397  void addedConstructor(ASTContext &Context, CXXConstructorDecl *ConDecl);
398
399  /// hasUserDeclaredConstructor - Whether this class has any
400  /// user-declared constructors. When true, a default constructor
401  /// will not be implicitly declared.
402  bool hasUserDeclaredConstructor() const { return UserDeclaredConstructor; }
403
404  /// hasUserDeclaredCopyConstructor - Whether this class has a
405  /// user-declared copy constructor. When false, a copy constructor
406  /// will be implicitly declared.
407  bool hasUserDeclaredCopyConstructor() const {
408    return UserDeclaredCopyConstructor;
409  }
410
411  /// addedAssignmentOperator - Notify the class that another assignment
412  /// operator has been added. This routine helps maintain information about the
413   /// class based on which operators have been added.
414  void addedAssignmentOperator(ASTContext &Context, CXXMethodDecl *OpDecl);
415
416  /// hasUserDeclaredCopyAssignment - Whether this class has a
417  /// user-declared copy assignment operator. When false, a copy
418  /// assigment operator will be implicitly declared.
419  bool hasUserDeclaredCopyAssignment() const {
420    return UserDeclaredCopyAssignment;
421  }
422
423  /// hasUserDeclaredDestructor - Whether this class has a
424  /// user-declared destructor. When false, a destructor will be
425  /// implicitly declared.
426  bool hasUserDeclaredDestructor() const { return UserDeclaredDestructor; }
427
428  /// setUserDeclaredDestructor - Set whether this class has a
429  /// user-declared destructor. If not set by the time the class is
430  /// fully defined, a destructor will be implicitly declared.
431  void setUserDeclaredDestructor(bool UCD) {
432    UserDeclaredDestructor = UCD;
433  }
434
435  /// getConversions - Retrieve the overload set containing all of the
436  /// conversion functions in this class.
437  OverloadedFunctionDecl *getConversionFunctions() {
438    return &Conversions;
439  }
440  const OverloadedFunctionDecl *getConversionFunctions() const {
441    return &Conversions;
442  }
443
444  /// addConversionFunction - Add a new conversion function to the
445  /// list of conversion functions.
446  void addConversionFunction(ASTContext &Context, CXXConversionDecl *ConvDecl);
447
448  /// isAggregate - Whether this class is an aggregate (C++
449  /// [dcl.init.aggr]), which is a class with no user-declared
450  /// constructors, no private or protected non-static data members,
451  /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1).
452  bool isAggregate() const { return Aggregate; }
453
454  /// setAggregate - Set whether this class is an aggregate (C++
455  /// [dcl.init.aggr]).
456  void setAggregate(bool Agg) { Aggregate = Agg; }
457
458  /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class
459  /// that is an aggregate that has no non-static non-POD data members, no
460  /// reference data members, no user-defined copy assignment operator and no
461  /// user-defined destructor.
462  bool isPOD() const { return PlainOldData; }
463
464  /// setPOD - Set whether this class is a POD-type (C++ [class]p4).
465  void setPOD(bool POD) { PlainOldData = POD; }
466
467  /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]),
468  /// which means that the class contains or inherits a virtual function.
469  bool isPolymorphic() const { return Polymorphic; }
470
471  /// setPolymorphic - Set whether this class is polymorphic (C++
472  /// [class.virtual]).
473  void setPolymorphic(bool Poly) { Polymorphic = Poly; }
474
475  /// isAbstract - Whether this class is abstract (C++ [class.abstract]),
476  /// which means that the class contains or inherits a pure virtual function.
477  bool isAbstract() const { return Abstract; }
478
479  /// setAbstract - Set whether this class is abstract (C++ [class.abstract])
480  void setAbstract(bool Abs) { Abstract = Abs; }
481
482  // hasTrivialConstructor - Whether this class has a trivial constructor
483  // (C++ [class.ctor]p5)
484  bool hasTrivialConstructor() const { return HasTrivialConstructor; }
485
486  // setHasTrivialConstructor - Set whether this class has a trivial constructor
487  // (C++ [class.ctor]p5)
488  void setHasTrivialConstructor(bool TC) { HasTrivialConstructor = TC; }
489
490  // hasTrivialDestructor - Whether this class has a trivial destructor
491  // (C++ [class.dtor]p3)
492  bool hasTrivialDestructor() const { return HasTrivialDestructor; }
493
494  // setHasTrivialDestructor - Set whether this class has a trivial destructor
495  // (C++ [class.dtor]p3)
496  void setHasTrivialDestructor(bool TC) { HasTrivialDestructor = TC; }
497
498  /// \brief If this record is an instantiation of a member class,
499  /// retrieves the member class from which it was instantiated.
500  ///
501  /// This routine will return non-NULL for (non-templated) member
502  /// classes of class templates. For example, given:
503  ///
504  /// \code
505  /// template<typename T>
506  /// struct X {
507  ///   struct A { };
508  /// };
509  /// \endcode
510  ///
511  /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
512  /// whose parent is the class template specialization X<int>. For
513  /// this declaration, getInstantiatedFromMemberClass() will return
514  /// the CXXRecordDecl X<T>::A. When a complete definition of
515  /// X<int>::A is required, it will be instantiated from the
516  /// declaration returned by getInstantiatedFromMemberClass().
517  CXXRecordDecl *getInstantiatedFromMemberClass() const {
518    return TemplateOrInstantiation.dyn_cast<CXXRecordDecl*>();
519  }
520
521  /// \brief Specify that this record is an instantiation of the
522  /// member class RD.
523  void setInstantiationOfMemberClass(CXXRecordDecl *RD) {
524    TemplateOrInstantiation = RD;
525  }
526
527  /// \brief Retrieves the class template that is described by this
528  /// class declaration.
529  ///
530  /// Every class template is represented as a ClassTemplateDecl and a
531  /// CXXRecordDecl. The former contains template properties (such as
532  /// the template parameter lists) while the latter contains the
533  /// actual description of the template's
534  /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
535  /// CXXRecordDecl that from a ClassTemplateDecl, while
536  /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
537  /// a CXXRecordDecl.
538  ClassTemplateDecl *getDescribedClassTemplate() const {
539    return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>();
540  }
541
542  void setDescribedClassTemplate(ClassTemplateDecl *Template) {
543    TemplateOrInstantiation = Template;
544  }
545
546  /// getDefaultConstructor - Returns the default constructor for this class
547  CXXConstructorDecl *getDefaultConstructor(ASTContext &Context);
548
549  /// getDestructor - Returns the destructor decl for this class.
550  const CXXDestructorDecl *getDestructor(ASTContext &Context);
551
552  /// isLocalClass - If the class is a local class [class.local], returns
553  /// the enclosing function declaration.
554  const FunctionDecl *isLocalClass() const {
555    if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
556      return RD->isLocalClass();
557
558    return dyn_cast<FunctionDecl>(getDeclContext());
559  }
560
561  /// viewInheritance - Renders and displays an inheritance diagram
562  /// for this C++ class and all of its base classes (transitively) using
563  /// GraphViz.
564  void viewInheritance(ASTContext& Context) const;
565
566  static bool classof(const Decl *D) {
567    return D->getKind() == CXXRecord ||
568           D->getKind() == ClassTemplateSpecialization ||
569           D->getKind() == ClassTemplatePartialSpecialization;
570  }
571  static bool classof(const CXXRecordDecl *D) { return true; }
572  static bool classof(const ClassTemplateSpecializationDecl *D) {
573    return true;
574  }
575};
576
577/// CXXMethodDecl - Represents a static or instance method of a
578/// struct/union/class.
579class CXXMethodDecl : public FunctionDecl {
580protected:
581  CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation L,
582                DeclarationName N, QualType T,
583                bool isStatic, bool isInline)
584    : FunctionDecl(DK, RD, L, N, T, (isStatic ? Static : None),
585                   isInline) {}
586
587public:
588  static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
589                              SourceLocation L, DeclarationName N,
590                              QualType T, bool isStatic = false,
591                              bool isInline = false);
592
593  bool isStatic() const { return getStorageClass() == Static; }
594  bool isInstance() const { return !isStatic(); }
595
596  bool isVirtual() const {
597    return isVirtualAsWritten() ||
598      (begin_overridden_methods() != end_overridden_methods());
599  }
600
601  ///
602  void addOverriddenMethod(const CXXMethodDecl *MD);
603
604  typedef const CXXMethodDecl ** method_iterator;
605
606  method_iterator begin_overridden_methods() const;
607  method_iterator end_overridden_methods() const;
608
609  /// getParent - Returns the parent of this method declaration, which
610  /// is the class in which this method is defined.
611  const CXXRecordDecl *getParent() const {
612    return cast<CXXRecordDecl>(FunctionDecl::getParent());
613  }
614
615  /// getParent - Returns the parent of this method declaration, which
616  /// is the class in which this method is defined.
617  CXXRecordDecl *getParent() {
618    return const_cast<CXXRecordDecl *>(
619             cast<CXXRecordDecl>(FunctionDecl::getParent()));
620  }
621
622  /// getThisType - Returns the type of 'this' pointer.
623  /// Should only be called for instance methods.
624  QualType getThisType(ASTContext &C) const;
625
626  unsigned getTypeQualifiers() const {
627    return getType()->getAsFunctionProtoType()->getTypeQuals();
628  }
629
630  // Implement isa/cast/dyncast/etc.
631  static bool classof(const Decl *D) {
632    return D->getKind() >= CXXMethod && D->getKind() <= CXXConversion;
633  }
634  static bool classof(const CXXMethodDecl *D) { return true; }
635};
636
637/// CXXBaseOrMemberInitializer - Represents a C++ base or member
638/// initializer, which is part of a constructor initializer that
639/// initializes one non-static member variable or one base class. For
640/// example, in the following, both 'A(a)' and 'f(3.14159)' are member
641/// initializers:
642///
643/// @code
644/// class A { };
645/// class B : public A {
646///   float f;
647/// public:
648///   B(A& a) : A(a), f(3.14159) { }
649/// };
650/// @endcode
651class CXXBaseOrMemberInitializer {
652  /// BaseOrMember - This points to the entity being initialized,
653  /// which is either a base class (a Type) or a non-static data
654  /// member. When the low bit is 1, it's a base
655  /// class; when the low bit is 0, it's a member.
656  uintptr_t BaseOrMember;
657
658  /// Args - The arguments used to initialize the base or member.
659  Expr **Args;
660  unsigned NumArgs;
661
662  /// IdLoc - Location of the id in ctor-initializer list.
663  SourceLocation IdLoc;
664
665public:
666  /// CXXBaseOrMemberInitializer - Creates a new base-class initializer.
667  explicit
668  CXXBaseOrMemberInitializer(QualType BaseType, Expr **Args, unsigned NumArgs,
669                             SourceLocation L);
670
671  /// CXXBaseOrMemberInitializer - Creates a new member initializer.
672  explicit
673  CXXBaseOrMemberInitializer(FieldDecl *Member, Expr **Args, unsigned NumArgs,
674                             SourceLocation L);
675
676  /// ~CXXBaseOrMemberInitializer - Destroy the base or member initializer.
677  ~CXXBaseOrMemberInitializer();
678
679  /// arg_iterator - Iterates through the member initialization
680  /// arguments.
681  typedef Expr **arg_iterator;
682
683  /// arg_const_iterator - Iterates through the member initialization
684  /// arguments.
685  typedef Expr * const * arg_const_iterator;
686
687  /// getBaseOrMember - get the generic 'member' representing either the field
688  /// or a base class.
689  void* getBaseOrMember() const { return reinterpret_cast<void*>(BaseOrMember); }
690
691  /// isBaseInitializer - Returns true when this initializer is
692  /// initializing a base class.
693  bool isBaseInitializer() const { return (BaseOrMember & 0x1) != 0; }
694
695  /// isMemberInitializer - Returns true when this initializer is
696  /// initializing a non-static data member.
697  bool isMemberInitializer() const { return (BaseOrMember & 0x1) == 0; }
698
699  /// getBaseClass - If this is a base class initializer, returns the
700  /// type used to specify the initializer. The resulting type will be
701  /// a class type or a typedef of a class type. If this is not a base
702  /// class initializer, returns NULL.
703  Type *getBaseClass() {
704    if (isBaseInitializer())
705      return reinterpret_cast<Type*>(BaseOrMember & ~0x01);
706    else
707      return 0;
708  }
709
710  /// getBaseClass - If this is a base class initializer, returns the
711  /// type used to specify the initializer. The resulting type will be
712  /// a class type or a typedef of a class type. If this is not a base
713  /// class initializer, returns NULL.
714  const Type *getBaseClass() const {
715    if (isBaseInitializer())
716      return reinterpret_cast<const Type*>(BaseOrMember & ~0x01);
717    else
718      return 0;
719  }
720
721  /// getMember - If this is a member initializer, returns the
722  /// declaration of the non-static data member being
723  /// initialized. Otherwise, returns NULL.
724  FieldDecl *getMember() {
725    if (isMemberInitializer())
726      return reinterpret_cast<FieldDecl *>(BaseOrMember);
727    else
728      return 0;
729  }
730
731  SourceLocation getSourceLocation() const { return IdLoc; }
732
733  /// begin() - Retrieve an iterator to the first initializer argument.
734  arg_iterator       begin()       { return Args; }
735  /// begin() - Retrieve an iterator to the first initializer argument.
736  arg_const_iterator begin() const { return Args; }
737
738  /// end() - Retrieve an iterator past the last initializer argument.
739  arg_iterator       end()       { return Args + NumArgs; }
740  /// end() - Retrieve an iterator past the last initializer argument.
741  arg_const_iterator end() const { return Args + NumArgs; }
742
743  /// getNumArgs - Determine the number of arguments used to
744  /// initialize the member or base.
745  unsigned getNumArgs() const { return NumArgs; }
746};
747
748/// CXXConstructorDecl - Represents a C++ constructor within a
749/// class. For example:
750///
751/// @code
752/// class X {
753/// public:
754///   explicit X(int); // represented by a CXXConstructorDecl.
755/// };
756/// @endcode
757class CXXConstructorDecl : public CXXMethodDecl {
758  /// Explicit - Whether this constructor is explicit.
759  bool Explicit : 1;
760
761  /// ImplicitlyDefined - Whether this constructor was implicitly
762  /// defined by the compiler. When false, the constructor was defined
763  /// by the user. In C++03, this flag will have the same value as
764  /// Implicit. In C++0x, however, a constructor that is
765  /// explicitly defaulted (i.e., defined with " = default") will have
766  /// @c !Implicit && ImplicitlyDefined.
767  bool ImplicitlyDefined : 1;
768
769  /// Support for base and member initializers.
770  /// BaseOrMemberInitializers - The arguments used to initialize the base
771  /// or member.
772  CXXBaseOrMemberInitializer **BaseOrMemberInitializers;
773  unsigned NumBaseOrMemberInitializers;
774
775  CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation L,
776                     DeclarationName N, QualType T,
777                     bool isExplicit, bool isInline, bool isImplicitlyDeclared)
778    : CXXMethodDecl(CXXConstructor, RD, L, N, T, false, isInline),
779      Explicit(isExplicit), ImplicitlyDefined(false),
780      BaseOrMemberInitializers(0), NumBaseOrMemberInitializers(0) {
781    setImplicit(isImplicitlyDeclared);
782  }
783  virtual void Destroy(ASTContext& C);
784
785public:
786  static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
787                                    SourceLocation L, DeclarationName N,
788                                    QualType T, bool isExplicit,
789                                    bool isInline, bool isImplicitlyDeclared);
790
791  /// isExplicit - Whether this constructor was marked "explicit" or not.
792  bool isExplicit() const { return Explicit; }
793
794  /// isImplicitlyDefined - Whether this constructor was implicitly
795  /// defined. If false, then this constructor was defined by the
796  /// user. This operation can only be invoked if the constructor has
797  /// already been defined.
798  bool isImplicitlyDefined(ASTContext &C) const {
799    assert(isThisDeclarationADefinition() &&
800           "Can only get the implicit-definition flag once the "
801           "constructor has been defined");
802    return ImplicitlyDefined;
803  }
804
805  /// setImplicitlyDefined - Set whether this constructor was
806  /// implicitly defined or not.
807  void setImplicitlyDefined(bool ID) {
808    assert(isThisDeclarationADefinition() &&
809           "Can only set the implicit-definition flag once the constructor "
810           "has been defined");
811    ImplicitlyDefined = ID;
812  }
813
814  /// init_iterator - Iterates through the member/base initializer list.
815  typedef CXXBaseOrMemberInitializer **init_iterator;
816
817  /// init_const_iterator - Iterates through the memberbase initializer list.
818  typedef CXXBaseOrMemberInitializer * const * init_const_iterator;
819
820  /// init_begin() - Retrieve an iterator to the first initializer.
821  init_iterator       init_begin()       { return BaseOrMemberInitializers; }
822  /// begin() - Retrieve an iterator to the first initializer.
823  init_const_iterator init_begin() const { return BaseOrMemberInitializers; }
824
825  /// init_end() - Retrieve an iterator past the last initializer.
826  init_iterator       init_end()       {
827    return BaseOrMemberInitializers + NumBaseOrMemberInitializers;
828  }
829  /// end() - Retrieve an iterator past the last initializer.
830  init_const_iterator init_end() const {
831    return BaseOrMemberInitializers + NumBaseOrMemberInitializers;
832  }
833
834  /// getNumArgs - Determine the number of arguments used to
835  /// initialize the member or base.
836  unsigned getNumBaseOrMemberInitializers() const {
837      return NumBaseOrMemberInitializers;
838  }
839
840  void setBaseOrMemberInitializers(ASTContext &C,
841                                   CXXBaseOrMemberInitializer **Initializers,
842                                   unsigned NumInitializers);
843
844  /// isDefaultConstructor - Whether this constructor is a default
845  /// constructor (C++ [class.ctor]p5), which can be used to
846  /// default-initialize a class of this type.
847  bool isDefaultConstructor() const;
848
849  /// isCopyConstructor - Whether this constructor is a copy
850  /// constructor (C++ [class.copy]p2, which can be used to copy the
851  /// class. @p TypeQuals will be set to the qualifiers on the
852  /// argument type. For example, @p TypeQuals would be set to @c
853  /// QualType::Const for the following copy constructor:
854  ///
855  /// @code
856  /// class X {
857  /// public:
858  ///   X(const X&);
859  /// };
860  /// @endcode
861  bool isCopyConstructor(ASTContext &Context, unsigned &TypeQuals) const;
862
863  /// isCopyConstructor - Whether this constructor is a copy
864  /// constructor (C++ [class.copy]p2, which can be used to copy the
865  /// class.
866  bool isCopyConstructor(ASTContext &Context) const {
867    unsigned TypeQuals = 0;
868    return isCopyConstructor(Context, TypeQuals);
869  }
870
871  /// isConvertingConstructor - Whether this constructor is a
872  /// converting constructor (C++ [class.conv.ctor]), which can be
873  /// used for user-defined conversions.
874  bool isConvertingConstructor() const;
875
876  // Implement isa/cast/dyncast/etc.
877  static bool classof(const Decl *D) {
878    return D->getKind() == CXXConstructor;
879  }
880  static bool classof(const CXXConstructorDecl *D) { return true; }
881};
882
883/// CXXDestructorDecl - Represents a C++ destructor within a
884/// class. For example:
885///
886/// @code
887/// class X {
888/// public:
889///   ~X(); // represented by a CXXDestructorDecl.
890/// };
891/// @endcode
892class CXXDestructorDecl : public CXXMethodDecl {
893  /// ImplicitlyDefined - Whether this destructor was implicitly
894  /// defined by the compiler. When false, the destructor was defined
895  /// by the user. In C++03, this flag will have the same value as
896  /// Implicit. In C++0x, however, a destructor that is
897  /// explicitly defaulted (i.e., defined with " = default") will have
898  /// @c !Implicit && ImplicitlyDefined.
899  bool ImplicitlyDefined : 1;
900
901  /// Support for base and member destruction.
902  /// BaseOrMemberDestructions - The arguments used to destruct the base
903  /// or member.
904  // FIXME. May want to use a new class as CXXBaseOrMemberInitializer has
905  // more info. than is needed. At the least, CXXBaseOrMemberInitializer need
906  // be renamed to something neutral.
907  CXXBaseOrMemberInitializer **BaseOrMemberDestructions;
908  unsigned NumBaseOrMemberDestructions;
909
910  CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation L,
911                    DeclarationName N, QualType T,
912                    bool isInline, bool isImplicitlyDeclared)
913    : CXXMethodDecl(CXXDestructor, RD, L, N, T, false, isInline),
914      ImplicitlyDefined(false),
915      BaseOrMemberDestructions(0), NumBaseOrMemberDestructions(0) {
916    setImplicit(isImplicitlyDeclared);
917  }
918
919public:
920  static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
921                                   SourceLocation L, DeclarationName N,
922                                   QualType T, bool isInline,
923                                   bool isImplicitlyDeclared);
924
925  /// isImplicitlyDefined - Whether this destructor was implicitly
926  /// defined. If false, then this destructor was defined by the
927  /// user. This operation can only be invoked if the destructor has
928  /// already been defined.
929  bool isImplicitlyDefined() const {
930    assert(isThisDeclarationADefinition() &&
931           "Can only get the implicit-definition flag once the destructor has been defined");
932    return ImplicitlyDefined;
933  }
934
935  /// setImplicitlyDefined - Set whether this destructor was
936  /// implicitly defined or not.
937  void setImplicitlyDefined(bool ID) {
938    assert(isThisDeclarationADefinition() &&
939           "Can only set the implicit-definition flag once the destructor has been defined");
940    ImplicitlyDefined = ID;
941  }
942
943  /// destr_iterator - Iterates through the member/base destruction list.
944  typedef CXXBaseOrMemberInitializer **destr_iterator;
945
946  /// destr_const_iterator - Iterates through the member/base destruction list.
947  typedef CXXBaseOrMemberInitializer * const * destr_const_iterator;
948
949  /// destr_begin() - Retrieve an iterator to the first destructed member/base.
950  destr_iterator       destr_begin()       { return BaseOrMemberDestructions; }
951  /// destr_begin() - Retrieve an iterator to the first destructed member/base.
952  destr_const_iterator destr_begin() const { return BaseOrMemberDestructions; }
953
954  /// destr_end() - Retrieve an iterator past the last destructed member/base.
955  destr_iterator       destr_end()       {
956    return BaseOrMemberDestructions + NumBaseOrMemberDestructions;
957  }
958  /// destr_end() - Retrieve an iterator past the last destructed member/base.
959  destr_const_iterator destr_end() const {
960    return BaseOrMemberDestructions + NumBaseOrMemberDestructions;
961  }
962
963  /// getNumArgs - Determine the number of arguments used to
964  /// destruct the member or base.
965  unsigned getNumBaseOrMemberDestructions() const {
966    return NumBaseOrMemberDestructions;
967  }
968
969  void setBaseOrMemberDestructions(ASTContext &C);
970
971  // Implement isa/cast/dyncast/etc.
972  static bool classof(const Decl *D) {
973    return D->getKind() == CXXDestructor;
974  }
975  static bool classof(const CXXDestructorDecl *D) { return true; }
976};
977
978/// CXXConversionDecl - Represents a C++ conversion function within a
979/// class. For example:
980///
981/// @code
982/// class X {
983/// public:
984///   operator bool();
985/// };
986/// @endcode
987class CXXConversionDecl : public CXXMethodDecl {
988  /// Explicit - Whether this conversion function is marked
989  /// "explicit", meaning that it can only be applied when the user
990  /// explicitly wrote a cast. This is a C++0x feature.
991  bool Explicit : 1;
992
993  CXXConversionDecl(CXXRecordDecl *RD, SourceLocation L,
994                    DeclarationName N, QualType T,
995                    bool isInline, bool isExplicit)
996    : CXXMethodDecl(CXXConversion, RD, L, N, T, false, isInline),
997      Explicit(isExplicit) { }
998
999public:
1000  static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1001                                   SourceLocation L, DeclarationName N,
1002                                   QualType T, bool isInline,
1003                                   bool isExplicit);
1004
1005  /// isExplicit - Whether this is an explicit conversion operator
1006  /// (C++0x only). Explicit conversion operators are only considered
1007  /// when the user has explicitly written a cast.
1008  bool isExplicit() const { return Explicit; }
1009
1010  /// getConversionType - Returns the type that this conversion
1011  /// function is converting to.
1012  QualType getConversionType() const {
1013    return getType()->getAsFunctionType()->getResultType();
1014  }
1015
1016  // Implement isa/cast/dyncast/etc.
1017  static bool classof(const Decl *D) {
1018    return D->getKind() == CXXConversion;
1019  }
1020  static bool classof(const CXXConversionDecl *D) { return true; }
1021};
1022
1023/// LinkageSpecDecl - This represents a linkage specification.  For example:
1024///   extern "C" void foo();
1025///
1026class LinkageSpecDecl : public Decl, public DeclContext {
1027public:
1028  /// LanguageIDs - Used to represent the language in a linkage
1029  /// specification.  The values are part of the serialization abi for
1030  /// ASTs and cannot be changed without altering that abi.  To help
1031  /// ensure a stable abi for this, we choose the DW_LANG_ encodings
1032  /// from the dwarf standard.
1033  enum LanguageIDs { lang_c = /* DW_LANG_C */ 0x0002,
1034  lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004 };
1035private:
1036  /// Language - The language for this linkage specification.
1037  LanguageIDs Language;
1038
1039  /// HadBraces - Whether this linkage specification had curly braces or not.
1040  bool HadBraces : 1;
1041
1042  LinkageSpecDecl(DeclContext *DC, SourceLocation L, LanguageIDs lang,
1043                  bool Braces)
1044    : Decl(LinkageSpec, DC, L),
1045      DeclContext(LinkageSpec), Language(lang), HadBraces(Braces) { }
1046
1047public:
1048  static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
1049                                 SourceLocation L, LanguageIDs Lang,
1050                                 bool Braces);
1051
1052  LanguageIDs getLanguage() const { return Language; }
1053
1054  /// hasBraces - Determines whether this linkage specification had
1055  /// braces in its syntactic form.
1056  bool hasBraces() const { return HadBraces; }
1057
1058  static bool classof(const Decl *D) {
1059    return D->getKind() == LinkageSpec;
1060  }
1061  static bool classof(const LinkageSpecDecl *D) { return true; }
1062  static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
1063    return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
1064  }
1065  static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
1066    return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
1067  }
1068};
1069
1070/// UsingDirectiveDecl - Represents C++ using-directive. For example:
1071///
1072///    using namespace std;
1073///
1074// NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide
1075// artificial name, for all using-directives in order to store
1076// them in DeclContext effectively.
1077class UsingDirectiveDecl : public NamedDecl {
1078
1079  /// SourceLocation - Location of 'namespace' token.
1080  SourceLocation NamespaceLoc;
1081
1082  /// \brief The source range that covers the nested-name-specifier
1083  /// preceding the namespace name.
1084  SourceRange QualifierRange;
1085
1086  /// \brief The nested-name-specifier that precedes the namespace
1087  /// name, if any.
1088  NestedNameSpecifier *Qualifier;
1089
1090  /// IdentLoc - Location of nominated namespace-name identifier.
1091  // FIXME: We don't store location of scope specifier.
1092  SourceLocation IdentLoc;
1093
1094  /// NominatedNamespace - Namespace nominated by using-directive.
1095  NamespaceDecl *NominatedNamespace;
1096
1097  /// Enclosing context containing both using-directive and nomintated
1098  /// namespace.
1099  DeclContext *CommonAncestor;
1100
1101  /// getUsingDirectiveName - Returns special DeclarationName used by
1102  /// using-directives. This is only used by DeclContext for storing
1103  /// UsingDirectiveDecls in its lookup structure.
1104  static DeclarationName getName() {
1105    return DeclarationName::getUsingDirectiveName();
1106  }
1107
1108  UsingDirectiveDecl(DeclContext *DC, SourceLocation L,
1109                     SourceLocation NamespcLoc,
1110                     SourceRange QualifierRange,
1111                     NestedNameSpecifier *Qualifier,
1112                     SourceLocation IdentLoc,
1113                     NamespaceDecl *Nominated,
1114                     DeclContext *CommonAncestor)
1115    : NamedDecl(Decl::UsingDirective, DC, L, getName()),
1116      NamespaceLoc(NamespcLoc), QualifierRange(QualifierRange),
1117      Qualifier(Qualifier), IdentLoc(IdentLoc),
1118      NominatedNamespace(Nominated? Nominated->getOriginalNamespace() : 0),
1119      CommonAncestor(CommonAncestor) {
1120  }
1121
1122public:
1123  /// \brief Retrieve the source range of the nested-name-specifier
1124  /// that qualifiers the namespace name.
1125  SourceRange getQualifierRange() const { return QualifierRange; }
1126
1127  /// \brief Retrieve the nested-name-specifier that qualifies the
1128  /// name of the namespace.
1129  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1130
1131  /// getNominatedNamespace - Returns namespace nominated by using-directive.
1132  NamespaceDecl *getNominatedNamespace() { return NominatedNamespace; }
1133
1134  const NamespaceDecl *getNominatedNamespace() const {
1135    return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
1136  }
1137
1138  /// getCommonAncestor - returns common ancestor context of using-directive,
1139  /// and nominated by it namespace.
1140  DeclContext *getCommonAncestor() { return CommonAncestor; }
1141  const DeclContext *getCommonAncestor() const { return CommonAncestor; }
1142
1143  /// getNamespaceKeyLocation - Returns location of namespace keyword.
1144  SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
1145
1146  /// getIdentLocation - Returns location of identifier.
1147  SourceLocation getIdentLocation() const { return IdentLoc; }
1148
1149  static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
1150                                    SourceLocation L,
1151                                    SourceLocation NamespaceLoc,
1152                                    SourceRange QualifierRange,
1153                                    NestedNameSpecifier *Qualifier,
1154                                    SourceLocation IdentLoc,
1155                                    NamespaceDecl *Nominated,
1156                                    DeclContext *CommonAncestor);
1157
1158  static bool classof(const Decl *D) {
1159    return D->getKind() == Decl::UsingDirective;
1160  }
1161  static bool classof(const UsingDirectiveDecl *D) { return true; }
1162
1163  // Friend for getUsingDirectiveName.
1164  friend class DeclContext;
1165};
1166
1167/// NamespaceAliasDecl - Represents a C++ namespace alias. For example:
1168///
1169/// @code
1170/// namespace Foo = Bar;
1171/// @endcode
1172class NamespaceAliasDecl : public NamedDecl {
1173  SourceLocation AliasLoc;
1174
1175  /// \brief The source range that covers the nested-name-specifier
1176  /// preceding the namespace name.
1177  SourceRange QualifierRange;
1178
1179  /// \brief The nested-name-specifier that precedes the namespace
1180  /// name, if any.
1181  NestedNameSpecifier *Qualifier;
1182
1183  /// IdentLoc - Location of namespace identifier.
1184  SourceLocation IdentLoc;
1185
1186  /// Namespace - The Decl that this alias points to. Can either be a
1187  /// NamespaceDecl or a NamespaceAliasDecl.
1188  NamedDecl *Namespace;
1189
1190  NamespaceAliasDecl(DeclContext *DC, SourceLocation L,
1191                     SourceLocation AliasLoc, IdentifierInfo *Alias,
1192                     SourceRange QualifierRange,
1193                     NestedNameSpecifier *Qualifier,
1194                     SourceLocation IdentLoc, NamedDecl *Namespace)
1195    : NamedDecl(Decl::NamespaceAlias, DC, L, Alias), AliasLoc(AliasLoc),
1196      QualifierRange(QualifierRange), Qualifier(Qualifier),
1197      IdentLoc(IdentLoc), Namespace(Namespace) { }
1198
1199public:
1200  /// \brief Retrieve the source range of the nested-name-specifier
1201  /// that qualifiers the namespace name.
1202  SourceRange getQualifierRange() const { return QualifierRange; }
1203
1204  /// \brief Retrieve the nested-name-specifier that qualifies the
1205  /// name of the namespace.
1206  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1207
1208  NamespaceDecl *getNamespace() {
1209    if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
1210      return AD->getNamespace();
1211
1212    return cast<NamespaceDecl>(Namespace);
1213  }
1214
1215  const NamespaceDecl *getNamespace() const {
1216    return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
1217  }
1218
1219  /// \brief Retrieve the namespace that this alias refers to, which
1220  /// may either be a NamespaceDecl or a NamespaceAliasDecl.
1221  NamedDecl *getAliasedNamespace() const { return Namespace; }
1222
1223  static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
1224                                    SourceLocation L, SourceLocation AliasLoc,
1225                                    IdentifierInfo *Alias,
1226                                    SourceRange QualifierRange,
1227                                    NestedNameSpecifier *Qualifier,
1228                                    SourceLocation IdentLoc,
1229                                    NamedDecl *Namespace);
1230
1231  static bool classof(const Decl *D) {
1232    return D->getKind() == Decl::NamespaceAlias;
1233  }
1234  static bool classof(const NamespaceAliasDecl *D) { return true; }
1235};
1236
1237/// UsingDecl - Represents a C++ using-declaration. For example:
1238///    using someNameSpace::someIdentifier;
1239class UsingDecl : public NamedDecl {
1240
1241  /// \brief The source range that covers the nested-name-specifier
1242  /// preceding the declaration name.
1243  SourceRange NestedNameRange;
1244  /// \brief The source location of the target declaration name.
1245  SourceLocation TargetNameLocation;
1246  /// \brief The source location of the "using" location itself.
1247  SourceLocation UsingLocation;
1248  /// \brief Target declaration.
1249  NamedDecl* TargetDecl;
1250  /// \brief Target declaration.
1251  NestedNameSpecifier* TargetNestedNameDecl;
1252
1253  // Had 'typename' keyword.
1254  bool IsTypeName;
1255
1256  UsingDecl(DeclContext *DC, SourceLocation L, SourceRange NNR,
1257            SourceLocation TargetNL, SourceLocation UL, NamedDecl* Target,
1258            NestedNameSpecifier* TargetNNS, bool IsTypeNameArg)
1259    : NamedDecl(Decl::Using, DC, L, Target->getDeclName()),
1260      NestedNameRange(NNR), TargetNameLocation(TargetNL),
1261      UsingLocation(UL), TargetDecl(Target),
1262      TargetNestedNameDecl(TargetNNS), IsTypeName(IsTypeNameArg) {
1263    this->IdentifierNamespace = TargetDecl->getIdentifierNamespace();
1264  }
1265
1266public:
1267  /// \brief Returns the source range that covers the nested-name-specifier
1268  /// preceding the namespace name.
1269  SourceRange getNestedNameRange() { return NestedNameRange; }
1270
1271  /// \brief Returns the source location of the target declaration name.
1272  SourceLocation getTargetNameLocation() { return TargetNameLocation; }
1273
1274  /// \brief Returns the source location of the "using" location itself.
1275  SourceLocation getUsingLocation() { return UsingLocation; }
1276
1277  /// \brief getTargetDecl - Returns target specified by using-decl.
1278  NamedDecl *getTargetDecl() { return TargetDecl; }
1279  const NamedDecl *getTargetDecl() const { return TargetDecl; }
1280
1281  /// \brief Get target nested name declaration.
1282  NestedNameSpecifier* getTargetNestedNameDecl() {
1283    return TargetNestedNameDecl;
1284  }
1285
1286  /// isTypeName - Return true if using decl had 'typename'.
1287  bool isTypeName() const { return IsTypeName; }
1288
1289  static UsingDecl *Create(ASTContext &C, DeclContext *DC,
1290      SourceLocation L, SourceRange NNR, SourceLocation TargetNL,
1291      SourceLocation UL, NamedDecl* Target,
1292      NestedNameSpecifier* TargetNNS, bool IsTypeNameArg);
1293
1294  static bool classof(const Decl *D) {
1295    return D->getKind() == Decl::Using;
1296  }
1297  static bool classof(const UsingDecl *D) { return true; }
1298};
1299
1300/// StaticAssertDecl - Represents a C++0x static_assert declaration.
1301class StaticAssertDecl : public Decl {
1302  Expr *AssertExpr;
1303  StringLiteral *Message;
1304
1305  StaticAssertDecl(DeclContext *DC, SourceLocation L,
1306                   Expr *assertexpr, StringLiteral *message)
1307  : Decl(StaticAssert, DC, L), AssertExpr(assertexpr), Message(message) { }
1308
1309public:
1310  static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
1311                                  SourceLocation L, Expr *AssertExpr,
1312                                  StringLiteral *Message);
1313
1314  Expr *getAssertExpr() { return AssertExpr; }
1315  const Expr *getAssertExpr() const { return AssertExpr; }
1316
1317  StringLiteral *getMessage() { return Message; }
1318  const StringLiteral *getMessage() const { return Message; }
1319
1320  virtual ~StaticAssertDecl();
1321  virtual void Destroy(ASTContext& C);
1322
1323  static bool classof(const Decl *D) {
1324    return D->getKind() == Decl::StaticAssert;
1325  }
1326  static bool classof(StaticAssertDecl *D) { return true; }
1327};
1328
1329/// Insertion operator for diagnostics.  This allows sending AccessSpecifier's
1330/// into a diagnostic with <<.
1331const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
1332                                    AccessSpecifier AS);
1333
1334} // end namespace clang
1335
1336#endif
1337