Initialization.h revision 6e4a0af697eec5b0c47ccf96dff170af56df826d
1ecfcd5655758955d8958dc2a7a7b2c8eff2395b7Sebastian Redl//===--- Initialization.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//===----------------------------------------------------------------------===//
13e737f5041a36d0befb39ffeed8d50ba15916d3daDouglas Gregor#ifndef LLVM_CLANG_SEMA_INITIALIZATION_H
14e737f5041a36d0befb39ffeed8d50ba15916d3daDouglas Gregor#define LLVM_CLANG_SEMA_INITIALIZATION_H
1520093b4bf698f292c664676987541d5103b65b15Douglas Gregor
16120d63cd4465230c2cd56508c7cd8e0ad00848e7John McCall#include "clang/Sema/Ownership.h"
17e737f5041a36d0befb39ffeed8d50ba15916d3daDouglas Gregor#include "clang/Sema/Overload.h"
18d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor#include "clang/AST/Type.h"
19b13b737a2450167c82e148590e8019b839ce6b98John McCall#include "clang/AST/UnresolvedSet.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
2520093b4bf698f292c664676987541d5103b65b15Douglas Gregornamespace clang {
2620093b4bf698f292c664676987541d5103b65b15Douglas Gregor
2720093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass CXXBaseSpecifier;
2820093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass DeclaratorDecl;
2920093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass DeclaratorInfo;
3020093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass FieldDecl;
3120093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass FunctionDecl;
3220093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass ParmVarDecl;
3320093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass Sema;
3420093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass TypeLoc;
3520093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass VarDecl;
3620093b4bf698f292c664676987541d5103b65b15Douglas Gregor
3720093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// \brief Describes an entity that is being initialized.
3820093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass InitializedEntity {
3920093b4bf698f292c664676987541d5103b65b15Douglas Gregorpublic:
4020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Specifies the kind of entity being initialized.
4120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  enum EntityKind {
4220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief The entity being initialized is a variable.
4320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    EK_Variable,
4420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief The entity being initialized is a function parameter.
4520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    EK_Parameter,
4620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief The entity being initialized is the result of a function call.
4720093b4bf698f292c664676987541d5103b65b15Douglas Gregor    EK_Result,
4820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief The entity being initialized is an exception object that
4920093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// is being thrown.
5020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    EK_Exception,
51a729bbb739ca97a8dc52b6b0495725590a0367dcAnders Carlsson    /// \brief The entity being initialized is a non-static data member
52a729bbb739ca97a8dc52b6b0495725590a0367dcAnders Carlsson    /// subobject.
53a729bbb739ca97a8dc52b6b0495725590a0367dcAnders Carlsson    EK_Member,
54a729bbb739ca97a8dc52b6b0495725590a0367dcAnders Carlsson    /// \brief The entity being initialized is an element of an array.
55a729bbb739ca97a8dc52b6b0495725590a0367dcAnders Carlsson    EK_ArrayElement,
5618ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor    /// \brief The entity being initialized is an object (or array of
5718ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor    /// objects) allocated via new.
5818ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor    EK_New,
5920093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief The entity being initialized is a temporary object.
6020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    EK_Temporary,
6120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief The entity being initialized is a base member subobject.
6220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    EK_Base,
634171766318a2564fbc9a739be0a2851f441c0d29Sean Hunt    /// \brief The initialization is being done by a delegating constructor.
64059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt    EK_Delegating,
65d3d824d45c32d457493e7cb79cc34a4761afb760Anders Carlsson    /// \brief The entity being initialized is an element of a vector.
66cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor    /// or vector.
67310b1c421665241d9b135c517d5031716d4a3221Fariborz Jahanian    EK_VectorElement,
68310b1c421665241d9b135c517d5031716d4a3221Fariborz Jahanian    /// \brief The entity being initialized is a field of block descriptor for
69310b1c421665241d9b135c517d5031716d4a3221Fariborz Jahanian    /// the copied-in c++ object.
700c706c29f20b6fa36759fa41333b9c3ec0bd2969Eli Friedman    EK_BlockElement,
710c706c29f20b6fa36759fa41333b9c3ec0bd2969Eli Friedman    /// \brief The entity being initialized is the real or imaginary part of a
720c706c29f20b6fa36759fa41333b9c3ec0bd2969Eli Friedman    /// complex number.
734773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    EK_ComplexElement,
744773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    /// \brief The entity being initialized is the field that captures a
754773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    /// variable in a lambda.
764773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    EK_LambdaCapture
7720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  };
7820093b4bf698f292c664676987541d5103b65b15Douglas Gregor
7920093b4bf698f292c664676987541d5103b65b15Douglas Gregorprivate:
8020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief The kind of entity being initialized.
8120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  EntityKind Kind;
8220093b4bf698f292c664676987541d5103b65b15Douglas Gregor
83cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// \brief If non-NULL, the parent entity in which this
84cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// initialization occurs.
85cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  const InitializedEntity *Parent;
86cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor
87d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor  /// \brief The type of the object or reference being initialized.
88d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor  QualType Type;
8920093b4bf698f292c664676987541d5103b65b15Douglas Gregor
9020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  union {
914773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    /// \brief When Kind == EK_Variable, or EK_Member, the VarDecl or
92f85e193739c953358c865005855253af4f68a497John McCall    /// FieldDecl, respectively.
9320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    DeclaratorDecl *VariableOrMember;
94f85e193739c953358c865005855253af4f68a497John McCall
95f85e193739c953358c865005855253af4f68a497John McCall    /// \brief When Kind == EK_Parameter, the ParmVarDecl, with the
96f85e193739c953358c865005855253af4f68a497John McCall    /// low bit indicating whether the parameter is "consumed".
97f85e193739c953358c865005855253af4f68a497John McCall    uintptr_t Parameter;
9820093b4bf698f292c664676987541d5103b65b15Douglas Gregor
99ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    /// \brief When Kind == EK_Temporary, the type source information for
100ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    /// the temporary.
101ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    TypeSourceInfo *TypeInfo;
102ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
1033c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor    struct {
1044773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor      /// \brief When Kind == EK_Result, EK_Exception, EK_New, the
1053c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor      /// location of the 'return', 'throw', or 'new' keyword,
1063c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor      /// respectively. When Kind == EK_Temporary, the location where
1073c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor      /// the temporary is being created.
1083c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor      unsigned Location;
1093c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor
1104926d832aa2f0af9d7c00633727d49e7967eb978Douglas Gregor      /// \brief Whether the entity being initialized may end up using the
1114926d832aa2f0af9d7c00633727d49e7967eb978Douglas Gregor      /// named return value optimization (NRVO).
1123c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor      bool NRVO;
1133c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor    } LocAndNRVO;
11420093b4bf698f292c664676987541d5103b65b15Douglas Gregor
11520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief When Kind == EK_Base, the base specifier that provides the
116711f34adb886cce8ba86c7b1b6513a1eaaf63bb5Anders Carlsson    /// base class. The lower bit specifies whether the base is an inherited
117711f34adb886cce8ba86c7b1b6513a1eaaf63bb5Anders Carlsson    /// virtual base.
118711f34adb886cce8ba86c7b1b6513a1eaaf63bb5Anders Carlsson    uintptr_t Base;
119cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor
1200c706c29f20b6fa36759fa41333b9c3ec0bd2969Eli Friedman    /// \brief When Kind == EK_ArrayElement, EK_VectorElement, or
1210c706c29f20b6fa36759fa41333b9c3ec0bd2969Eli Friedman    /// EK_ComplexElement, the index of the array or vector element being
1220c706c29f20b6fa36759fa41333b9c3ec0bd2969Eli Friedman    /// initialized.
123cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor    unsigned Index;
1244773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor
1254773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    struct {
1264773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor      /// \brief The variable being captured by an EK_LambdaCapture.
1274773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor      VarDecl *Var;
1284773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor
1294773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor      /// \brief The source location at which the capture occurs.
1304773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor      unsigned Location;
1314773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    } Capture;
13220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  };
13320093b4bf698f292c664676987541d5103b65b15Douglas Gregor
13420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  InitializedEntity() { }
13520093b4bf698f292c664676987541d5103b65b15Douglas Gregor
13620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create the initialization entity for a variable.
13720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  InitializedEntity(VarDecl *Var)
138d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor    : Kind(EK_Variable), Parent(0), Type(Var->getType()),
139606f65665421d594458e1409b4413005fb521c25Francois Pichet      VariableOrMember(Var) { }
14020093b4bf698f292c664676987541d5103b65b15Douglas Gregor
141a188ff2d8a18140541fcd5884deda4552dac71a7Douglas Gregor  /// \brief Create the initialization entity for the result of a
142a188ff2d8a18140541fcd5884deda4552dac71a7Douglas Gregor  /// function, throwing an object, performing an explicit cast, or
143a188ff2d8a18140541fcd5884deda4552dac71a7Douglas Gregor  /// initializing a parameter for which there is no declaration.
1443c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor  InitializedEntity(EntityKind Kind, SourceLocation Loc, QualType Type,
1453c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor                    bool NRVO = false)
1463c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor    : Kind(Kind), Parent(0), Type(Type)
1473c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor  {
1483c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor    LocAndNRVO.Location = Loc.getRawEncoding();
1493c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor    LocAndNRVO.NRVO = NRVO;
1503c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor  }
15120093b4bf698f292c664676987541d5103b65b15Douglas Gregor
15220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create the initialization entity for a member subobject.
153cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  InitializedEntity(FieldDecl *Member, const InitializedEntity *Parent)
154d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor    : Kind(EK_Member), Parent(Parent), Type(Member->getType()),
155606f65665421d594458e1409b4413005fb521c25Francois Pichet      VariableOrMember(Member) { }
15620093b4bf698f292c664676987541d5103b65b15Douglas Gregor
157cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// \brief Create the initialization entity for an array element.
158cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  InitializedEntity(ASTContext &Context, unsigned Index,
159cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor                    const InitializedEntity &Parent);
160cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor
1614773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  /// \brief Create the initialization entity for a lambda capture.
1624773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  InitializedEntity(VarDecl *Var, FieldDecl *Field, SourceLocation Loc)
1634773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    : Kind(EK_LambdaCapture), Parent(0), Type(Field->getType())
1644773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  {
1654773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    Capture.Var = Var;
1664773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    Capture.Location = Loc.getRawEncoding();
1674773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  }
1684773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor
16920093b4bf698f292c664676987541d5103b65b15Douglas Gregorpublic:
17020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create the initialization entity for a variable.
17120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializedEntity InitializeVariable(VarDecl *Var) {
17220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return InitializedEntity(Var);
17320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
17420093b4bf698f292c664676987541d5103b65b15Douglas Gregor
17520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create the initialization entity for a parameter.
176745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian  static InitializedEntity InitializeParameter(ASTContext &Context,
177745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian                                               ParmVarDecl *Parm) {
1784e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie    bool Consumed = (Context.getLangOpts().ObjCAutoRefCount &&
179f85e193739c953358c865005855253af4f68a497John McCall                     Parm->hasAttr<NSConsumedAttr>());
180f85e193739c953358c865005855253af4f68a497John McCall
181f85e193739c953358c865005855253af4f68a497John McCall    InitializedEntity Entity;
182f85e193739c953358c865005855253af4f68a497John McCall    Entity.Kind = EK_Parameter;
183f85e193739c953358c865005855253af4f68a497John McCall    Entity.Type = Context.getVariableArrayDecayedType(
184f85e193739c953358c865005855253af4f68a497John McCall                                       Parm->getType().getUnqualifiedType());
185f85e193739c953358c865005855253af4f68a497John McCall    Entity.Parent = 0;
18682d1cc06ea533267e24ffe8b5885062ca062b479John McCall    Entity.Parameter
18782d1cc06ea533267e24ffe8b5885062ca062b479John McCall      = (static_cast<uintptr_t>(Consumed) | reinterpret_cast<uintptr_t>(Parm));
188f85e193739c953358c865005855253af4f68a497John McCall    return Entity;
18920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
19020093b4bf698f292c664676987541d5103b65b15Douglas Gregor
191a188ff2d8a18140541fcd5884deda4552dac71a7Douglas Gregor  /// \brief Create the initialization entity for a parameter that is
192a188ff2d8a18140541fcd5884deda4552dac71a7Douglas Gregor  /// only known by its type.
193745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian  static InitializedEntity InitializeParameter(ASTContext &Context,
194f85e193739c953358c865005855253af4f68a497John McCall                                               QualType Type,
195f85e193739c953358c865005855253af4f68a497John McCall                                               bool Consumed) {
196688fc9b9b4323a294f5bf4f8a83f7c365edec573Douglas Gregor    InitializedEntity Entity;
197688fc9b9b4323a294f5bf4f8a83f7c365edec573Douglas Gregor    Entity.Kind = EK_Parameter;
198745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian    Entity.Type = Context.getVariableArrayDecayedType(Type);
199688fc9b9b4323a294f5bf4f8a83f7c365edec573Douglas Gregor    Entity.Parent = 0;
200f85e193739c953358c865005855253af4f68a497John McCall    Entity.Parameter = (Consumed);
201688fc9b9b4323a294f5bf4f8a83f7c365edec573Douglas Gregor    return Entity;
202a188ff2d8a18140541fcd5884deda4552dac71a7Douglas Gregor  }
203a188ff2d8a18140541fcd5884deda4552dac71a7Douglas Gregor
20420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create the initialization entity for the result of a function.
20520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializedEntity InitializeResult(SourceLocation ReturnLoc,
2063c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor                                            QualType Type, bool NRVO) {
2073c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor    return InitializedEntity(EK_Result, ReturnLoc, Type, NRVO);
20820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
20920093b4bf698f292c664676987541d5103b65b15Douglas Gregor
210310b1c421665241d9b135c517d5031716d4a3221Fariborz Jahanian  static InitializedEntity InitializeBlock(SourceLocation BlockVarLoc,
211310b1c421665241d9b135c517d5031716d4a3221Fariborz Jahanian                                           QualType Type, bool NRVO) {
212310b1c421665241d9b135c517d5031716d4a3221Fariborz Jahanian    return InitializedEntity(EK_BlockElement, BlockVarLoc, Type, NRVO);
213310b1c421665241d9b135c517d5031716d4a3221Fariborz Jahanian  }
214310b1c421665241d9b135c517d5031716d4a3221Fariborz Jahanian
21520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create the initialization entity for an exception object.
21620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializedEntity InitializeException(SourceLocation ThrowLoc,
2173c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor                                               QualType Type, bool NRVO) {
2183c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor    return InitializedEntity(EK_Exception, ThrowLoc, Type, NRVO);
21920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
22018ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor
22118ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor  /// \brief Create the initialization entity for an object allocated via new.
222d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor  static InitializedEntity InitializeNew(SourceLocation NewLoc, QualType Type) {
223d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor    return InitializedEntity(EK_New, NewLoc, Type);
22418ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor  }
22520093b4bf698f292c664676987541d5103b65b15Douglas Gregor
22620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create the initialization entity for a temporary.
227d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor  static InitializedEntity InitializeTemporary(QualType Type) {
2286e4a0af697eec5b0c47ccf96dff170af56df826dRichard Smith    InitializedEntity Result(EK_Temporary, SourceLocation(), Type);
2296e4a0af697eec5b0c47ccf96dff170af56df826dRichard Smith    Result.TypeInfo = 0;
2306e4a0af697eec5b0c47ccf96dff170af56df826dRichard Smith    return Result;
23120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
232ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
233ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// \brief Create the initialization entity for a temporary.
234ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  static InitializedEntity InitializeTemporary(TypeSourceInfo *TypeInfo) {
235ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    InitializedEntity Result(EK_Temporary, SourceLocation(),
236ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                             TypeInfo->getType());
237ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    Result.TypeInfo = TypeInfo;
238ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return Result;
239ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  }
240ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
24120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create the initialization entity for a base class subobject.
24220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializedEntity InitializeBase(ASTContext &Context,
243711f34adb886cce8ba86c7b1b6513a1eaaf63bb5Anders Carlsson                                          CXXBaseSpecifier *Base,
244711f34adb886cce8ba86c7b1b6513a1eaaf63bb5Anders Carlsson                                          bool IsInheritedVirtualBase);
2454171766318a2564fbc9a739be0a2851f441c0d29Sean Hunt
2464171766318a2564fbc9a739be0a2851f441c0d29Sean Hunt  /// \brief Create the initialization entity for a delegated constructor.
2474171766318a2564fbc9a739be0a2851f441c0d29Sean Hunt  static InitializedEntity InitializeDelegation(QualType Type) {
248059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt    return InitializedEntity(EK_Delegating, SourceLocation(), Type);
2494171766318a2564fbc9a739be0a2851f441c0d29Sean Hunt  }
25020093b4bf698f292c664676987541d5103b65b15Douglas Gregor
251cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// \brief Create the initialization entity for a member subobject.
252cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  static InitializedEntity InitializeMember(FieldDecl *Member,
253cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor                                          const InitializedEntity *Parent = 0) {
254cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor    return InitializedEntity(Member, Parent);
25520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
25620093b4bf698f292c664676987541d5103b65b15Douglas Gregor
25700eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet  /// \brief Create the initialization entity for a member subobject.
25800eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet  static InitializedEntity InitializeMember(IndirectFieldDecl *Member,
25900eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet                                      const InitializedEntity *Parent = 0) {
26000eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet    return InitializedEntity(Member->getAnonField(), Parent);
26100eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet  }
26200eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet
263cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// \brief Create the initialization entity for an array element.
264cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  static InitializedEntity InitializeElement(ASTContext &Context,
265cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor                                             unsigned Index,
266cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor                                             const InitializedEntity &Parent) {
267cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor    return InitializedEntity(Context, Index, Parent);
268cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  }
269cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor
2704773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  /// \brief Create the initialization entity for a lambda capture.
2714773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  static InitializedEntity InitializeLambdaCapture(VarDecl *Var,
2724773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor                                                   FieldDecl *Field,
2734773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor                                                   SourceLocation Loc) {
2744773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    return InitializedEntity(Var, Field, Loc);
2754773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  }
2764773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor
27720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine the kind of initialization.
27820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  EntityKind getKind() const { return Kind; }
27920093b4bf698f292c664676987541d5103b65b15Douglas Gregor
280cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// \brief Retrieve the parent of the entity being initialized, when
281fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner  /// the initialization itself is occurring within the context of a
282cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// larger initialization.
283cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  const InitializedEntity *getParent() const { return Parent; }
284cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor
28520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Retrieve type being initialized.
286d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor  QualType getType() const { return Type; }
28720093b4bf698f292c664676987541d5103b65b15Douglas Gregor
288ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// \brief Retrieve complete type-source information for the object being
289ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// constructed, if known.
290ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const {
291ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    if (Kind == EK_Temporary)
292ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      return TypeInfo;
293ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
294ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return 0;
295ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  }
296ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
29799a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  /// \brief Retrieve the name of the entity being initialized.
29899a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  DeclarationName getName() const;
2997abfbdbc97ad8e7f340789f751df1e32b10118b4Douglas Gregor
3007abfbdbc97ad8e7f340789f751df1e32b10118b4Douglas Gregor  /// \brief Retrieve the variable, parameter, or field being
3017abfbdbc97ad8e7f340789f751df1e32b10118b4Douglas Gregor  /// initialized.
3027abfbdbc97ad8e7f340789f751df1e32b10118b4Douglas Gregor  DeclaratorDecl *getDecl() const;
3037abfbdbc97ad8e7f340789f751df1e32b10118b4Douglas Gregor
3043c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor  /// \brief Determine whether this initialization allows the named return
3053c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor  /// value optimization, which also applies to thrown objects.
3063c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor  bool allowsNRVO() const;
307f85e193739c953358c865005855253af4f68a497John McCall
308f85e193739c953358c865005855253af4f68a497John McCall  /// \brief Determine whether this initialization consumes the
309f85e193739c953358c865005855253af4f68a497John McCall  /// parameter.
310f85e193739c953358c865005855253af4f68a497John McCall  bool isParameterConsumed() const {
311f85e193739c953358c865005855253af4f68a497John McCall    assert(getKind() == EK_Parameter && "Not a parameter");
312f85e193739c953358c865005855253af4f68a497John McCall    return (Parameter & 1);
313f85e193739c953358c865005855253af4f68a497John McCall  }
3143c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor
3159db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor  /// \brief Retrieve the base specifier.
3169db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor  CXXBaseSpecifier *getBaseSpecifier() const {
3179db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor    assert(getKind() == EK_Base && "Not a base specifier");
318711f34adb886cce8ba86c7b1b6513a1eaaf63bb5Anders Carlsson    return reinterpret_cast<CXXBaseSpecifier *>(Base & ~0x1);
319711f34adb886cce8ba86c7b1b6513a1eaaf63bb5Anders Carlsson  }
320711f34adb886cce8ba86c7b1b6513a1eaaf63bb5Anders Carlsson
321711f34adb886cce8ba86c7b1b6513a1eaaf63bb5Anders Carlsson  /// \brief Return whether the base is an inherited virtual base.
322711f34adb886cce8ba86c7b1b6513a1eaaf63bb5Anders Carlsson  bool isInheritedVirtualBase() const {
323711f34adb886cce8ba86c7b1b6513a1eaaf63bb5Anders Carlsson    assert(getKind() == EK_Base && "Not a base specifier");
324711f34adb886cce8ba86c7b1b6513a1eaaf63bb5Anders Carlsson    return Base & 0x1;
3259db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor  }
3269db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor
32720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine the location of the 'return' keyword when initializing
32820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// the result of a function call.
32920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  SourceLocation getReturnLoc() const {
33020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    assert(getKind() == EK_Result && "No 'return' location!");
3313c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor    return SourceLocation::getFromRawEncoding(LocAndNRVO.Location);
33220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
333f85e193739c953358c865005855253af4f68a497John McCall
33420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine the location of the 'throw' keyword when initializing
33520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// an exception object.
33620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  SourceLocation getThrowLoc() const {
33720093b4bf698f292c664676987541d5103b65b15Douglas Gregor    assert(getKind() == EK_Exception && "No 'throw' location!");
3383c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor    return SourceLocation::getFromRawEncoding(LocAndNRVO.Location);
33920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
340cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor
341cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// \brief If this is already the initializer for an array or vector
342cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// element, sets the element index.
343cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  void setElementIndex(unsigned Index) {
3440c706c29f20b6fa36759fa41333b9c3ec0bd2969Eli Friedman    assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement ||
345eb52f86a62db523e3c993686b3ed92c55d59d53cDavid Blaikie           getKind() == EK_ComplexElement);
346cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor    this->Index = Index;
347cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  }
3484773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor
3494773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  /// \brief Retrieve the variable for a captured variable in a lambda.
3504773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  VarDecl *getCapturedVar() const {
3514773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    assert(getKind() == EK_LambdaCapture && "Not a lambda capture!");
3524773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    return Capture.Var;
3534773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  }
3544773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor
3554773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  /// \brief Determine the location of the capture when initializing
3564773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  /// field from a captured variable in a lambda.
3574773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  SourceLocation getCaptureLoc() const {
3584773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    assert(getKind() == EK_LambdaCapture && "Not a lambda capture!");
3594773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    return SourceLocation::getFromRawEncoding(Capture.Location);
3604773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  }
36120093b4bf698f292c664676987541d5103b65b15Douglas Gregor};
36220093b4bf698f292c664676987541d5103b65b15Douglas Gregor
36320093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// \brief Describes the kind of initialization being performed, along with
36420093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// location information for tokens related to the initialization (equal sign,
36520093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// parentheses).
36620093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass InitializationKind {
36720093b4bf698f292c664676987541d5103b65b15Douglas Gregorpublic:
36820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief The kind of initialization being performed.
36920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  enum InitKind {
370ed878af7914df535b32d64f555fa118413186672Douglas Gregor    IK_Direct,       ///< Direct initialization
371ed878af7914df535b32d64f555fa118413186672Douglas Gregor    IK_DirectList,   ///< Direct list-initialization
372ed878af7914df535b32d64f555fa118413186672Douglas Gregor    IK_Copy,         ///< Copy initialization
373ed878af7914df535b32d64f555fa118413186672Douglas Gregor    IK_Default,      ///< Default initialization
374ed878af7914df535b32d64f555fa118413186672Douglas Gregor    IK_Value         ///< Value initialization
37520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  };
37620093b4bf698f292c664676987541d5103b65b15Douglas Gregor
37720093b4bf698f292c664676987541d5103b65b15Douglas Gregorprivate:
3783a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl  /// \brief The context of the initialization.
3793a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl  enum InitContext {
3803a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    IC_Normal,         ///< Normal context
381ed878af7914df535b32d64f555fa118413186672Douglas Gregor    IC_ExplicitConvs,  ///< Normal context, but allows explicit conversion funcs
3823a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    IC_Implicit,       ///< Implicit context (value initialization)
3833a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    IC_StaticCast,     ///< Static cast context
3843a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    IC_CStyleCast,     ///< C-style cast context
3853a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    IC_FunctionalCast  ///< Functional cast context
38620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  };
38720093b4bf698f292c664676987541d5103b65b15Douglas Gregor
38820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief The kind of initialization being performed.
3893a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl  InitKind Kind : 8;
3903a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl
3913a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl  /// \brief The context of the initialization.
3923a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl  InitContext Context : 8;
39320093b4bf698f292c664676987541d5103b65b15Douglas Gregor
39420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief The source locations involved in the initialization.
39520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  SourceLocation Locations[3];
39620093b4bf698f292c664676987541d5103b65b15Douglas Gregor
3973a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl  InitializationKind(InitKind Kind, InitContext Context, SourceLocation Loc1,
39820093b4bf698f292c664676987541d5103b65b15Douglas Gregor                     SourceLocation Loc2, SourceLocation Loc3)
3993a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    : Kind(Kind), Context(Context)
40020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  {
40120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    Locations[0] = Loc1;
40220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    Locations[1] = Loc2;
40320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    Locations[2] = Loc3;
40420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
40520093b4bf698f292c664676987541d5103b65b15Douglas Gregor
40620093b4bf698f292c664676987541d5103b65b15Douglas Gregorpublic:
40720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create a direct initialization.
40820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializationKind CreateDirect(SourceLocation InitLoc,
40920093b4bf698f292c664676987541d5103b65b15Douglas Gregor                                         SourceLocation LParenLoc,
41020093b4bf698f292c664676987541d5103b65b15Douglas Gregor                                         SourceLocation RParenLoc) {
4113a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    return InitializationKind(IK_Direct, IC_Normal,
4123a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl                              InitLoc, LParenLoc, RParenLoc);
41320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
41420093b4bf698f292c664676987541d5103b65b15Douglas Gregor
4155b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  static InitializationKind CreateDirectList(SourceLocation InitLoc) {
4163a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    return InitializationKind(IK_DirectList, IC_Normal,
4173a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl                              InitLoc, InitLoc, InitLoc);
4185b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  }
4195b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl
420f85e193739c953358c865005855253af4f68a497John McCall  /// \brief Create a direct initialization due to a cast that isn't a C-style
421f85e193739c953358c865005855253af4f68a497John McCall  /// or functional cast.
422c8d7f586180995ba33d03c0f6115b6a7bdefe326Richard Smith  static InitializationKind CreateCast(SourceRange TypeRange) {
4233a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    return InitializationKind(IK_Direct, IC_StaticCast, TypeRange.getBegin(),
4243a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl                              TypeRange.getBegin(), TypeRange.getEnd());
42520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
42620093b4bf698f292c664676987541d5103b65b15Douglas Gregor
427f85e193739c953358c865005855253af4f68a497John McCall  /// \brief Create a direct initialization for a C-style cast.
428f85e193739c953358c865005855253af4f68a497John McCall  static InitializationKind CreateCStyleCast(SourceLocation StartLoc,
4293a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl                                             SourceRange TypeRange,
4303a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl                                             bool InitList) {
4313a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    // C++ cast syntax doesn't permit init lists, but C compound literals are
4323a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    // exactly that.
4333a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    return InitializationKind(InitList ? IK_DirectList : IK_Direct,
4343a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl                              IC_CStyleCast, StartLoc, TypeRange.getBegin(),
435f85e193739c953358c865005855253af4f68a497John McCall                              TypeRange.getEnd());
436f85e193739c953358c865005855253af4f68a497John McCall  }
437f85e193739c953358c865005855253af4f68a497John McCall
438f85e193739c953358c865005855253af4f68a497John McCall  /// \brief Create a direct initialization for a functional cast.
4393a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl  static InitializationKind CreateFunctionalCast(SourceRange TypeRange,
4403a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl                                                 bool InitList) {
4413a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    return InitializationKind(InitList ? IK_DirectList : IK_Direct,
4423a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl                              IC_FunctionalCast, TypeRange.getBegin(),
4433a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl                              TypeRange.getBegin(), TypeRange.getEnd());
444f85e193739c953358c865005855253af4f68a497John McCall  }
445f85e193739c953358c865005855253af4f68a497John McCall
44620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create a copy initialization.
44720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializationKind CreateCopy(SourceLocation InitLoc,
448ed878af7914df535b32d64f555fa118413186672Douglas Gregor                                       SourceLocation EqualLoc,
449ed878af7914df535b32d64f555fa118413186672Douglas Gregor                                       bool AllowExplicitConvs = false) {
450ed878af7914df535b32d64f555fa118413186672Douglas Gregor    return InitializationKind(IK_Copy,
451ed878af7914df535b32d64f555fa118413186672Douglas Gregor                              AllowExplicitConvs? IC_ExplicitConvs : IC_Normal,
452ed878af7914df535b32d64f555fa118413186672Douglas Gregor                              InitLoc, EqualLoc, EqualLoc);
45320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
45420093b4bf698f292c664676987541d5103b65b15Douglas Gregor
45520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create a default initialization.
45620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializationKind CreateDefault(SourceLocation InitLoc) {
4573a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    return InitializationKind(IK_Default, IC_Normal, InitLoc, InitLoc, InitLoc);
45820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
45920093b4bf698f292c664676987541d5103b65b15Douglas Gregor
46020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create a value initialization.
46120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializationKind CreateValue(SourceLocation InitLoc,
46220093b4bf698f292c664676987541d5103b65b15Douglas Gregor                                        SourceLocation LParenLoc,
463cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor                                        SourceLocation RParenLoc,
464cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor                                        bool isImplicit = false) {
4653a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    return InitializationKind(IK_Value, isImplicit ? IC_Implicit : IC_Normal,
466cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor                              InitLoc, LParenLoc, RParenLoc);
46720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
46820093b4bf698f292c664676987541d5103b65b15Douglas Gregor
46920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine the initialization kind.
47020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  InitKind getKind() const {
4713a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    return Kind;
47220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
47320093b4bf698f292c664676987541d5103b65b15Douglas Gregor
47420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine whether this initialization is an explicit cast.
47520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  bool isExplicitCast() const {
4763a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    return Context >= IC_StaticCast;
47720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
47820093b4bf698f292c664676987541d5103b65b15Douglas Gregor
47920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine whether this initialization is a C-style cast.
48020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  bool isCStyleOrFunctionalCast() const {
4813a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    return Context >= IC_CStyleCast;
482f85e193739c953358c865005855253af4f68a497John McCall  }
483f85e193739c953358c865005855253af4f68a497John McCall
4843a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl  /// \brief Determine whether this is a C-style cast.
485f85e193739c953358c865005855253af4f68a497John McCall  bool isCStyleCast() const {
4863a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    return Context == IC_CStyleCast;
487f85e193739c953358c865005855253af4f68a497John McCall  }
488f85e193739c953358c865005855253af4f68a497John McCall
4893a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl  /// \brief Determine whether this is a functional-style cast.
490f85e193739c953358c865005855253af4f68a497John McCall  bool isFunctionalCast() const {
4913a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    return Context == IC_FunctionalCast;
49220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
493cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor
494cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// \brief Determine whether this initialization is an implicit
495cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// value-initialization, e.g., as occurs during aggregate
496cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// initialization.
4973a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl  bool isImplicitValueInit() const { return Context == IC_Implicit; }
498cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor
49920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Retrieve the location at which initialization is occurring.
50020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  SourceLocation getLocation() const { return Locations[0]; }
50120093b4bf698f292c664676987541d5103b65b15Douglas Gregor
50220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Retrieve the source range that covers the initialization.
50320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  SourceRange getRange() const {
50471d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor    return SourceRange(Locations[0], Locations[2]);
50520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
50620093b4bf698f292c664676987541d5103b65b15Douglas Gregor
50720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Retrieve the location of the equal sign for copy initialization
50820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// (if present).
50920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  SourceLocation getEqualLoc() const {
5103a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    assert(Kind == IK_Copy && "Only copy initialization has an '='");
51120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return Locations[1];
51220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
513168319c81b8f4e7addf36ad15ef24919faf23504Sebastian Redl
5143a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl  bool isCopyInit() const { return Kind == IK_Copy; }
515168319c81b8f4e7addf36ad15ef24919faf23504Sebastian Redl
516168319c81b8f4e7addf36ad15ef24919faf23504Sebastian Redl  /// \brief Retrieve whether this initialization allows the use of explicit
517168319c81b8f4e7addf36ad15ef24919faf23504Sebastian Redl  ///        constructors.
518168319c81b8f4e7addf36ad15ef24919faf23504Sebastian Redl  bool AllowExplicit() const { return !isCopyInit(); }
519168319c81b8f4e7addf36ad15ef24919faf23504Sebastian Redl
520ed878af7914df535b32d64f555fa118413186672Douglas Gregor  /// \brief Retrieve whether this initialization allows the use of explicit
521ed878af7914df535b32d64f555fa118413186672Douglas Gregor  /// conversion functions.
522ed878af7914df535b32d64f555fa118413186672Douglas Gregor  bool allowExplicitConversionFunctions() const {
523ed878af7914df535b32d64f555fa118413186672Douglas Gregor    return !isCopyInit() || Context == IC_ExplicitConvs;
524ed878af7914df535b32d64f555fa118413186672Douglas Gregor  }
525ed878af7914df535b32d64f555fa118413186672Douglas Gregor
52620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Retrieve the source range containing the locations of the open
52720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// and closing parentheses for value and direct initializations.
52820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  SourceRange getParenRange() const {
5293a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    assert((Kind == IK_Direct || Kind == IK_Value) &&
53020093b4bf698f292c664676987541d5103b65b15Douglas Gregor           "Only direct- and value-initialization have parentheses");
53120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return SourceRange(Locations[1], Locations[2]);
53220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
53320093b4bf698f292c664676987541d5103b65b15Douglas Gregor};
53420093b4bf698f292c664676987541d5103b65b15Douglas Gregor
53520093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// \brief Describes the sequence of initializations required to initialize
53620093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// a given object or reference with a set of arguments.
53720093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass InitializationSequence {
53820093b4bf698f292c664676987541d5103b65b15Douglas Gregorpublic:
53920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Describes the kind of initialization sequence computed.
54020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  enum SequenceKind {
54120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief A failed initialization sequence. The failure kind tells what
54220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// happened.
54320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FailedSequence = 0,
5447491c499e826682e128a400038361ebcbde30eecSebastian Redl
54520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief A dependent initialization, which could not be
54620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// type-checked due to the presence of dependent types or
5477491c499e826682e128a400038361ebcbde30eecSebastian Redl    /// dependently-typed expressions.
54820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    DependentSequence,
54920093b4bf698f292c664676987541d5103b65b15Douglas Gregor
5507491c499e826682e128a400038361ebcbde30eecSebastian Redl    /// \brief A normal sequence.
5513b80232b50c29b245e674f5aa02047b408e41018Sebastian Redl    NormalSequence
55220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  };
55320093b4bf698f292c664676987541d5103b65b15Douglas Gregor
55420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Describes the kind of a particular step in an initialization
55520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// sequence.
55620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  enum StepKind {
55720093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Resolve the address of an overloaded function to a specific
55820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// function declaration.
55920093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SK_ResolveAddressOfOverloadedFunction,
56020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Perform a derived-to-base cast, producing an rvalue.
56120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SK_CastDerivedToBaseRValue,
562906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl    /// \brief Perform a derived-to-base cast, producing an xvalue.
563906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl    SK_CastDerivedToBaseXValue,
56420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Perform a derived-to-base cast, producing an lvalue.
56520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SK_CastDerivedToBaseLValue,
56620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Reference binding to an lvalue.
56720093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SK_BindReference,
56820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Reference binding to a temporary.
56920093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SK_BindReferenceToTemporary,
570523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor    /// \brief An optional copy of a temporary object to another
571523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor    /// temporary object, which is permitted (but not required) by
572523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor    /// C++98/03 but not C++0x.
573523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor    SK_ExtraneousCopyToTemporary,
57420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Perform a user-defined conversion, either via a conversion
57520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// function or via a constructor.
57620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SK_UserConversion,
57720093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Perform a qualification conversion, producing an rvalue.
57820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SK_QualificationConversionRValue,
579906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl    /// \brief Perform a qualification conversion, producing an xvalue.
580906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl    SK_QualificationConversionXValue,
58120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Perform a qualification conversion, producing an lvalue.
58220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SK_QualificationConversionLValue,
58320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Perform an implicit conversion sequence.
584d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    SK_ConversionSequence,
5858713d4e874f2adc2928ebfb86c845574a14e3b3eSebastian Redl    /// \brief Perform list-initialization without a constructor
58651c56d6c8a944c2e49dd714db65a780d9f627e15Douglas Gregor    SK_ListInitialization,
5878713d4e874f2adc2928ebfb86c845574a14e3b3eSebastian Redl    /// \brief Perform list-initialization with a constructor.
5888713d4e874f2adc2928ebfb86c845574a14e3b3eSebastian Redl    SK_ListConstructorCall,
58913dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl    /// \brief Unwrap the single-element initializer list for a reference.
59013dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl    SK_UnwrapInitList,
59113dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl    /// \brief Rewrap the single-element initializer list for a reference.
59213dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl    SK_RewrapInitList,
59351c56d6c8a944c2e49dd714db65a780d9f627e15Douglas Gregor    /// \brief Perform initialization via a constructor.
59471d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor    SK_ConstructorInitialization,
59571d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor    /// \brief Zero-initialize the object
59618ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor    SK_ZeroInitialization,
59718ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor    /// \brief C assignment
598cfdc81a83467973b14e4ea5e9e9af1690f135415Eli Friedman    SK_CAssignment,
599cfdc81a83467973b14e4ea5e9e9af1690f135415Eli Friedman    /// \brief Initialization by string
600569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor    SK_StringInit,
601569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor    /// \brief An initialization that "converts" an Objective-C object
602569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor    /// (not a point to an object) to another Objective-C object type.
603cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregor    SK_ObjCObjectConversion,
604cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregor    /// \brief Array initialization (from an array rvalue).
605cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregor    /// This is a GNU C extension.
606f85e193739c953358c865005855253af4f68a497John McCall    SK_ArrayInit,
6070f163e964289bc18e9bc1ec37a6a01018ba62640Richard Smith    /// \brief Array initialization from a parenthesized initializer list.
6080f163e964289bc18e9bc1ec37a6a01018ba62640Richard Smith    /// This is a GNU C++ extension.
6090f163e964289bc18e9bc1ec37a6a01018ba62640Richard Smith    SK_ParenthesizedArrayInit,
610f85e193739c953358c865005855253af4f68a497John McCall    /// \brief Pass an object by indirect copy-and-restore.
611f85e193739c953358c865005855253af4f68a497John McCall    SK_PassByIndirectCopyRestore,
612f85e193739c953358c865005855253af4f68a497John McCall    /// \brief Pass an object by indirect restore.
613f85e193739c953358c865005855253af4f68a497John McCall    SK_PassByIndirectRestore,
614f85e193739c953358c865005855253af4f68a497John McCall    /// \brief Produce an Objective-C object pointer.
6152b916b8b55aaf0152ab9ad630c8454bf6373b085Sebastian Redl    SK_ProduceObjCObject,
6162b916b8b55aaf0152ab9ad630c8454bf6373b085Sebastian Redl    /// \brief Construct a std::initializer_list from an initializer list.
6172b916b8b55aaf0152ab9ad630c8454bf6373b085Sebastian Redl    SK_StdInitializerList
61820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  };
61920093b4bf698f292c664676987541d5103b65b15Douglas Gregor
62020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief A single step in the initialization sequence.
62120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  class Step {
62220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  public:
62320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief The kind of conversion or initialization step we are taking.
62420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    StepKind Kind;
62520093b4bf698f292c664676987541d5103b65b15Douglas Gregor
62620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    // \brief The type that results from this initialization.
62720093b4bf698f292c664676987541d5103b65b15Douglas Gregor    QualType Type;
62820093b4bf698f292c664676987541d5103b65b15Douglas Gregor
62920093b4bf698f292c664676987541d5103b65b15Douglas Gregor    union {
63020093b4bf698f292c664676987541d5103b65b15Douglas Gregor      /// \brief When Kind == SK_ResolvedOverloadedFunction or Kind ==
63120093b4bf698f292c664676987541d5103b65b15Douglas Gregor      /// SK_UserConversion, the function that the expression should be
63220093b4bf698f292c664676987541d5103b65b15Douglas Gregor      /// resolved to or the conversion function to call, respectively.
6338713d4e874f2adc2928ebfb86c845574a14e3b3eSebastian Redl      /// When Kind == SK_ConstructorInitialization or SK_ListConstruction,
6348713d4e874f2adc2928ebfb86c845574a14e3b3eSebastian Redl      /// the constructor to be called.
635b13b737a2450167c82e148590e8019b839ce6b98John McCall      ///
6367cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara      /// Always a FunctionDecl, plus a Boolean flag telling if it was
6377cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara      /// selected from an overloaded set having size greater than 1.
638b13b737a2450167c82e148590e8019b839ce6b98John McCall      /// For conversion decls, the naming class is the source type.
639b13b737a2450167c82e148590e8019b839ce6b98John McCall      /// For construct decls, the naming class is the target type.
6409aa472c45d2bd81b7b52c225e8acc560d716db97John McCall      struct {
6417cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara        bool HadMultipleCandidates;
6429aa472c45d2bd81b7b52c225e8acc560d716db97John McCall        FunctionDecl *Function;
6439aa472c45d2bd81b7b52c225e8acc560d716db97John McCall        DeclAccessPair FoundDecl;
6449aa472c45d2bd81b7b52c225e8acc560d716db97John McCall      } Function;
6458713d4e874f2adc2928ebfb86c845574a14e3b3eSebastian Redl
64620093b4bf698f292c664676987541d5103b65b15Douglas Gregor      /// \brief When Kind = SK_ConversionSequence, the implicit conversion
64713dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl      /// sequence.
64820093b4bf698f292c664676987541d5103b65b15Douglas Gregor      ImplicitConversionSequence *ICS;
64913dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl
65013dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl      /// \brief When Kind = SK_RewrapInitList, the syntactic form of the
65113dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl      /// wrapping list.
65213dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl      InitListExpr *WrappingSyntacticList;
65320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    };
6548713d4e874f2adc2928ebfb86c845574a14e3b3eSebastian Redl
65520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    void Destroy();
65620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  };
65720093b4bf698f292c664676987541d5103b65b15Douglas Gregor
65820093b4bf698f292c664676987541d5103b65b15Douglas Gregorprivate:
65920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief The kind of initialization sequence computed.
66020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  enum SequenceKind SequenceKind;
66120093b4bf698f292c664676987541d5103b65b15Douglas Gregor
66220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Steps taken by this initialization.
663686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<Step, 4> Steps;
66420093b4bf698f292c664676987541d5103b65b15Douglas Gregor
66520093b4bf698f292c664676987541d5103b65b15Douglas Gregorpublic:
66620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Describes why initialization failed.
66720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  enum FailureKind {
66820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Too many initializers provided for a reference.
66920093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_TooManyInitsForReference,
67020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Array must be initialized with an initializer list.
67120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_ArrayNeedsInitList,
67220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Array must be initialized with an initializer list or a
67320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// string literal.
67420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_ArrayNeedsInitListOrStringLiteral,
675cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregor    /// \brief Array type mismatch.
676cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregor    FK_ArrayTypeMismatch,
677cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregor    /// \brief Non-constant array initializer
678cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregor    FK_NonConstantArrayInit,
67920093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Cannot resolve the address of an overloaded function.
68020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_AddressOfOverloadFailed,
68120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Overloading due to reference initialization failed.
68220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_ReferenceInitOverloadFailed,
68320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Non-const lvalue reference binding to a temporary.
68420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_NonConstLValueReferenceBindingToTemporary,
68520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Non-const lvalue reference binding to an lvalue of unrelated
68620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// type.
68720093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_NonConstLValueReferenceBindingToUnrelated,
68820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Rvalue reference binding to an lvalue.
68920093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_RValueReferenceBindingToLValue,
69020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Reference binding drops qualifiers.
69120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_ReferenceInitDropsQualifiers,
69220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Reference binding failed.
69320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_ReferenceInitFailed,
69420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Implicit conversion failed.
695d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    FK_ConversionFailed,
696429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    /// \brief Implicit conversion failed.
697429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    FK_ConversionFromPropertyFailed,
698d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    /// \brief Too many initializers for scalar
699d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    FK_TooManyInitsForScalar,
700d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    /// \brief Reference initialization from an initializer list
701d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    FK_ReferenceBindingToInitList,
702d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    /// \brief Initialization of some unused destination type with an
703d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    /// initializer list.
7044a520a2bd8a6b79fa5d4771f02e34e7bd6bc461dDouglas Gregor    FK_InitListBadDestinationType,
7054a520a2bd8a6b79fa5d4771f02e34e7bd6bc461dDouglas Gregor    /// \brief Overloading for a user-defined conversion failed.
70651c56d6c8a944c2e49dd714db65a780d9f627e15Douglas Gregor    FK_UserConversionOverloadFailed,
707cf15cef8447e8b3ae08e81ad25ae9eb443038acfSebastian Redl    /// \brief Overloading for initialization by constructor failed.
70899a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor    FK_ConstructorOverloadFailed,
709cf15cef8447e8b3ae08e81ad25ae9eb443038acfSebastian Redl    /// \brief Overloading for list-initialization by constructor failed.
710cf15cef8447e8b3ae08e81ad25ae9eb443038acfSebastian Redl    FK_ListConstructorOverloadFailed,
71199a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor    /// \brief Default-initialization of a 'const' object.
71272a43bbf6802c8fcfd04dcb2be8eafcb0b8fe29cDouglas Gregor    FK_DefaultInitOfConst,
71372a43bbf6802c8fcfd04dcb2be8eafcb0b8fe29cDouglas Gregor    /// \brief Initialization of an incomplete type.
7148713d4e874f2adc2928ebfb86c845574a14e3b3eSebastian Redl    FK_Incomplete,
71573076431605556fdbf28d287d084a73a24a8b8d4John McCall    /// \brief Variable-length array must not have an initializer.
71673076431605556fdbf28d287d084a73a24a8b8d4John McCall    FK_VariableLengthArrayHasInitializer,
7178713d4e874f2adc2928ebfb86c845574a14e3b3eSebastian Redl    /// \brief List initialization failed at some point.
7185acb0c98b363400f6ade0ae7250f0102224e806bJohn McCall    FK_ListInitializationFailed,
7195acb0c98b363400f6ade0ae7250f0102224e806bJohn McCall    /// \brief Initializer has a placeholder type which cannot be
7205acb0c98b363400f6ade0ae7250f0102224e806bJohn McCall    /// resolved by initialization.
7212b916b8b55aaf0152ab9ad630c8454bf6373b085Sebastian Redl    FK_PlaceholderType,
7222b916b8b55aaf0152ab9ad630c8454bf6373b085Sebastian Redl    /// \brief Failed to initialize a std::initializer_list because copy
7232b916b8b55aaf0152ab9ad630c8454bf6373b085Sebastian Redl    /// construction of some element failed.
72470e24fccc8ef4aa8be03a778e9655bfcfa79dd14Sebastian Redl    FK_InitListElementCopyFailure,
72570e24fccc8ef4aa8be03a778e9655bfcfa79dd14Sebastian Redl    /// \brief List-copy-initialization chose an explicit constructor.
72670e24fccc8ef4aa8be03a778e9655bfcfa79dd14Sebastian Redl    FK_ExplicitConstructor
72720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  };
72820093b4bf698f292c664676987541d5103b65b15Douglas Gregor
72920093b4bf698f292c664676987541d5103b65b15Douglas Gregorprivate:
7305d3d41d0873d51b405972baf38e1f3a7ef5b49e0Sebastian Redl  /// \brief The reason why initialization failed.
73120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  FailureKind Failure;
73220093b4bf698f292c664676987541d5103b65b15Douglas Gregor
73320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief The failed result of overload resolution.
73420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  OverloadingResult FailedOverloadResult;
73520093b4bf698f292c664676987541d5103b65b15Douglas Gregor
73620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief The candidate set created when initialization failed.
73720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  OverloadCandidateSet FailedCandidateSet;
738a41a8c5972c2632247ae7913cf6ce65d45f7e702Douglas Gregor
73969a30b838c723cb1850de55cfa48a402cfeeb6e0Douglas Gregor  /// \brief The incomplete type that caused a failure.
74069a30b838c723cb1850de55cfa48a402cfeeb6e0Douglas Gregor  QualType FailedIncompleteType;
74169a30b838c723cb1850de55cfa48a402cfeeb6e0Douglas Gregor
742a41a8c5972c2632247ae7913cf6ce65d45f7e702Douglas Gregor  /// \brief Prints a follow-up note that highlights the location of
743a41a8c5972c2632247ae7913cf6ce65d45f7e702Douglas Gregor  /// the initialized entity, if it's remote.
744a41a8c5972c2632247ae7913cf6ce65d45f7e702Douglas Gregor  void PrintInitLocationNote(Sema &S, const InitializedEntity &Entity);
745a41a8c5972c2632247ae7913cf6ce65d45f7e702Douglas Gregor
74620093b4bf698f292c664676987541d5103b65b15Douglas Gregorpublic:
74720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Try to perform initialization of the given entity, creating a
74820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// record of the steps required to perform the initialization.
74920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
75020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// The generated initialization sequence will either contain enough
75120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// information to diagnose
75220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
75320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param S the semantic analysis object.
75420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
75520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param Entity the entity being initialized.
75620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
75720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param Kind the kind of initialization being performed.
75820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
75920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param Args the argument(s) provided for initialization.
76020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
76120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param NumArgs the number of arguments provided for initialization.
76220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  InitializationSequence(Sema &S,
76320093b4bf698f292c664676987541d5103b65b15Douglas Gregor                         const InitializedEntity &Entity,
76420093b4bf698f292c664676987541d5103b65b15Douglas Gregor                         const InitializationKind &Kind,
76520093b4bf698f292c664676987541d5103b65b15Douglas Gregor                         Expr **Args,
76620093b4bf698f292c664676987541d5103b65b15Douglas Gregor                         unsigned NumArgs);
76720093b4bf698f292c664676987541d5103b65b15Douglas Gregor
76820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ~InitializationSequence();
76920093b4bf698f292c664676987541d5103b65b15Douglas Gregor
77020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Perform the actual initialization of the given entity based on
77120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// the computed initialization sequence.
77220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
77320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param S the semantic analysis object.
77420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
77520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param Entity the entity being initialized.
77620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
77720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param Kind the kind of initialization being performed.
77820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
77920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param Args the argument(s) provided for initialization, ownership of
780fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner  /// which is transferred into the routine.
78120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
782d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor  /// \param ResultType if non-NULL, will be set to the type of the
783d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor  /// initialized object, which is the type of the declaration in most
784d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor  /// cases. However, when the initialized object is a variable of
785d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor  /// incomplete array type and the initializer is an initializer
786d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor  /// list, this type will be set to the completed array type.
787d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor  ///
78820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \returns an expression that performs the actual object initialization, if
78920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// the initialization is well-formed. Otherwise, emits diagnostics
79020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// and returns an invalid expression.
79160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Perform(Sema &S,
79260d7b3a319d84d688752be3870615ac0f111fb16John McCall                     const InitializedEntity &Entity,
79360d7b3a319d84d688752be3870615ac0f111fb16John McCall                     const InitializationKind &Kind,
794120d63cd4465230c2cd56508c7cd8e0ad00848e7John McCall                     MultiExprArg Args,
79560d7b3a319d84d688752be3870615ac0f111fb16John McCall                     QualType *ResultType = 0);
79620093b4bf698f292c664676987541d5103b65b15Douglas Gregor
79720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Diagnose an potentially-invalid initialization sequence.
79820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
79920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \returns true if the initialization sequence was ill-formed,
80020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// false otherwise.
80120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  bool Diagnose(Sema &S,
80220093b4bf698f292c664676987541d5103b65b15Douglas Gregor                const InitializedEntity &Entity,
80320093b4bf698f292c664676987541d5103b65b15Douglas Gregor                const InitializationKind &Kind,
80420093b4bf698f292c664676987541d5103b65b15Douglas Gregor                Expr **Args, unsigned NumArgs);
80520093b4bf698f292c664676987541d5103b65b15Douglas Gregor
80620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine the kind of initialization sequence computed.
80720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  enum SequenceKind getKind() const { return SequenceKind; }
80820093b4bf698f292c664676987541d5103b65b15Douglas Gregor
80920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Set the kind of sequence computed.
81020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  void setSequenceKind(enum SequenceKind SK) { SequenceKind = SK; }
81120093b4bf698f292c664676987541d5103b65b15Douglas Gregor
81220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine whether the initialization sequence is valid.
8137491c499e826682e128a400038361ebcbde30eecSebastian Redl  operator bool() const { return !Failed(); }
814383616cd2e61131a534afd9364ef53f643e1f834Sebastian Redl
815383616cd2e61131a534afd9364ef53f643e1f834Sebastian Redl  /// \brief Determine whether the initialization sequence is invalid.
816383616cd2e61131a534afd9364ef53f643e1f834Sebastian Redl  bool Failed() const { return SequenceKind == FailedSequence; }
81720093b4bf698f292c664676987541d5103b65b15Douglas Gregor
818686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  typedef SmallVector<Step, 4>::const_iterator step_iterator;
81920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  step_iterator step_begin() const { return Steps.begin(); }
82020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  step_iterator step_end()   const { return Steps.end(); }
82120093b4bf698f292c664676987541d5103b65b15Douglas Gregor
822b70cf44bf1b1956e0c6b98373c4f69b23afa0052Douglas Gregor  /// \brief Determine whether this initialization is a direct reference
823b70cf44bf1b1956e0c6b98373c4f69b23afa0052Douglas Gregor  /// binding (C++ [dcl.init.ref]).
824b70cf44bf1b1956e0c6b98373c4f69b23afa0052Douglas Gregor  bool isDirectReferenceBinding() const;
825b70cf44bf1b1956e0c6b98373c4f69b23afa0052Douglas Gregor
826b70cf44bf1b1956e0c6b98373c4f69b23afa0052Douglas Gregor  /// \brief Determine whether this initialization failed due to an ambiguity.
827b70cf44bf1b1956e0c6b98373c4f69b23afa0052Douglas Gregor  bool isAmbiguous() const;
828b70cf44bf1b1956e0c6b98373c4f69b23afa0052Douglas Gregor
829d6e44a3c4193bd422bfa78c8086fb16bb2168e34Douglas Gregor  /// \brief Determine whether this initialization is direct call to a
830d6e44a3c4193bd422bfa78c8086fb16bb2168e34Douglas Gregor  /// constructor.
831d6e44a3c4193bd422bfa78c8086fb16bb2168e34Douglas Gregor  bool isConstructorInitialization() const;
832191591336f639dad1504e863733fb831645c1644Jeffrey Yasskin
8335d3d41d0873d51b405972baf38e1f3a7ef5b49e0Sebastian Redl  /// \brief Returns whether the last step in this initialization sequence is a
8345d3d41d0873d51b405972baf38e1f3a7ef5b49e0Sebastian Redl  /// narrowing conversion, defined by C++0x [dcl.init.list]p7.
8355d3d41d0873d51b405972baf38e1f3a7ef5b49e0Sebastian Redl  ///
8365d3d41d0873d51b405972baf38e1f3a7ef5b49e0Sebastian Redl  /// If this function returns true, *isInitializerConstant will be set to
8375d3d41d0873d51b405972baf38e1f3a7ef5b49e0Sebastian Redl  /// describe whether *Initializer was a constant expression.  If
8385d3d41d0873d51b405972baf38e1f3a7ef5b49e0Sebastian Redl  /// *isInitializerConstant is set to true, *ConstantValue will be set to the
8395d3d41d0873d51b405972baf38e1f3a7ef5b49e0Sebastian Redl  /// evaluated value of *Initializer.
840191591336f639dad1504e863733fb831645c1644Jeffrey Yasskin  bool endsWithNarrowing(ASTContext &Ctx, const Expr *Initializer,
841191591336f639dad1504e863733fb831645c1644Jeffrey Yasskin                         bool *isInitializerConstant,
842191591336f639dad1504e863733fb831645c1644Jeffrey Yasskin                         APValue *ConstantValue) const;
843191591336f639dad1504e863733fb831645c1644Jeffrey Yasskin
84420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Add a new step in the initialization that resolves the address
84520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// of an overloaded function to a specific function declaration.
84620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
84720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param Function the function to which the overloaded function reference
84820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// resolves.
8496bb8017bb9e828d118e15e59d71c66bba323c364John McCall  void AddAddressOverloadResolutionStep(FunctionDecl *Function,
85022c107b2b99887b5aec6d1fd38210031e944e31fAbramo Bagnara                                        DeclAccessPair Found,
85122c107b2b99887b5aec6d1fd38210031e944e31fAbramo Bagnara                                        bool HadMultipleCandidates);
85222c107b2b99887b5aec6d1fd38210031e944e31fAbramo Bagnara
85320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Add a new step in the initialization that performs a derived-to-
85420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// base cast.
85520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
85620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param BaseType the base type to which we will be casting.
85720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
85820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param IsLValue true if the result of this cast will be treated as
85920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// an lvalue.
860906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl  void AddDerivedToBaseCastStep(QualType BaseType,
8615baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall                                ExprValueKind Category);
86220093b4bf698f292c664676987541d5103b65b15Douglas Gregor
86320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Add a new step binding a reference to an object.
86420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
865523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  /// \param BindingTemporary True if we are binding a reference to a temporary
86620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// object (thereby extending its lifetime); false if we are binding to an
86720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// lvalue or an lvalue treated as an rvalue.
868523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  ///
869523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  /// \param UnnecessaryCopy True if we should check for a copy
870523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  /// constructor for a completely unnecessary but
87120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  void AddReferenceBindingStep(QualType T, bool BindingTemporary);
872523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor
873523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  /// \brief Add a new step that makes an extraneous copy of the input
874523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  /// to a temporary of the same class type.
875523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  ///
876523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  /// This extraneous copy only occurs during reference binding in
877523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  /// C++98/03, where we are permitted (but not required) to introduce
878523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  /// an extra copy. At a bare minimum, we must check that we could
879523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  /// call the copy constructor, and produce a diagnostic if the copy
880523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  /// constructor is inaccessible or no copy constructor matches.
881523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  //
882523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  /// \param T The type of the temporary being created.
883523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  void AddExtraneousCopyToTemporary(QualType T);
884523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor
88520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Add a new step invoking a conversion function, which is either
88620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// a constructor or a conversion function.
887b13b737a2450167c82e148590e8019b839ce6b98John McCall  void AddUserConversionStep(FunctionDecl *Function,
8889aa472c45d2bd81b7b52c225e8acc560d716db97John McCall                             DeclAccessPair FoundDecl,
88922c107b2b99887b5aec6d1fd38210031e944e31fAbramo Bagnara                             QualType T,
89022c107b2b99887b5aec6d1fd38210031e944e31fAbramo Bagnara                             bool HadMultipleCandidates);
89122c107b2b99887b5aec6d1fd38210031e944e31fAbramo Bagnara
89220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Add a new step that performs a qualification conversion to the
89320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// given type.
894906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl  void AddQualificationConversionStep(QualType Ty,
8955baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall                                     ExprValueKind Category);
89620093b4bf698f292c664676987541d5103b65b15Douglas Gregor
89720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Add a new step that applies an implicit conversion sequence.
89820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  void AddConversionSequenceStep(const ImplicitConversionSequence &ICS,
89920093b4bf698f292c664676987541d5103b65b15Douglas Gregor                                 QualType T);
900d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor
90110f04a6267eb07d3be00db1fd0369e1398f5d0a8Sebastian Redl  /// \brief Add a list-initialization step.
902d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor  void AddListInitializationStep(QualType T);
903d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor
90471d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor  /// \brief Add a constructor-initialization step.
9056cd03dbb310f472b14b8d6d69d8c9b5b7f1200e2Sebastian Redl  ///
9066cd03dbb310f472b14b8d6d69d8c9b5b7f1200e2Sebastian Redl  /// \arg FromInitList The constructor call is syntactically an initializer
9076cd03dbb310f472b14b8d6d69d8c9b5b7f1200e2Sebastian Redl  /// list.
9086cd03dbb310f472b14b8d6d69d8c9b5b7f1200e2Sebastian Redl  /// \arg AsInitList The constructor is called as an init list constructor.
90951c56d6c8a944c2e49dd714db65a780d9f627e15Douglas Gregor  void AddConstructorInitializationStep(CXXConstructorDecl *Constructor,
910b13b737a2450167c82e148590e8019b839ce6b98John McCall                                        AccessSpecifier Access,
91122c107b2b99887b5aec6d1fd38210031e944e31fAbramo Bagnara                                        QualType T,
91210f04a6267eb07d3be00db1fd0369e1398f5d0a8Sebastian Redl                                        bool HadMultipleCandidates,
9136cd03dbb310f472b14b8d6d69d8c9b5b7f1200e2Sebastian Redl                                        bool FromInitList, bool AsInitList);
91471d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor
91571d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor  /// \brief Add a zero-initialization step.
91671d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor  void AddZeroInitializationStep(QualType T);
91710f04a6267eb07d3be00db1fd0369e1398f5d0a8Sebastian Redl
91818ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor  /// \brief Add a C assignment step.
91918ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor  //
92018ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor  // FIXME: It isn't clear whether this should ever be needed;
92118ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor  // ideally, we would handle everything needed in C in the common
92218ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor  // path. However, that isn't the case yet.
92318ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor  void AddCAssignmentStep(QualType T);
92418ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor
925cfdc81a83467973b14e4ea5e9e9af1690f135415Eli Friedman  /// \brief Add a string init step.
926cfdc81a83467973b14e4ea5e9e9af1690f135415Eli Friedman  void AddStringInitStep(QualType T);
927cfdc81a83467973b14e4ea5e9e9af1690f135415Eli Friedman
928569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor  /// \brief Add an Objective-C object conversion step, which is
929569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor  /// always a no-op.
930569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor  void AddObjCObjectConversionStep(QualType T);
931569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor
932cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregor  /// \brief Add an array initialization step.
933cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregor  void AddArrayInitStep(QualType T);
934cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregor
9350f163e964289bc18e9bc1ec37a6a01018ba62640Richard Smith  /// \brief Add a parenthesized array initialization step.
9360f163e964289bc18e9bc1ec37a6a01018ba62640Richard Smith  void AddParenthesizedArrayInitStep(QualType T);
9370f163e964289bc18e9bc1ec37a6a01018ba62640Richard Smith
938f85e193739c953358c865005855253af4f68a497John McCall  /// \brief Add a step to pass an object by indirect copy-restore.
939f85e193739c953358c865005855253af4f68a497John McCall  void AddPassByIndirectCopyRestoreStep(QualType T, bool shouldCopy);
940f85e193739c953358c865005855253af4f68a497John McCall
941f85e193739c953358c865005855253af4f68a497John McCall  /// \brief Add a step to "produce" an Objective-C object (by
942f85e193739c953358c865005855253af4f68a497John McCall  /// retaining it).
943f85e193739c953358c865005855253af4f68a497John McCall  void AddProduceObjCObjectStep(QualType T);
944f85e193739c953358c865005855253af4f68a497John McCall
9452b916b8b55aaf0152ab9ad630c8454bf6373b085Sebastian Redl  /// \brief Add a step to construct a std::initializer_list object from an
9462b916b8b55aaf0152ab9ad630c8454bf6373b085Sebastian Redl  /// initializer list.
9472b916b8b55aaf0152ab9ad630c8454bf6373b085Sebastian Redl  void AddStdInitializerListConstructionStep(QualType T);
9482b916b8b55aaf0152ab9ad630c8454bf6373b085Sebastian Redl
94913dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl  /// \brief Add steps to unwrap a initializer list for a reference around a
95013dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl  /// single element and rewrap it at the end.
95113dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl  void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic);
95213dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl
95320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Note that this initialization sequence failed.
95420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  void SetFailed(FailureKind Failure) {
95520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SequenceKind = FailedSequence;
95620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    this->Failure = Failure;
95769a30b838c723cb1850de55cfa48a402cfeeb6e0Douglas Gregor    assert((Failure != FK_Incomplete || !FailedIncompleteType.isNull()) &&
95869a30b838c723cb1850de55cfa48a402cfeeb6e0Douglas Gregor           "Incomplete type failure requires a type!");
95920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
96020093b4bf698f292c664676987541d5103b65b15Douglas Gregor
96120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Note that this initialization sequence failed due to failed
96220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// overload resolution.
96320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  void SetOverloadFailure(FailureKind Failure, OverloadingResult Result);
96420093b4bf698f292c664676987541d5103b65b15Douglas Gregor
96520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Retrieve a reference to the candidate set when overload
96620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// resolution fails.
96720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  OverloadCandidateSet &getFailedCandidateSet() {
96820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return FailedCandidateSet;
96920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
97020093b4bf698f292c664676987541d5103b65b15Douglas Gregor
9712b916b8b55aaf0152ab9ad630c8454bf6373b085Sebastian Redl  /// \brief Get the overloading result, for when the initialization
97279ab2c8104ef5df233d271560ccc734836738e56John McCall  /// sequence failed due to a bad overload.
97379ab2c8104ef5df233d271560ccc734836738e56John McCall  OverloadingResult getFailedOverloadResult() const {
97479ab2c8104ef5df233d271560ccc734836738e56John McCall    return FailedOverloadResult;
97579ab2c8104ef5df233d271560ccc734836738e56John McCall  }
97679ab2c8104ef5df233d271560ccc734836738e56John McCall
97769a30b838c723cb1850de55cfa48a402cfeeb6e0Douglas Gregor  /// \brief Note that this initialization sequence failed due to an
97869a30b838c723cb1850de55cfa48a402cfeeb6e0Douglas Gregor  /// incomplete type.
97969a30b838c723cb1850de55cfa48a402cfeeb6e0Douglas Gregor  void setIncompleteTypeFailure(QualType IncompleteType) {
98069a30b838c723cb1850de55cfa48a402cfeeb6e0Douglas Gregor    FailedIncompleteType = IncompleteType;
98169a30b838c723cb1850de55cfa48a402cfeeb6e0Douglas Gregor    SetFailed(FK_Incomplete);
98269a30b838c723cb1850de55cfa48a402cfeeb6e0Douglas Gregor  }
98369a30b838c723cb1850de55cfa48a402cfeeb6e0Douglas Gregor
98420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine why initialization failed.
98520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  FailureKind getFailureKind() const {
986d695d6bb7323672e29dbb1556a3dafde3d3b2732Sebastian Redl    assert(Failed() && "Not an initialization failure!");
98720093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return Failure;
98820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
98979ab2c8104ef5df233d271560ccc734836738e56John McCall
990de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor  /// \brief Dump a representation of this initialization sequence to
991de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor  /// the given stream, for debugging purposes.
9928cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void dump(raw_ostream &OS) const;
993de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor
994de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor  /// \brief Dump a representation of this initialization sequence to
995de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor  /// standard error, for debugging purposes.
996de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor  void dump() const;
99720093b4bf698f292c664676987541d5103b65b15Douglas Gregor};
99820093b4bf698f292c664676987541d5103b65b15Douglas Gregor
99920093b4bf698f292c664676987541d5103b65b15Douglas Gregor} // end namespace clang
100020093b4bf698f292c664676987541d5103b65b15Douglas Gregor
1001e737f5041a36d0befb39ffeed8d50ba15916d3daDouglas Gregor#endif // LLVM_CLANG_SEMA_INITIALIZATION_H
1002