Initialization.h revision d6e44a3c4193bd422bfa78c8086fb16bb2168e34
1d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor//===--- SemaInit.h - Semantic Analysis for Initializers --------*- C++ -*-===//
220093b4bf698f292c664676987541d5103b65b15Douglas Gregor//
320093b4bf698f292c664676987541d5103b65b15Douglas Gregor//                     The LLVM Compiler Infrastructure
420093b4bf698f292c664676987541d5103b65b15Douglas Gregor//
520093b4bf698f292c664676987541d5103b65b15Douglas Gregor// This file is distributed under the University of Illinois Open Source
620093b4bf698f292c664676987541d5103b65b15Douglas Gregor// License. See LICENSE.TXT for details.
720093b4bf698f292c664676987541d5103b65b15Douglas Gregor//
820093b4bf698f292c664676987541d5103b65b15Douglas Gregor//===----------------------------------------------------------------------===//
920093b4bf698f292c664676987541d5103b65b15Douglas Gregor//
1020093b4bf698f292c664676987541d5103b65b15Douglas Gregor// This file provides supporting data types for initialization of objects.
1120093b4bf698f292c664676987541d5103b65b15Douglas Gregor//
1220093b4bf698f292c664676987541d5103b65b15Douglas Gregor//===----------------------------------------------------------------------===//
1320093b4bf698f292c664676987541d5103b65b15Douglas Gregor#ifndef LLVM_CLANG_SEMA_INIT_H
1420093b4bf698f292c664676987541d5103b65b15Douglas Gregor#define LLVM_CLANG_SEMA_INIT_H
1520093b4bf698f292c664676987541d5103b65b15Douglas Gregor
1620093b4bf698f292c664676987541d5103b65b15Douglas Gregor#include "SemaOverload.h"
17d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor#include "clang/AST/Type.h"
18b13b737a2450167c82e148590e8019b839ce6b98John McCall#include "clang/AST/UnresolvedSet.h"
1920093b4bf698f292c664676987541d5103b65b15Douglas Gregor#include "clang/Parse/Action.h"
2020093b4bf698f292c664676987541d5103b65b15Douglas Gregor#include "clang/Basic/SourceLocation.h"
2120093b4bf698f292c664676987541d5103b65b15Douglas Gregor#include "llvm/ADT/PointerIntPair.h"
2220093b4bf698f292c664676987541d5103b65b15Douglas Gregor#include "llvm/ADT/SmallVector.h"
2320093b4bf698f292c664676987541d5103b65b15Douglas Gregor#include <cassert>
2420093b4bf698f292c664676987541d5103b65b15Douglas Gregor
25de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregornamespace llvm {
26de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor  class raw_ostream;
27de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor}
28de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor
2920093b4bf698f292c664676987541d5103b65b15Douglas Gregornamespace clang {
3020093b4bf698f292c664676987541d5103b65b15Douglas Gregor
3120093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass CXXBaseSpecifier;
3220093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass DeclaratorDecl;
3320093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass DeclaratorInfo;
3420093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass FieldDecl;
3520093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass FunctionDecl;
3620093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass ParmVarDecl;
3720093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass Sema;
3820093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass TypeLoc;
3920093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass VarDecl;
4020093b4bf698f292c664676987541d5103b65b15Douglas Gregor
4120093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// \brief Describes an entity that is being initialized.
4220093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass InitializedEntity {
4320093b4bf698f292c664676987541d5103b65b15Douglas Gregorpublic:
4420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Specifies the kind of entity being initialized.
4520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  enum EntityKind {
4620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief The entity being initialized is a variable.
4720093b4bf698f292c664676987541d5103b65b15Douglas Gregor    EK_Variable,
4820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief The entity being initialized is a function parameter.
4920093b4bf698f292c664676987541d5103b65b15Douglas Gregor    EK_Parameter,
5020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief The entity being initialized is the result of a function call.
5120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    EK_Result,
5220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief The entity being initialized is an exception object that
5320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// is being thrown.
5420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    EK_Exception,
55a729bbb739ca97a8dc52b6b0495725590a0367dcAnders Carlsson    /// \brief The entity being initialized is a non-static data member
56a729bbb739ca97a8dc52b6b0495725590a0367dcAnders Carlsson    /// subobject.
57a729bbb739ca97a8dc52b6b0495725590a0367dcAnders Carlsson    EK_Member,
58a729bbb739ca97a8dc52b6b0495725590a0367dcAnders Carlsson    /// \brief The entity being initialized is an element of an array.
59a729bbb739ca97a8dc52b6b0495725590a0367dcAnders Carlsson    EK_ArrayElement,
6018ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor    /// \brief The entity being initialized is an object (or array of
6118ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor    /// objects) allocated via new.
6218ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor    EK_New,
6320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief The entity being initialized is a temporary object.
6420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    EK_Temporary,
6520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief The entity being initialized is a base member subobject.
6620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    EK_Base,
67d3d824d45c32d457493e7cb79cc34a4761afb760Anders Carlsson    /// \brief The entity being initialized is an element of a vector.
68cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor    /// or vector.
69d3d824d45c32d457493e7cb79cc34a4761afb760Anders Carlsson    EK_VectorElement
7020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  };
7120093b4bf698f292c664676987541d5103b65b15Douglas Gregor
7220093b4bf698f292c664676987541d5103b65b15Douglas Gregorprivate:
7320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief The kind of entity being initialized.
7420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  EntityKind Kind;
7520093b4bf698f292c664676987541d5103b65b15Douglas Gregor
76cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// \brief If non-NULL, the parent entity in which this
77cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// initialization occurs.
78cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  const InitializedEntity *Parent;
79cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor
80d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor  /// \brief The type of the object or reference being initialized.
81d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor  QualType Type;
8220093b4bf698f292c664676987541d5103b65b15Douglas Gregor
8320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  union {
8420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief When Kind == EK_Variable, EK_Parameter, or EK_Member,
8520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// the VarDecl, ParmVarDecl, or FieldDecl, respectively.
8620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    DeclaratorDecl *VariableOrMember;
8720093b4bf698f292c664676987541d5103b65b15Douglas Gregor
8818ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor    /// \brief When Kind == EK_Result, EK_Exception, or EK_New, the
8918ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor    /// location of the 'return', 'throw', or 'new' keyword,
9018ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor    /// respectively. When Kind == EK_Temporary, the location where
9118ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor    /// the temporary is being created.
9220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    unsigned Location;
9320093b4bf698f292c664676987541d5103b65b15Douglas Gregor
9420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief When Kind == EK_Base, the base specifier that provides the
9520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// base class.
9620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    CXXBaseSpecifier *Base;
97cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor
989db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor    /// \brief When Kind = EK_ArrayElement or EK_VectorElement, the
999db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor    /// index of the array or vector element being initialized.
100cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor    unsigned Index;
10120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  };
10220093b4bf698f292c664676987541d5103b65b15Douglas Gregor
10320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  InitializedEntity() { }
10420093b4bf698f292c664676987541d5103b65b15Douglas Gregor
10520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create the initialization entity for a variable.
10620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  InitializedEntity(VarDecl *Var)
107d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor    : Kind(EK_Variable), Parent(0), Type(Var->getType()),
108d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor      VariableOrMember(reinterpret_cast<DeclaratorDecl*>(Var)) { }
10920093b4bf698f292c664676987541d5103b65b15Douglas Gregor
11020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create the initialization entity for a parameter.
11120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  InitializedEntity(ParmVarDecl *Parm)
1126e790ab61bf4835944971955e84279112833ef0cDouglas Gregor    : Kind(EK_Parameter), Parent(0), Type(Parm->getType().getUnqualifiedType()),
113d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor      VariableOrMember(reinterpret_cast<DeclaratorDecl*>(Parm)) { }
11420093b4bf698f292c664676987541d5103b65b15Douglas Gregor
115a188ff2d8a18140541fcd5884deda4552dac71a7Douglas Gregor  /// \brief Create the initialization entity for the result of a
116a188ff2d8a18140541fcd5884deda4552dac71a7Douglas Gregor  /// function, throwing an object, performing an explicit cast, or
117a188ff2d8a18140541fcd5884deda4552dac71a7Douglas Gregor  /// initializing a parameter for which there is no declaration.
118d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor  InitializedEntity(EntityKind Kind, SourceLocation Loc, QualType Type)
119d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor    : Kind(Kind), Parent(0), Type(Type), Location(Loc.getRawEncoding()) { }
12020093b4bf698f292c664676987541d5103b65b15Douglas Gregor
12120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create the initialization entity for a member subobject.
122cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  InitializedEntity(FieldDecl *Member, const InitializedEntity *Parent)
123d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor    : Kind(EK_Member), Parent(Parent), Type(Member->getType()),
124d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor      VariableOrMember(reinterpret_cast<DeclaratorDecl*>(Member)) { }
12520093b4bf698f292c664676987541d5103b65b15Douglas Gregor
126cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// \brief Create the initialization entity for an array element.
127cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  InitializedEntity(ASTContext &Context, unsigned Index,
128cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor                    const InitializedEntity &Parent);
129cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor
13020093b4bf698f292c664676987541d5103b65b15Douglas Gregorpublic:
13120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create the initialization entity for a variable.
13220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializedEntity InitializeVariable(VarDecl *Var) {
13320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return InitializedEntity(Var);
13420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
13520093b4bf698f292c664676987541d5103b65b15Douglas Gregor
13620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create the initialization entity for a parameter.
13720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializedEntity InitializeParameter(ParmVarDecl *Parm) {
13820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return InitializedEntity(Parm);
13920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
14020093b4bf698f292c664676987541d5103b65b15Douglas Gregor
141a188ff2d8a18140541fcd5884deda4552dac71a7Douglas Gregor  /// \brief Create the initialization entity for a parameter that is
142a188ff2d8a18140541fcd5884deda4552dac71a7Douglas Gregor  /// only known by its type.
143a188ff2d8a18140541fcd5884deda4552dac71a7Douglas Gregor  static InitializedEntity InitializeParameter(QualType Type) {
144a188ff2d8a18140541fcd5884deda4552dac71a7Douglas Gregor    return InitializedEntity(EK_Parameter, SourceLocation(), Type);
145a188ff2d8a18140541fcd5884deda4552dac71a7Douglas Gregor  }
146a188ff2d8a18140541fcd5884deda4552dac71a7Douglas Gregor
14720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create the initialization entity for the result of a function.
14820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializedEntity InitializeResult(SourceLocation ReturnLoc,
149d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor                                            QualType Type) {
150d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor    return InitializedEntity(EK_Result, ReturnLoc, Type);
15120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
15220093b4bf698f292c664676987541d5103b65b15Douglas Gregor
15320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create the initialization entity for an exception object.
15420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializedEntity InitializeException(SourceLocation ThrowLoc,
155d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor                                               QualType Type) {
156d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor    return InitializedEntity(EK_Exception, ThrowLoc, Type);
15720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
15818ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor
15918ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor  /// \brief Create the initialization entity for an object allocated via new.
160d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor  static InitializedEntity InitializeNew(SourceLocation NewLoc, QualType Type) {
161d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor    return InitializedEntity(EK_New, NewLoc, Type);
16218ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor  }
16320093b4bf698f292c664676987541d5103b65b15Douglas Gregor
16420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create the initialization entity for a temporary.
165d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor  static InitializedEntity InitializeTemporary(QualType Type) {
166d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor    return InitializedEntity(EK_Temporary, SourceLocation(), Type);
16720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
16820093b4bf698f292c664676987541d5103b65b15Douglas Gregor
16920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create the initialization entity for a base class subobject.
17020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializedEntity InitializeBase(ASTContext &Context,
17120093b4bf698f292c664676987541d5103b65b15Douglas Gregor                                          CXXBaseSpecifier *Base);
17220093b4bf698f292c664676987541d5103b65b15Douglas Gregor
173cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// \brief Create the initialization entity for a member subobject.
174cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  static InitializedEntity InitializeMember(FieldDecl *Member,
175cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor                                          const InitializedEntity *Parent = 0) {
176cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor    return InitializedEntity(Member, Parent);
17720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
17820093b4bf698f292c664676987541d5103b65b15Douglas Gregor
179cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// \brief Create the initialization entity for an array element.
180cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  static InitializedEntity InitializeElement(ASTContext &Context,
181cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor                                             unsigned Index,
182cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor                                             const InitializedEntity &Parent) {
183cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor    return InitializedEntity(Context, Index, Parent);
184cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  }
185cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor
18620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine the kind of initialization.
18720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  EntityKind getKind() const { return Kind; }
18820093b4bf698f292c664676987541d5103b65b15Douglas Gregor
189cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// \brief Retrieve the parent of the entity being initialized, when
190cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// the initialization itself is occuring within the context of a
191cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// larger initialization.
192cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  const InitializedEntity *getParent() const { return Parent; }
193cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor
19420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Retrieve type being initialized.
195d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor  QualType getType() const { return Type; }
19620093b4bf698f292c664676987541d5103b65b15Douglas Gregor
19799a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  /// \brief Retrieve the name of the entity being initialized.
19899a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  DeclarationName getName() const;
1997abfbdbc97ad8e7f340789f751df1e32b10118b4Douglas Gregor
2007abfbdbc97ad8e7f340789f751df1e32b10118b4Douglas Gregor  /// \brief Retrieve the variable, parameter, or field being
2017abfbdbc97ad8e7f340789f751df1e32b10118b4Douglas Gregor  /// initialized.
2027abfbdbc97ad8e7f340789f751df1e32b10118b4Douglas Gregor  DeclaratorDecl *getDecl() const;
2037abfbdbc97ad8e7f340789f751df1e32b10118b4Douglas Gregor
2049db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor  /// \brief Retrieve the base specifier.
2059db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor  CXXBaseSpecifier *getBaseSpecifier() const {
2069db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor    assert(getKind() == EK_Base && "Not a base specifier");
2079db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor    return Base;
2089db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor  }
2099db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor
21020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine the location of the 'return' keyword when initializing
21120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// the result of a function call.
21220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  SourceLocation getReturnLoc() const {
21320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    assert(getKind() == EK_Result && "No 'return' location!");
21420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return SourceLocation::getFromRawEncoding(Location);
21520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
21620093b4bf698f292c664676987541d5103b65b15Douglas Gregor
21720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine the location of the 'throw' keyword when initializing
21820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// an exception object.
21920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  SourceLocation getThrowLoc() const {
22020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    assert(getKind() == EK_Exception && "No 'throw' location!");
22120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return SourceLocation::getFromRawEncoding(Location);
22220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
223cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor
224cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// \brief If this is already the initializer for an array or vector
225cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// element, sets the element index.
226cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  void setElementIndex(unsigned Index) {
227d3d824d45c32d457493e7cb79cc34a4761afb760Anders Carlsson    assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement);
228cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor    this->Index = Index;
229cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  }
23020093b4bf698f292c664676987541d5103b65b15Douglas Gregor};
23120093b4bf698f292c664676987541d5103b65b15Douglas Gregor
23220093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// \brief Describes the kind of initialization being performed, along with
23320093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// location information for tokens related to the initialization (equal sign,
23420093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// parentheses).
23520093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass InitializationKind {
23620093b4bf698f292c664676987541d5103b65b15Douglas Gregorpublic:
23720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief The kind of initialization being performed.
23820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  enum InitKind {
23920093b4bf698f292c664676987541d5103b65b15Douglas Gregor    IK_Direct,  ///< Direct initialization
24020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    IK_Copy,    ///< Copy initialization
24120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    IK_Default, ///< Default initialization
24220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    IK_Value    ///< Value initialization
24320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  };
24420093b4bf698f292c664676987541d5103b65b15Douglas Gregor
24520093b4bf698f292c664676987541d5103b65b15Douglas Gregorprivate:
24620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief The kind of initialization that we're storing.
24720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  enum StoredInitKind {
24820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SIK_Direct = IK_Direct,   ///< Direct initialization
24920093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SIK_Copy = IK_Copy,       ///< Copy initialization
25020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SIK_Default = IK_Default, ///< Default initialization
25120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SIK_Value = IK_Value,     ///< Value initialization
252cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor    SIK_ImplicitValue,        ///< Implicit value initialization
25320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SIK_DirectCast,  ///< Direct initialization due to a cast
25420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Direct initialization due to a C-style or functional cast.
25520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SIK_DirectCStyleOrFunctionalCast
25620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  };
25720093b4bf698f292c664676987541d5103b65b15Douglas Gregor
25820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief The kind of initialization being performed.
25920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  StoredInitKind Kind;
26020093b4bf698f292c664676987541d5103b65b15Douglas Gregor
26120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief The source locations involved in the initialization.
26220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  SourceLocation Locations[3];
26320093b4bf698f292c664676987541d5103b65b15Douglas Gregor
26420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  InitializationKind(StoredInitKind Kind, SourceLocation Loc1,
26520093b4bf698f292c664676987541d5103b65b15Douglas Gregor                     SourceLocation Loc2, SourceLocation Loc3)
26620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    : Kind(Kind)
26720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  {
26820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    Locations[0] = Loc1;
26920093b4bf698f292c664676987541d5103b65b15Douglas Gregor    Locations[1] = Loc2;
27020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    Locations[2] = Loc3;
27120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
27220093b4bf698f292c664676987541d5103b65b15Douglas Gregor
27320093b4bf698f292c664676987541d5103b65b15Douglas Gregorpublic:
27420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create a direct initialization.
27520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializationKind CreateDirect(SourceLocation InitLoc,
27620093b4bf698f292c664676987541d5103b65b15Douglas Gregor                                         SourceLocation LParenLoc,
27720093b4bf698f292c664676987541d5103b65b15Douglas Gregor                                         SourceLocation RParenLoc) {
27820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return InitializationKind(SIK_Direct, InitLoc, LParenLoc, RParenLoc);
27920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
28020093b4bf698f292c664676987541d5103b65b15Douglas Gregor
28120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create a direct initialization due to a cast.
28220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializationKind CreateCast(SourceRange TypeRange,
28320093b4bf698f292c664676987541d5103b65b15Douglas Gregor                                       bool IsCStyleCast) {
28420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return InitializationKind(IsCStyleCast? SIK_DirectCStyleOrFunctionalCast
28520093b4bf698f292c664676987541d5103b65b15Douglas Gregor                                          : SIK_DirectCast,
28620093b4bf698f292c664676987541d5103b65b15Douglas Gregor                              TypeRange.getBegin(), TypeRange.getBegin(),
28720093b4bf698f292c664676987541d5103b65b15Douglas Gregor                              TypeRange.getEnd());
28820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
28920093b4bf698f292c664676987541d5103b65b15Douglas Gregor
29020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create a copy initialization.
29120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializationKind CreateCopy(SourceLocation InitLoc,
29220093b4bf698f292c664676987541d5103b65b15Douglas Gregor                                       SourceLocation EqualLoc) {
29320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return InitializationKind(SIK_Copy, InitLoc, EqualLoc, EqualLoc);
29420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
29520093b4bf698f292c664676987541d5103b65b15Douglas Gregor
29620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create a default initialization.
29720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializationKind CreateDefault(SourceLocation InitLoc) {
29820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return InitializationKind(SIK_Default, InitLoc, InitLoc, InitLoc);
29920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
30020093b4bf698f292c664676987541d5103b65b15Douglas Gregor
30120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create a value initialization.
30220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializationKind CreateValue(SourceLocation InitLoc,
30320093b4bf698f292c664676987541d5103b65b15Douglas Gregor                                        SourceLocation LParenLoc,
304cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor                                        SourceLocation RParenLoc,
305cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor                                        bool isImplicit = false) {
306cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor    return InitializationKind(isImplicit? SIK_ImplicitValue : SIK_Value,
307cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor                              InitLoc, LParenLoc, RParenLoc);
30820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
30920093b4bf698f292c664676987541d5103b65b15Douglas Gregor
31020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine the initialization kind.
31120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  InitKind getKind() const {
312cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor    if (Kind > SIK_ImplicitValue)
31320093b4bf698f292c664676987541d5103b65b15Douglas Gregor      return IK_Direct;
314cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor    if (Kind == SIK_ImplicitValue)
315cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor      return IK_Value;
316cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor
31720093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return (InitKind)Kind;
31820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
31920093b4bf698f292c664676987541d5103b65b15Douglas Gregor
32020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine whether this initialization is an explicit cast.
32120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  bool isExplicitCast() const {
32220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return Kind == SIK_DirectCast || Kind == SIK_DirectCStyleOrFunctionalCast;
32320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
32420093b4bf698f292c664676987541d5103b65b15Douglas Gregor
32520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine whether this initialization is a C-style cast.
32620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  bool isCStyleOrFunctionalCast() const {
32720093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return Kind == SIK_DirectCStyleOrFunctionalCast;
32820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
329cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor
330cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// \brief Determine whether this initialization is an implicit
331cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// value-initialization, e.g., as occurs during aggregate
332cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// initialization.
333cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  bool isImplicitValueInit() const { return Kind == SIK_ImplicitValue; }
334cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor
33520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Retrieve the location at which initialization is occurring.
33620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  SourceLocation getLocation() const { return Locations[0]; }
33720093b4bf698f292c664676987541d5103b65b15Douglas Gregor
33820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Retrieve the source range that covers the initialization.
33920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  SourceRange getRange() const {
34071d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor    return SourceRange(Locations[0], Locations[2]);
34120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
34220093b4bf698f292c664676987541d5103b65b15Douglas Gregor
34320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Retrieve the location of the equal sign for copy initialization
34420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// (if present).
34520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  SourceLocation getEqualLoc() const {
34620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    assert(Kind == SIK_Copy && "Only copy initialization has an '='");
34720093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return Locations[1];
34820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
34920093b4bf698f292c664676987541d5103b65b15Douglas Gregor
35020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Retrieve the source range containing the locations of the open
35120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// and closing parentheses for value and direct initializations.
35220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  SourceRange getParenRange() const {
35320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    assert((getKind() == IK_Direct || Kind == SIK_Value) &&
35420093b4bf698f292c664676987541d5103b65b15Douglas Gregor           "Only direct- and value-initialization have parentheses");
35520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return SourceRange(Locations[1], Locations[2]);
35620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
35720093b4bf698f292c664676987541d5103b65b15Douglas Gregor};
35820093b4bf698f292c664676987541d5103b65b15Douglas Gregor
35920093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// \brief Describes the sequence of initializations required to initialize
36020093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// a given object or reference with a set of arguments.
36120093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass InitializationSequence {
36220093b4bf698f292c664676987541d5103b65b15Douglas Gregorpublic:
36320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Describes the kind of initialization sequence computed.
36471d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor  ///
36571d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor  /// FIXME: Much of this information is in the initialization steps... why is
36671d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor  /// it duplicated here?
36720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  enum SequenceKind {
36820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief A failed initialization sequence. The failure kind tells what
36920093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// happened.
37020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FailedSequence = 0,
37120093b4bf698f292c664676987541d5103b65b15Douglas Gregor
37220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief A dependent initialization, which could not be
37320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// type-checked due to the presence of dependent types or
37420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// dependently-type expressions.
37520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    DependentSequence,
37620093b4bf698f292c664676987541d5103b65b15Douglas Gregor
3774a520a2bd8a6b79fa5d4771f02e34e7bd6bc461dDouglas Gregor    /// \brief A user-defined conversion sequence.
3784a520a2bd8a6b79fa5d4771f02e34e7bd6bc461dDouglas Gregor    UserDefinedConversion,
3794a520a2bd8a6b79fa5d4771f02e34e7bd6bc461dDouglas Gregor
38051c56d6c8a944c2e49dd714db65a780d9f627e15Douglas Gregor    /// \brief A constructor call.
381a6ca65075490a1f217bbe5f83fe7b80e821df2d8Douglas Gregor    ConstructorInitialization,
38251c56d6c8a944c2e49dd714db65a780d9f627e15Douglas Gregor
38320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief A reference binding.
384d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    ReferenceBinding,
385d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor
386d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    /// \brief List initialization
38771d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor    ListInitialization,
38871d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor
38971d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor    /// \brief Zero-initialization.
39099a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor    ZeroInitialization,
39199a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor
39299a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor    /// \brief No initialization required.
39399a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor    NoInitialization,
39499a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor
39599a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor    /// \brief Standard conversion sequence.
39618ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor    StandardConversion,
39718ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor
39818ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor    /// \brief C conversion sequence.
399cfdc81a83467973b14e4ea5e9e9af1690f135415Eli Friedman    CAssignment,
400cfdc81a83467973b14e4ea5e9e9af1690f135415Eli Friedman
401cfdc81a83467973b14e4ea5e9e9af1690f135415Eli Friedman    /// \brief String initialization
402cfdc81a83467973b14e4ea5e9e9af1690f135415Eli Friedman    StringInit
40320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  };
40420093b4bf698f292c664676987541d5103b65b15Douglas Gregor
40520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Describes the kind of a particular step in an initialization
40620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// sequence.
40720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  enum StepKind {
40820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Resolve the address of an overloaded function to a specific
40920093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// function declaration.
41020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SK_ResolveAddressOfOverloadedFunction,
41120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Perform a derived-to-base cast, producing an rvalue.
41220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SK_CastDerivedToBaseRValue,
41320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Perform a derived-to-base cast, producing an lvalue.
41420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SK_CastDerivedToBaseLValue,
41520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Reference binding to an lvalue.
41620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SK_BindReference,
41720093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Reference binding to a temporary.
41820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SK_BindReferenceToTemporary,
41920093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Perform a user-defined conversion, either via a conversion
42020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// function or via a constructor.
42120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SK_UserConversion,
42220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Perform a qualification conversion, producing an rvalue.
42320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SK_QualificationConversionRValue,
42420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Perform a qualification conversion, producing an lvalue.
42520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SK_QualificationConversionLValue,
42620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Perform an implicit conversion sequence.
427d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    SK_ConversionSequence,
428d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    /// \brief Perform list-initialization
42951c56d6c8a944c2e49dd714db65a780d9f627e15Douglas Gregor    SK_ListInitialization,
43051c56d6c8a944c2e49dd714db65a780d9f627e15Douglas Gregor    /// \brief Perform initialization via a constructor.
43171d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor    SK_ConstructorInitialization,
43271d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor    /// \brief Zero-initialize the object
43318ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor    SK_ZeroInitialization,
43418ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor    /// \brief C assignment
435cfdc81a83467973b14e4ea5e9e9af1690f135415Eli Friedman    SK_CAssignment,
436cfdc81a83467973b14e4ea5e9e9af1690f135415Eli Friedman    /// \brief Initialization by string
437cfdc81a83467973b14e4ea5e9e9af1690f135415Eli Friedman    SK_StringInit
43820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  };
43920093b4bf698f292c664676987541d5103b65b15Douglas Gregor
44020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief A single step in the initialization sequence.
44120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  class Step {
44220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  public:
44320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief The kind of conversion or initialization step we are taking.
44420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    StepKind Kind;
44520093b4bf698f292c664676987541d5103b65b15Douglas Gregor
44620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    // \brief The type that results from this initialization.
44720093b4bf698f292c664676987541d5103b65b15Douglas Gregor    QualType Type;
44820093b4bf698f292c664676987541d5103b65b15Douglas Gregor
44920093b4bf698f292c664676987541d5103b65b15Douglas Gregor    union {
45020093b4bf698f292c664676987541d5103b65b15Douglas Gregor      /// \brief When Kind == SK_ResolvedOverloadedFunction or Kind ==
45120093b4bf698f292c664676987541d5103b65b15Douglas Gregor      /// SK_UserConversion, the function that the expression should be
45220093b4bf698f292c664676987541d5103b65b15Douglas Gregor      /// resolved to or the conversion function to call, respectively.
453b13b737a2450167c82e148590e8019b839ce6b98John McCall      ///
454b13b737a2450167c82e148590e8019b839ce6b98John McCall      /// Always a FunctionDecl.
455b13b737a2450167c82e148590e8019b839ce6b98John McCall      /// For conversion decls, the naming class is the source type.
456b13b737a2450167c82e148590e8019b839ce6b98John McCall      /// For construct decls, the naming class is the target type.
4579aa472c45d2bd81b7b52c225e8acc560d716db97John McCall      struct {
4589aa472c45d2bd81b7b52c225e8acc560d716db97John McCall        FunctionDecl *Function;
4599aa472c45d2bd81b7b52c225e8acc560d716db97John McCall        DeclAccessPair FoundDecl;
4609aa472c45d2bd81b7b52c225e8acc560d716db97John McCall      } Function;
46120093b4bf698f292c664676987541d5103b65b15Douglas Gregor
46220093b4bf698f292c664676987541d5103b65b15Douglas Gregor      /// \brief When Kind = SK_ConversionSequence, the implicit conversion
46320093b4bf698f292c664676987541d5103b65b15Douglas Gregor      /// sequence
46420093b4bf698f292c664676987541d5103b65b15Douglas Gregor      ImplicitConversionSequence *ICS;
46520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    };
46620093b4bf698f292c664676987541d5103b65b15Douglas Gregor
46720093b4bf698f292c664676987541d5103b65b15Douglas Gregor    void Destroy();
46820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  };
46920093b4bf698f292c664676987541d5103b65b15Douglas Gregor
47020093b4bf698f292c664676987541d5103b65b15Douglas Gregorprivate:
47120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief The kind of initialization sequence computed.
47220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  enum SequenceKind SequenceKind;
47320093b4bf698f292c664676987541d5103b65b15Douglas Gregor
47420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Steps taken by this initialization.
47520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  llvm::SmallVector<Step, 4> Steps;
47620093b4bf698f292c664676987541d5103b65b15Douglas Gregor
47720093b4bf698f292c664676987541d5103b65b15Douglas Gregorpublic:
47820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Describes why initialization failed.
47920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  enum FailureKind {
48020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Too many initializers provided for a reference.
48120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_TooManyInitsForReference,
48220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Array must be initialized with an initializer list.
48320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_ArrayNeedsInitList,
48420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Array must be initialized with an initializer list or a
48520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// string literal.
48620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_ArrayNeedsInitListOrStringLiteral,
48720093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Cannot resolve the address of an overloaded function.
48820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_AddressOfOverloadFailed,
48920093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Overloading due to reference initialization failed.
49020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_ReferenceInitOverloadFailed,
49120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Non-const lvalue reference binding to a temporary.
49220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_NonConstLValueReferenceBindingToTemporary,
49320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Non-const lvalue reference binding to an lvalue of unrelated
49420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// type.
49520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_NonConstLValueReferenceBindingToUnrelated,
49620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Rvalue reference binding to an lvalue.
49720093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_RValueReferenceBindingToLValue,
49820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Reference binding drops qualifiers.
49920093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_ReferenceInitDropsQualifiers,
50020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Reference binding failed.
50120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_ReferenceInitFailed,
50220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Implicit conversion failed.
503d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    FK_ConversionFailed,
504d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    /// \brief Too many initializers for scalar
505d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    FK_TooManyInitsForScalar,
506d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    /// \brief Reference initialization from an initializer list
507d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    FK_ReferenceBindingToInitList,
508d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    /// \brief Initialization of some unused destination type with an
509d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    /// initializer list.
5104a520a2bd8a6b79fa5d4771f02e34e7bd6bc461dDouglas Gregor    FK_InitListBadDestinationType,
5114a520a2bd8a6b79fa5d4771f02e34e7bd6bc461dDouglas Gregor    /// \brief Overloading for a user-defined conversion failed.
51251c56d6c8a944c2e49dd714db65a780d9f627e15Douglas Gregor    FK_UserConversionOverloadFailed,
51351c56d6c8a944c2e49dd714db65a780d9f627e15Douglas Gregor    /// \brief Overloaded for initialization by constructor failed.
51499a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor    FK_ConstructorOverloadFailed,
51599a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor    /// \brief Default-initialization of a 'const' object.
51699a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor    FK_DefaultInitOfConst
51720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  };
51820093b4bf698f292c664676987541d5103b65b15Douglas Gregor
51920093b4bf698f292c664676987541d5103b65b15Douglas Gregorprivate:
52020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief The reason why initialization failued.
52120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  FailureKind Failure;
52220093b4bf698f292c664676987541d5103b65b15Douglas Gregor
52320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief The failed result of overload resolution.
52420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  OverloadingResult FailedOverloadResult;
52520093b4bf698f292c664676987541d5103b65b15Douglas Gregor
52620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief The candidate set created when initialization failed.
52720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  OverloadCandidateSet FailedCandidateSet;
52820093b4bf698f292c664676987541d5103b65b15Douglas Gregor
52920093b4bf698f292c664676987541d5103b65b15Douglas Gregorpublic:
53020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Try to perform initialization of the given entity, creating a
53120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// record of the steps required to perform the initialization.
53220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
53320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// The generated initialization sequence will either contain enough
53420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// information to diagnose
53520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
53620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param S the semantic analysis object.
53720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
53820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param Entity the entity being initialized.
53920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
54020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param Kind the kind of initialization being performed.
54120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
54220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param Args the argument(s) provided for initialization.
54320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
54420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param NumArgs the number of arguments provided for initialization.
54520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  InitializationSequence(Sema &S,
54620093b4bf698f292c664676987541d5103b65b15Douglas Gregor                         const InitializedEntity &Entity,
54720093b4bf698f292c664676987541d5103b65b15Douglas Gregor                         const InitializationKind &Kind,
54820093b4bf698f292c664676987541d5103b65b15Douglas Gregor                         Expr **Args,
54920093b4bf698f292c664676987541d5103b65b15Douglas Gregor                         unsigned NumArgs);
55020093b4bf698f292c664676987541d5103b65b15Douglas Gregor
55120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ~InitializationSequence();
55220093b4bf698f292c664676987541d5103b65b15Douglas Gregor
55320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Perform the actual initialization of the given entity based on
55420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// the computed initialization sequence.
55520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
55620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param S the semantic analysis object.
55720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
55820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param Entity the entity being initialized.
55920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
56020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param Kind the kind of initialization being performed.
56120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
56220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param Args the argument(s) provided for initialization, ownership of
56320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// which is transfered into the routine.
56420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
565d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor  /// \param ResultType if non-NULL, will be set to the type of the
566d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor  /// initialized object, which is the type of the declaration in most
567d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor  /// cases. However, when the initialized object is a variable of
568d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor  /// incomplete array type and the initializer is an initializer
569d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor  /// list, this type will be set to the completed array type.
570d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor  ///
57120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \returns an expression that performs the actual object initialization, if
57220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// the initialization is well-formed. Otherwise, emits diagnostics
57320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// and returns an invalid expression.
57420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  Action::OwningExprResult Perform(Sema &S,
57520093b4bf698f292c664676987541d5103b65b15Douglas Gregor                                   const InitializedEntity &Entity,
57620093b4bf698f292c664676987541d5103b65b15Douglas Gregor                                   const InitializationKind &Kind,
577d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor                                   Action::MultiExprArg Args,
578d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor                                   QualType *ResultType = 0);
57920093b4bf698f292c664676987541d5103b65b15Douglas Gregor
58020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Diagnose an potentially-invalid initialization sequence.
58120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
58220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \returns true if the initialization sequence was ill-formed,
58320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// false otherwise.
58420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  bool Diagnose(Sema &S,
58520093b4bf698f292c664676987541d5103b65b15Douglas Gregor                const InitializedEntity &Entity,
58620093b4bf698f292c664676987541d5103b65b15Douglas Gregor                const InitializationKind &Kind,
58720093b4bf698f292c664676987541d5103b65b15Douglas Gregor                Expr **Args, unsigned NumArgs);
58820093b4bf698f292c664676987541d5103b65b15Douglas Gregor
58920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine the kind of initialization sequence computed.
59020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  enum SequenceKind getKind() const { return SequenceKind; }
59120093b4bf698f292c664676987541d5103b65b15Douglas Gregor
59220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Set the kind of sequence computed.
59320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  void setSequenceKind(enum SequenceKind SK) { SequenceKind = SK; }
59420093b4bf698f292c664676987541d5103b65b15Douglas Gregor
59520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine whether the initialization sequence is valid.
59620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  operator bool() const { return SequenceKind != FailedSequence; }
59720093b4bf698f292c664676987541d5103b65b15Douglas Gregor
59820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  typedef llvm::SmallVector<Step, 4>::const_iterator step_iterator;
59920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  step_iterator step_begin() const { return Steps.begin(); }
60020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  step_iterator step_end()   const { return Steps.end(); }
60120093b4bf698f292c664676987541d5103b65b15Douglas Gregor
602b70cf44bf1b1956e0c6b98373c4f69b23afa0052Douglas Gregor  /// \brief Determine whether this initialization is a direct reference
603b70cf44bf1b1956e0c6b98373c4f69b23afa0052Douglas Gregor  /// binding (C++ [dcl.init.ref]).
604b70cf44bf1b1956e0c6b98373c4f69b23afa0052Douglas Gregor  bool isDirectReferenceBinding() const;
605b70cf44bf1b1956e0c6b98373c4f69b23afa0052Douglas Gregor
606b70cf44bf1b1956e0c6b98373c4f69b23afa0052Douglas Gregor  /// \brief Determine whether this initialization failed due to an ambiguity.
607b70cf44bf1b1956e0c6b98373c4f69b23afa0052Douglas Gregor  bool isAmbiguous() const;
608b70cf44bf1b1956e0c6b98373c4f69b23afa0052Douglas Gregor
609d6e44a3c4193bd422bfa78c8086fb16bb2168e34Douglas Gregor  /// \brief Determine whether this initialization is direct call to a
610d6e44a3c4193bd422bfa78c8086fb16bb2168e34Douglas Gregor  /// constructor.
611d6e44a3c4193bd422bfa78c8086fb16bb2168e34Douglas Gregor  bool isConstructorInitialization() const;
612d6e44a3c4193bd422bfa78c8086fb16bb2168e34Douglas Gregor
61320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Add a new step in the initialization that resolves the address
61420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// of an overloaded function to a specific function declaration.
61520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
61620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param Function the function to which the overloaded function reference
61720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// resolves.
6186bb8017bb9e828d118e15e59d71c66bba323c364John McCall  void AddAddressOverloadResolutionStep(FunctionDecl *Function,
6196bb8017bb9e828d118e15e59d71c66bba323c364John McCall                                        DeclAccessPair Found);
62020093b4bf698f292c664676987541d5103b65b15Douglas Gregor
62120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Add a new step in the initialization that performs a derived-to-
62220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// base cast.
62320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
62420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param BaseType the base type to which we will be casting.
62520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
62620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param IsLValue true if the result of this cast will be treated as
62720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// an lvalue.
62820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  void AddDerivedToBaseCastStep(QualType BaseType, bool IsLValue);
62920093b4bf698f292c664676987541d5103b65b15Douglas Gregor
63020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Add a new step binding a reference to an object.
63120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
63220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param BindingTemporary true if we are binding a reference to a temporary
63320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// object (thereby extending its lifetime); false if we are binding to an
63420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// lvalue or an lvalue treated as an rvalue.
63520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  void AddReferenceBindingStep(QualType T, bool BindingTemporary);
63620093b4bf698f292c664676987541d5103b65b15Douglas Gregor
63720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Add a new step invoking a conversion function, which is either
63820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// a constructor or a conversion function.
639b13b737a2450167c82e148590e8019b839ce6b98John McCall  void AddUserConversionStep(FunctionDecl *Function,
6409aa472c45d2bd81b7b52c225e8acc560d716db97John McCall                             DeclAccessPair FoundDecl,
641b13b737a2450167c82e148590e8019b839ce6b98John McCall                             QualType T);
64220093b4bf698f292c664676987541d5103b65b15Douglas Gregor
64320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Add a new step that performs a qualification conversion to the
64420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// given type.
64520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  void AddQualificationConversionStep(QualType Ty, bool IsLValue);
64620093b4bf698f292c664676987541d5103b65b15Douglas Gregor
64720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Add a new step that applies an implicit conversion sequence.
64820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  void AddConversionSequenceStep(const ImplicitConversionSequence &ICS,
64920093b4bf698f292c664676987541d5103b65b15Douglas Gregor                                 QualType T);
650d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor
651d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor  /// \brief Add a list-initialiation step
652d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor  void AddListInitializationStep(QualType T);
653d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor
65471d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor  /// \brief Add a constructor-initialization step.
65551c56d6c8a944c2e49dd714db65a780d9f627e15Douglas Gregor  void AddConstructorInitializationStep(CXXConstructorDecl *Constructor,
656b13b737a2450167c82e148590e8019b839ce6b98John McCall                                        AccessSpecifier Access,
65751c56d6c8a944c2e49dd714db65a780d9f627e15Douglas Gregor                                        QualType T);
65871d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor
65971d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor  /// \brief Add a zero-initialization step.
66071d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor  void AddZeroInitializationStep(QualType T);
66151c56d6c8a944c2e49dd714db65a780d9f627e15Douglas Gregor
66218ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor  /// \brief Add a C assignment step.
66318ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor  //
66418ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor  // FIXME: It isn't clear whether this should ever be needed;
66518ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor  // ideally, we would handle everything needed in C in the common
66618ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor  // path. However, that isn't the case yet.
66718ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor  void AddCAssignmentStep(QualType T);
66818ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor
669cfdc81a83467973b14e4ea5e9e9af1690f135415Eli Friedman  /// \brief Add a string init step.
670cfdc81a83467973b14e4ea5e9e9af1690f135415Eli Friedman  void AddStringInitStep(QualType T);
671cfdc81a83467973b14e4ea5e9e9af1690f135415Eli Friedman
67220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Note that this initialization sequence failed.
67320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  void SetFailed(FailureKind Failure) {
67420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SequenceKind = FailedSequence;
67520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    this->Failure = Failure;
67620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
67720093b4bf698f292c664676987541d5103b65b15Douglas Gregor
67820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Note that this initialization sequence failed due to failed
67920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// overload resolution.
68020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  void SetOverloadFailure(FailureKind Failure, OverloadingResult Result);
68120093b4bf698f292c664676987541d5103b65b15Douglas Gregor
68220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Retrieve a reference to the candidate set when overload
68320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// resolution fails.
68420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  OverloadCandidateSet &getFailedCandidateSet() {
68520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return FailedCandidateSet;
68620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
68720093b4bf698f292c664676987541d5103b65b15Douglas Gregor
68820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine why initialization failed.
68920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  FailureKind getFailureKind() const {
69020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    assert(getKind() == FailedSequence && "Not an initialization failure!");
69120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return Failure;
69220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
693de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor
694de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor  /// \brief Dump a representation of this initialization sequence to
695de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor  /// the given stream, for debugging purposes.
696de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor  void dump(llvm::raw_ostream &OS) const;
697de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor
698de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor  /// \brief Dump a representation of this initialization sequence to
699de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor  /// standard error, for debugging purposes.
700de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor  void dump() const;
70120093b4bf698f292c664676987541d5103b65b15Douglas Gregor};
70220093b4bf698f292c664676987541d5103b65b15Douglas Gregor
70320093b4bf698f292c664676987541d5103b65b15Douglas Gregor} // end namespace clang
70420093b4bf698f292c664676987541d5103b65b15Douglas Gregor
70520093b4bf698f292c664676987541d5103b65b15Douglas Gregor#endif // LLVM_CLANG_SEMA_INIT_H
706