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