DeclCXX.h revision 6ad9ac097918fbdeb443ea7b99d4db9e49b28534
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, other than those for
11//  templates (in DeclTemplate.h) and friends (in DeclFriend.h).
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_AST_DECLCXX_H
16#define LLVM_CLANG_AST_DECLCXX_H
17
18#include "clang/AST/Expr.h"
19#include "clang/AST/Decl.h"
20#include "clang/AST/UnresolvedSet.h"
21#include "llvm/ADT/SmallVector.h"
22#include "llvm/ADT/SmallPtrSet.h"
23
24namespace clang {
25
26class ClassTemplateDecl;
27class ClassTemplateSpecializationDecl;
28class CXXBasePath;
29class CXXBasePaths;
30class CXXConstructorDecl;
31class CXXConversionDecl;
32class CXXDestructorDecl;
33class CXXMethodDecl;
34class CXXRecordDecl;
35class CXXMemberLookupCriteria;
36class CXXFinalOverriderMap;
37class FriendDecl;
38
39/// \brief Represents any kind of function declaration, whether it is a
40/// concrete function or a function template.
41class AnyFunctionDecl {
42  NamedDecl *Function;
43
44  AnyFunctionDecl(NamedDecl *ND) : Function(ND) { }
45
46public:
47  AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { }
48  AnyFunctionDecl(FunctionTemplateDecl *FTD);
49
50  /// \brief Implicily converts any function or function template into a
51  /// named declaration.
52  operator NamedDecl *() const { return Function; }
53
54  /// \brief Retrieve the underlying function or function template.
55  NamedDecl *get() const { return Function; }
56
57  static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) {
58    return AnyFunctionDecl(ND);
59  }
60};
61
62} // end namespace clang
63
64namespace llvm {
65  /// Implement simplify_type for AnyFunctionDecl, so that we can dyn_cast from
66  /// AnyFunctionDecl to any function or function template declaration.
67  template<> struct simplify_type<const ::clang::AnyFunctionDecl> {
68    typedef ::clang::NamedDecl* SimpleType;
69    static SimpleType getSimplifiedValue(const ::clang::AnyFunctionDecl &Val) {
70      return Val;
71    }
72  };
73  template<> struct simplify_type< ::clang::AnyFunctionDecl>
74  : public simplify_type<const ::clang::AnyFunctionDecl> {};
75
76  // Provide PointerLikeTypeTraits for non-cvr pointers.
77  template<>
78  class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
79  public:
80    static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
81      return F.get();
82    }
83    static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
84      return ::clang::AnyFunctionDecl::getFromNamedDecl(
85                                      static_cast< ::clang::NamedDecl*>(P));
86    }
87
88    enum { NumLowBitsAvailable = 2 };
89  };
90
91} // end namespace llvm
92
93namespace clang {
94
95/// CXXBaseSpecifier - A base class of a C++ class.
96///
97/// Each CXXBaseSpecifier represents a single, direct base class (or
98/// struct) of a C++ class (or struct). It specifies the type of that
99/// base class, whether it is a virtual or non-virtual base, and what
100/// level of access (public, protected, private) is used for the
101/// derivation. For example:
102///
103/// @code
104///   class A { };
105///   class B { };
106///   class C : public virtual A, protected B { };
107/// @endcode
108///
109/// In this code, C will have two CXXBaseSpecifiers, one for "public
110/// virtual A" and the other for "protected B".
111class CXXBaseSpecifier {
112  /// Range - The source code range that covers the full base
113  /// specifier, including the "virtual" (if present) and access
114  /// specifier (if present).
115  // FIXME: Move over to a TypeLoc!
116  SourceRange Range;
117
118  /// Virtual - Whether this is a virtual base class or not.
119  bool Virtual : 1;
120
121  /// BaseOfClass - Whether this is the base of a class (true) or of a
122  /// struct (false). This determines the mapping from the access
123  /// specifier as written in the source code to the access specifier
124  /// used for semantic analysis.
125  bool BaseOfClass : 1;
126
127  /// Access - Access specifier as written in the source code (which
128  /// may be AS_none). The actual type of data stored here is an
129  /// AccessSpecifier, but we use "unsigned" here to work around a
130  /// VC++ bug.
131  unsigned Access : 2;
132
133  /// BaseType - The type of the base class. This will be a class or
134  /// struct (or a typedef of such).
135  QualType BaseType;
136
137public:
138  CXXBaseSpecifier() { }
139
140  CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, QualType T)
141    : Range(R), Virtual(V), BaseOfClass(BC), Access(A), BaseType(T) { }
142
143  /// getSourceRange - Retrieves the source range that contains the
144  /// entire base specifier.
145  SourceRange getSourceRange() const { return Range; }
146
147  /// isVirtual - Determines whether the base class is a virtual base
148  /// class (or not).
149  bool isVirtual() const { return Virtual; }
150
151  /// \brief Determine whether this base class if a base of a class declared
152  /// with the 'class' keyword (vs. one declared with the 'struct' keyword).
153  bool isBaseOfClass() const { return BaseOfClass; }
154
155  /// getAccessSpecifier - Returns the access specifier for this base
156  /// specifier. This is the actual base specifier as used for
157  /// semantic analysis, so the result can never be AS_none. To
158  /// retrieve the access specifier as written in the source code, use
159  /// getAccessSpecifierAsWritten().
160  AccessSpecifier getAccessSpecifier() const {
161    if ((AccessSpecifier)Access == AS_none)
162      return BaseOfClass? AS_private : AS_public;
163    else
164      return (AccessSpecifier)Access;
165  }
166
167  /// getAccessSpecifierAsWritten - Retrieves the access specifier as
168  /// written in the source code (which may mean that no access
169  /// specifier was explicitly written). Use getAccessSpecifier() to
170  /// retrieve the access specifier for use in semantic analysis.
171  AccessSpecifier getAccessSpecifierAsWritten() const {
172    return (AccessSpecifier)Access;
173  }
174
175  /// getType - Retrieves the type of the base class. This type will
176  /// always be an unqualified class type.
177  QualType getType() const { return BaseType; }
178};
179
180/// CXXRecordDecl - Represents a C++ struct/union/class.
181/// FIXME: This class will disappear once we've properly taught RecordDecl
182/// to deal with C++-specific things.
183class CXXRecordDecl : public RecordDecl {
184
185  friend void TagDecl::startDefinition();
186
187  struct DefinitionData {
188    DefinitionData(CXXRecordDecl *D);
189
190    /// UserDeclaredConstructor - True when this class has a
191    /// user-declared constructor.
192    bool UserDeclaredConstructor : 1;
193
194    /// UserDeclaredCopyConstructor - True when this class has a
195    /// user-declared copy constructor.
196    bool UserDeclaredCopyConstructor : 1;
197
198    /// UserDeclaredCopyAssignment - True when this class has a
199    /// user-declared copy assignment operator.
200    bool UserDeclaredCopyAssignment : 1;
201
202    /// UserDeclaredDestructor - True when this class has a
203    /// user-declared destructor.
204    bool UserDeclaredDestructor : 1;
205
206    /// Aggregate - True when this class is an aggregate.
207    bool Aggregate : 1;
208
209    /// PlainOldData - True when this class is a POD-type.
210    bool PlainOldData : 1;
211
212    /// Empty - true when this class is empty for traits purposes,
213    /// i.e. has no data members other than 0-width bit-fields, has no
214    /// virtual function/base, and doesn't inherit from a non-empty
215    /// class. Doesn't take union-ness into account.
216    bool Empty : 1;
217
218    /// Polymorphic - True when this class is polymorphic, i.e. has at
219    /// least one virtual member or derives from a polymorphic class.
220    bool Polymorphic : 1;
221
222    /// Abstract - True when this class is abstract, i.e. has at least
223    /// one pure virtual function, (that can come from a base class).
224    bool Abstract : 1;
225
226    /// HasTrivialConstructor - True when this class has a trivial constructor.
227    ///
228    /// C++ [class.ctor]p5.  A constructor is trivial if it is an
229    /// implicitly-declared default constructor and if:
230    /// * its class has no virtual functions and no virtual base classes, and
231    /// * all the direct base classes of its class have trivial constructors, and
232    /// * for all the nonstatic data members of its class that are of class type
233    ///   (or array thereof), each such class has a trivial constructor.
234    bool HasTrivialConstructor : 1;
235
236    /// HasTrivialCopyConstructor - True when this class has a trivial copy
237    /// constructor.
238    ///
239    /// C++ [class.copy]p6.  A copy constructor for class X is trivial
240    /// if it is implicitly declared and if
241    /// * class X has no virtual functions and no virtual base classes, and
242    /// * each direct base class of X has a trivial copy constructor, and
243    /// * for all the nonstatic data members of X that are of class type (or
244    ///   array thereof), each such class type has a trivial copy constructor;
245    /// otherwise the copy constructor is non-trivial.
246    bool HasTrivialCopyConstructor : 1;
247
248    /// HasTrivialCopyAssignment - True when this class has a trivial copy
249    /// assignment operator.
250    ///
251    /// C++ [class.copy]p11.  A copy assignment operator for class X is
252    /// trivial if it is implicitly declared and if
253    /// * class X has no virtual functions and no virtual base classes, and
254    /// * each direct base class of X has a trivial copy assignment operator, and
255    /// * for all the nonstatic data members of X that are of class type (or
256    ///   array thereof), each such class type has a trivial copy assignment
257    ///   operator;
258    /// otherwise the copy assignment operator is non-trivial.
259    bool HasTrivialCopyAssignment : 1;
260
261    /// HasTrivialDestructor - True when this class has a trivial destructor.
262    ///
263    /// C++ [class.dtor]p3.  A destructor is trivial if it is an
264    /// implicitly-declared destructor and if:
265    /// * all of the direct base classes of its class have trivial destructors
266    ///   and
267    /// * for all of the non-static data members of its class that are of class
268    ///   type (or array thereof), each such class has a trivial destructor.
269    bool HasTrivialDestructor : 1;
270
271    /// ComputedVisibleConversions - True when visible conversion functions are
272    /// already computed and are available.
273    bool ComputedVisibleConversions : 1;
274
275    /// Bases - Base classes of this class.
276    /// FIXME: This is wasted space for a union.
277    CXXBaseSpecifier *Bases;
278
279    /// NumBases - The number of base class specifiers in Bases.
280    unsigned NumBases;
281
282    /// VBases - direct and indirect virtual base classes of this class.
283    CXXBaseSpecifier *VBases;
284
285    /// NumVBases - The number of virtual base class specifiers in VBases.
286    unsigned NumVBases;
287
288    /// Conversions - Overload set containing the conversion functions
289    /// of this C++ class (but not its inherited conversion
290    /// functions). Each of the entries in this overload set is a
291    /// CXXConversionDecl.
292    UnresolvedSet<4> Conversions;
293
294    /// VisibleConversions - Overload set containing the conversion
295    /// functions of this C++ class and all those inherited conversion
296    /// functions that are visible in this class. Each of the entries
297    /// in this overload set is a CXXConversionDecl or a
298    /// FunctionTemplateDecl.
299    UnresolvedSet<4> VisibleConversions;
300
301    /// Definition - The declaration which defines this record.
302    CXXRecordDecl *Definition;
303
304    /// FirstFriend - The first friend declaration in this class, or
305    /// null if there aren't any.  This is actually currently stored
306    /// in reverse order.
307    FriendDecl *FirstFriend;
308
309  } *DefinitionData;
310
311  struct DefinitionData &data() {
312    assert(DefinitionData && "queried property of class with no definition");
313    return *DefinitionData;
314  }
315
316  const struct DefinitionData &data() const {
317    assert(DefinitionData && "queried property of class with no definition");
318    return *DefinitionData;
319  }
320
321  /// \brief The template or declaration that this declaration
322  /// describes or was instantiated from, respectively.
323  ///
324  /// For non-templates, this value will be NULL. For record
325  /// declarations that describe a class template, this will be a
326  /// pointer to a ClassTemplateDecl. For member
327  /// classes of class template specializations, this will be the
328  /// MemberSpecializationInfo referring to the member class that was
329  /// instantiated or specialized.
330  llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*>
331    TemplateOrInstantiation;
332
333#ifndef NDEBUG
334  void CheckConversionFunction(NamedDecl *D);
335#endif
336
337protected:
338  CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
339                SourceLocation L, IdentifierInfo *Id,
340                CXXRecordDecl *PrevDecl,
341                SourceLocation TKL = SourceLocation());
342
343  ~CXXRecordDecl();
344
345public:
346  /// base_class_iterator - Iterator that traverses the base classes
347  /// of a class.
348  typedef CXXBaseSpecifier*       base_class_iterator;
349
350  /// base_class_const_iterator - Iterator that traverses the base
351  /// classes of a class.
352  typedef const CXXBaseSpecifier* base_class_const_iterator;
353
354  /// reverse_base_class_iterator = Iterator that traverses the base classes
355  /// of a class in reverse order.
356  typedef std::reverse_iterator<base_class_iterator>
357    reverse_base_class_iterator;
358
359  /// reverse_base_class_iterator = Iterator that traverses the base classes
360  /// of a class in reverse order.
361  typedef std::reverse_iterator<base_class_const_iterator>
362    reverse_base_class_const_iterator;
363
364  virtual CXXRecordDecl *getCanonicalDecl() {
365    return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
366  }
367  virtual const CXXRecordDecl *getCanonicalDecl() const {
368    return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
369  }
370
371  CXXRecordDecl *getDefinition() const {
372    if (!DefinitionData) return 0;
373    return data().Definition;
374  }
375
376  bool hasDefinition() const { return DefinitionData != 0; }
377
378  static CXXRecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC,
379                               SourceLocation L, IdentifierInfo *Id,
380                               SourceLocation TKL = SourceLocation(),
381                               CXXRecordDecl* PrevDecl=0,
382                               bool DelayTypeCreation = false);
383
384  virtual void Destroy(ASTContext& C);
385
386  bool isDynamicClass() const {
387    return data().Polymorphic || data().NumVBases != 0;
388  }
389
390  /// setBases - Sets the base classes of this struct or class.
391  void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
392
393  /// getNumBases - Retrieves the number of base classes of this
394  /// class.
395  unsigned getNumBases() const { return data().NumBases; }
396
397  base_class_iterator bases_begin() { return data().Bases; }
398  base_class_const_iterator bases_begin() const { return data().Bases; }
399  base_class_iterator bases_end() { return bases_begin() + data().NumBases; }
400  base_class_const_iterator bases_end() const {
401    return bases_begin() + data().NumBases;
402  }
403  reverse_base_class_iterator       bases_rbegin() {
404    return reverse_base_class_iterator(bases_end());
405  }
406  reverse_base_class_const_iterator bases_rbegin() const {
407    return reverse_base_class_const_iterator(bases_end());
408  }
409  reverse_base_class_iterator bases_rend() {
410    return reverse_base_class_iterator(bases_begin());
411  }
412  reverse_base_class_const_iterator bases_rend() const {
413    return reverse_base_class_const_iterator(bases_begin());
414  }
415
416  /// getNumVBases - Retrieves the number of virtual base classes of this
417  /// class.
418  unsigned getNumVBases() const { return data().NumVBases; }
419
420  base_class_iterator vbases_begin() { return data().VBases; }
421  base_class_const_iterator vbases_begin() const { return data().VBases; }
422  base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; }
423  base_class_const_iterator vbases_end() const {
424    return vbases_begin() + data().NumVBases;
425  }
426  reverse_base_class_iterator vbases_rbegin() {
427    return reverse_base_class_iterator(vbases_end());
428  }
429  reverse_base_class_const_iterator vbases_rbegin() const {
430    return reverse_base_class_const_iterator(vbases_end());
431  }
432  reverse_base_class_iterator vbases_rend() {
433    return reverse_base_class_iterator(vbases_begin());
434  }
435  reverse_base_class_const_iterator vbases_rend() const {
436    return reverse_base_class_const_iterator(vbases_begin());
437 }
438
439  /// \brief Determine whether this class has any dependent base classes.
440  bool hasAnyDependentBases() const;
441
442  /// Iterator access to method members.  The method iterator visits
443  /// all method members of the class, including non-instance methods,
444  /// special methods, etc.
445  typedef specific_decl_iterator<CXXMethodDecl> method_iterator;
446
447  /// method_begin - Method begin iterator.  Iterates in the order the methods
448  /// were declared.
449  method_iterator method_begin() const {
450    return method_iterator(decls_begin());
451  }
452  /// method_end - Method end iterator.
453  method_iterator method_end() const {
454    return method_iterator(decls_end());
455  }
456
457  /// Iterator access to constructor members.
458  typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator;
459
460  ctor_iterator ctor_begin() const {
461    return ctor_iterator(decls_begin());
462  }
463  ctor_iterator ctor_end() const {
464    return ctor_iterator(decls_end());
465  }
466
467  /// An iterator over friend declarations.  All of these are defined
468  /// in DeclFriend.h.
469  class friend_iterator;
470  friend_iterator friend_begin() const;
471  friend_iterator friend_end() const;
472  void pushFriendDecl(FriendDecl *FD);
473
474  /// Determines whether this record has any friends.
475  bool hasFriends() const {
476    return data().FirstFriend != 0;
477  }
478
479  /// hasConstCopyConstructor - Determines whether this class has a
480  /// copy constructor that accepts a const-qualified argument.
481  bool hasConstCopyConstructor(ASTContext &Context) const;
482
483  /// getCopyConstructor - Returns the copy constructor for this class
484  CXXConstructorDecl *getCopyConstructor(ASTContext &Context,
485                                         unsigned TypeQuals) const;
486
487  /// hasConstCopyAssignment - Determines whether this class has a
488  /// copy assignment operator that accepts a const-qualified argument.
489  /// It returns its decl in MD if found.
490  bool hasConstCopyAssignment(ASTContext &Context,
491                              const CXXMethodDecl *&MD) const;
492
493  /// addedConstructor - Notify the class that another constructor has
494  /// been added. This routine helps maintain information about the
495  /// class based on which constructors have been added.
496  void addedConstructor(ASTContext &Context, CXXConstructorDecl *ConDecl);
497
498  /// hasUserDeclaredConstructor - Whether this class has any
499  /// user-declared constructors. When true, a default constructor
500  /// will not be implicitly declared.
501  bool hasUserDeclaredConstructor() const {
502    return data().UserDeclaredConstructor;
503  }
504
505  /// hasUserDeclaredCopyConstructor - Whether this class has a
506  /// user-declared copy constructor. When false, a copy constructor
507  /// will be implicitly declared.
508  bool hasUserDeclaredCopyConstructor() const {
509    return data().UserDeclaredCopyConstructor;
510  }
511
512  /// addedAssignmentOperator - Notify the class that another assignment
513  /// operator has been added. This routine helps maintain information about the
514   /// class based on which operators have been added.
515  void addedAssignmentOperator(ASTContext &Context, CXXMethodDecl *OpDecl);
516
517  /// hasUserDeclaredCopyAssignment - Whether this class has a
518  /// user-declared copy assignment operator. When false, a copy
519  /// assigment operator will be implicitly declared.
520  bool hasUserDeclaredCopyAssignment() const {
521    return data().UserDeclaredCopyAssignment;
522  }
523
524  /// hasUserDeclaredDestructor - Whether this class has a
525  /// user-declared destructor. When false, a destructor will be
526  /// implicitly declared.
527  bool hasUserDeclaredDestructor() const {
528    return data().UserDeclaredDestructor;
529  }
530
531  /// setUserDeclaredDestructor - Set whether this class has a
532  /// user-declared destructor. If not set by the time the class is
533  /// fully defined, a destructor will be implicitly declared.
534  void setUserDeclaredDestructor(bool UCD) {
535    data().UserDeclaredDestructor = UCD;
536  }
537
538  /// getConversions - Retrieve the overload set containing all of the
539  /// conversion functions in this class.
540  UnresolvedSetImpl *getConversionFunctions() {
541    return &data().Conversions;
542  }
543  const UnresolvedSetImpl *getConversionFunctions() const {
544    return &data().Conversions;
545  }
546
547  typedef UnresolvedSetImpl::iterator conversion_iterator;
548  conversion_iterator conversion_begin() const {
549    return getConversionFunctions()->begin();
550  }
551  conversion_iterator conversion_end() const {
552    return getConversionFunctions()->end();
553  }
554
555  /// Replaces a conversion function with a new declaration.
556  ///
557  /// Returns true if the old conversion was found.
558  bool replaceConversion(const NamedDecl* Old, NamedDecl *New) {
559    return getConversionFunctions()->replace(Old, New);
560  }
561
562  /// Removes a conversion function from this class.  The conversion
563  /// function must currently be a member of this class.  Furthermore,
564  /// this class must currently be in the process of being defined.
565  void removeConversion(const NamedDecl *Old);
566
567  /// getVisibleConversionFunctions - get all conversion functions visible
568  /// in current class; including conversion function templates.
569  const UnresolvedSetImpl *getVisibleConversionFunctions();
570
571  /// addConversionFunction - Registers a conversion function which
572  /// this class declares directly.
573  void addConversionFunction(NamedDecl *Decl) {
574#ifndef NDEBUG
575    CheckConversionFunction(Decl);
576#endif
577
578    // We intentionally don't use the decl's access here because it
579    // hasn't been set yet.  That's really just a misdesign in Sema.
580    data().Conversions.addDecl(Decl);
581  }
582
583  /// isAggregate - Whether this class is an aggregate (C++
584  /// [dcl.init.aggr]), which is a class with no user-declared
585  /// constructors, no private or protected non-static data members,
586  /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1).
587  bool isAggregate() const { return data().Aggregate; }
588
589  /// setAggregate - Set whether this class is an aggregate (C++
590  /// [dcl.init.aggr]).
591  void setAggregate(bool Agg) { data().Aggregate = Agg; }
592
593  /// setMethodAsVirtual - Make input method virtual and set the necesssary
594  /// special function bits and other bits accordingly.
595  void setMethodAsVirtual(FunctionDecl *Method);
596
597  /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class
598  /// that is an aggregate that has no non-static non-POD data members, no
599  /// reference data members, no user-defined copy assignment operator and no
600  /// user-defined destructor.
601  bool isPOD() const { return data().PlainOldData; }
602
603  /// setPOD - Set whether this class is a POD-type (C++ [class]p4).
604  void setPOD(bool POD) { data().PlainOldData = POD; }
605
606  /// isEmpty - Whether this class is empty (C++0x [meta.unary.prop]), which
607  /// means it has a virtual function, virtual base, data member (other than
608  /// 0-width bit-field) or inherits from a non-empty class. Does NOT include
609  /// a check for union-ness.
610  bool isEmpty() const { return data().Empty; }
611
612  /// Set whether this class is empty (C++0x [meta.unary.prop])
613  void setEmpty(bool Emp) { data().Empty = Emp; }
614
615  /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]),
616  /// which means that the class contains or inherits a virtual function.
617  bool isPolymorphic() const { return data().Polymorphic; }
618
619  /// setPolymorphic - Set whether this class is polymorphic (C++
620  /// [class.virtual]).
621  void setPolymorphic(bool Poly) { data().Polymorphic = Poly; }
622
623  /// isAbstract - Whether this class is abstract (C++ [class.abstract]),
624  /// which means that the class contains or inherits a pure virtual function.
625  bool isAbstract() const { return data().Abstract; }
626
627  /// setAbstract - Set whether this class is abstract (C++ [class.abstract])
628  void setAbstract(bool Abs) { data().Abstract = Abs; }
629
630  // hasTrivialConstructor - Whether this class has a trivial constructor
631  // (C++ [class.ctor]p5)
632  bool hasTrivialConstructor() const { return data().HasTrivialConstructor; }
633
634  // setHasTrivialConstructor - Set whether this class has a trivial constructor
635  // (C++ [class.ctor]p5)
636  void setHasTrivialConstructor(bool TC) { data().HasTrivialConstructor = TC; }
637
638  // hasTrivialCopyConstructor - Whether this class has a trivial copy
639  // constructor (C++ [class.copy]p6)
640  bool hasTrivialCopyConstructor() const {
641    return data().HasTrivialCopyConstructor;
642  }
643
644  // setHasTrivialCopyConstructor - Set whether this class has a trivial
645  // copy constructor (C++ [class.copy]p6)
646  void setHasTrivialCopyConstructor(bool TC) {
647    data().HasTrivialCopyConstructor = TC;
648  }
649
650  // hasTrivialCopyAssignment - Whether this class has a trivial copy
651  // assignment operator (C++ [class.copy]p11)
652  bool hasTrivialCopyAssignment() const {
653    return data().HasTrivialCopyAssignment;
654  }
655
656  // setHasTrivialCopyAssignment - Set whether this class has a
657  // trivial copy assignment operator (C++ [class.copy]p11)
658  void setHasTrivialCopyAssignment(bool TC) {
659    data().HasTrivialCopyAssignment = TC;
660  }
661
662  // hasTrivialDestructor - Whether this class has a trivial destructor
663  // (C++ [class.dtor]p3)
664  bool hasTrivialDestructor() const { return data().HasTrivialDestructor; }
665
666  // setHasTrivialDestructor - Set whether this class has a trivial destructor
667  // (C++ [class.dtor]p3)
668  void setHasTrivialDestructor(bool TC) { data().HasTrivialDestructor = TC; }
669
670  /// \brief If this record is an instantiation of a member class,
671  /// retrieves the member class from which it was instantiated.
672  ///
673  /// This routine will return non-NULL for (non-templated) member
674  /// classes of class templates. For example, given:
675  ///
676  /// \code
677  /// template<typename T>
678  /// struct X {
679  ///   struct A { };
680  /// };
681  /// \endcode
682  ///
683  /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
684  /// whose parent is the class template specialization X<int>. For
685  /// this declaration, getInstantiatedFromMemberClass() will return
686  /// the CXXRecordDecl X<T>::A. When a complete definition of
687  /// X<int>::A is required, it will be instantiated from the
688  /// declaration returned by getInstantiatedFromMemberClass().
689  CXXRecordDecl *getInstantiatedFromMemberClass() const;
690
691  /// \brief If this class is an instantiation of a member class of a
692  /// class template specialization, retrieves the member specialization
693  /// information.
694  MemberSpecializationInfo *getMemberSpecializationInfo() const;
695
696  /// \brief Specify that this record is an instantiation of the
697  /// member class RD.
698  void setInstantiationOfMemberClass(CXXRecordDecl *RD,
699                                     TemplateSpecializationKind TSK);
700
701  /// \brief Retrieves the class template that is described by this
702  /// class declaration.
703  ///
704  /// Every class template is represented as a ClassTemplateDecl and a
705  /// CXXRecordDecl. The former contains template properties (such as
706  /// the template parameter lists) while the latter contains the
707  /// actual description of the template's
708  /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
709  /// CXXRecordDecl that from a ClassTemplateDecl, while
710  /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
711  /// a CXXRecordDecl.
712  ClassTemplateDecl *getDescribedClassTemplate() const {
713    return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>();
714  }
715
716  void setDescribedClassTemplate(ClassTemplateDecl *Template) {
717    TemplateOrInstantiation = Template;
718  }
719
720  /// \brief Determine whether this particular class is a specialization or
721  /// instantiation of a class template or member class of a class template,
722  /// and how it was instantiated or specialized.
723  TemplateSpecializationKind getTemplateSpecializationKind() const;
724
725  /// \brief Set the kind of specialization or template instantiation this is.
726  void setTemplateSpecializationKind(TemplateSpecializationKind TSK);
727
728  /// getDefaultConstructor - Returns the default constructor for this class
729  CXXConstructorDecl *getDefaultConstructor(ASTContext &Context);
730
731  /// getDestructor - Returns the destructor decl for this class.
732  CXXDestructorDecl *getDestructor(ASTContext &Context) const;
733
734  /// isLocalClass - If the class is a local class [class.local], returns
735  /// the enclosing function declaration.
736  const FunctionDecl *isLocalClass() const {
737    if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
738      return RD->isLocalClass();
739
740    return dyn_cast<FunctionDecl>(getDeclContext());
741  }
742
743  /// \brief Determine whether this class is derived from the class \p Base.
744  ///
745  /// This routine only determines whether this class is derived from \p Base,
746  /// but does not account for factors that may make a Derived -> Base class
747  /// ill-formed, such as private/protected inheritance or multiple, ambiguous
748  /// base class subobjects.
749  ///
750  /// \param Base the base class we are searching for.
751  ///
752  /// \returns true if this class is derived from Base, false otherwise.
753  bool isDerivedFrom(CXXRecordDecl *Base) const;
754
755  /// \brief Determine whether this class is derived from the type \p Base.
756  ///
757  /// This routine only determines whether this class is derived from \p Base,
758  /// but does not account for factors that may make a Derived -> Base class
759  /// ill-formed, such as private/protected inheritance or multiple, ambiguous
760  /// base class subobjects.
761  ///
762  /// \param Base the base class we are searching for.
763  ///
764  /// \param Paths will contain the paths taken from the current class to the
765  /// given \p Base class.
766  ///
767  /// \returns true if this class is derived from Base, false otherwise.
768  ///
769  /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than
770  /// tangling input and output in \p Paths
771  bool isDerivedFrom(CXXRecordDecl *Base, CXXBasePaths &Paths) const;
772
773  /// \brief Determine whether this class is virtually derived from
774  /// the class \p Base.
775  ///
776  /// This routine only determines whether this class is virtually
777  /// derived from \p Base, but does not account for factors that may
778  /// make a Derived -> Base class ill-formed, such as
779  /// private/protected inheritance or multiple, ambiguous base class
780  /// subobjects.
781  ///
782  /// \param Base the base class we are searching for.
783  ///
784  /// \returns true if this class is virtually derived from Base,
785  /// false otherwise.
786  bool isVirtuallyDerivedFrom(CXXRecordDecl *Base) const;
787
788  /// \brief Determine whether this class is provably not derived from
789  /// the type \p Base.
790  bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
791
792  /// \brief Function type used by forallBases() as a callback.
793  ///
794  /// \param Base the definition of the base class
795  ///
796  /// \returns true if this base matched the search criteria
797  typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition,
798                                   void *UserData);
799
800  /// \brief Determines if the given callback holds for all the direct
801  /// or indirect base classes of this type.
802  ///
803  /// The class itself does not count as a base class.  This routine
804  /// returns false if the class has non-computable base classes.
805  ///
806  /// \param AllowShortCircuit if false, forces the callback to be called
807  /// for every base class, even if a dependent or non-matching base was
808  /// found.
809  bool forallBases(ForallBasesCallback *BaseMatches, void *UserData,
810                   bool AllowShortCircuit = true) const;
811
812  /// \brief Function type used by lookupInBases() to determine whether a
813  /// specific base class subobject matches the lookup criteria.
814  ///
815  /// \param Specifier the base-class specifier that describes the inheritance
816  /// from the base class we are trying to match.
817  ///
818  /// \param Path the current path, from the most-derived class down to the
819  /// base named by the \p Specifier.
820  ///
821  /// \param UserData a single pointer to user-specified data, provided to
822  /// lookupInBases().
823  ///
824  /// \returns true if this base matched the search criteria, false otherwise.
825  typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier,
826                                   CXXBasePath &Path,
827                                   void *UserData);
828
829  /// \brief Look for entities within the base classes of this C++ class,
830  /// transitively searching all base class subobjects.
831  ///
832  /// This routine uses the callback function \p BaseMatches to find base
833  /// classes meeting some search criteria, walking all base class subobjects
834  /// and populating the given \p Paths structure with the paths through the
835  /// inheritance hierarchy that resulted in a match. On a successful search,
836  /// the \p Paths structure can be queried to retrieve the matching paths and
837  /// to determine if there were any ambiguities.
838  ///
839  /// \param BaseMatches callback function used to determine whether a given
840  /// base matches the user-defined search criteria.
841  ///
842  /// \param UserData user data pointer that will be provided to \p BaseMatches.
843  ///
844  /// \param Paths used to record the paths from this class to its base class
845  /// subobjects that match the search criteria.
846  ///
847  /// \returns true if there exists any path from this class to a base class
848  /// subobject that matches the search criteria.
849  bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData,
850                     CXXBasePaths &Paths) const;
851
852  /// \brief Base-class lookup callback that determines whether the given
853  /// base class specifier refers to a specific class declaration.
854  ///
855  /// This callback can be used with \c lookupInBases() to determine whether
856  /// a given derived class has is a base class subobject of a particular type.
857  /// The user data pointer should refer to the canonical CXXRecordDecl of the
858  /// base class that we are searching for.
859  static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
860                            CXXBasePath &Path, void *BaseRecord);
861
862  /// \brief Base-class lookup callback that determines whether the
863  /// given base class specifier refers to a specific class
864  /// declaration and describes virtual derivation.
865  ///
866  /// This callback can be used with \c lookupInBases() to determine
867  /// whether a given derived class has is a virtual base class
868  /// subobject of a particular type.  The user data pointer should
869  /// refer to the canonical CXXRecordDecl of the base class that we
870  /// are searching for.
871  static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
872                                   CXXBasePath &Path, void *BaseRecord);
873
874  /// \brief Base-class lookup callback that determines whether there exists
875  /// a tag with the given name.
876  ///
877  /// This callback can be used with \c lookupInBases() to find tag members
878  /// of the given name within a C++ class hierarchy. The user data pointer
879  /// is an opaque \c DeclarationName pointer.
880  static bool FindTagMember(const CXXBaseSpecifier *Specifier,
881                            CXXBasePath &Path, void *Name);
882
883  /// \brief Base-class lookup callback that determines whether there exists
884  /// a member with the given name.
885  ///
886  /// This callback can be used with \c lookupInBases() to find members
887  /// of the given name within a C++ class hierarchy. The user data pointer
888  /// is an opaque \c DeclarationName pointer.
889  static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
890                                 CXXBasePath &Path, void *Name);
891
892  /// \brief Base-class lookup callback that determines whether there exists
893  /// a member with the given name that can be used in a nested-name-specifier.
894  ///
895  /// This callback can be used with \c lookupInBases() to find membes of
896  /// the given name within a C++ class hierarchy that can occur within
897  /// nested-name-specifiers.
898  static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier,
899                                            CXXBasePath &Path,
900                                            void *UserData);
901
902  /// \brief Retrieve the final overriders for each virtual member
903  /// function in the class hierarchy where this class is the
904  /// most-derived class in the class hierarchy.
905  void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const;
906
907  /// viewInheritance - Renders and displays an inheritance diagram
908  /// for this C++ class and all of its base classes (transitively) using
909  /// GraphViz.
910  void viewInheritance(ASTContext& Context) const;
911
912  /// MergeAccess - Calculates the access of a decl that is reached
913  /// along a path.
914  static AccessSpecifier MergeAccess(AccessSpecifier PathAccess,
915                                     AccessSpecifier DeclAccess) {
916    assert(DeclAccess != AS_none);
917    if (DeclAccess == AS_private) return AS_none;
918    return (PathAccess > DeclAccess ? PathAccess : DeclAccess);
919  }
920
921  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
922  static bool classofKind(Kind K) {
923    return K == CXXRecord ||
924           K == ClassTemplateSpecialization ||
925           K == ClassTemplatePartialSpecialization;
926  }
927  static bool classof(const CXXRecordDecl *D) { return true; }
928  static bool classof(const ClassTemplateSpecializationDecl *D) {
929    return true;
930  }
931};
932
933/// CXXMethodDecl - Represents a static or instance method of a
934/// struct/union/class.
935class CXXMethodDecl : public FunctionDecl {
936protected:
937  CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation L,
938                DeclarationName N, QualType T, TypeSourceInfo *TInfo,
939                bool isStatic, StorageClass SCAsWritten, bool isInline)
940    : FunctionDecl(DK, RD, L, N, T, TInfo, (isStatic ? Static : None),
941                   SCAsWritten, isInline) {}
942
943public:
944  static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
945                              SourceLocation L, DeclarationName N,
946                              QualType T, TypeSourceInfo *TInfo,
947                              bool isStatic = false,
948                              StorageClass SCAsWritten = FunctionDecl::None,
949                              bool isInline = false);
950
951  bool isStatic() const { return getStorageClass() == Static; }
952  bool isInstance() const { return !isStatic(); }
953
954  bool isVirtual() const {
955    CXXMethodDecl *CD =
956      cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl());
957
958    if (CD->isVirtualAsWritten())
959      return true;
960
961    return (CD->begin_overridden_methods() != CD->end_overridden_methods());
962  }
963
964  /// \brief Determine whether this is a usual deallocation function
965  /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded
966  /// delete or delete[] operator with a particular signature.
967  bool isUsualDeallocationFunction() const;
968
969  /// \brief Determine whether this is a copy-assignment operator, regardless
970  /// of whether it was declared implicitly or explicitly.
971  bool isCopyAssignmentOperator() const;
972
973  const CXXMethodDecl *getCanonicalDecl() const {
974    return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
975  }
976  CXXMethodDecl *getCanonicalDecl() {
977    return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
978  }
979
980  ///
981  void addOverriddenMethod(const CXXMethodDecl *MD);
982
983  typedef const CXXMethodDecl ** method_iterator;
984
985  method_iterator begin_overridden_methods() const;
986  method_iterator end_overridden_methods() const;
987
988  /// getParent - Returns the parent of this method declaration, which
989  /// is the class in which this method is defined.
990  const CXXRecordDecl *getParent() const {
991    return cast<CXXRecordDecl>(FunctionDecl::getParent());
992  }
993
994  /// getParent - Returns the parent of this method declaration, which
995  /// is the class in which this method is defined.
996  CXXRecordDecl *getParent() {
997    return const_cast<CXXRecordDecl *>(
998             cast<CXXRecordDecl>(FunctionDecl::getParent()));
999  }
1000
1001  /// getThisType - Returns the type of 'this' pointer.
1002  /// Should only be called for instance methods.
1003  QualType getThisType(ASTContext &C) const;
1004
1005  unsigned getTypeQualifiers() const {
1006    return getType()->getAs<FunctionProtoType>()->getTypeQuals();
1007  }
1008
1009  bool hasInlineBody() const;
1010
1011  // Implement isa/cast/dyncast/etc.
1012  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1013  static bool classof(const CXXMethodDecl *D) { return true; }
1014  static bool classofKind(Kind K) {
1015    return K >= CXXMethod && K <= CXXConversion;
1016  }
1017};
1018
1019/// CXXBaseOrMemberInitializer - Represents a C++ base or member
1020/// initializer, which is part of a constructor initializer that
1021/// initializes one non-static member variable or one base class. For
1022/// example, in the following, both 'A(a)' and 'f(3.14159)' are member
1023/// initializers:
1024///
1025/// @code
1026/// class A { };
1027/// class B : public A {
1028///   float f;
1029/// public:
1030///   B(A& a) : A(a), f(3.14159) { }
1031/// };
1032/// @endcode
1033class CXXBaseOrMemberInitializer {
1034  /// \brief Either the base class name (stored as a TypeSourceInfo*) or the
1035  /// field being initialized.
1036  llvm::PointerUnion<TypeSourceInfo *, FieldDecl *> BaseOrMember;
1037
1038  /// \brief The source location for the field name.
1039  SourceLocation MemberLocation;
1040
1041  /// \brief The argument used to initialize the base or member, which may
1042  /// end up constructing an object (when multiple arguments are involved).
1043  Stmt *Init;
1044
1045  /// \brief Stores either the constructor to call to initialize this base or
1046  /// member (a CXXConstructorDecl pointer), or stores the anonymous union of
1047  /// which the initialized value is a member.
1048  ///
1049  /// When the value is a FieldDecl pointer, 'BaseOrMember' is class's
1050  /// anonymous union data member, this field holds the FieldDecl for the
1051  /// member of the anonymous union being initialized.
1052  /// @code
1053  /// struct X {
1054  ///   X() : au_i1(123) {}
1055  ///   union {
1056  ///     int au_i1;
1057  ///     float au_f1;
1058  ///   };
1059  /// };
1060  /// @endcode
1061  /// In above example, BaseOrMember holds the field decl. for anonymous union
1062  /// and AnonUnionMember holds field decl for au_i1.
1063  FieldDecl *AnonUnionMember;
1064
1065  /// LParenLoc - Location of the left paren of the ctor-initializer.
1066  SourceLocation LParenLoc;
1067
1068  /// RParenLoc - Location of the right paren of the ctor-initializer.
1069  SourceLocation RParenLoc;
1070
1071  /// \brief The number of array index variables stored after this object
1072  /// in memory.
1073  unsigned NumArrayIndices;
1074
1075  /// IsVirtual - If the initializer is a base initializer, this keeps track
1076  /// of whether the base is virtual or not.
1077  bool IsVirtual;
1078
1079  CXXBaseOrMemberInitializer(ASTContext &Context,
1080                             FieldDecl *Member, SourceLocation MemberLoc,
1081                             SourceLocation L,
1082                             Expr *Init,
1083                             SourceLocation R,
1084                             VarDecl **Indices,
1085                             unsigned NumIndices);
1086
1087public:
1088  /// CXXBaseOrMemberInitializer - Creates a new base-class initializer.
1089  explicit
1090  CXXBaseOrMemberInitializer(ASTContext &Context,
1091                             TypeSourceInfo *TInfo, bool IsVirtual,
1092                             SourceLocation L,
1093                             Expr *Init,
1094                             SourceLocation R);
1095
1096  /// CXXBaseOrMemberInitializer - Creates a new member initializer.
1097  explicit
1098  CXXBaseOrMemberInitializer(ASTContext &Context,
1099                             FieldDecl *Member, SourceLocation MemberLoc,
1100                             SourceLocation L,
1101                             Expr *Init,
1102                             SourceLocation R);
1103
1104  /// \brief Creates a new member initializer that optionally contains
1105  /// array indices used to describe an elementwise initialization.
1106  static CXXBaseOrMemberInitializer *Create(ASTContext &Context,
1107                                            FieldDecl *Member,
1108                                            SourceLocation MemberLoc,
1109                                            SourceLocation L,
1110                                            Expr *Init,
1111                                            SourceLocation R,
1112                                            VarDecl **Indices,
1113                                            unsigned NumIndices);
1114
1115  /// \brief Destroy the base or member initializer.
1116  void Destroy(ASTContext &Context);
1117
1118  /// isBaseInitializer - Returns true when this initializer is
1119  /// initializing a base class.
1120  bool isBaseInitializer() const { return BaseOrMember.is<TypeSourceInfo*>(); }
1121
1122  /// isMemberInitializer - Returns true when this initializer is
1123  /// initializing a non-static data member.
1124  bool isMemberInitializer() const { return BaseOrMember.is<FieldDecl*>(); }
1125
1126  /// If this is a base class initializer, returns the type of the
1127  /// base class with location information. Otherwise, returns an NULL
1128  /// type location.
1129  TypeLoc getBaseClassLoc() const;
1130
1131  /// If this is a base class initializer, returns the type of the base class.
1132  /// Otherwise, returns NULL.
1133  const Type *getBaseClass() const;
1134  Type *getBaseClass();
1135
1136  /// Returns whether the base is virtual or not.
1137  bool isBaseVirtual() const {
1138    assert(isBaseInitializer() && "Must call this on base initializer!");
1139
1140    return IsVirtual;
1141  }
1142
1143  /// \brief Returns the declarator information for a base class initializer.
1144  TypeSourceInfo *getBaseClassInfo() const {
1145    return BaseOrMember.dyn_cast<TypeSourceInfo *>();
1146  }
1147
1148  /// getMember - If this is a member initializer, returns the
1149  /// declaration of the non-static data member being
1150  /// initialized. Otherwise, returns NULL.
1151  FieldDecl *getMember() {
1152    if (isMemberInitializer())
1153      return BaseOrMember.get<FieldDecl*>();
1154    else
1155      return 0;
1156  }
1157
1158  SourceLocation getMemberLocation() const {
1159    return MemberLocation;
1160  }
1161
1162  void setMember(FieldDecl *Member) {
1163    assert(isMemberInitializer());
1164    BaseOrMember = Member;
1165  }
1166
1167  /// \brief Determine the source location of the initializer.
1168  SourceLocation getSourceLocation() const;
1169
1170  /// \brief Determine the source range covering the entire initializer.
1171  SourceRange getSourceRange() const;
1172
1173  FieldDecl *getAnonUnionMember() const {
1174    return AnonUnionMember;
1175  }
1176  void setAnonUnionMember(FieldDecl *anonMember) {
1177    AnonUnionMember = anonMember;
1178  }
1179
1180
1181  SourceLocation getLParenLoc() const { return LParenLoc; }
1182  SourceLocation getRParenLoc() const { return RParenLoc; }
1183
1184  /// \brief Determine the number of implicit array indices used while
1185  /// described an array member initialization.
1186  unsigned getNumArrayIndices() const { return NumArrayIndices; }
1187
1188  /// \brief Retrieve a particular array index variable used to
1189  /// describe an array member initialization.
1190  VarDecl *getArrayIndex(unsigned I) {
1191    assert(I < NumArrayIndices && "Out of bounds member array index");
1192    return reinterpret_cast<VarDecl **>(this + 1)[I];
1193  }
1194  const VarDecl *getArrayIndex(unsigned I) const {
1195    assert(I < NumArrayIndices && "Out of bounds member array index");
1196    return reinterpret_cast<const VarDecl * const *>(this + 1)[I];
1197  }
1198  void setArrayIndex(unsigned I, VarDecl *Index) {
1199    assert(I < NumArrayIndices && "Out of bounds member array index");
1200    reinterpret_cast<VarDecl **>(this + 1)[I] = Index;
1201  }
1202
1203  Expr *getInit() { return static_cast<Expr *>(Init); }
1204};
1205
1206/// CXXConstructorDecl - Represents a C++ constructor within a
1207/// class. For example:
1208///
1209/// @code
1210/// class X {
1211/// public:
1212///   explicit X(int); // represented by a CXXConstructorDecl.
1213/// };
1214/// @endcode
1215class CXXConstructorDecl : public CXXMethodDecl {
1216  /// IsExplicitSpecified - Whether this constructor declaration has the
1217  /// 'explicit' keyword specified.
1218  bool IsExplicitSpecified : 1;
1219
1220  /// ImplicitlyDefined - Whether this constructor was implicitly
1221  /// defined by the compiler. When false, the constructor was defined
1222  /// by the user. In C++03, this flag will have the same value as
1223  /// Implicit. In C++0x, however, a constructor that is
1224  /// explicitly defaulted (i.e., defined with " = default") will have
1225  /// @c !Implicit && ImplicitlyDefined.
1226  bool ImplicitlyDefined : 1;
1227
1228  /// Support for base and member initializers.
1229  /// BaseOrMemberInitializers - The arguments used to initialize the base
1230  /// or member.
1231  CXXBaseOrMemberInitializer **BaseOrMemberInitializers;
1232  unsigned NumBaseOrMemberInitializers;
1233
1234  CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation L,
1235                     DeclarationName N, QualType T, TypeSourceInfo *TInfo,
1236                     bool isExplicitSpecified, bool isInline,
1237                     bool isImplicitlyDeclared)
1238    : CXXMethodDecl(CXXConstructor, RD, L, N, T, TInfo, false,
1239                    FunctionDecl::None, isInline),
1240      IsExplicitSpecified(isExplicitSpecified), ImplicitlyDefined(false),
1241      BaseOrMemberInitializers(0), NumBaseOrMemberInitializers(0) {
1242    setImplicit(isImplicitlyDeclared);
1243  }
1244  virtual void Destroy(ASTContext& C);
1245
1246public:
1247  static CXXConstructorDecl *Create(ASTContext &C, EmptyShell Empty);
1248  static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1249                                    SourceLocation L, DeclarationName N,
1250                                    QualType T, TypeSourceInfo *TInfo,
1251                                    bool isExplicit,
1252                                    bool isInline, bool isImplicitlyDeclared);
1253
1254  /// isExplicitSpecified - Whether this constructor declaration has the
1255  /// 'explicit' keyword specified.
1256  bool isExplicitSpecified() const { return IsExplicitSpecified; }
1257
1258  /// isExplicit - Whether this constructor was marked "explicit" or not.
1259  bool isExplicit() const {
1260    return cast<CXXConstructorDecl>(getFirstDeclaration())
1261      ->isExplicitSpecified();
1262  }
1263
1264  /// isImplicitlyDefined - Whether this constructor was implicitly
1265  /// defined. If false, then this constructor was defined by the
1266  /// user. This operation can only be invoked if the constructor has
1267  /// already been defined.
1268  bool isImplicitlyDefined() const {
1269    assert(isThisDeclarationADefinition() &&
1270           "Can only get the implicit-definition flag once the "
1271           "constructor has been defined");
1272    return ImplicitlyDefined;
1273  }
1274
1275  /// setImplicitlyDefined - Set whether this constructor was
1276  /// implicitly defined or not.
1277  void setImplicitlyDefined(bool ID) {
1278    assert(isThisDeclarationADefinition() &&
1279           "Can only set the implicit-definition flag once the constructor "
1280           "has been defined");
1281    ImplicitlyDefined = ID;
1282  }
1283
1284  /// init_iterator - Iterates through the member/base initializer list.
1285  typedef CXXBaseOrMemberInitializer **init_iterator;
1286
1287  /// init_const_iterator - Iterates through the memberbase initializer list.
1288  typedef CXXBaseOrMemberInitializer * const * init_const_iterator;
1289
1290  /// init_begin() - Retrieve an iterator to the first initializer.
1291  init_iterator       init_begin()       { return BaseOrMemberInitializers; }
1292  /// begin() - Retrieve an iterator to the first initializer.
1293  init_const_iterator init_begin() const { return BaseOrMemberInitializers; }
1294
1295  /// init_end() - Retrieve an iterator past the last initializer.
1296  init_iterator       init_end()       {
1297    return BaseOrMemberInitializers + NumBaseOrMemberInitializers;
1298  }
1299  /// end() - Retrieve an iterator past the last initializer.
1300  init_const_iterator init_end() const {
1301    return BaseOrMemberInitializers + NumBaseOrMemberInitializers;
1302  }
1303
1304  /// getNumArgs - Determine the number of arguments used to
1305  /// initialize the member or base.
1306  unsigned getNumBaseOrMemberInitializers() const {
1307      return NumBaseOrMemberInitializers;
1308  }
1309
1310  void setNumBaseOrMemberInitializers(unsigned numBaseOrMemberInitializers) {
1311    NumBaseOrMemberInitializers = numBaseOrMemberInitializers;
1312  }
1313
1314  void setBaseOrMemberInitializers(CXXBaseOrMemberInitializer ** initializers) {
1315    BaseOrMemberInitializers = initializers;
1316  }
1317  /// isDefaultConstructor - Whether this constructor is a default
1318  /// constructor (C++ [class.ctor]p5), which can be used to
1319  /// default-initialize a class of this type.
1320  bool isDefaultConstructor() const;
1321
1322  /// isCopyConstructor - Whether this constructor is a copy
1323  /// constructor (C++ [class.copy]p2, which can be used to copy the
1324  /// class. @p TypeQuals will be set to the qualifiers on the
1325  /// argument type. For example, @p TypeQuals would be set to @c
1326  /// QualType::Const for the following copy constructor:
1327  ///
1328  /// @code
1329  /// class X {
1330  /// public:
1331  ///   X(const X&);
1332  /// };
1333  /// @endcode
1334  bool isCopyConstructor(unsigned &TypeQuals) const;
1335
1336  /// isCopyConstructor - Whether this constructor is a copy
1337  /// constructor (C++ [class.copy]p2, which can be used to copy the
1338  /// class.
1339  bool isCopyConstructor() const {
1340    unsigned TypeQuals = 0;
1341    return isCopyConstructor(TypeQuals);
1342  }
1343
1344  /// isConvertingConstructor - Whether this constructor is a
1345  /// converting constructor (C++ [class.conv.ctor]), which can be
1346  /// used for user-defined conversions.
1347  bool isConvertingConstructor(bool AllowExplicit) const;
1348
1349  /// \brief Determine whether this is a member template specialization that
1350  /// looks like a copy constructor. Such constructors are never used to copy
1351  /// an object.
1352  bool isCopyConstructorLikeSpecialization() const;
1353
1354  // Implement isa/cast/dyncast/etc.
1355  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1356  static bool classof(const CXXConstructorDecl *D) { return true; }
1357  static bool classofKind(Kind K) { return K == CXXConstructor; }
1358};
1359
1360/// CXXDestructorDecl - Represents a C++ destructor within a
1361/// class. For example:
1362///
1363/// @code
1364/// class X {
1365/// public:
1366///   ~X(); // represented by a CXXDestructorDecl.
1367/// };
1368/// @endcode
1369class CXXDestructorDecl : public CXXMethodDecl {
1370  /// ImplicitlyDefined - Whether this destructor was implicitly
1371  /// defined by the compiler. When false, the destructor was defined
1372  /// by the user. In C++03, this flag will have the same value as
1373  /// Implicit. In C++0x, however, a destructor that is
1374  /// explicitly defaulted (i.e., defined with " = default") will have
1375  /// @c !Implicit && ImplicitlyDefined.
1376  bool ImplicitlyDefined : 1;
1377
1378  FunctionDecl *OperatorDelete;
1379
1380  CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation L,
1381                    DeclarationName N, QualType T,
1382                    bool isInline, bool isImplicitlyDeclared)
1383    : CXXMethodDecl(CXXDestructor, RD, L, N, T, /*TInfo=*/0, false,
1384                    FunctionDecl::None, isInline),
1385      ImplicitlyDefined(false), OperatorDelete(0) {
1386    setImplicit(isImplicitlyDeclared);
1387  }
1388
1389public:
1390  static CXXDestructorDecl *Create(ASTContext& C, EmptyShell Empty);
1391  static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1392                                   SourceLocation L, DeclarationName N,
1393                                   QualType T, bool isInline,
1394                                   bool isImplicitlyDeclared);
1395
1396  /// isImplicitlyDefined - Whether this destructor was implicitly
1397  /// defined. If false, then this destructor was defined by the
1398  /// user. This operation can only be invoked if the destructor has
1399  /// already been defined.
1400  bool isImplicitlyDefined() const {
1401    assert(isThisDeclarationADefinition() &&
1402           "Can only get the implicit-definition flag once the destructor has been defined");
1403    return ImplicitlyDefined;
1404  }
1405
1406  /// setImplicitlyDefined - Set whether this destructor was
1407  /// implicitly defined or not.
1408  void setImplicitlyDefined(bool ID) {
1409    assert(isThisDeclarationADefinition() &&
1410           "Can only set the implicit-definition flag once the destructor has been defined");
1411    ImplicitlyDefined = ID;
1412  }
1413
1414  void setOperatorDelete(FunctionDecl *OD) { OperatorDelete = OD; }
1415  const FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1416
1417  // Implement isa/cast/dyncast/etc.
1418  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1419  static bool classof(const CXXDestructorDecl *D) { return true; }
1420  static bool classofKind(Kind K) { return K == CXXDestructor; }
1421};
1422
1423/// CXXConversionDecl - Represents a C++ conversion function within a
1424/// class. For example:
1425///
1426/// @code
1427/// class X {
1428/// public:
1429///   operator bool();
1430/// };
1431/// @endcode
1432class CXXConversionDecl : public CXXMethodDecl {
1433  /// IsExplicitSpecified - Whether this conversion function declaration is
1434  /// marked "explicit", meaning that it can only be applied when the user
1435  /// explicitly wrote a cast. This is a C++0x feature.
1436  bool IsExplicitSpecified : 1;
1437
1438  CXXConversionDecl(CXXRecordDecl *RD, SourceLocation L,
1439                    DeclarationName N, QualType T, TypeSourceInfo *TInfo,
1440                    bool isInline, bool isExplicitSpecified)
1441    : CXXMethodDecl(CXXConversion, RD, L, N, T, TInfo, false,
1442                    FunctionDecl::None, isInline),
1443      IsExplicitSpecified(isExplicitSpecified) { }
1444
1445public:
1446  static CXXConversionDecl *Create(ASTContext &C, EmptyShell Empty);
1447  static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1448                                   SourceLocation L, DeclarationName N,
1449                                   QualType T, TypeSourceInfo *TInfo,
1450                                   bool isInline, bool isExplicit);
1451
1452  /// IsExplicitSpecified - Whether this conversion function declaration is
1453  /// marked "explicit", meaning that it can only be applied when the user
1454  /// explicitly wrote a cast. This is a C++0x feature.
1455  bool isExplicitSpecified() const { return IsExplicitSpecified; }
1456
1457  /// isExplicit - Whether this is an explicit conversion operator
1458  /// (C++0x only). Explicit conversion operators are only considered
1459  /// when the user has explicitly written a cast.
1460  bool isExplicit() const {
1461    return cast<CXXConversionDecl>(getFirstDeclaration())
1462      ->isExplicitSpecified();
1463  }
1464
1465  /// getConversionType - Returns the type that this conversion
1466  /// function is converting to.
1467  QualType getConversionType() const {
1468    return getType()->getAs<FunctionType>()->getResultType();
1469  }
1470
1471  // Implement isa/cast/dyncast/etc.
1472  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1473  static bool classof(const CXXConversionDecl *D) { return true; }
1474  static bool classofKind(Kind K) { return K == CXXConversion; }
1475};
1476
1477/// LinkageSpecDecl - This represents a linkage specification.  For example:
1478///   extern "C" void foo();
1479///
1480class LinkageSpecDecl : public Decl, public DeclContext {
1481public:
1482  /// LanguageIDs - Used to represent the language in a linkage
1483  /// specification.  The values are part of the serialization abi for
1484  /// ASTs and cannot be changed without altering that abi.  To help
1485  /// ensure a stable abi for this, we choose the DW_LANG_ encodings
1486  /// from the dwarf standard.
1487  enum LanguageIDs {
1488    lang_c = /* DW_LANG_C */ 0x0002,
1489    lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004
1490  };
1491private:
1492  /// Language - The language for this linkage specification.
1493  LanguageIDs Language;
1494
1495  /// HadBraces - Whether this linkage specification had curly braces or not.
1496  bool HadBraces : 1;
1497
1498  LinkageSpecDecl(DeclContext *DC, SourceLocation L, LanguageIDs lang,
1499                  bool Braces)
1500    : Decl(LinkageSpec, DC, L),
1501      DeclContext(LinkageSpec), Language(lang), HadBraces(Braces) { }
1502
1503public:
1504  static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
1505                                 SourceLocation L, LanguageIDs Lang,
1506                                 bool Braces);
1507
1508  /// \brief Return the language specified by this linkage specification.
1509  LanguageIDs getLanguage() const { return Language; }
1510
1511  /// \brief Set the language specified by this linkage specification.
1512  void setLanguage(LanguageIDs L) { Language = L; }
1513
1514  /// \brief Determines whether this linkage specification had braces in
1515  /// its syntactic form.
1516  bool hasBraces() const { return HadBraces; }
1517
1518  /// \brief Set whether this linkage specification has braces in its
1519  /// syntactic form.
1520  void setHasBraces(bool B) { HadBraces = B; }
1521
1522  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1523  static bool classof(const LinkageSpecDecl *D) { return true; }
1524  static bool classofKind(Kind K) { return K == LinkageSpec; }
1525  static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
1526    return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
1527  }
1528  static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
1529    return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
1530  }
1531};
1532
1533/// UsingDirectiveDecl - Represents C++ using-directive. For example:
1534///
1535///    using namespace std;
1536///
1537// NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide
1538// artificial name, for all using-directives in order to store
1539// them in DeclContext effectively.
1540class UsingDirectiveDecl : public NamedDecl {
1541
1542  /// SourceLocation - Location of 'namespace' token.
1543  SourceLocation NamespaceLoc;
1544
1545  /// \brief The source range that covers the nested-name-specifier
1546  /// preceding the namespace name.
1547  SourceRange QualifierRange;
1548
1549  /// \brief The nested-name-specifier that precedes the namespace
1550  /// name, if any.
1551  NestedNameSpecifier *Qualifier;
1552
1553  /// IdentLoc - Location of nominated namespace-name identifier.
1554  // FIXME: We don't store location of scope specifier.
1555  SourceLocation IdentLoc;
1556
1557  /// NominatedNamespace - Namespace nominated by using-directive.
1558  NamedDecl *NominatedNamespace;
1559
1560  /// Enclosing context containing both using-directive and nominated
1561  /// namespace.
1562  DeclContext *CommonAncestor;
1563
1564  /// getUsingDirectiveName - Returns special DeclarationName used by
1565  /// using-directives. This is only used by DeclContext for storing
1566  /// UsingDirectiveDecls in its lookup structure.
1567  static DeclarationName getName() {
1568    return DeclarationName::getUsingDirectiveName();
1569  }
1570
1571  UsingDirectiveDecl(DeclContext *DC, SourceLocation L,
1572                     SourceLocation NamespcLoc,
1573                     SourceRange QualifierRange,
1574                     NestedNameSpecifier *Qualifier,
1575                     SourceLocation IdentLoc,
1576                     NamedDecl *Nominated,
1577                     DeclContext *CommonAncestor)
1578    : NamedDecl(Decl::UsingDirective, DC, L, getName()),
1579      NamespaceLoc(NamespcLoc), QualifierRange(QualifierRange),
1580      Qualifier(Qualifier), IdentLoc(IdentLoc),
1581      NominatedNamespace(Nominated),
1582      CommonAncestor(CommonAncestor) {
1583  }
1584
1585public:
1586  /// \brief Retrieve the source range of the nested-name-specifier
1587  /// that qualifies the namespace name.
1588  SourceRange getQualifierRange() const { return QualifierRange; }
1589
1590  /// \brief Set the source range of the nested-name-specifier that
1591  /// qualifies the namespace name.
1592  void setQualifierRange(SourceRange R) { QualifierRange = R; }
1593
1594  /// \brief Retrieve the nested-name-specifier that qualifies the
1595  /// name of the namespace.
1596  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1597
1598  /// \brief Set the nested-name-specifier that qualifes the name of the
1599  /// namespace.
1600  void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; }
1601
1602  NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
1603  const NamedDecl *getNominatedNamespaceAsWritten() const {
1604    return NominatedNamespace;
1605  }
1606
1607  /// getNominatedNamespace - Returns namespace nominated by using-directive.
1608  NamespaceDecl *getNominatedNamespace();
1609
1610  const NamespaceDecl *getNominatedNamespace() const {
1611    return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
1612  }
1613
1614  /// setNominatedNamespace - Set the namespace nominataed by the
1615  /// using-directive.
1616  void setNominatedNamespace(NamedDecl* NS);
1617
1618  /// \brief Returns the common ancestor context of this using-directive and
1619  /// its nominated namespace.
1620  DeclContext *getCommonAncestor() { return CommonAncestor; }
1621  const DeclContext *getCommonAncestor() const { return CommonAncestor; }
1622
1623  /// \brief Set the common ancestor context of this using-directive and its
1624  /// nominated namespace.
1625  void setCommonAncestor(DeclContext* Cxt) { CommonAncestor = Cxt; }
1626
1627  // FIXME: Could omit 'Key' in name.
1628  /// getNamespaceKeyLocation - Returns location of namespace keyword.
1629  SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
1630
1631  /// setNamespaceKeyLocation - Set the the location of the namespacekeyword.
1632  void setNamespaceKeyLocation(SourceLocation L) { NamespaceLoc = L; }
1633
1634  /// getIdentLocation - Returns location of identifier.
1635  SourceLocation getIdentLocation() const { return IdentLoc; }
1636
1637  /// setIdentLocation - set the location of the identifier.
1638  void setIdentLocation(SourceLocation L) { IdentLoc = L; }
1639
1640  static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
1641                                    SourceLocation L,
1642                                    SourceLocation NamespaceLoc,
1643                                    SourceRange QualifierRange,
1644                                    NestedNameSpecifier *Qualifier,
1645                                    SourceLocation IdentLoc,
1646                                    NamedDecl *Nominated,
1647                                    DeclContext *CommonAncestor);
1648
1649  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1650  static bool classof(const UsingDirectiveDecl *D) { return true; }
1651  static bool classofKind(Kind K) { return K == Decl::UsingDirective; }
1652
1653  // Friend for getUsingDirectiveName.
1654  friend class DeclContext;
1655};
1656
1657/// NamespaceAliasDecl - Represents a C++ namespace alias. For example:
1658///
1659/// @code
1660/// namespace Foo = Bar;
1661/// @endcode
1662class NamespaceAliasDecl : public NamedDecl {
1663  SourceLocation AliasLoc;
1664
1665  /// \brief The source range that covers the nested-name-specifier
1666  /// preceding the namespace name.
1667  SourceRange QualifierRange;
1668
1669  /// \brief The nested-name-specifier that precedes the namespace
1670  /// name, if any.
1671  NestedNameSpecifier *Qualifier;
1672
1673  /// IdentLoc - Location of namespace identifier. Accessed by TargetNameLoc.
1674  SourceLocation IdentLoc;
1675
1676  /// Namespace - The Decl that this alias points to. Can either be a
1677  /// NamespaceDecl or a NamespaceAliasDecl.
1678  NamedDecl *Namespace;
1679
1680  NamespaceAliasDecl(DeclContext *DC, SourceLocation L,
1681                     SourceLocation AliasLoc, IdentifierInfo *Alias,
1682                     SourceRange QualifierRange,
1683                     NestedNameSpecifier *Qualifier,
1684                     SourceLocation IdentLoc, NamedDecl *Namespace)
1685    : NamedDecl(Decl::NamespaceAlias, DC, L, Alias), AliasLoc(AliasLoc),
1686      QualifierRange(QualifierRange), Qualifier(Qualifier),
1687      IdentLoc(IdentLoc), Namespace(Namespace) { }
1688
1689public:
1690  /// \brief Retrieve the source range of the nested-name-specifier
1691  /// that qualifiers the namespace name.
1692  SourceRange getQualifierRange() const { return QualifierRange; }
1693
1694  /// \brief Set the source range of the nested-name-specifier that qualifies
1695  /// the namespace name.
1696  void setQualifierRange(SourceRange R) { QualifierRange = R; }
1697
1698  /// \brief Retrieve the nested-name-specifier that qualifies the
1699  /// name of the namespace.
1700  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1701
1702  /// \brief Set the nested-name-specifier that qualifies the name of the
1703  /// namespace.
1704  void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; }
1705
1706  /// \brief Retrieve the namespace declaration aliased by this directive.
1707  NamespaceDecl *getNamespace() {
1708    if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
1709      return AD->getNamespace();
1710
1711    return cast<NamespaceDecl>(Namespace);
1712  }
1713
1714  const NamespaceDecl *getNamespace() const {
1715    return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
1716  }
1717
1718  /// Returns the location of the alias name, i.e. 'foo' in
1719  /// "namespace foo = ns::bar;".
1720  SourceLocation getAliasLoc() const { return AliasLoc; }
1721
1722  /// Set the location o;f the alias name, e.e., 'foo' in
1723  /// "namespace foo = ns::bar;".
1724  void setAliasLoc(SourceLocation L) { AliasLoc = L; }
1725
1726  /// Returns the location of the 'namespace' keyword.
1727  SourceLocation getNamespaceLoc() const { return getLocation(); }
1728
1729  /// Returns the location of the identifier in the named namespace.
1730  SourceLocation getTargetNameLoc() const { return IdentLoc; }
1731
1732  /// Set the location of the identifier in the named namespace.
1733  void setTargetNameLoc(SourceLocation L) { IdentLoc = L; }
1734
1735  /// \brief Retrieve the namespace that this alias refers to, which
1736  /// may either be a NamespaceDecl or a NamespaceAliasDecl.
1737  NamedDecl *getAliasedNamespace() const { return Namespace; }
1738
1739  /// \brief Set the namespace or namespace alias pointed to by this
1740  /// alias decl.
1741  void setAliasedNamespace(NamedDecl *ND) {
1742    assert((isa<NamespaceAliasDecl>(ND) || isa<NamespaceDecl>(ND)) &&
1743      "expecting namespace or namespace alias decl");
1744      Namespace = ND;
1745  }
1746
1747  static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
1748                                    SourceLocation L, SourceLocation AliasLoc,
1749                                    IdentifierInfo *Alias,
1750                                    SourceRange QualifierRange,
1751                                    NestedNameSpecifier *Qualifier,
1752                                    SourceLocation IdentLoc,
1753                                    NamedDecl *Namespace);
1754
1755  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1756  static bool classof(const NamespaceAliasDecl *D) { return true; }
1757  static bool classofKind(Kind K) { return K == Decl::NamespaceAlias; }
1758};
1759
1760/// UsingShadowDecl - Represents a shadow declaration introduced into
1761/// a scope by a (resolved) using declaration.  For example,
1762///
1763/// namespace A {
1764///   void foo();
1765/// }
1766/// namespace B {
1767///   using A::foo(); // <- a UsingDecl
1768///                   // Also creates a UsingShadowDecl for A::foo in B
1769/// }
1770///
1771class UsingShadowDecl : public NamedDecl {
1772  /// The referenced declaration.
1773  NamedDecl *Underlying;
1774
1775  /// The using declaration which introduced this decl.
1776  UsingDecl *Using;
1777
1778  UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using,
1779                  NamedDecl *Target)
1780    : NamedDecl(UsingShadow, DC, Loc, Target->getDeclName()),
1781      Underlying(Target), Using(Using) {
1782    IdentifierNamespace = Target->getIdentifierNamespace();
1783    setImplicit();
1784  }
1785
1786public:
1787  static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
1788                                 SourceLocation Loc, UsingDecl *Using,
1789                                 NamedDecl *Target) {
1790    return new (C) UsingShadowDecl(DC, Loc, Using, Target);
1791  }
1792
1793  /// \brief Gets the underlying declaration which has been brought into the
1794  /// local scope.
1795  NamedDecl *getTargetDecl() const { return Underlying; }
1796
1797  /// \brief Sets the underlying declaration which has been brought into the
1798  /// local scope.
1799  void setTargetDecl(NamedDecl* ND) { Underlying = ND; }
1800
1801  /// \brief Gets the using declaration to which this declaration is tied.
1802  UsingDecl *getUsingDecl() const { return Using; }
1803
1804  /// \brief Sets the using declaration that introduces this target
1805  /// declaration.
1806  void setUsingDecl(UsingDecl* UD) { Using = UD; }
1807
1808  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1809  static bool classof(const UsingShadowDecl *D) { return true; }
1810  static bool classofKind(Kind K) { return K == Decl::UsingShadow; }
1811};
1812
1813/// UsingDecl - Represents a C++ using-declaration. For example:
1814///    using someNameSpace::someIdentifier;
1815class UsingDecl : public NamedDecl {
1816  /// \brief The source range that covers the nested-name-specifier
1817  /// preceding the declaration name.
1818  SourceRange NestedNameRange;
1819
1820  /// \brief The source location of the "using" location itself.
1821  SourceLocation UsingLocation;
1822
1823  /// \brief Target nested name specifier.
1824  NestedNameSpecifier* TargetNestedName;
1825
1826  /// \brief The collection of shadow declarations associated with
1827  /// this using declaration.  This set can change as a class is
1828  /// processed.
1829  llvm::SmallPtrSet<UsingShadowDecl*, 8> Shadows;
1830
1831  // \brief Has 'typename' keyword.
1832  bool IsTypeName;
1833
1834  UsingDecl(DeclContext *DC, SourceLocation L, SourceRange NNR,
1835            SourceLocation UL, NestedNameSpecifier* TargetNNS,
1836            DeclarationName Name, bool IsTypeNameArg)
1837    : NamedDecl(Decl::Using, DC, L, Name),
1838      NestedNameRange(NNR), UsingLocation(UL), TargetNestedName(TargetNNS),
1839      IsTypeName(IsTypeNameArg) {
1840  }
1841
1842public:
1843  // FIXME: Should be const?
1844  /// \brief Returns the source range that covers the nested-name-specifier
1845  /// preceding the namespace name.
1846  SourceRange getNestedNameRange() { return NestedNameRange; }
1847
1848  /// \brief Set the source range of the nested-name-specifier.
1849  void setNestedNameRange(SourceRange R) { NestedNameRange = R; }
1850
1851  // FIXME; Should be const?
1852  // FIXME: Naming is inconsistent with other get*Loc functions.
1853  /// \brief Returns the source location of the "using" keyword.
1854  SourceLocation getUsingLocation() { return UsingLocation; }
1855
1856  /// \brief Set the source location of the 'using' keyword.
1857  void setUsingLocation(SourceLocation L) { UsingLocation = L; }
1858
1859
1860  /// \brief Get the target nested name declaration.
1861  NestedNameSpecifier* getTargetNestedNameDecl() {
1862    return TargetNestedName;
1863  }
1864
1865  /// \brief Set the target nested name declaration.
1866  void setTargetNestedNameDecl(NestedNameSpecifier *NNS) {
1867    TargetNestedName = NNS;
1868  }
1869
1870  /// \brief Return true if the using declaration has 'typename'.
1871  bool isTypeName() const { return IsTypeName; }
1872
1873  /// \brief Sets whether the using declaration has 'typename'.
1874  void setTypeName(bool TN) { IsTypeName = TN; }
1875
1876  typedef llvm::SmallPtrSet<UsingShadowDecl*,8>::const_iterator shadow_iterator;
1877  shadow_iterator shadow_begin() const { return Shadows.begin(); }
1878  shadow_iterator shadow_end() const { return Shadows.end(); }
1879
1880  void addShadowDecl(UsingShadowDecl *S) {
1881    assert(S->getUsingDecl() == this);
1882    if (!Shadows.insert(S)) {
1883      assert(false && "declaration already in set");
1884    }
1885  }
1886  void removeShadowDecl(UsingShadowDecl *S) {
1887    assert(S->getUsingDecl() == this);
1888    if (!Shadows.erase(S)) {
1889      assert(false && "declaration not in set");
1890    }
1891  }
1892
1893  /// \brief Return the number of shadowed declarations associated with this
1894  /// using declaration.
1895  unsigned getNumShadowDecls() const {
1896    return Shadows.size();
1897  }
1898
1899  static UsingDecl *Create(ASTContext &C, DeclContext *DC,
1900      SourceLocation IdentL, SourceRange NNR, SourceLocation UsingL,
1901      NestedNameSpecifier* TargetNNS, DeclarationName Name, bool IsTypeNameArg);
1902
1903  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1904  static bool classof(const UsingDecl *D) { return true; }
1905  static bool classofKind(Kind K) { return K == Decl::Using; }
1906};
1907
1908/// UnresolvedUsingValueDecl - Represents a dependent using
1909/// declaration which was not marked with 'typename'.  Unlike
1910/// non-dependent using declarations, these *only* bring through
1911/// non-types; otherwise they would break two-phase lookup.
1912///
1913/// template <class T> class A : public Base<T> {
1914///   using Base<T>::foo;
1915/// };
1916class UnresolvedUsingValueDecl : public ValueDecl {
1917  /// \brief The source range that covers the nested-name-specifier
1918  /// preceding the declaration name.
1919  SourceRange TargetNestedNameRange;
1920
1921  /// \brief The source location of the 'using' keyword
1922  SourceLocation UsingLocation;
1923
1924  NestedNameSpecifier *TargetNestedNameSpecifier;
1925
1926  UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
1927                           SourceLocation UsingLoc, SourceRange TargetNNR,
1928                           NestedNameSpecifier *TargetNNS,
1929                           SourceLocation TargetNameLoc,
1930                           DeclarationName TargetName)
1931    : ValueDecl(Decl::UnresolvedUsingValue, DC, TargetNameLoc, TargetName, Ty),
1932    TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc),
1933    TargetNestedNameSpecifier(TargetNNS)
1934  { }
1935
1936public:
1937  /// \brief Returns the source range that covers the nested-name-specifier
1938  /// preceding the namespace name.
1939  SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; }
1940
1941  /// \brief Set the source range coverting the nested-name-specifier preceding
1942  /// the namespace name.
1943  void setTargetNestedNameRange(SourceRange R) { TargetNestedNameRange = R; }
1944
1945  /// \brief Get target nested name declaration.
1946  NestedNameSpecifier* getTargetNestedNameSpecifier() {
1947    return TargetNestedNameSpecifier;
1948  }
1949
1950  /// \brief Set the nested name declaration.
1951  void setTargetNestedNameSpecifier(NestedNameSpecifier* NNS) {
1952    TargetNestedNameSpecifier = NNS;
1953  }
1954
1955  /// \brief Returns the source location of the 'using' keyword.
1956  SourceLocation getUsingLoc() const { return UsingLocation; }
1957
1958  /// \brief Set the source location of the 'using' keyword.
1959  void setUsingLoc(SourceLocation L) { UsingLocation = L; }
1960
1961  static UnresolvedUsingValueDecl *
1962    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
1963           SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
1964           SourceLocation TargetNameLoc, DeclarationName TargetName);
1965
1966  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1967  static bool classof(const UnresolvedUsingValueDecl *D) { return true; }
1968  static bool classofKind(Kind K) { return K == Decl::UnresolvedUsingValue; }
1969};
1970
1971/// UnresolvedUsingTypenameDecl - Represents a dependent using
1972/// declaration which was marked with 'typename'.
1973///
1974/// template <class T> class A : public Base<T> {
1975///   using typename Base<T>::foo;
1976/// };
1977///
1978/// The type associated with a unresolved using typename decl is
1979/// currently always a typename type.
1980class UnresolvedUsingTypenameDecl : public TypeDecl {
1981  /// \brief The source range that covers the nested-name-specifier
1982  /// preceding the declaration name.
1983  SourceRange TargetNestedNameRange;
1984
1985  /// \brief The source location of the 'using' keyword
1986  SourceLocation UsingLocation;
1987
1988  /// \brief The source location of the 'typename' keyword
1989  SourceLocation TypenameLocation;
1990
1991  NestedNameSpecifier *TargetNestedNameSpecifier;
1992
1993  UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
1994                    SourceLocation TypenameLoc,
1995                    SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
1996                    SourceLocation TargetNameLoc, IdentifierInfo *TargetName)
1997  : TypeDecl(Decl::UnresolvedUsingTypename, DC, TargetNameLoc, TargetName),
1998    TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc),
1999    TypenameLocation(TypenameLoc), TargetNestedNameSpecifier(TargetNNS)
2000  { }
2001
2002public:
2003  /// \brief Returns the source range that covers the nested-name-specifier
2004  /// preceding the namespace name.
2005  SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; }
2006
2007  /// \brief Set the source range coverting the nested-name-specifier preceding
2008  /// the namespace name.
2009  void setTargetNestedNameRange(SourceRange R) { TargetNestedNameRange = R; }
2010
2011  /// \brief Get target nested name declaration.
2012  NestedNameSpecifier* getTargetNestedNameSpecifier() {
2013    return TargetNestedNameSpecifier;
2014  }
2015
2016  /// \brief Set the nested name declaration.
2017  void setTargetNestedNameSpecifier(NestedNameSpecifier* NNS) {
2018    TargetNestedNameSpecifier = NNS;
2019  }
2020
2021  /// \brief Returns the source location of the 'using' keyword.
2022  SourceLocation getUsingLoc() const { return UsingLocation; }
2023
2024  /// \brief Set the source location of the 'using' keyword.
2025  void setUsingLoc(SourceLocation L) { UsingLocation = L; }
2026
2027  /// \brief Returns the source location of the 'typename' keyword.
2028  SourceLocation getTypenameLoc() const { return TypenameLocation; }
2029
2030  /// \brief Set the source location of the 'typename' keyword.
2031  void setTypenameLoc(SourceLocation L) { TypenameLocation = L; }
2032
2033  static UnresolvedUsingTypenameDecl *
2034    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
2035           SourceLocation TypenameLoc,
2036           SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
2037           SourceLocation TargetNameLoc, DeclarationName TargetName);
2038
2039  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2040  static bool classof(const UnresolvedUsingTypenameDecl *D) { return true; }
2041  static bool classofKind(Kind K) { return K == Decl::UnresolvedUsingTypename; }
2042};
2043
2044/// StaticAssertDecl - Represents a C++0x static_assert declaration.
2045class StaticAssertDecl : public Decl {
2046  Expr *AssertExpr;
2047  StringLiteral *Message;
2048
2049  StaticAssertDecl(DeclContext *DC, SourceLocation L,
2050                   Expr *assertexpr, StringLiteral *message)
2051  : Decl(StaticAssert, DC, L), AssertExpr(assertexpr), Message(message) { }
2052
2053public:
2054  static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
2055                                  SourceLocation L, Expr *AssertExpr,
2056                                  StringLiteral *Message);
2057
2058  Expr *getAssertExpr() { return AssertExpr; }
2059  const Expr *getAssertExpr() const { return AssertExpr; }
2060
2061  StringLiteral *getMessage() { return Message; }
2062  const StringLiteral *getMessage() const { return Message; }
2063
2064  virtual ~StaticAssertDecl();
2065  virtual void Destroy(ASTContext& C);
2066
2067  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2068  static bool classof(StaticAssertDecl *D) { return true; }
2069  static bool classofKind(Kind K) { return K == Decl::StaticAssert; }
2070};
2071
2072/// Insertion operator for diagnostics.  This allows sending AccessSpecifier's
2073/// into a diagnostic with <<.
2074const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
2075                                    AccessSpecifier AS);
2076
2077} // end namespace clang
2078
2079#endif
2080