DeclCXX.h revision 202879
139213Sgibbs//===-- DeclCXX.h - Classes for representing C++ declarations -*- C++ -*-=====//
239213Sgibbs//
339213Sgibbs//                     The LLVM Compiler Infrastructure
439213Sgibbs//
539213Sgibbs// This file is distributed under the University of Illinois Open Source
639213Sgibbs// License. See LICENSE.TXT for details.
739213Sgibbs//
839213Sgibbs//===----------------------------------------------------------------------===//
939213Sgibbs//
1039213Sgibbs//  This file defines the C++ Decl subclasses.
1139213Sgibbs//
1239213Sgibbs//===----------------------------------------------------------------------===//
1339213Sgibbs
1439213Sgibbs#ifndef LLVM_CLANG_AST_DECLCXX_H
1539213Sgibbs#define LLVM_CLANG_AST_DECLCXX_H
1639213Sgibbs
1739213Sgibbs#include "clang/AST/Expr.h"
1839213Sgibbs#include "clang/AST/Decl.h"
1939213Sgibbs#include "clang/AST/UnresolvedSet.h"
2039213Sgibbs#include "llvm/ADT/SmallVector.h"
2139213Sgibbs#include "llvm/ADT/SmallPtrSet.h"
2239213Sgibbs
2339213Sgibbsnamespace clang {
2439213Sgibbs
2539213Sgibbsclass ClassTemplateDecl;
2639213Sgibbsclass ClassTemplateSpecializationDecl;
2739213Sgibbsclass CXXBasePath;
2850477Speterclass CXXBasePaths;
2939213Sgibbsclass CXXConstructorDecl;
3039213Sgibbsclass CXXConversionDecl;
3139213Sgibbsclass CXXDestructorDecl;
3239213Sgibbsclass CXXMethodDecl;
3339213Sgibbsclass CXXRecordDecl;
3439213Sgibbsclass CXXMemberLookupCriteria;
3539213Sgibbs
3660041Sphk/// \brief Represents any kind of function declaration, whether it is a
3739213Sgibbs/// concrete function or a function template.
3839213Sgibbsclass AnyFunctionDecl {
3939213Sgibbs  NamedDecl *Function;
4050073Sken
4139213Sgibbs  AnyFunctionDecl(NamedDecl *ND) : Function(ND) { }
4239213Sgibbs
4339213Sgibbspublic:
4439213Sgibbs  AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { }
4539213Sgibbs  AnyFunctionDecl(FunctionTemplateDecl *FTD);
4639213Sgibbs
4739213Sgibbs  /// \brief Implicily converts any function or function template into a
4839213Sgibbs  /// named declaration.
4939213Sgibbs  operator NamedDecl *() const { return Function; }
5039213Sgibbs
5139213Sgibbs  /// \brief Retrieve the underlying function or function template.
5239213Sgibbs  NamedDecl *get() const { return Function; }
5350073Sken
5450073Sken  static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) {
5539213Sgibbs    return AnyFunctionDecl(ND);
5639213Sgibbs  }
5739213Sgibbs};
5839213Sgibbs
5939213Sgibbs} // end namespace clang
6039213Sgibbs
6139213Sgibbsnamespace llvm {
6239213Sgibbs  /// Implement simplify_type for AnyFunctionDecl, so that we can dyn_cast from
6339213Sgibbs  /// AnyFunctionDecl to any function or function template declaration.
6439213Sgibbs  template<> struct simplify_type<const ::clang::AnyFunctionDecl> {
6539213Sgibbs    typedef ::clang::NamedDecl* SimpleType;
6639213Sgibbs    static SimpleType getSimplifiedValue(const ::clang::AnyFunctionDecl &Val) {
6739213Sgibbs      return Val;
6839213Sgibbs    }
6939213Sgibbs  };
7039213Sgibbs  template<> struct simplify_type< ::clang::AnyFunctionDecl>
7139213Sgibbs  : public simplify_type<const ::clang::AnyFunctionDecl> {};
7239213Sgibbs
7339213Sgibbs  // Provide PointerLikeTypeTraits for non-cvr pointers.
7439213Sgibbs  template<>
7539213Sgibbs  class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
7639213Sgibbs  public:
7739213Sgibbs    static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
7839213Sgibbs      return F.get();
7959249Sphk    }
8039213Sgibbs    static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
8160938Sjake      return ::clang::AnyFunctionDecl::getFromNamedDecl(
8239213Sgibbs                                      static_cast< ::clang::NamedDecl*>(P));
8339213Sgibbs    }
8439213Sgibbs
8550073Sken    enum { NumLowBitsAvailable = 2 };
8653257Sken  };
8739213Sgibbs
8839213Sgibbs} // end namespace llvm
8939213Sgibbs
9039213Sgibbsnamespace clang {
9139213Sgibbs
9239213Sgibbs/// CXXBaseSpecifier - A base class of a C++ class.
9339213Sgibbs///
9439213Sgibbs/// Each CXXBaseSpecifier represents a single, direct base class (or
9539213Sgibbs/// struct) of a C++ class (or struct). It specifies the type of that
9640603Sken/// base class, whether it is a virtual or non-virtual base, and what
9739213Sgibbs/// level of access (public, protected, private) is used for the
9839213Sgibbs/// derivation. For example:
9939213Sgibbs///
10039213Sgibbs/// @code
10150073Sken///   class A { };
10239213Sgibbs///   class B { };
10339213Sgibbs///   class C : public virtual A, protected B { };
10439213Sgibbs/// @endcode
10539213Sgibbs///
10639213Sgibbs/// In this code, C will have two CXXBaseSpecifiers, one for "public
10739213Sgibbs/// virtual A" and the other for "protected B".
10839213Sgibbsclass CXXBaseSpecifier {
10939213Sgibbs  /// Range - The source code range that covers the full base
11039213Sgibbs  /// specifier, including the "virtual" (if present) and access
11139213Sgibbs  /// specifier (if present).
11239213Sgibbs  // FIXME: Move over to a TypeLoc!
11339213Sgibbs  SourceRange Range;
11439213Sgibbs
11539213Sgibbs  /// Virtual - Whether this is a virtual base class or not.
11639213Sgibbs  bool Virtual : 1;
11739213Sgibbs
11839213Sgibbs  /// BaseOfClass - Whether this is the base of a class (true) or of a
11939213Sgibbs  /// struct (false). This determines the mapping from the access
12039213Sgibbs  /// specifier as written in the source code to the access specifier
12147625Sphk  /// used for semantic analysis.
12247625Sphk  bool BaseOfClass : 1;
12347625Sphk
12447625Sphk  /// Access - Access specifier as written in the source code (which
12547625Sphk  /// may be AS_none). The actual type of data stored here is an
12650073Sken  /// AccessSpecifier, but we use "unsigned" here to work around a
12747625Sphk  /// VC++ bug.
12847625Sphk  unsigned Access : 2;
12947625Sphk
13047625Sphk  /// BaseType - The type of the base class. This will be a class or
13147625Sphk  /// struct (or a typedef of such).
13247625Sphk  QualType BaseType;
13347625Sphk
13447625Sphkpublic:
13547625Sphk  CXXBaseSpecifier() { }
13639213Sgibbs
13739213Sgibbs  CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, QualType T)
13839213Sgibbs    : Range(R), Virtual(V), BaseOfClass(BC), Access(A), BaseType(T) { }
13939213Sgibbs
14050073Sken  /// getSourceRange - Retrieves the source range that contains the
14150073Sken  /// entire base specifier.
14250073Sken  SourceRange getSourceRange() const { return Range; }
14350073Sken
14439213Sgibbs  /// isVirtual - Determines whether the base class is a virtual base
14539213Sgibbs  /// class (or not).
14639213Sgibbs  bool isVirtual() const { return Virtual; }
14739213Sgibbs
14839213Sgibbs  /// getAccessSpecifier - Returns the access specifier for this base
14939213Sgibbs  /// specifier. This is the actual base specifier as used for
15039213Sgibbs  /// semantic analysis, so the result can never be AS_none. To
15140603Sken  /// retrieve the access specifier as written in the source code, use
15239213Sgibbs  /// getAccessSpecifierAsWritten().
15339213Sgibbs  AccessSpecifier getAccessSpecifier() const {
15439213Sgibbs    if ((AccessSpecifier)Access == AS_none)
15539213Sgibbs      return BaseOfClass? AS_private : AS_public;
15639213Sgibbs    else
15739213Sgibbs      return (AccessSpecifier)Access;
15839213Sgibbs  }
15939213Sgibbs
16040603Sken  /// getAccessSpecifierAsWritten - Retrieves the access specifier as
16140603Sken  /// written in the source code (which may mean that no access
16240603Sken  /// specifier was explicitly written). Use getAccessSpecifier() to
16340603Sken  /// retrieve the access specifier for use in semantic analysis.
16440603Sken  AccessSpecifier getAccessSpecifierAsWritten() const {
16540603Sken    return (AccessSpecifier)Access;
16639213Sgibbs  }
16749982Sbillf
16839213Sgibbs  /// getType - Retrieves the type of the base class. This type will
16941297Sken  /// always be an unqualified class type.
17041297Sken  QualType getType() const { return BaseType; }
17139213Sgibbs};
17241297Sken
17339213Sgibbs/// CXXRecordDecl - Represents a C++ struct/union/class.
17441297Sken/// FIXME: This class will disappear once we've properly taught RecordDecl
17541297Sken/// to deal with C++-specific things.
17639213Sgibbsclass CXXRecordDecl : public RecordDecl {
17739213Sgibbs  /// UserDeclaredConstructor - True when this class has a
17839213Sgibbs  /// user-declared constructor.
17939213Sgibbs  bool UserDeclaredConstructor : 1;
18039213Sgibbs
18139213Sgibbs  /// UserDeclaredCopyConstructor - True when this class has a
18239213Sgibbs  /// user-declared copy constructor.
18339213Sgibbs  bool UserDeclaredCopyConstructor : 1;
18439213Sgibbs
18539213Sgibbs  /// UserDeclaredCopyAssignment - True when this class has a
18639213Sgibbs  /// user-declared copy assignment operator.
18739213Sgibbs  bool UserDeclaredCopyAssignment : 1;
18839213Sgibbs
18939213Sgibbs  /// UserDeclaredDestructor - True when this class has a
19039213Sgibbs  /// user-declared destructor.
19139213Sgibbs  bool UserDeclaredDestructor : 1;
19239213Sgibbs
19339213Sgibbs  /// Aggregate - True when this class is an aggregate.
19439213Sgibbs  bool Aggregate : 1;
19539213Sgibbs
19639213Sgibbs  /// PlainOldData - True when this class is a POD-type.
19739213Sgibbs  bool PlainOldData : 1;
19839213Sgibbs
19939213Sgibbs  /// Empty - true when this class is empty for traits purposes, i.e. has no
20039213Sgibbs  /// data members other than 0-width bit-fields, has no virtual function/base,
20139213Sgibbs  /// and doesn't inherit from a non-empty class. Doesn't take union-ness into
20239213Sgibbs  /// account.
20339213Sgibbs  bool Empty : 1;
20439213Sgibbs
20539213Sgibbs  /// Polymorphic - True when this class is polymorphic, i.e. has at least one
20639213Sgibbs  /// virtual member or derives from a polymorphic class.
20739213Sgibbs  bool Polymorphic : 1;
20839213Sgibbs
20939213Sgibbs  /// Abstract - True when this class is abstract, i.e. has at least one
21039213Sgibbs  /// pure virtual function, (that can come from a base class).
21139213Sgibbs  bool Abstract : 1;
21239213Sgibbs
21339213Sgibbs  /// HasTrivialConstructor - True when this class has a trivial constructor.
21439213Sgibbs  ///
21539213Sgibbs  /// C++ [class.ctor]p5.  A constructor is trivial if it is an
21639213Sgibbs  /// implicitly-declared default constructor and if:
21739213Sgibbs  /// * its class has no virtual functions and no virtual base classes, and
21859249Sphk  /// * all the direct base classes of its class have trivial constructors, and
21939213Sgibbs  /// * for all the nonstatic data members of its class that are of class type
22039213Sgibbs  ///   (or array thereof), each such class has a trivial constructor.
22139213Sgibbs  bool HasTrivialConstructor : 1;
22239213Sgibbs
22339213Sgibbs  /// HasTrivialCopyConstructor - True when this class has a trivial copy
22439213Sgibbs  /// constructor.
22559249Sphk  ///
22639213Sgibbs  /// C++ [class.copy]p6.  A copy constructor for class X is trivial
22739213Sgibbs  /// if it is implicitly declared and if
22859249Sphk  /// * class X has no virtual functions and no virtual base classes, and
22939213Sgibbs  /// * each direct base class of X has a trivial copy constructor, and
23039213Sgibbs  /// * for all the nonstatic data members of X that are of class type (or
23139213Sgibbs  ///   array thereof), each such class type has a trivial copy constructor;
23239213Sgibbs  /// otherwise the copy constructor is non-trivial.
23339213Sgibbs  bool HasTrivialCopyConstructor : 1;
23439213Sgibbs
23539213Sgibbs  /// HasTrivialCopyAssignment - True when this class has a trivial copy
23639213Sgibbs  /// assignment operator.
23739213Sgibbs  ///
23839213Sgibbs  /// C++ [class.copy]p11.  A copy assignment operator for class X is
23939213Sgibbs  /// trivial if it is implicitly declared and if
24039213Sgibbs  /// * class X has no virtual functions and no virtual base classes, and
24139213Sgibbs  /// * each direct base class of X has a trivial copy assignment operator, and
24239213Sgibbs  /// * for all the nonstatic data members of X that are of class type (or
24339213Sgibbs  ///   array thereof), each such class type has a trivial copy assignment
24439213Sgibbs  ///   operator;
24559249Sphk  /// otherwise the copy assignment operator is non-trivial.
24639213Sgibbs  bool HasTrivialCopyAssignment : 1;
24739213Sgibbs
24839213Sgibbs  /// HasTrivialDestructor - True when this class has a trivial destructor.
24939213Sgibbs  ///
25039213Sgibbs  /// C++ [class.dtor]p3.  A destructor is trivial if it is an
25139213Sgibbs  /// implicitly-declared destructor and if:
25259249Sphk  /// * all of the direct base classes of its class have trivial destructors
25339213Sgibbs  ///   and
25439213Sgibbs  /// * for all of the non-static data members of its class that are of class
25539213Sgibbs  ///   type (or array thereof), each such class has a trivial destructor.
25639213Sgibbs  bool HasTrivialDestructor : 1;
25739213Sgibbs
25839213Sgibbs  /// ComputedVisibleConversions - True when visible conversion functions are
25939213Sgibbs  /// already computed and are available.
26039213Sgibbs  bool ComputedVisibleConversions : 1;
26139213Sgibbs
26239213Sgibbs  /// Bases - Base classes of this class.
26359249Sphk  /// FIXME: This is wasted space for a union.
26439213Sgibbs  CXXBaseSpecifier *Bases;
26539213Sgibbs
26639213Sgibbs  /// NumBases - The number of base class specifiers in Bases.
26739213Sgibbs  unsigned NumBases;
26859249Sphk
26939213Sgibbs  /// VBases - direct and indirect virtual base classes of this class.
27039213Sgibbs  CXXBaseSpecifier *VBases;
27139213Sgibbs
27239213Sgibbs  /// NumVBases - The number of virtual base class specifiers in VBases.
27339213Sgibbs  unsigned NumVBases;
27439213Sgibbs
27539213Sgibbs  /// Conversions - Overload set containing the conversion functions
27639213Sgibbs  /// of this C++ class (but not its inherited conversion
27739213Sgibbs  /// functions). Each of the entries in this overload set is a
27839213Sgibbs  /// CXXConversionDecl.
27939213Sgibbs  UnresolvedSet<4> Conversions;
28039213Sgibbs
28139213Sgibbs  /// VisibleConversions - Overload set containing the conversion functions
28239213Sgibbs  /// of this C++ class and all those inherited conversion functions that
28339213Sgibbs  /// are visible in this class. Each of the entries in this overload set is
28439213Sgibbs  /// a CXXConversionDecl or a FunctionTemplateDecl.
28539213Sgibbs  UnresolvedSet<4> VisibleConversions;
28639213Sgibbs
28739213Sgibbs  /// \brief The template or declaration that this declaration
28839213Sgibbs  /// describes or was instantiated from, respectively.
28939213Sgibbs  ///
29039213Sgibbs  /// For non-templates, this value will be NULL. For record
29139213Sgibbs  /// declarations that describe a class template, this will be a
29239213Sgibbs  /// pointer to a ClassTemplateDecl. For member
29339213Sgibbs  /// classes of class template specializations, this will be the
29439213Sgibbs  /// MemberSpecializationInfo referring to the member class that was
29539213Sgibbs  /// instantiated or specialized.
29639213Sgibbs  llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*>
29739213Sgibbs    TemplateOrInstantiation;
29839213Sgibbs
29939213Sgibbs  void getNestedVisibleConversionFunctions(CXXRecordDecl *RD,
30039213Sgibbs          const llvm::SmallPtrSet<CanQualType, 8> &TopConversionsTypeSet,
30139213Sgibbs          const llvm::SmallPtrSet<CanQualType, 8> &HiddenConversionTypes);
30239213Sgibbs  void collectConversionFunctions(
30339213Sgibbs    llvm::SmallPtrSet<CanQualType, 8>& ConversionsTypeSet) const;
30439213Sgibbs
30539213Sgibbsprotected:
30639213Sgibbs  CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
30739213Sgibbs                SourceLocation L, IdentifierInfo *Id,
30839213Sgibbs                CXXRecordDecl *PrevDecl,
30939213Sgibbs                SourceLocation TKL = SourceLocation());
31039213Sgibbs
31139213Sgibbs  ~CXXRecordDecl();
31239213Sgibbs
31339213Sgibbspublic:
31439213Sgibbs  /// base_class_iterator - Iterator that traverses the base classes
31539213Sgibbs  /// of a class.
31639213Sgibbs  typedef CXXBaseSpecifier*       base_class_iterator;
31739213Sgibbs
31839213Sgibbs  /// base_class_const_iterator - Iterator that traverses the base
31939213Sgibbs  /// classes of a class.
32039213Sgibbs  typedef const CXXBaseSpecifier* base_class_const_iterator;
32139213Sgibbs
32239213Sgibbs  /// reverse_base_class_iterator = Iterator that traverses the base classes
32339213Sgibbs  /// of a class in reverse order.
32439213Sgibbs  typedef std::reverse_iterator<base_class_iterator>
32539213Sgibbs    reverse_base_class_iterator;
32639213Sgibbs
32739213Sgibbs  /// reverse_base_class_iterator = Iterator that traverses the base classes
32839213Sgibbs  /// of a class in reverse order.
32939213Sgibbs  typedef std::reverse_iterator<base_class_const_iterator>
33039213Sgibbs    reverse_base_class_const_iterator;
33139213Sgibbs
33239213Sgibbs  virtual CXXRecordDecl *getCanonicalDecl() {
33339213Sgibbs    return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
33439213Sgibbs  }
33539213Sgibbs  virtual const CXXRecordDecl *getCanonicalDecl() const {
33639213Sgibbs    return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
33739213Sgibbs  }
33839213Sgibbs
33939213Sgibbs  static CXXRecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC,
34039213Sgibbs                               SourceLocation L, IdentifierInfo *Id,
34139213Sgibbs                               SourceLocation TKL = SourceLocation(),
34259249Sphk                               CXXRecordDecl* PrevDecl=0,
34339213Sgibbs                               bool DelayTypeCreation = false);
34450073Sken
34550073Sken  virtual void Destroy(ASTContext& C);
34639213Sgibbs
34739213Sgibbs  bool isDynamicClass() const {
34839213Sgibbs    return Polymorphic || NumVBases != 0;
34939213Sgibbs  }
35039213Sgibbs
35139213Sgibbs  /// setBases - Sets the base classes of this struct or class.
35239213Sgibbs  void setBases(ASTContext &C,
35356148Smjacob                CXXBaseSpecifier const * const *Bases, unsigned NumBases);
35443819Sken
35539213Sgibbs  /// getNumBases - Retrieves the number of base classes of this
35653257Sken  /// class.
35753257Sken  unsigned getNumBases() const { return NumBases; }
35853257Sken
35939213Sgibbs  base_class_iterator       bases_begin()       { return Bases; }
36039213Sgibbs  base_class_const_iterator bases_begin() const { return Bases; }
36139213Sgibbs  base_class_iterator       bases_end()         { return Bases + NumBases; }
36239213Sgibbs  base_class_const_iterator bases_end()   const { return Bases + NumBases; }
36339213Sgibbs  reverse_base_class_iterator       bases_rbegin() {
36439213Sgibbs    return reverse_base_class_iterator(bases_end());
36539213Sgibbs  }
36639213Sgibbs  reverse_base_class_const_iterator bases_rbegin() const {
36739213Sgibbs    return reverse_base_class_const_iterator(bases_end());
36839213Sgibbs  }
36939213Sgibbs  reverse_base_class_iterator bases_rend() {
37039213Sgibbs    return reverse_base_class_iterator(bases_begin());
37139213Sgibbs  }
37239213Sgibbs  reverse_base_class_const_iterator bases_rend() const {
37339213Sgibbs    return reverse_base_class_const_iterator(bases_begin());
37439213Sgibbs  }
37539213Sgibbs
37639213Sgibbs  /// getNumVBases - Retrieves the number of virtual base classes of this
37739213Sgibbs  /// class.
37839213Sgibbs  unsigned getNumVBases() const { return NumVBases; }
37939213Sgibbs
38039213Sgibbs  base_class_iterator       vbases_begin()       { return VBases; }
38140603Sken  base_class_const_iterator vbases_begin() const { return VBases; }
38240603Sken  base_class_iterator       vbases_end()         { return VBases + NumVBases; }
38340603Sken  base_class_const_iterator vbases_end()   const { return VBases + NumVBases; }
38440603Sken  reverse_base_class_iterator vbases_rbegin() {
38559249Sphk    return reverse_base_class_iterator(vbases_end());
38640603Sken  }
38740603Sken  reverse_base_class_const_iterator vbases_rbegin() const {
38840603Sken    return reverse_base_class_const_iterator(vbases_end());
38940603Sken  }
39040603Sken  reverse_base_class_iterator vbases_rend() {
39140603Sken    return reverse_base_class_iterator(vbases_begin());
39240603Sken  }
39340603Sken  reverse_base_class_const_iterator vbases_rend() const {
39440603Sken    return reverse_base_class_const_iterator(vbases_begin());
39540603Sken }
39640603Sken
39740603Sken  /// \brief Determine whether this class has any dependent base classes.
39840603Sken  bool hasAnyDependentBases() const;
39940603Sken
40040603Sken  /// Iterator access to method members.  The method iterator visits
40140603Sken  /// all method members of the class, including non-instance methods,
40240603Sken  /// special methods, etc.
40340603Sken  typedef specific_decl_iterator<CXXMethodDecl> method_iterator;
40440603Sken
40540603Sken  /// method_begin - Method begin iterator.  Iterates in the order the methods
40640603Sken  /// were declared.
40740603Sken  method_iterator method_begin() const {
40840603Sken    return method_iterator(decls_begin());
40940603Sken  }
41040603Sken  /// method_end - Method end iterator.
41140603Sken  method_iterator method_end() const {
41240603Sken    return method_iterator(decls_end());
41340603Sken  }
41440603Sken
41559249Sphk  /// Iterator access to constructor members.
41659249Sphk  typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator;
41759249Sphk
41859249Sphk  ctor_iterator ctor_begin() const {
41959249Sphk    return ctor_iterator(decls_begin());
42040603Sken  }
42140603Sken  ctor_iterator ctor_end() const {
42240603Sken    return ctor_iterator(decls_end());
42340603Sken  }
42440603Sken
42540603Sken  /// hasConstCopyConstructor - Determines whether this class has a
42640603Sken  /// copy constructor that accepts a const-qualified argument.
42740603Sken  bool hasConstCopyConstructor(ASTContext &Context) const;
42840603Sken
42940603Sken  /// getCopyConstructor - Returns the copy constructor for this class
43039213Sgibbs  CXXConstructorDecl *getCopyConstructor(ASTContext &Context,
43139213Sgibbs                                         unsigned TypeQuals) const;
43240603Sken
43340603Sken  /// hasConstCopyAssignment - Determines whether this class has a
43440603Sken  /// copy assignment operator that accepts a const-qualified argument.
43540603Sken  /// It returns its decl in MD if found.
43640603Sken  bool hasConstCopyAssignment(ASTContext &Context,
43740603Sken                              const CXXMethodDecl *&MD) const;
43853257Sken
43953257Sken  /// addedConstructor - Notify the class that another constructor has
44039213Sgibbs  /// been added. This routine helps maintain information about the
44139213Sgibbs  /// class based on which constructors have been added.
44239213Sgibbs  void addedConstructor(ASTContext &Context, CXXConstructorDecl *ConDecl);
44340603Sken
44439213Sgibbs  /// hasUserDeclaredConstructor - Whether this class has any
44539213Sgibbs  /// user-declared constructors. When true, a default constructor
44639213Sgibbs  /// will not be implicitly declared.
44739213Sgibbs  bool hasUserDeclaredConstructor() const {
44839213Sgibbs    assert((isDefinition() ||
44939213Sgibbs            cast<RecordType>(getTypeForDecl())->isBeingDefined()) &&
45039213Sgibbs           "Incomplete record decl!");
45139213Sgibbs    return UserDeclaredConstructor;
45239213Sgibbs  }
45339213Sgibbs
45439213Sgibbs  /// hasUserDeclaredCopyConstructor - Whether this class has a
45539213Sgibbs  /// user-declared copy constructor. When false, a copy constructor
45639213Sgibbs  /// will be implicitly declared.
45739213Sgibbs  bool hasUserDeclaredCopyConstructor() const {
45839213Sgibbs    return UserDeclaredCopyConstructor;
45939213Sgibbs  }
46056148Smjacob
46139213Sgibbs  /// addedAssignmentOperator - Notify the class that another assignment
46239213Sgibbs  /// operator has been added. This routine helps maintain information about the
46339213Sgibbs   /// class based on which operators have been added.
46439213Sgibbs  void addedAssignmentOperator(ASTContext &Context, CXXMethodDecl *OpDecl);
46539213Sgibbs
46639213Sgibbs  /// hasUserDeclaredCopyAssignment - Whether this class has a
46739213Sgibbs  /// user-declared copy assignment operator. When false, a copy
46840603Sken  /// assigment operator will be implicitly declared.
46940603Sken  bool hasUserDeclaredCopyAssignment() const {
47040603Sken    return UserDeclaredCopyAssignment;
47140603Sken  }
47239213Sgibbs
47339213Sgibbs  /// hasUserDeclaredDestructor - Whether this class has a
47439213Sgibbs  /// user-declared destructor. When false, a destructor will be
47539213Sgibbs  /// implicitly declared.
47639213Sgibbs  bool hasUserDeclaredDestructor() const { return UserDeclaredDestructor; }
47739213Sgibbs
47839213Sgibbs  /// setUserDeclaredDestructor - Set whether this class has a
47939213Sgibbs  /// user-declared destructor. If not set by the time the class is
48039213Sgibbs  /// fully defined, a destructor will be implicitly declared.
48139213Sgibbs  void setUserDeclaredDestructor(bool UCD) {
48239213Sgibbs    UserDeclaredDestructor = UCD;
48339213Sgibbs  }
48439213Sgibbs
48539213Sgibbs  /// getConversions - Retrieve the overload set containing all of the
48639213Sgibbs  /// conversion functions in this class.
48739213Sgibbs  UnresolvedSetImpl *getConversionFunctions() {
48839213Sgibbs    assert((this->isDefinition() ||
48939213Sgibbs            cast<RecordType>(getTypeForDecl())->isBeingDefined()) &&
49039213Sgibbs           "getConversionFunctions() called on incomplete type");
49139213Sgibbs    return &Conversions;
49239213Sgibbs  }
49339213Sgibbs  const UnresolvedSetImpl *getConversionFunctions() const {
49439213Sgibbs    assert((this->isDefinition() ||
49539213Sgibbs            cast<RecordType>(getTypeForDecl())->isBeingDefined()) &&
49639213Sgibbs           "getConversionFunctions() called on incomplete type");
49747413Sgibbs    return &Conversions;
49839213Sgibbs  }
49939213Sgibbs
50047413Sgibbs  typedef UnresolvedSetImpl::iterator conversion_iterator;
50139213Sgibbs  conversion_iterator conversion_begin() const { return Conversions.begin(); }
50239213Sgibbs  conversion_iterator conversion_end() const { return Conversions.end(); }
50339213Sgibbs
50439213Sgibbs  /// Replaces a conversion function with a new declaration.
50539213Sgibbs  ///
50639213Sgibbs  /// Returns true if the old conversion was found.
50739213Sgibbs  bool replaceConversion(const NamedDecl* Old, NamedDecl *New) {
50839213Sgibbs    return Conversions.replace(Old, New);
50959249Sphk  }
51039213Sgibbs
51139213Sgibbs  /// getVisibleConversionFunctions - get all conversion functions visible
51239213Sgibbs  /// in current class; including conversion function templates.
51339213Sgibbs  const UnresolvedSetImpl *getVisibleConversionFunctions();
51439213Sgibbs
51539213Sgibbs  /// addVisibleConversionFunction - Add a new conversion function to the
51639213Sgibbs  /// list of visible conversion functions.
51739213Sgibbs  void addVisibleConversionFunction(CXXConversionDecl *ConvDecl);
51859249Sphk
51939213Sgibbs  /// \brief Add a new conversion function template to the list of visible
52039213Sgibbs  /// conversion functions.
52139213Sgibbs  void addVisibleConversionFunction(FunctionTemplateDecl *ConvDecl);
52239213Sgibbs
52339213Sgibbs  /// addConversionFunction - Add a new conversion function to the
52439213Sgibbs  /// list of conversion functions.
52539213Sgibbs  void addConversionFunction(CXXConversionDecl *ConvDecl);
52639213Sgibbs
52739213Sgibbs  /// \brief Add a new conversion function template to the list of conversion
52839213Sgibbs  /// functions.
52939213Sgibbs  void addConversionFunction(FunctionTemplateDecl *ConvDecl);
53039213Sgibbs
53139213Sgibbs  /// isAggregate - Whether this class is an aggregate (C++
53239213Sgibbs  /// [dcl.init.aggr]), which is a class with no user-declared
53339213Sgibbs  /// constructors, no private or protected non-static data members,
53459249Sphk  /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1).
53539213Sgibbs  bool isAggregate() const { return Aggregate; }
53639213Sgibbs
53739213Sgibbs  /// setAggregate - Set whether this class is an aggregate (C++
53839213Sgibbs  /// [dcl.init.aggr]).
53939213Sgibbs  void setAggregate(bool Agg) { Aggregate = Agg; }
54039213Sgibbs
54139213Sgibbs  /// setMethodAsVirtual - Make input method virtual and set the necesssary
54259249Sphk  /// special function bits and other bits accordingly.
54339213Sgibbs  void setMethodAsVirtual(FunctionDecl *Method);
54459249Sphk
54559249Sphk  /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class
54639213Sgibbs  /// that is an aggregate that has no non-static non-POD data members, no
54750073Sken  /// reference data members, no user-defined copy assignment operator and no
54839213Sgibbs  /// user-defined destructor.
54939213Sgibbs  bool isPOD() const { return PlainOldData; }
55039213Sgibbs
55139213Sgibbs  /// setPOD - Set whether this class is a POD-type (C++ [class]p4).
55239213Sgibbs  void setPOD(bool POD) { PlainOldData = POD; }
55339213Sgibbs
55439213Sgibbs  /// isEmpty - Whether this class is empty (C++0x [meta.unary.prop]), which
55539213Sgibbs  /// means it has a virtual function, virtual base, data member (other than
55639213Sgibbs  /// 0-width bit-field) or inherits from a non-empty class. Does NOT include
55739213Sgibbs  /// a check for union-ness.
55839213Sgibbs  bool isEmpty() const { return Empty; }
55939213Sgibbs
56039213Sgibbs  /// Set whether this class is empty (C++0x [meta.unary.prop])
56159249Sphk  void setEmpty(bool Emp) { Empty = Emp; }
56239213Sgibbs
56339213Sgibbs  /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]),
56439213Sgibbs  /// which means that the class contains or inherits a virtual function.
56539213Sgibbs  bool isPolymorphic() const { return Polymorphic; }
56639213Sgibbs
56739213Sgibbs  /// setPolymorphic - Set whether this class is polymorphic (C++
56839213Sgibbs  /// [class.virtual]).
56939213Sgibbs  void setPolymorphic(bool Poly) { Polymorphic = Poly; }
57039213Sgibbs
57139213Sgibbs  /// isAbstract - Whether this class is abstract (C++ [class.abstract]),
57239213Sgibbs  /// which means that the class contains or inherits a pure virtual function.
57339213Sgibbs  bool isAbstract() const { return Abstract; }
57439213Sgibbs
57539213Sgibbs  /// setAbstract - Set whether this class is abstract (C++ [class.abstract])
57639213Sgibbs  void setAbstract(bool Abs) { Abstract = Abs; }
57739213Sgibbs
57839213Sgibbs  // hasTrivialConstructor - Whether this class has a trivial constructor
57939213Sgibbs  // (C++ [class.ctor]p5)
58039213Sgibbs  bool hasTrivialConstructor() const { return HasTrivialConstructor; }
58139213Sgibbs
58239213Sgibbs  // setHasTrivialConstructor - Set whether this class has a trivial constructor
58339213Sgibbs  // (C++ [class.ctor]p5)
58439213Sgibbs  void setHasTrivialConstructor(bool TC) { HasTrivialConstructor = TC; }
58559249Sphk
58639213Sgibbs  // hasTrivialCopyConstructor - Whether this class has a trivial copy
58739213Sgibbs  // constructor (C++ [class.copy]p6)
58859249Sphk  bool hasTrivialCopyConstructor() const { return HasTrivialCopyConstructor; }
58939213Sgibbs
59039213Sgibbs  // setHasTrivialCopyConstructor - Set whether this class has a trivial
59139213Sgibbs  // copy constructor (C++ [class.copy]p6)
59239213Sgibbs  void setHasTrivialCopyConstructor(bool TC) { HasTrivialCopyConstructor = TC; }
59339213Sgibbs
59439213Sgibbs  // hasTrivialCopyAssignment - Whether this class has a trivial copy
59539213Sgibbs  // assignment operator (C++ [class.copy]p11)
59639213Sgibbs  bool hasTrivialCopyAssignment() const { return HasTrivialCopyAssignment; }
59739213Sgibbs
59839213Sgibbs  // setHasTrivialCopyAssignment - Set whether this class has a
59946747Sken  // trivial copy assignment operator (C++ [class.copy]p11)
60046747Sken  void setHasTrivialCopyAssignment(bool TC) { HasTrivialCopyAssignment = TC; }
60139213Sgibbs
60239213Sgibbs  // hasTrivialDestructor - Whether this class has a trivial destructor
60339213Sgibbs  // (C++ [class.dtor]p3)
60439213Sgibbs  bool hasTrivialDestructor() const { return HasTrivialDestructor; }
60539213Sgibbs
60639213Sgibbs  // setHasTrivialDestructor - Set whether this class has a trivial destructor
60739213Sgibbs  // (C++ [class.dtor]p3)
60839213Sgibbs  void setHasTrivialDestructor(bool TC) { HasTrivialDestructor = TC; }
60959249Sphk
61039213Sgibbs  /// \brief If this record is an instantiation of a member class,
61139213Sgibbs  /// retrieves the member class from which it was instantiated.
61239213Sgibbs  ///
61339213Sgibbs  /// This routine will return non-NULL for (non-templated) member
61439213Sgibbs  /// classes of class templates. For example, given:
61539213Sgibbs  ///
61639213Sgibbs  /// \code
61739213Sgibbs  /// template<typename T>
61839213Sgibbs  /// struct X {
61939213Sgibbs  ///   struct A { };
62039213Sgibbs  /// };
62139213Sgibbs  /// \endcode
62239213Sgibbs  ///
62339213Sgibbs  /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
62439213Sgibbs  /// whose parent is the class template specialization X<int>. For
62539213Sgibbs  /// this declaration, getInstantiatedFromMemberClass() will return
62639213Sgibbs  /// the CXXRecordDecl X<T>::A. When a complete definition of
62739213Sgibbs  /// X<int>::A is required, it will be instantiated from the
62859249Sphk  /// declaration returned by getInstantiatedFromMemberClass().
62939213Sgibbs  CXXRecordDecl *getInstantiatedFromMemberClass() const;
63059249Sphk
63159249Sphk  /// \brief If this class is an instantiation of a member class of a
63259249Sphk  /// class template specialization, retrieves the member specialization
63359249Sphk  /// information.
63439213Sgibbs  MemberSpecializationInfo *getMemberSpecializationInfo() const;
63539213Sgibbs
63639213Sgibbs  /// \brief Specify that this record is an instantiation of the
63759249Sphk  /// member class RD.
63859249Sphk  void setInstantiationOfMemberClass(CXXRecordDecl *RD,
63959249Sphk                                     TemplateSpecializationKind TSK);
64039213Sgibbs
64159249Sphk  /// \brief Retrieves the class template that is described by this
64259249Sphk  /// class declaration.
64359249Sphk  ///
64439213Sgibbs  /// Every class template is represented as a ClassTemplateDecl and a
64559249Sphk  /// CXXRecordDecl. The former contains template properties (such as
64639213Sgibbs  /// the template parameter lists) while the latter contains the
64739213Sgibbs  /// actual description of the template's
64839213Sgibbs  /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
64939213Sgibbs  /// CXXRecordDecl that from a ClassTemplateDecl, while
65039213Sgibbs  /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
65139213Sgibbs  /// a CXXRecordDecl.
65239213Sgibbs  ClassTemplateDecl *getDescribedClassTemplate() const {
65339213Sgibbs    return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>();
65439213Sgibbs  }
65559249Sphk
65659249Sphk  void setDescribedClassTemplate(ClassTemplateDecl *Template) {
65759249Sphk    TemplateOrInstantiation = Template;
65839213Sgibbs  }
65939213Sgibbs
66039213Sgibbs  /// \brief Determine whether this particular class is a specialization or
66139213Sgibbs  /// instantiation of a class template or member class of a class template,
66239213Sgibbs  /// and how it was instantiated or specialized.
66339213Sgibbs  TemplateSpecializationKind getTemplateSpecializationKind() const;
66439213Sgibbs
66539213Sgibbs  /// \brief Set the kind of specialization or template instantiation this is.
66639213Sgibbs  void setTemplateSpecializationKind(TemplateSpecializationKind TSK);
66739213Sgibbs
66859249Sphk  /// getDefaultConstructor - Returns the default constructor for this class
66939213Sgibbs  CXXConstructorDecl *getDefaultConstructor(ASTContext &Context);
67039213Sgibbs
67139213Sgibbs  /// getDestructor - Returns the destructor decl for this class.
67239213Sgibbs  CXXDestructorDecl *getDestructor(ASTContext &Context);
67339213Sgibbs
67439213Sgibbs  /// isLocalClass - If the class is a local class [class.local], returns
67539213Sgibbs  /// the enclosing function declaration.
67639213Sgibbs  const FunctionDecl *isLocalClass() const {
67739213Sgibbs    if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
67839213Sgibbs      return RD->isLocalClass();
67939213Sgibbs
68039213Sgibbs    return dyn_cast<FunctionDecl>(getDeclContext());
68139213Sgibbs  }
68239213Sgibbs
68339213Sgibbs  /// \brief Determine whether this class is derived from the class \p Base.
68439213Sgibbs  ///
68539213Sgibbs  /// This routine only determines whether this class is derived from \p Base,
68639213Sgibbs  /// but does not account for factors that may make a Derived -> Base class
68739213Sgibbs  /// ill-formed, such as private/protected inheritance or multiple, ambiguous
68839213Sgibbs  /// base class subobjects.
68939213Sgibbs  ///
69039213Sgibbs  /// \param Base the base class we are searching for.
69139213Sgibbs  ///
69239213Sgibbs  /// \returns true if this class is derived from Base, false otherwise.
69350073Sken  bool isDerivedFrom(CXXRecordDecl *Base) const;
69450073Sken
69550073Sken  /// \brief Determine whether this class is derived from the type \p Base.
69650073Sken  ///
69750073Sken  /// This routine only determines whether this class is derived from \p Base,
69850073Sken  /// but does not account for factors that may make a Derived -> Base class
69950073Sken  /// ill-formed, such as private/protected inheritance or multiple, ambiguous
70050073Sken  /// base class subobjects.
70150073Sken  ///
70250073Sken  /// \param Base the base class we are searching for.
70350073Sken  ///
70450073Sken  /// \param Paths will contain the paths taken from the current class to the
70550073Sken  /// given \p Base class.
70650073Sken  ///
70750073Sken  /// \returns true if this class is derived from Base, false otherwise.
70850073Sken  ///
70950073Sken  /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than
71050073Sken  /// tangling input and output in \p Paths
71150073Sken  bool isDerivedFrom(CXXRecordDecl *Base, CXXBasePaths &Paths) const;
71250073Sken
71350073Sken  /// \brief Determine whether this class is provably not derived from
71450073Sken  /// the type \p Base.
71550073Sken  bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
71650073Sken
71750073Sken  /// \brief Function type used by forallBases() as a callback.
71850073Sken  ///
71950073Sken  /// \param Base the definition of the base class
72050073Sken  ///
72150073Sken  /// \returns true if this base matched the search criteria
72250073Sken  typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition,
72350073Sken                                   void *UserData);
72450073Sken
72550073Sken  /// \brief Determines if the given callback holds for all the direct
72650073Sken  /// or indirect base classes of this type.
72750073Sken  ///
72850073Sken  /// The class itself does not count as a base class.  This routine
72950073Sken  /// returns false if the class has non-computable base classes.
73050073Sken  ///
73150073Sken  /// \param AllowShortCircuit if false, forces the callback to be called
73250073Sken  /// for every base class, even if a dependent or non-matching base was
73350073Sken  /// found.
73450073Sken  bool forallBases(ForallBasesCallback *BaseMatches, void *UserData,
73550073Sken                   bool AllowShortCircuit = true) const;
73650073Sken
73750073Sken  /// \brief Function type used by lookupInBases() to determine whether a
73850073Sken  /// specific base class subobject matches the lookup criteria.
73950073Sken  ///
74050073Sken  /// \param Specifier the base-class specifier that describes the inheritance
74150073Sken  /// from the base class we are trying to match.
74250073Sken  ///
74350073Sken  /// \param Path the current path, from the most-derived class down to the
74450073Sken  /// base named by the \p Specifier.
74539213Sgibbs  ///
74639213Sgibbs  /// \param UserData a single pointer to user-specified data, provided to
74739213Sgibbs  /// lookupInBases().
74839213Sgibbs  ///
74939213Sgibbs  /// \returns true if this base matched the search criteria, false otherwise.
75039213Sgibbs  typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier,
75139213Sgibbs                                   CXXBasePath &Path,
75239213Sgibbs                                   void *UserData);
75339213Sgibbs
75439213Sgibbs  /// \brief Look for entities within the base classes of this C++ class,
75539213Sgibbs  /// transitively searching all base class subobjects.
75639213Sgibbs  ///
75739213Sgibbs  /// This routine uses the callback function \p BaseMatches to find base
75839213Sgibbs  /// classes meeting some search criteria, walking all base class subobjects
75939213Sgibbs  /// and populating the given \p Paths structure with the paths through the
76039213Sgibbs  /// inheritance hierarchy that resulted in a match. On a successful search,
76139213Sgibbs  /// the \p Paths structure can be queried to retrieve the matching paths and
76239213Sgibbs  /// to determine if there were any ambiguities.
76339213Sgibbs  ///
76439213Sgibbs  /// \param BaseMatches callback function used to determine whether a given
76539213Sgibbs  /// base matches the user-defined search criteria.
76639213Sgibbs  ///
76739213Sgibbs  /// \param UserData user data pointer that will be provided to \p BaseMatches.
76839213Sgibbs  ///
76939213Sgibbs  /// \param Paths used to record the paths from this class to its base class
77039213Sgibbs  /// subobjects that match the search criteria.
771  ///
772  /// \returns true if there exists any path from this class to a base class
773  /// subobject that matches the search criteria.
774  bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData,
775                     CXXBasePaths &Paths) const;
776
777  /// \brief Base-class lookup callback that determines whether the given
778  /// base class specifier refers to a specific class declaration.
779  ///
780  /// This callback can be used with \c lookupInBases() to determine whether
781  /// a given derived class has is a base class subobject of a particular type.
782  /// The user data pointer should refer to the canonical CXXRecordDecl of the
783  /// base class that we are searching for.
784  static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
785                            CXXBasePath &Path, void *BaseRecord);
786
787  /// \brief Base-class lookup callback that determines whether there exists
788  /// a tag with the given name.
789  ///
790  /// This callback can be used with \c lookupInBases() to find tag members
791  /// of the given name within a C++ class hierarchy. The user data pointer
792  /// is an opaque \c DeclarationName pointer.
793  static bool FindTagMember(const CXXBaseSpecifier *Specifier,
794                            CXXBasePath &Path, void *Name);
795
796  /// \brief Base-class lookup callback that determines whether there exists
797  /// a member with the given name.
798  ///
799  /// This callback can be used with \c lookupInBases() to find members
800  /// of the given name within a C++ class hierarchy. The user data pointer
801  /// is an opaque \c DeclarationName pointer.
802  static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
803                                 CXXBasePath &Path, void *Name);
804
805  /// \brief Base-class lookup callback that determines whether there exists
806  /// a member with the given name that can be used in a nested-name-specifier.
807  ///
808  /// This callback can be used with \c lookupInBases() to find membes of
809  /// the given name within a C++ class hierarchy that can occur within
810  /// nested-name-specifiers.
811  static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier,
812                                            CXXBasePath &Path,
813                                            void *UserData);
814
815  /// viewInheritance - Renders and displays an inheritance diagram
816  /// for this C++ class and all of its base classes (transitively) using
817  /// GraphViz.
818  void viewInheritance(ASTContext& Context) const;
819
820  /// MergeAccess - Calculates the access of a decl that is reached
821  /// along a path.
822  static AccessSpecifier MergeAccess(AccessSpecifier PathAccess,
823                                     AccessSpecifier DeclAccess) {
824    assert(DeclAccess != AS_none);
825    if (DeclAccess == AS_private) return AS_none;
826    return (PathAccess > DeclAccess ? PathAccess : DeclAccess);
827  }
828
829  static bool classof(const Decl *D) {
830    return D->getKind() == CXXRecord ||
831           D->getKind() == ClassTemplateSpecialization ||
832           D->getKind() == ClassTemplatePartialSpecialization;
833  }
834  static bool classof(const CXXRecordDecl *D) { return true; }
835  static bool classof(const ClassTemplateSpecializationDecl *D) {
836    return true;
837  }
838};
839
840/// CXXMethodDecl - Represents a static or instance method of a
841/// struct/union/class.
842class CXXMethodDecl : public FunctionDecl {
843protected:
844  CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation L,
845                DeclarationName N, QualType T, TypeSourceInfo *TInfo,
846                bool isStatic, bool isInline)
847    : FunctionDecl(DK, RD, L, N, T, TInfo, (isStatic ? Static : None),
848                   isInline) {}
849
850public:
851  static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
852                              SourceLocation L, DeclarationName N,
853                              QualType T, TypeSourceInfo *TInfo,
854                              bool isStatic = false,
855                              bool isInline = false);
856
857  bool isStatic() const { return getStorageClass() == Static; }
858  bool isInstance() const { return !isStatic(); }
859
860  bool isVirtual() const {
861    CXXMethodDecl *CD =
862      cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl());
863
864    if (CD->isVirtualAsWritten())
865      return true;
866
867    return (CD->begin_overridden_methods() != CD->end_overridden_methods());
868  }
869
870  /// \brief Determine whether this is a usual deallocation function
871  /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded
872  /// delete or delete[] operator with a particular signature.
873  bool isUsualDeallocationFunction() const;
874
875  const CXXMethodDecl *getCanonicalDecl() const {
876    return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
877  }
878  CXXMethodDecl *getCanonicalDecl() {
879    return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
880  }
881
882  ///
883  void addOverriddenMethod(const CXXMethodDecl *MD);
884
885  typedef const CXXMethodDecl ** method_iterator;
886
887  method_iterator begin_overridden_methods() const;
888  method_iterator end_overridden_methods() const;
889
890  /// getParent - Returns the parent of this method declaration, which
891  /// is the class in which this method is defined.
892  const CXXRecordDecl *getParent() const {
893    return cast<CXXRecordDecl>(FunctionDecl::getParent());
894  }
895
896  /// getParent - Returns the parent of this method declaration, which
897  /// is the class in which this method is defined.
898  CXXRecordDecl *getParent() {
899    return const_cast<CXXRecordDecl *>(
900             cast<CXXRecordDecl>(FunctionDecl::getParent()));
901  }
902
903  /// getThisType - Returns the type of 'this' pointer.
904  /// Should only be called for instance methods.
905  QualType getThisType(ASTContext &C) const;
906
907  unsigned getTypeQualifiers() const {
908    return getType()->getAs<FunctionProtoType>()->getTypeQuals();
909  }
910
911  bool hasInlineBody() const;
912
913  // Implement isa/cast/dyncast/etc.
914  static bool classof(const Decl *D) {
915    return D->getKind() >= CXXMethod && D->getKind() <= CXXConversion;
916  }
917  static bool classof(const CXXMethodDecl *D) { return true; }
918};
919
920/// CXXBaseOrMemberInitializer - Represents a C++ base or member
921/// initializer, which is part of a constructor initializer that
922/// initializes one non-static member variable or one base class. For
923/// example, in the following, both 'A(a)' and 'f(3.14159)' are member
924/// initializers:
925///
926/// @code
927/// class A { };
928/// class B : public A {
929///   float f;
930/// public:
931///   B(A& a) : A(a), f(3.14159) { }
932/// };
933/// @endcode
934class CXXBaseOrMemberInitializer {
935  /// \brief Either the base class name (stored as a TypeSourceInfo*) or the
936  /// field being initialized.
937  llvm::PointerUnion<TypeSourceInfo *, FieldDecl *> BaseOrMember;
938
939  /// \brief The source location for the field name.
940  SourceLocation MemberLocation;
941
942  /// Args - The arguments used to initialize the base or member.
943  Stmt **Args;
944  unsigned NumArgs;
945
946  /// \brief Stores either the constructor to call to initialize this base or
947  /// member (a CXXConstructorDecl pointer), or stores the anonymous union of
948  /// which the initialized value is a member.
949  ///
950  /// When the value is a FieldDecl pointer, 'BaseOrMember' is class's
951  /// anonymous union data member, this field holds the FieldDecl for the
952  /// member of the anonymous union being initialized.
953  /// @code
954  /// struct X {
955  ///   X() : au_i1(123) {}
956  ///   union {
957  ///     int au_i1;
958  ///     float au_f1;
959  ///   };
960  /// };
961  /// @endcode
962  /// In above example, BaseOrMember holds the field decl. for anonymous union
963  /// and AnonUnionMember holds field decl for au_i1.
964  llvm::PointerUnion<CXXConstructorDecl *, FieldDecl *> CtorOrAnonUnion;
965
966  /// LParenLoc - Location of the left paren of the ctor-initializer.
967  SourceLocation LParenLoc;
968
969  /// RParenLoc - Location of the right paren of the ctor-initializer.
970  SourceLocation RParenLoc;
971
972public:
973  /// CXXBaseOrMemberInitializer - Creates a new base-class initializer.
974  explicit
975  CXXBaseOrMemberInitializer(ASTContext &Context,
976                             TypeSourceInfo *TInfo, CXXConstructorDecl *C,
977                             SourceLocation L,
978                             Expr **Args, unsigned NumArgs,
979                             SourceLocation R);
980
981  /// CXXBaseOrMemberInitializer - Creates a new member initializer.
982  explicit
983  CXXBaseOrMemberInitializer(ASTContext &Context,
984                             FieldDecl *Member, SourceLocation MemberLoc,
985                             CXXConstructorDecl *C, SourceLocation L,
986                             Expr **Args, unsigned NumArgs,
987                             SourceLocation R);
988
989  /// \brief Destroy the base or member initializer.
990  void Destroy(ASTContext &Context);
991
992  /// arg_iterator - Iterates through the member initialization
993  /// arguments.
994  typedef ExprIterator arg_iterator;
995
996  /// arg_const_iterator - Iterates through the member initialization
997  /// arguments.
998  typedef ConstExprIterator const_arg_iterator;
999
1000  /// isBaseInitializer - Returns true when this initializer is
1001  /// initializing a base class.
1002  bool isBaseInitializer() const { return BaseOrMember.is<TypeSourceInfo*>(); }
1003
1004  /// isMemberInitializer - Returns true when this initializer is
1005  /// initializing a non-static data member.
1006  bool isMemberInitializer() const { return BaseOrMember.is<FieldDecl*>(); }
1007
1008  /// If this is a base class initializer, returns the type of the
1009  /// base class with location information. Otherwise, returns an NULL
1010  /// type location.
1011  TypeLoc getBaseClassLoc() const;
1012
1013  /// If this is a base class initializer, returns the type of the base class.
1014  /// Otherwise, returns NULL.
1015  const Type *getBaseClass() const;
1016  Type *getBaseClass();
1017
1018  /// \brief Returns the declarator information for a base class initializer.
1019  TypeSourceInfo *getBaseClassInfo() const {
1020    return BaseOrMember.dyn_cast<TypeSourceInfo *>();
1021  }
1022
1023  /// getMember - If this is a member initializer, returns the
1024  /// declaration of the non-static data member being
1025  /// initialized. Otherwise, returns NULL.
1026  FieldDecl *getMember() {
1027    if (isMemberInitializer())
1028      return BaseOrMember.get<FieldDecl*>();
1029    else
1030      return 0;
1031  }
1032
1033  SourceLocation getMemberLocation() const {
1034    return MemberLocation;
1035  }
1036
1037  void setMember(FieldDecl *Member) {
1038    assert(isMemberInitializer());
1039    BaseOrMember = Member;
1040  }
1041
1042  /// \brief Determine the source location of the initializer.
1043  SourceLocation getSourceLocation() const;
1044
1045  /// \brief Determine the source range covering the entire initializer.
1046  SourceRange getSourceRange() const;
1047
1048  FieldDecl *getAnonUnionMember() const {
1049    return CtorOrAnonUnion.dyn_cast<FieldDecl *>();
1050  }
1051  void setAnonUnionMember(FieldDecl *anonMember) {
1052    CtorOrAnonUnion = anonMember;
1053  }
1054
1055  const CXXConstructorDecl *getConstructor() const {
1056    return CtorOrAnonUnion.dyn_cast<CXXConstructorDecl *>();
1057  }
1058
1059  SourceLocation getLParenLoc() const { return LParenLoc; }
1060  SourceLocation getRParenLoc() const { return RParenLoc; }
1061
1062  /// arg_begin() - Retrieve an iterator to the first initializer argument.
1063  arg_iterator       arg_begin()       { return Args; }
1064  /// arg_begin() - Retrieve an iterator to the first initializer argument.
1065  const_arg_iterator const_arg_begin() const { return Args; }
1066
1067  /// arg_end() - Retrieve an iterator past the last initializer argument.
1068  arg_iterator       arg_end()       { return Args + NumArgs; }
1069  /// arg_end() - Retrieve an iterator past the last initializer argument.
1070  const_arg_iterator const_arg_end() const { return Args + NumArgs; }
1071
1072  /// getNumArgs - Determine the number of arguments used to
1073  /// initialize the member or base.
1074  unsigned getNumArgs() const { return NumArgs; }
1075};
1076
1077/// CXXConstructorDecl - Represents a C++ constructor within a
1078/// class. For example:
1079///
1080/// @code
1081/// class X {
1082/// public:
1083///   explicit X(int); // represented by a CXXConstructorDecl.
1084/// };
1085/// @endcode
1086class CXXConstructorDecl : public CXXMethodDecl {
1087  /// Explicit - Whether this constructor is explicit.
1088  bool Explicit : 1;
1089
1090  /// ImplicitlyDefined - Whether this constructor was implicitly
1091  /// defined by the compiler. When false, the constructor was defined
1092  /// by the user. In C++03, this flag will have the same value as
1093  /// Implicit. In C++0x, however, a constructor that is
1094  /// explicitly defaulted (i.e., defined with " = default") will have
1095  /// @c !Implicit && ImplicitlyDefined.
1096  bool ImplicitlyDefined : 1;
1097
1098  /// Support for base and member initializers.
1099  /// BaseOrMemberInitializers - The arguments used to initialize the base
1100  /// or member.
1101  CXXBaseOrMemberInitializer **BaseOrMemberInitializers;
1102  unsigned NumBaseOrMemberInitializers;
1103
1104  CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation L,
1105                     DeclarationName N, QualType T, TypeSourceInfo *TInfo,
1106                     bool isExplicit, bool isInline, bool isImplicitlyDeclared)
1107    : CXXMethodDecl(CXXConstructor, RD, L, N, T, TInfo, false, isInline),
1108      Explicit(isExplicit), ImplicitlyDefined(false),
1109      BaseOrMemberInitializers(0), NumBaseOrMemberInitializers(0) {
1110    setImplicit(isImplicitlyDeclared);
1111  }
1112  virtual void Destroy(ASTContext& C);
1113
1114public:
1115  static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1116                                    SourceLocation L, DeclarationName N,
1117                                    QualType T, TypeSourceInfo *TInfo,
1118                                    bool isExplicit,
1119                                    bool isInline, bool isImplicitlyDeclared);
1120
1121  /// isExplicit - Whether this constructor was marked "explicit" or not.
1122  bool isExplicit() const { return Explicit; }
1123
1124  /// isImplicitlyDefined - Whether this constructor was implicitly
1125  /// defined. If false, then this constructor was defined by the
1126  /// user. This operation can only be invoked if the constructor has
1127  /// already been defined.
1128  bool isImplicitlyDefined(ASTContext &C) const {
1129    assert(isThisDeclarationADefinition() &&
1130           "Can only get the implicit-definition flag once the "
1131           "constructor has been defined");
1132    return ImplicitlyDefined;
1133  }
1134
1135  /// setImplicitlyDefined - Set whether this constructor was
1136  /// implicitly defined or not.
1137  void setImplicitlyDefined(bool ID) {
1138    assert(isThisDeclarationADefinition() &&
1139           "Can only set the implicit-definition flag once the constructor "
1140           "has been defined");
1141    ImplicitlyDefined = ID;
1142  }
1143
1144  /// init_iterator - Iterates through the member/base initializer list.
1145  typedef CXXBaseOrMemberInitializer **init_iterator;
1146
1147  /// init_const_iterator - Iterates through the memberbase initializer list.
1148  typedef CXXBaseOrMemberInitializer * const * init_const_iterator;
1149
1150  /// init_begin() - Retrieve an iterator to the first initializer.
1151  init_iterator       init_begin()       { return BaseOrMemberInitializers; }
1152  /// begin() - Retrieve an iterator to the first initializer.
1153  init_const_iterator init_begin() const { return BaseOrMemberInitializers; }
1154
1155  /// init_end() - Retrieve an iterator past the last initializer.
1156  init_iterator       init_end()       {
1157    return BaseOrMemberInitializers + NumBaseOrMemberInitializers;
1158  }
1159  /// end() - Retrieve an iterator past the last initializer.
1160  init_const_iterator init_end() const {
1161    return BaseOrMemberInitializers + NumBaseOrMemberInitializers;
1162  }
1163
1164  /// getNumArgs - Determine the number of arguments used to
1165  /// initialize the member or base.
1166  unsigned getNumBaseOrMemberInitializers() const {
1167      return NumBaseOrMemberInitializers;
1168  }
1169
1170  void setNumBaseOrMemberInitializers(unsigned numBaseOrMemberInitializers) {
1171    NumBaseOrMemberInitializers = numBaseOrMemberInitializers;
1172  }
1173
1174  void setBaseOrMemberInitializers(CXXBaseOrMemberInitializer ** initializers) {
1175    BaseOrMemberInitializers = initializers;
1176  }
1177  /// isDefaultConstructor - Whether this constructor is a default
1178  /// constructor (C++ [class.ctor]p5), which can be used to
1179  /// default-initialize a class of this type.
1180  bool isDefaultConstructor() const;
1181
1182  /// isCopyConstructor - Whether this constructor is a copy
1183  /// constructor (C++ [class.copy]p2, which can be used to copy the
1184  /// class. @p TypeQuals will be set to the qualifiers on the
1185  /// argument type. For example, @p TypeQuals would be set to @c
1186  /// QualType::Const for the following copy constructor:
1187  ///
1188  /// @code
1189  /// class X {
1190  /// public:
1191  ///   X(const X&);
1192  /// };
1193  /// @endcode
1194  bool isCopyConstructor(unsigned &TypeQuals) const;
1195
1196  /// isCopyConstructor - Whether this constructor is a copy
1197  /// constructor (C++ [class.copy]p2, which can be used to copy the
1198  /// class.
1199  bool isCopyConstructor() const {
1200    unsigned TypeQuals = 0;
1201    return isCopyConstructor(TypeQuals);
1202  }
1203
1204  /// isConvertingConstructor - Whether this constructor is a
1205  /// converting constructor (C++ [class.conv.ctor]), which can be
1206  /// used for user-defined conversions.
1207  bool isConvertingConstructor(bool AllowExplicit) const;
1208
1209  /// \brief Determine whether this is a member template specialization that
1210  /// looks like a copy constructor. Such constructors are never used to copy
1211  /// an object.
1212  bool isCopyConstructorLikeSpecialization() const;
1213
1214  // Implement isa/cast/dyncast/etc.
1215  static bool classof(const Decl *D) {
1216    return D->getKind() == CXXConstructor;
1217  }
1218  static bool classof(const CXXConstructorDecl *D) { return true; }
1219};
1220
1221/// CXXDestructorDecl - Represents a C++ destructor within a
1222/// class. For example:
1223///
1224/// @code
1225/// class X {
1226/// public:
1227///   ~X(); // represented by a CXXDestructorDecl.
1228/// };
1229/// @endcode
1230class CXXDestructorDecl : public CXXMethodDecl {
1231  /// ImplicitlyDefined - Whether this destructor was implicitly
1232  /// defined by the compiler. When false, the destructor was defined
1233  /// by the user. In C++03, this flag will have the same value as
1234  /// Implicit. In C++0x, however, a destructor that is
1235  /// explicitly defaulted (i.e., defined with " = default") will have
1236  /// @c !Implicit && ImplicitlyDefined.
1237  bool ImplicitlyDefined : 1;
1238
1239  FunctionDecl *OperatorDelete;
1240
1241  CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation L,
1242                    DeclarationName N, QualType T,
1243                    bool isInline, bool isImplicitlyDeclared)
1244    : CXXMethodDecl(CXXDestructor, RD, L, N, T, /*TInfo=*/0, false, isInline),
1245      ImplicitlyDefined(false), OperatorDelete(0) {
1246    setImplicit(isImplicitlyDeclared);
1247  }
1248
1249public:
1250  static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1251                                   SourceLocation L, DeclarationName N,
1252                                   QualType T, bool isInline,
1253                                   bool isImplicitlyDeclared);
1254
1255  /// isImplicitlyDefined - Whether this destructor was implicitly
1256  /// defined. If false, then this destructor was defined by the
1257  /// user. This operation can only be invoked if the destructor has
1258  /// already been defined.
1259  bool isImplicitlyDefined() const {
1260    assert(isThisDeclarationADefinition() &&
1261           "Can only get the implicit-definition flag once the destructor has been defined");
1262    return ImplicitlyDefined;
1263  }
1264
1265  /// setImplicitlyDefined - Set whether this destructor was
1266  /// implicitly defined or not.
1267  void setImplicitlyDefined(bool ID) {
1268    assert(isThisDeclarationADefinition() &&
1269           "Can only set the implicit-definition flag once the destructor has been defined");
1270    ImplicitlyDefined = ID;
1271  }
1272
1273  void setOperatorDelete(FunctionDecl *OD) { OperatorDelete = OD; }
1274  const FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1275
1276  // Implement isa/cast/dyncast/etc.
1277  static bool classof(const Decl *D) {
1278    return D->getKind() == CXXDestructor;
1279  }
1280  static bool classof(const CXXDestructorDecl *D) { return true; }
1281};
1282
1283/// CXXConversionDecl - Represents a C++ conversion function within a
1284/// class. For example:
1285///
1286/// @code
1287/// class X {
1288/// public:
1289///   operator bool();
1290/// };
1291/// @endcode
1292class CXXConversionDecl : public CXXMethodDecl {
1293  /// Explicit - Whether this conversion function is marked
1294  /// "explicit", meaning that it can only be applied when the user
1295  /// explicitly wrote a cast. This is a C++0x feature.
1296  bool Explicit : 1;
1297
1298  CXXConversionDecl(CXXRecordDecl *RD, SourceLocation L,
1299                    DeclarationName N, QualType T, TypeSourceInfo *TInfo,
1300                    bool isInline, bool isExplicit)
1301    : CXXMethodDecl(CXXConversion, RD, L, N, T, TInfo, false, isInline),
1302      Explicit(isExplicit) { }
1303
1304public:
1305  static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1306                                   SourceLocation L, DeclarationName N,
1307                                   QualType T, TypeSourceInfo *TInfo,
1308                                   bool isInline, bool isExplicit);
1309
1310  /// isExplicit - Whether this is an explicit conversion operator
1311  /// (C++0x only). Explicit conversion operators are only considered
1312  /// when the user has explicitly written a cast.
1313  bool isExplicit() const { return Explicit; }
1314
1315  /// getConversionType - Returns the type that this conversion
1316  /// function is converting to.
1317  QualType getConversionType() const {
1318    return getType()->getAs<FunctionType>()->getResultType();
1319  }
1320
1321  // Implement isa/cast/dyncast/etc.
1322  static bool classof(const Decl *D) {
1323    return D->getKind() == CXXConversion;
1324  }
1325  static bool classof(const CXXConversionDecl *D) { return true; }
1326};
1327
1328/// FriendDecl - Represents the declaration of a friend entity,
1329/// which can be a function, a type, or a templated function or type.
1330//  For example:
1331///
1332/// @code
1333/// template <typename T> class A {
1334///   friend int foo(T);
1335///   friend class B;
1336///   friend T; // only in C++0x
1337///   template <typename U> friend class C;
1338///   template <typename U> friend A& operator+=(A&, const U&) { ... }
1339/// };
1340/// @endcode
1341///
1342/// The semantic context of a friend decl is its declaring class.
1343class FriendDecl : public Decl {
1344public:
1345  typedef llvm::PointerUnion<NamedDecl*,Type*> FriendUnion;
1346
1347private:
1348  // The declaration that's a friend of this class.
1349  FriendUnion Friend;
1350
1351  // Location of the 'friend' specifier.
1352  SourceLocation FriendLoc;
1353
1354  // FIXME: Hack to keep track of whether this was a friend function
1355  // template specialization.
1356  bool WasSpecialization;
1357
1358  FriendDecl(DeclContext *DC, SourceLocation L, FriendUnion Friend,
1359             SourceLocation FriendL)
1360    : Decl(Decl::Friend, DC, L),
1361      Friend(Friend),
1362      FriendLoc(FriendL),
1363      WasSpecialization(false) {
1364  }
1365
1366public:
1367  static FriendDecl *Create(ASTContext &C, DeclContext *DC,
1368                            SourceLocation L, FriendUnion Friend_,
1369                            SourceLocation FriendL);
1370
1371  /// If this friend declaration names an (untemplated but
1372  /// possibly dependent) type, return the type;  otherwise
1373  /// return null.  This is used only for C++0x's unelaborated
1374  /// friend type declarations.
1375  Type *getFriendType() const {
1376    return Friend.dyn_cast<Type*>();
1377  }
1378
1379  /// If this friend declaration doesn't name an unelaborated
1380  /// type, return the inner declaration.
1381  NamedDecl *getFriendDecl() const {
1382    return Friend.dyn_cast<NamedDecl*>();
1383  }
1384
1385  /// Retrieves the location of the 'friend' keyword.
1386  SourceLocation getFriendLoc() const {
1387    return FriendLoc;
1388  }
1389
1390  bool wasSpecialization() const { return WasSpecialization; }
1391  void setSpecialization(bool WS) { WasSpecialization = WS; }
1392
1393  // Implement isa/cast/dyncast/etc.
1394  static bool classof(const Decl *D) {
1395    return D->getKind() == Decl::Friend;
1396  }
1397  static bool classof(const FriendDecl *D) { return true; }
1398};
1399
1400/// LinkageSpecDecl - This represents a linkage specification.  For example:
1401///   extern "C" void foo();
1402///
1403class LinkageSpecDecl : public Decl, public DeclContext {
1404public:
1405  /// LanguageIDs - Used to represent the language in a linkage
1406  /// specification.  The values are part of the serialization abi for
1407  /// ASTs and cannot be changed without altering that abi.  To help
1408  /// ensure a stable abi for this, we choose the DW_LANG_ encodings
1409  /// from the dwarf standard.
1410  enum LanguageIDs { lang_c = /* DW_LANG_C */ 0x0002,
1411  lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004 };
1412private:
1413  /// Language - The language for this linkage specification.
1414  LanguageIDs Language;
1415
1416  /// HadBraces - Whether this linkage specification had curly braces or not.
1417  bool HadBraces : 1;
1418
1419  LinkageSpecDecl(DeclContext *DC, SourceLocation L, LanguageIDs lang,
1420                  bool Braces)
1421    : Decl(LinkageSpec, DC, L),
1422      DeclContext(LinkageSpec), Language(lang), HadBraces(Braces) { }
1423
1424public:
1425  static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
1426                                 SourceLocation L, LanguageIDs Lang,
1427                                 bool Braces);
1428
1429  LanguageIDs getLanguage() const { return Language; }
1430
1431  /// hasBraces - Determines whether this linkage specification had
1432  /// braces in its syntactic form.
1433  bool hasBraces() const { return HadBraces; }
1434
1435  static bool classof(const Decl *D) {
1436    return D->getKind() == LinkageSpec;
1437  }
1438  static bool classof(const LinkageSpecDecl *D) { return true; }
1439  static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
1440    return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
1441  }
1442  static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
1443    return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
1444  }
1445};
1446
1447/// UsingDirectiveDecl - Represents C++ using-directive. For example:
1448///
1449///    using namespace std;
1450///
1451// NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide
1452// artificial name, for all using-directives in order to store
1453// them in DeclContext effectively.
1454class UsingDirectiveDecl : public NamedDecl {
1455
1456  /// SourceLocation - Location of 'namespace' token.
1457  SourceLocation NamespaceLoc;
1458
1459  /// \brief The source range that covers the nested-name-specifier
1460  /// preceding the namespace name.
1461  SourceRange QualifierRange;
1462
1463  /// \brief The nested-name-specifier that precedes the namespace
1464  /// name, if any.
1465  NestedNameSpecifier *Qualifier;
1466
1467  /// IdentLoc - Location of nominated namespace-name identifier.
1468  // FIXME: We don't store location of scope specifier.
1469  SourceLocation IdentLoc;
1470
1471  /// NominatedNamespace - Namespace nominated by using-directive.
1472  NamedDecl *NominatedNamespace;
1473
1474  /// Enclosing context containing both using-directive and nominated
1475  /// namespace.
1476  DeclContext *CommonAncestor;
1477
1478  /// getUsingDirectiveName - Returns special DeclarationName used by
1479  /// using-directives. This is only used by DeclContext for storing
1480  /// UsingDirectiveDecls in its lookup structure.
1481  static DeclarationName getName() {
1482    return DeclarationName::getUsingDirectiveName();
1483  }
1484
1485  UsingDirectiveDecl(DeclContext *DC, SourceLocation L,
1486                     SourceLocation NamespcLoc,
1487                     SourceRange QualifierRange,
1488                     NestedNameSpecifier *Qualifier,
1489                     SourceLocation IdentLoc,
1490                     NamedDecl *Nominated,
1491                     DeclContext *CommonAncestor)
1492    : NamedDecl(Decl::UsingDirective, DC, L, getName()),
1493      NamespaceLoc(NamespcLoc), QualifierRange(QualifierRange),
1494      Qualifier(Qualifier), IdentLoc(IdentLoc),
1495      NominatedNamespace(Nominated),
1496      CommonAncestor(CommonAncestor) {
1497  }
1498
1499public:
1500  /// \brief Retrieve the source range of the nested-name-specifier
1501  /// that qualifiers the namespace name.
1502  SourceRange getQualifierRange() const { return QualifierRange; }
1503
1504  /// \brief Retrieve the nested-name-specifier that qualifies the
1505  /// name of the namespace.
1506  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1507
1508  NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
1509  const NamedDecl *getNominatedNamespaceAsWritten() const {
1510    return NominatedNamespace;
1511  }
1512
1513  /// getNominatedNamespace - Returns namespace nominated by using-directive.
1514  NamespaceDecl *getNominatedNamespace();
1515
1516  const NamespaceDecl *getNominatedNamespace() const {
1517    return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
1518  }
1519
1520  /// getCommonAncestor - returns common ancestor context of using-directive,
1521  /// and nominated by it namespace.
1522  DeclContext *getCommonAncestor() { return CommonAncestor; }
1523  const DeclContext *getCommonAncestor() const { return CommonAncestor; }
1524
1525  /// getNamespaceKeyLocation - Returns location of namespace keyword.
1526  SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
1527
1528  /// getIdentLocation - Returns location of identifier.
1529  SourceLocation getIdentLocation() const { return IdentLoc; }
1530
1531  static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
1532                                    SourceLocation L,
1533                                    SourceLocation NamespaceLoc,
1534                                    SourceRange QualifierRange,
1535                                    NestedNameSpecifier *Qualifier,
1536                                    SourceLocation IdentLoc,
1537                                    NamedDecl *Nominated,
1538                                    DeclContext *CommonAncestor);
1539
1540  static bool classof(const Decl *D) {
1541    return D->getKind() == Decl::UsingDirective;
1542  }
1543  static bool classof(const UsingDirectiveDecl *D) { return true; }
1544
1545  // Friend for getUsingDirectiveName.
1546  friend class DeclContext;
1547};
1548
1549/// NamespaceAliasDecl - Represents a C++ namespace alias. For example:
1550///
1551/// @code
1552/// namespace Foo = Bar;
1553/// @endcode
1554class NamespaceAliasDecl : public NamedDecl {
1555  SourceLocation AliasLoc;
1556
1557  /// \brief The source range that covers the nested-name-specifier
1558  /// preceding the namespace name.
1559  SourceRange QualifierRange;
1560
1561  /// \brief The nested-name-specifier that precedes the namespace
1562  /// name, if any.
1563  NestedNameSpecifier *Qualifier;
1564
1565  /// IdentLoc - Location of namespace identifier.
1566  SourceLocation IdentLoc;
1567
1568  /// Namespace - The Decl that this alias points to. Can either be a
1569  /// NamespaceDecl or a NamespaceAliasDecl.
1570  NamedDecl *Namespace;
1571
1572  NamespaceAliasDecl(DeclContext *DC, SourceLocation L,
1573                     SourceLocation AliasLoc, IdentifierInfo *Alias,
1574                     SourceRange QualifierRange,
1575                     NestedNameSpecifier *Qualifier,
1576                     SourceLocation IdentLoc, NamedDecl *Namespace)
1577    : NamedDecl(Decl::NamespaceAlias, DC, L, Alias), AliasLoc(AliasLoc),
1578      QualifierRange(QualifierRange), Qualifier(Qualifier),
1579      IdentLoc(IdentLoc), Namespace(Namespace) { }
1580
1581public:
1582  /// \brief Retrieve the source range of the nested-name-specifier
1583  /// that qualifiers the namespace name.
1584  SourceRange getQualifierRange() const { return QualifierRange; }
1585
1586  /// \brief Retrieve the nested-name-specifier that qualifies the
1587  /// name of the namespace.
1588  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1589
1590  NamespaceDecl *getNamespace() {
1591    if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
1592      return AD->getNamespace();
1593
1594    return cast<NamespaceDecl>(Namespace);
1595  }
1596
1597  const NamespaceDecl *getNamespace() const {
1598    return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
1599  }
1600
1601  /// \brief Retrieve the namespace that this alias refers to, which
1602  /// may either be a NamespaceDecl or a NamespaceAliasDecl.
1603  NamedDecl *getAliasedNamespace() const { return Namespace; }
1604
1605  static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
1606                                    SourceLocation L, SourceLocation AliasLoc,
1607                                    IdentifierInfo *Alias,
1608                                    SourceRange QualifierRange,
1609                                    NestedNameSpecifier *Qualifier,
1610                                    SourceLocation IdentLoc,
1611                                    NamedDecl *Namespace);
1612
1613  static bool classof(const Decl *D) {
1614    return D->getKind() == Decl::NamespaceAlias;
1615  }
1616  static bool classof(const NamespaceAliasDecl *D) { return true; }
1617};
1618
1619/// UsingShadowDecl - Represents a shadow declaration introduced into
1620/// a scope by a (resolved) using declaration.  For example,
1621///
1622/// namespace A {
1623///   void foo();
1624/// }
1625/// namespace B {
1626///   using A::foo(); // <- a UsingDecl
1627///                   // Also creates a UsingShadowDecl for A::foo in B
1628/// }
1629///
1630class UsingShadowDecl : public NamedDecl {
1631  /// The referenced declaration.
1632  NamedDecl *Underlying;
1633
1634  /// The using declaration which introduced this decl.
1635  UsingDecl *Using;
1636
1637  UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using,
1638                  NamedDecl *Target)
1639    : NamedDecl(UsingShadow, DC, Loc, Target->getDeclName()),
1640      Underlying(Target), Using(Using) {
1641    IdentifierNamespace = Target->getIdentifierNamespace();
1642    setImplicit();
1643  }
1644
1645public:
1646  static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
1647                                 SourceLocation Loc, UsingDecl *Using,
1648                                 NamedDecl *Target) {
1649    return new (C) UsingShadowDecl(DC, Loc, Using, Target);
1650  }
1651
1652  /// Gets the underlying declaration which has been brought into the
1653  /// local scope.
1654  NamedDecl *getTargetDecl() const {
1655    return Underlying;
1656  }
1657
1658  /// Gets the using declaration to which this declaration is tied.
1659  UsingDecl *getUsingDecl() const {
1660    return Using;
1661  }
1662
1663  static bool classof(const Decl *D) {
1664    return D->getKind() == Decl::UsingShadow;
1665  }
1666  static bool classof(const UsingShadowDecl *D) { return true; }
1667};
1668
1669/// UsingDecl - Represents a C++ using-declaration. For example:
1670///    using someNameSpace::someIdentifier;
1671class UsingDecl : public NamedDecl {
1672  /// \brief The source range that covers the nested-name-specifier
1673  /// preceding the declaration name.
1674  SourceRange NestedNameRange;
1675
1676  /// \brief The source location of the "using" location itself.
1677  SourceLocation UsingLocation;
1678
1679  /// \brief Target nested name specifier.
1680  NestedNameSpecifier* TargetNestedName;
1681
1682  /// \brief The collection of shadow declarations associated with
1683  /// this using declaration.  This set can change as a class is
1684  /// processed.
1685  llvm::SmallPtrSet<UsingShadowDecl*, 8> Shadows;
1686
1687  // \brief Has 'typename' keyword.
1688  bool IsTypeName;
1689
1690  UsingDecl(DeclContext *DC, SourceLocation L, SourceRange NNR,
1691            SourceLocation UL, NestedNameSpecifier* TargetNNS,
1692            DeclarationName Name, bool IsTypeNameArg)
1693    : NamedDecl(Decl::Using, DC, L, Name),
1694      NestedNameRange(NNR), UsingLocation(UL), TargetNestedName(TargetNNS),
1695      IsTypeName(IsTypeNameArg) {
1696  }
1697
1698public:
1699  /// \brief Returns the source range that covers the nested-name-specifier
1700  /// preceding the namespace name.
1701  SourceRange getNestedNameRange() { return NestedNameRange; }
1702
1703  /// \brief Returns the source location of the "using" location itself.
1704  SourceLocation getUsingLocation() { return UsingLocation; }
1705
1706  /// \brief Get target nested name declaration.
1707  NestedNameSpecifier* getTargetNestedNameDecl() {
1708    return TargetNestedName;
1709  }
1710
1711  /// isTypeName - Return true if using decl has 'typename'.
1712  bool isTypeName() const { return IsTypeName; }
1713
1714  typedef llvm::SmallPtrSet<UsingShadowDecl*,8>::const_iterator shadow_iterator;
1715  shadow_iterator shadow_begin() const { return Shadows.begin(); }
1716  shadow_iterator shadow_end() const { return Shadows.end(); }
1717
1718  void addShadowDecl(UsingShadowDecl *S) {
1719    assert(S->getUsingDecl() == this);
1720    if (!Shadows.insert(S)) {
1721      assert(false && "declaration already in set");
1722    }
1723  }
1724  void removeShadowDecl(UsingShadowDecl *S) {
1725    assert(S->getUsingDecl() == this);
1726    if (!Shadows.erase(S)) {
1727      assert(false && "declaration not in set");
1728    }
1729  }
1730
1731  static UsingDecl *Create(ASTContext &C, DeclContext *DC,
1732      SourceLocation IdentL, SourceRange NNR, SourceLocation UsingL,
1733      NestedNameSpecifier* TargetNNS, DeclarationName Name, bool IsTypeNameArg);
1734
1735  static bool classof(const Decl *D) {
1736    return D->getKind() == Decl::Using;
1737  }
1738  static bool classof(const UsingDecl *D) { return true; }
1739};
1740
1741/// UnresolvedUsingValueDecl - Represents a dependent using
1742/// declaration which was not marked with 'typename'.  Unlike
1743/// non-dependent using declarations, these *only* bring through
1744/// non-types; otherwise they would break two-phase lookup.
1745///
1746/// template <class T> class A : public Base<T> {
1747///   using Base<T>::foo;
1748/// };
1749class UnresolvedUsingValueDecl : public ValueDecl {
1750  /// \brief The source range that covers the nested-name-specifier
1751  /// preceding the declaration name.
1752  SourceRange TargetNestedNameRange;
1753
1754  /// \brief The source location of the 'using' keyword
1755  SourceLocation UsingLocation;
1756
1757  NestedNameSpecifier *TargetNestedNameSpecifier;
1758
1759  UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
1760                           SourceLocation UsingLoc, SourceRange TargetNNR,
1761                           NestedNameSpecifier *TargetNNS,
1762                           SourceLocation TargetNameLoc,
1763                           DeclarationName TargetName)
1764    : ValueDecl(Decl::UnresolvedUsingValue, DC, TargetNameLoc, TargetName, Ty),
1765    TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc),
1766    TargetNestedNameSpecifier(TargetNNS)
1767  { }
1768
1769public:
1770  /// \brief Returns the source range that covers the nested-name-specifier
1771  /// preceding the namespace name.
1772  SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; }
1773
1774  /// \brief Get target nested name declaration.
1775  NestedNameSpecifier* getTargetNestedNameSpecifier() {
1776    return TargetNestedNameSpecifier;
1777  }
1778
1779  /// \brief Returns the source location of the 'using' keyword.
1780  SourceLocation getUsingLoc() const { return UsingLocation; }
1781
1782  static UnresolvedUsingValueDecl *
1783    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
1784           SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
1785           SourceLocation TargetNameLoc, DeclarationName TargetName);
1786
1787  static bool classof(const Decl *D) {
1788    return D->getKind() == Decl::UnresolvedUsingValue;
1789  }
1790  static bool classof(const UnresolvedUsingValueDecl *D) { return true; }
1791};
1792
1793/// UnresolvedUsingTypenameDecl - Represents a dependent using
1794/// declaration which was marked with 'typename'.
1795///
1796/// template <class T> class A : public Base<T> {
1797///   using typename Base<T>::foo;
1798/// };
1799///
1800/// The type associated with a unresolved using typename decl is
1801/// currently always a typename type.
1802class UnresolvedUsingTypenameDecl : public TypeDecl {
1803  /// \brief The source range that covers the nested-name-specifier
1804  /// preceding the declaration name.
1805  SourceRange TargetNestedNameRange;
1806
1807  /// \brief The source location of the 'using' keyword
1808  SourceLocation UsingLocation;
1809
1810  /// \brief The source location of the 'typename' keyword
1811  SourceLocation TypenameLocation;
1812
1813  NestedNameSpecifier *TargetNestedNameSpecifier;
1814
1815  UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
1816                    SourceLocation TypenameLoc,
1817                    SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
1818                    SourceLocation TargetNameLoc, IdentifierInfo *TargetName)
1819  : TypeDecl(Decl::UnresolvedUsingTypename, DC, TargetNameLoc, TargetName),
1820    TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc),
1821    TypenameLocation(TypenameLoc), TargetNestedNameSpecifier(TargetNNS)
1822  { }
1823
1824public:
1825  /// \brief Returns the source range that covers the nested-name-specifier
1826  /// preceding the namespace name.
1827  SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; }
1828
1829  /// \brief Get target nested name declaration.
1830  NestedNameSpecifier* getTargetNestedNameSpecifier() {
1831    return TargetNestedNameSpecifier;
1832  }
1833
1834  /// \brief Returns the source location of the 'using' keyword.
1835  SourceLocation getUsingLoc() const { return UsingLocation; }
1836
1837  /// \brief Returns the source location of the 'typename' keyword.
1838  SourceLocation getTypenameLoc() const { return TypenameLocation; }
1839
1840  static UnresolvedUsingTypenameDecl *
1841    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
1842           SourceLocation TypenameLoc,
1843           SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
1844           SourceLocation TargetNameLoc, DeclarationName TargetName);
1845
1846  static bool classof(const Decl *D) {
1847    return D->getKind() == Decl::UnresolvedUsingTypename;
1848  }
1849  static bool classof(const UnresolvedUsingTypenameDecl *D) { return true; }
1850};
1851
1852/// StaticAssertDecl - Represents a C++0x static_assert declaration.
1853class StaticAssertDecl : public Decl {
1854  Expr *AssertExpr;
1855  StringLiteral *Message;
1856
1857  StaticAssertDecl(DeclContext *DC, SourceLocation L,
1858                   Expr *assertexpr, StringLiteral *message)
1859  : Decl(StaticAssert, DC, L), AssertExpr(assertexpr), Message(message) { }
1860
1861public:
1862  static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
1863                                  SourceLocation L, Expr *AssertExpr,
1864                                  StringLiteral *Message);
1865
1866  Expr *getAssertExpr() { return AssertExpr; }
1867  const Expr *getAssertExpr() const { return AssertExpr; }
1868
1869  StringLiteral *getMessage() { return Message; }
1870  const StringLiteral *getMessage() const { return Message; }
1871
1872  virtual ~StaticAssertDecl();
1873  virtual void Destroy(ASTContext& C);
1874
1875  static bool classof(const Decl *D) {
1876    return D->getKind() == Decl::StaticAssert;
1877  }
1878  static bool classof(StaticAssertDecl *D) { return true; }
1879};
1880
1881/// Insertion operator for diagnostics.  This allows sending AccessSpecifier's
1882/// into a diagnostic with <<.
1883const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
1884                                    AccessSpecifier AS);
1885
1886} // end namespace clang
1887
1888#endif
1889