Douglas Gregor | d87b61f | 2009-12-10 17:56:55 +0000 | [diff] [blame] | 1 | //===--- SemaInit.h - Semantic Analysis for Initializers --------*- C++ -*-===// |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file provides supporting data types for initialization of objects. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | #ifndef LLVM_CLANG_SEMA_INIT_H |
| 14 | #define LLVM_CLANG_SEMA_INIT_H |
| 15 | |
| 16 | #include "SemaOverload.h" |
Douglas Gregor | d6542d8 | 2009-12-22 15:35:07 +0000 | [diff] [blame] | 17 | #include "clang/AST/Type.h" |
John McCall | b13b737 | 2010-02-01 03:16:54 +0000 | [diff] [blame] | 18 | #include "clang/AST/UnresolvedSet.h" |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 19 | #include "clang/Parse/Action.h" |
| 20 | #include "clang/Basic/SourceLocation.h" |
| 21 | #include "llvm/ADT/PointerIntPair.h" |
| 22 | #include "llvm/ADT/SmallVector.h" |
| 23 | #include <cassert> |
| 24 | |
Douglas Gregor | de4b1d8 | 2010-01-29 19:14:02 +0000 | [diff] [blame] | 25 | namespace llvm { |
| 26 | class raw_ostream; |
| 27 | } |
| 28 | |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 29 | namespace clang { |
| 30 | |
| 31 | class CXXBaseSpecifier; |
| 32 | class DeclaratorDecl; |
| 33 | class DeclaratorInfo; |
| 34 | class FieldDecl; |
| 35 | class FunctionDecl; |
| 36 | class ParmVarDecl; |
| 37 | class Sema; |
| 38 | class TypeLoc; |
| 39 | class VarDecl; |
| 40 | |
| 41 | /// \brief Describes an entity that is being initialized. |
| 42 | class InitializedEntity { |
| 43 | public: |
| 44 | /// \brief Specifies the kind of entity being initialized. |
| 45 | enum EntityKind { |
| 46 | /// \brief The entity being initialized is a variable. |
| 47 | EK_Variable, |
| 48 | /// \brief The entity being initialized is a function parameter. |
| 49 | EK_Parameter, |
| 50 | /// \brief The entity being initialized is the result of a function call. |
| 51 | EK_Result, |
| 52 | /// \brief The entity being initialized is an exception object that |
| 53 | /// is being thrown. |
| 54 | EK_Exception, |
Anders Carlsson | a729bbb | 2010-01-23 05:47:27 +0000 | [diff] [blame] | 55 | /// \brief The entity being initialized is a non-static data member |
| 56 | /// subobject. |
| 57 | EK_Member, |
| 58 | /// \brief The entity being initialized is an element of an array. |
| 59 | EK_ArrayElement, |
Douglas Gregor | 18ef5e2 | 2009-12-18 05:02:21 +0000 | [diff] [blame] | 60 | /// \brief The entity being initialized is an object (or array of |
| 61 | /// objects) allocated via new. |
| 62 | EK_New, |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 63 | /// \brief The entity being initialized is a temporary object. |
| 64 | EK_Temporary, |
| 65 | /// \brief The entity being initialized is a base member subobject. |
| 66 | EK_Base, |
Anders Carlsson | d3d824d | 2010-01-23 04:34:47 +0000 | [diff] [blame] | 67 | /// \brief The entity being initialized is an element of a vector. |
Douglas Gregor | cb57fb9 | 2009-12-16 06:35:08 +0000 | [diff] [blame] | 68 | /// or vector. |
Fariborz Jahanian | 310b1c4 | 2010-06-07 16:14:00 +0000 | [diff] [blame] | 69 | EK_VectorElement, |
| 70 | /// \brief The entity being initialized is a field of block descriptor for |
| 71 | /// the copied-in c++ object. |
| 72 | EK_BlockElement |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | private: |
| 76 | /// \brief The kind of entity being initialized. |
| 77 | EntityKind Kind; |
| 78 | |
Douglas Gregor | cb57fb9 | 2009-12-16 06:35:08 +0000 | [diff] [blame] | 79 | /// \brief If non-NULL, the parent entity in which this |
| 80 | /// initialization occurs. |
| 81 | const InitializedEntity *Parent; |
| 82 | |
Douglas Gregor | d6542d8 | 2009-12-22 15:35:07 +0000 | [diff] [blame] | 83 | /// \brief The type of the object or reference being initialized. |
| 84 | QualType Type; |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 85 | |
| 86 | union { |
| 87 | /// \brief When Kind == EK_Variable, EK_Parameter, or EK_Member, |
| 88 | /// the VarDecl, ParmVarDecl, or FieldDecl, respectively. |
| 89 | DeclaratorDecl *VariableOrMember; |
| 90 | |
Douglas Gregor | 3c9034c | 2010-05-15 00:13:29 +0000 | [diff] [blame] | 91 | struct { |
| 92 | /// \brief When Kind == EK_Result, EK_Exception, or EK_New, the |
| 93 | /// location of the 'return', 'throw', or 'new' keyword, |
| 94 | /// respectively. When Kind == EK_Temporary, the location where |
| 95 | /// the temporary is being created. |
| 96 | unsigned Location; |
| 97 | |
| 98 | /// \brief Whether the |
| 99 | bool NRVO; |
| 100 | } LocAndNRVO; |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 101 | |
| 102 | /// \brief When Kind == EK_Base, the base specifier that provides the |
Anders Carlsson | 711f34a | 2010-04-21 19:52:01 +0000 | [diff] [blame] | 103 | /// base class. The lower bit specifies whether the base is an inherited |
| 104 | /// virtual base. |
| 105 | uintptr_t Base; |
Douglas Gregor | cb57fb9 | 2009-12-16 06:35:08 +0000 | [diff] [blame] | 106 | |
Anders Carlsson | 711f34a | 2010-04-21 19:52:01 +0000 | [diff] [blame] | 107 | /// \brief When Kind == EK_ArrayElement or EK_VectorElement, the |
| 108 | /// index of the array or vector element being initialized. |
Douglas Gregor | cb57fb9 | 2009-12-16 06:35:08 +0000 | [diff] [blame] | 109 | unsigned Index; |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | InitializedEntity() { } |
| 113 | |
| 114 | /// \brief Create the initialization entity for a variable. |
| 115 | InitializedEntity(VarDecl *Var) |
Douglas Gregor | d6542d8 | 2009-12-22 15:35:07 +0000 | [diff] [blame] | 116 | : Kind(EK_Variable), Parent(0), Type(Var->getType()), |
| 117 | VariableOrMember(reinterpret_cast<DeclaratorDecl*>(Var)) { } |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 118 | |
| 119 | /// \brief Create the initialization entity for a parameter. |
| 120 | InitializedEntity(ParmVarDecl *Parm) |
Douglas Gregor | 6e790ab | 2009-12-22 23:42:49 +0000 | [diff] [blame] | 121 | : Kind(EK_Parameter), Parent(0), Type(Parm->getType().getUnqualifiedType()), |
Douglas Gregor | d6542d8 | 2009-12-22 15:35:07 +0000 | [diff] [blame] | 122 | VariableOrMember(reinterpret_cast<DeclaratorDecl*>(Parm)) { } |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 123 | |
Douglas Gregor | a188ff2 | 2009-12-22 16:09:06 +0000 | [diff] [blame] | 124 | /// \brief Create the initialization entity for the result of a |
| 125 | /// function, throwing an object, performing an explicit cast, or |
| 126 | /// initializing a parameter for which there is no declaration. |
Douglas Gregor | 3c9034c | 2010-05-15 00:13:29 +0000 | [diff] [blame] | 127 | InitializedEntity(EntityKind Kind, SourceLocation Loc, QualType Type, |
| 128 | bool NRVO = false) |
| 129 | : Kind(Kind), Parent(0), Type(Type) |
| 130 | { |
| 131 | LocAndNRVO.Location = Loc.getRawEncoding(); |
| 132 | LocAndNRVO.NRVO = NRVO; |
| 133 | } |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 134 | |
| 135 | /// \brief Create the initialization entity for a member subobject. |
Douglas Gregor | cb57fb9 | 2009-12-16 06:35:08 +0000 | [diff] [blame] | 136 | InitializedEntity(FieldDecl *Member, const InitializedEntity *Parent) |
Douglas Gregor | d6542d8 | 2009-12-22 15:35:07 +0000 | [diff] [blame] | 137 | : Kind(EK_Member), Parent(Parent), Type(Member->getType()), |
| 138 | VariableOrMember(reinterpret_cast<DeclaratorDecl*>(Member)) { } |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 139 | |
Douglas Gregor | cb57fb9 | 2009-12-16 06:35:08 +0000 | [diff] [blame] | 140 | /// \brief Create the initialization entity for an array element. |
| 141 | InitializedEntity(ASTContext &Context, unsigned Index, |
| 142 | const InitializedEntity &Parent); |
| 143 | |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 144 | public: |
| 145 | /// \brief Create the initialization entity for a variable. |
| 146 | static InitializedEntity InitializeVariable(VarDecl *Var) { |
| 147 | return InitializedEntity(Var); |
| 148 | } |
| 149 | |
| 150 | /// \brief Create the initialization entity for a parameter. |
| 151 | static InitializedEntity InitializeParameter(ParmVarDecl *Parm) { |
| 152 | return InitializedEntity(Parm); |
| 153 | } |
| 154 | |
Douglas Gregor | a188ff2 | 2009-12-22 16:09:06 +0000 | [diff] [blame] | 155 | /// \brief Create the initialization entity for a parameter that is |
| 156 | /// only known by its type. |
| 157 | static InitializedEntity InitializeParameter(QualType Type) { |
Douglas Gregor | 688fc9b | 2010-04-21 23:24:10 +0000 | [diff] [blame] | 158 | InitializedEntity Entity; |
| 159 | Entity.Kind = EK_Parameter; |
| 160 | Entity.Type = Type; |
| 161 | Entity.Parent = 0; |
| 162 | Entity.VariableOrMember = 0; |
| 163 | return Entity; |
Douglas Gregor | a188ff2 | 2009-12-22 16:09:06 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 166 | /// \brief Create the initialization entity for the result of a function. |
| 167 | static InitializedEntity InitializeResult(SourceLocation ReturnLoc, |
Douglas Gregor | 3c9034c | 2010-05-15 00:13:29 +0000 | [diff] [blame] | 168 | QualType Type, bool NRVO) { |
| 169 | return InitializedEntity(EK_Result, ReturnLoc, Type, NRVO); |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Fariborz Jahanian | 310b1c4 | 2010-06-07 16:14:00 +0000 | [diff] [blame] | 172 | static InitializedEntity InitializeBlock(SourceLocation BlockVarLoc, |
| 173 | QualType Type, bool NRVO) { |
| 174 | return InitializedEntity(EK_BlockElement, BlockVarLoc, Type, NRVO); |
| 175 | } |
| 176 | |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 177 | /// \brief Create the initialization entity for an exception object. |
| 178 | static InitializedEntity InitializeException(SourceLocation ThrowLoc, |
Douglas Gregor | 3c9034c | 2010-05-15 00:13:29 +0000 | [diff] [blame] | 179 | QualType Type, bool NRVO) { |
| 180 | return InitializedEntity(EK_Exception, ThrowLoc, Type, NRVO); |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 181 | } |
Douglas Gregor | 18ef5e2 | 2009-12-18 05:02:21 +0000 | [diff] [blame] | 182 | |
| 183 | /// \brief Create the initialization entity for an object allocated via new. |
Douglas Gregor | d6542d8 | 2009-12-22 15:35:07 +0000 | [diff] [blame] | 184 | static InitializedEntity InitializeNew(SourceLocation NewLoc, QualType Type) { |
| 185 | return InitializedEntity(EK_New, NewLoc, Type); |
Douglas Gregor | 18ef5e2 | 2009-12-18 05:02:21 +0000 | [diff] [blame] | 186 | } |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 187 | |
| 188 | /// \brief Create the initialization entity for a temporary. |
Douglas Gregor | d6542d8 | 2009-12-22 15:35:07 +0000 | [diff] [blame] | 189 | static InitializedEntity InitializeTemporary(QualType Type) { |
| 190 | return InitializedEntity(EK_Temporary, SourceLocation(), Type); |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | /// \brief Create the initialization entity for a base class subobject. |
| 194 | static InitializedEntity InitializeBase(ASTContext &Context, |
Anders Carlsson | 711f34a | 2010-04-21 19:52:01 +0000 | [diff] [blame] | 195 | CXXBaseSpecifier *Base, |
| 196 | bool IsInheritedVirtualBase); |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 197 | |
Douglas Gregor | cb57fb9 | 2009-12-16 06:35:08 +0000 | [diff] [blame] | 198 | /// \brief Create the initialization entity for a member subobject. |
| 199 | static InitializedEntity InitializeMember(FieldDecl *Member, |
| 200 | const InitializedEntity *Parent = 0) { |
| 201 | return InitializedEntity(Member, Parent); |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Douglas Gregor | cb57fb9 | 2009-12-16 06:35:08 +0000 | [diff] [blame] | 204 | /// \brief Create the initialization entity for an array element. |
| 205 | static InitializedEntity InitializeElement(ASTContext &Context, |
| 206 | unsigned Index, |
| 207 | const InitializedEntity &Parent) { |
| 208 | return InitializedEntity(Context, Index, Parent); |
| 209 | } |
| 210 | |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 211 | /// \brief Determine the kind of initialization. |
| 212 | EntityKind getKind() const { return Kind; } |
| 213 | |
Douglas Gregor | cb57fb9 | 2009-12-16 06:35:08 +0000 | [diff] [blame] | 214 | /// \brief Retrieve the parent of the entity being initialized, when |
| 215 | /// the initialization itself is occuring within the context of a |
| 216 | /// larger initialization. |
| 217 | const InitializedEntity *getParent() const { return Parent; } |
| 218 | |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 219 | /// \brief Retrieve type being initialized. |
Douglas Gregor | d6542d8 | 2009-12-22 15:35:07 +0000 | [diff] [blame] | 220 | QualType getType() const { return Type; } |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 221 | |
Douglas Gregor | 99a2e60 | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 222 | /// \brief Retrieve the name of the entity being initialized. |
| 223 | DeclarationName getName() const; |
Douglas Gregor | 7abfbdb | 2009-12-19 03:01:41 +0000 | [diff] [blame] | 224 | |
| 225 | /// \brief Retrieve the variable, parameter, or field being |
| 226 | /// initialized. |
| 227 | DeclaratorDecl *getDecl() const; |
| 228 | |
Douglas Gregor | 3c9034c | 2010-05-15 00:13:29 +0000 | [diff] [blame] | 229 | /// \brief Determine whether this initialization allows the named return |
| 230 | /// value optimization, which also applies to thrown objects. |
| 231 | bool allowsNRVO() const; |
| 232 | |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 233 | /// \brief Retrieve the base specifier. |
| 234 | CXXBaseSpecifier *getBaseSpecifier() const { |
| 235 | assert(getKind() == EK_Base && "Not a base specifier"); |
Anders Carlsson | 711f34a | 2010-04-21 19:52:01 +0000 | [diff] [blame] | 236 | return reinterpret_cast<CXXBaseSpecifier *>(Base & ~0x1); |
| 237 | } |
| 238 | |
| 239 | /// \brief Return whether the base is an inherited virtual base. |
| 240 | bool isInheritedVirtualBase() const { |
| 241 | assert(getKind() == EK_Base && "Not a base specifier"); |
| 242 | return Base & 0x1; |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 243 | } |
| 244 | |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 245 | /// \brief Determine the location of the 'return' keyword when initializing |
| 246 | /// the result of a function call. |
| 247 | SourceLocation getReturnLoc() const { |
| 248 | assert(getKind() == EK_Result && "No 'return' location!"); |
Douglas Gregor | 3c9034c | 2010-05-15 00:13:29 +0000 | [diff] [blame] | 249 | return SourceLocation::getFromRawEncoding(LocAndNRVO.Location); |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | /// \brief Determine the location of the 'throw' keyword when initializing |
| 253 | /// an exception object. |
| 254 | SourceLocation getThrowLoc() const { |
| 255 | assert(getKind() == EK_Exception && "No 'throw' location!"); |
Douglas Gregor | 3c9034c | 2010-05-15 00:13:29 +0000 | [diff] [blame] | 256 | return SourceLocation::getFromRawEncoding(LocAndNRVO.Location); |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 257 | } |
Douglas Gregor | cb57fb9 | 2009-12-16 06:35:08 +0000 | [diff] [blame] | 258 | |
| 259 | /// \brief If this is already the initializer for an array or vector |
| 260 | /// element, sets the element index. |
| 261 | void setElementIndex(unsigned Index) { |
Anders Carlsson | d3d824d | 2010-01-23 04:34:47 +0000 | [diff] [blame] | 262 | assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement); |
Douglas Gregor | cb57fb9 | 2009-12-16 06:35:08 +0000 | [diff] [blame] | 263 | this->Index = Index; |
| 264 | } |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 265 | }; |
| 266 | |
| 267 | /// \brief Describes the kind of initialization being performed, along with |
| 268 | /// location information for tokens related to the initialization (equal sign, |
| 269 | /// parentheses). |
| 270 | class InitializationKind { |
| 271 | public: |
| 272 | /// \brief The kind of initialization being performed. |
| 273 | enum InitKind { |
| 274 | IK_Direct, ///< Direct initialization |
| 275 | IK_Copy, ///< Copy initialization |
| 276 | IK_Default, ///< Default initialization |
| 277 | IK_Value ///< Value initialization |
| 278 | }; |
| 279 | |
| 280 | private: |
| 281 | /// \brief The kind of initialization that we're storing. |
| 282 | enum StoredInitKind { |
| 283 | SIK_Direct = IK_Direct, ///< Direct initialization |
| 284 | SIK_Copy = IK_Copy, ///< Copy initialization |
| 285 | SIK_Default = IK_Default, ///< Default initialization |
| 286 | SIK_Value = IK_Value, ///< Value initialization |
Douglas Gregor | cb57fb9 | 2009-12-16 06:35:08 +0000 | [diff] [blame] | 287 | SIK_ImplicitValue, ///< Implicit value initialization |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 288 | SIK_DirectCast, ///< Direct initialization due to a cast |
| 289 | /// \brief Direct initialization due to a C-style or functional cast. |
| 290 | SIK_DirectCStyleOrFunctionalCast |
| 291 | }; |
| 292 | |
| 293 | /// \brief The kind of initialization being performed. |
| 294 | StoredInitKind Kind; |
| 295 | |
| 296 | /// \brief The source locations involved in the initialization. |
| 297 | SourceLocation Locations[3]; |
| 298 | |
| 299 | InitializationKind(StoredInitKind Kind, SourceLocation Loc1, |
| 300 | SourceLocation Loc2, SourceLocation Loc3) |
| 301 | : Kind(Kind) |
| 302 | { |
| 303 | Locations[0] = Loc1; |
| 304 | Locations[1] = Loc2; |
| 305 | Locations[2] = Loc3; |
| 306 | } |
| 307 | |
| 308 | public: |
| 309 | /// \brief Create a direct initialization. |
| 310 | static InitializationKind CreateDirect(SourceLocation InitLoc, |
| 311 | SourceLocation LParenLoc, |
| 312 | SourceLocation RParenLoc) { |
| 313 | return InitializationKind(SIK_Direct, InitLoc, LParenLoc, RParenLoc); |
| 314 | } |
| 315 | |
| 316 | /// \brief Create a direct initialization due to a cast. |
| 317 | static InitializationKind CreateCast(SourceRange TypeRange, |
| 318 | bool IsCStyleCast) { |
| 319 | return InitializationKind(IsCStyleCast? SIK_DirectCStyleOrFunctionalCast |
| 320 | : SIK_DirectCast, |
| 321 | TypeRange.getBegin(), TypeRange.getBegin(), |
| 322 | TypeRange.getEnd()); |
| 323 | } |
| 324 | |
| 325 | /// \brief Create a copy initialization. |
| 326 | static InitializationKind CreateCopy(SourceLocation InitLoc, |
| 327 | SourceLocation EqualLoc) { |
| 328 | return InitializationKind(SIK_Copy, InitLoc, EqualLoc, EqualLoc); |
| 329 | } |
| 330 | |
| 331 | /// \brief Create a default initialization. |
| 332 | static InitializationKind CreateDefault(SourceLocation InitLoc) { |
| 333 | return InitializationKind(SIK_Default, InitLoc, InitLoc, InitLoc); |
| 334 | } |
| 335 | |
| 336 | /// \brief Create a value initialization. |
| 337 | static InitializationKind CreateValue(SourceLocation InitLoc, |
| 338 | SourceLocation LParenLoc, |
Douglas Gregor | cb57fb9 | 2009-12-16 06:35:08 +0000 | [diff] [blame] | 339 | SourceLocation RParenLoc, |
| 340 | bool isImplicit = false) { |
| 341 | return InitializationKind(isImplicit? SIK_ImplicitValue : SIK_Value, |
| 342 | InitLoc, LParenLoc, RParenLoc); |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | /// \brief Determine the initialization kind. |
| 346 | InitKind getKind() const { |
Douglas Gregor | cb57fb9 | 2009-12-16 06:35:08 +0000 | [diff] [blame] | 347 | if (Kind > SIK_ImplicitValue) |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 348 | return IK_Direct; |
Douglas Gregor | cb57fb9 | 2009-12-16 06:35:08 +0000 | [diff] [blame] | 349 | if (Kind == SIK_ImplicitValue) |
| 350 | return IK_Value; |
| 351 | |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 352 | return (InitKind)Kind; |
| 353 | } |
| 354 | |
| 355 | /// \brief Determine whether this initialization is an explicit cast. |
| 356 | bool isExplicitCast() const { |
| 357 | return Kind == SIK_DirectCast || Kind == SIK_DirectCStyleOrFunctionalCast; |
| 358 | } |
| 359 | |
| 360 | /// \brief Determine whether this initialization is a C-style cast. |
| 361 | bool isCStyleOrFunctionalCast() const { |
| 362 | return Kind == SIK_DirectCStyleOrFunctionalCast; |
| 363 | } |
Douglas Gregor | cb57fb9 | 2009-12-16 06:35:08 +0000 | [diff] [blame] | 364 | |
| 365 | /// \brief Determine whether this initialization is an implicit |
| 366 | /// value-initialization, e.g., as occurs during aggregate |
| 367 | /// initialization. |
| 368 | bool isImplicitValueInit() const { return Kind == SIK_ImplicitValue; } |
| 369 | |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 370 | /// \brief Retrieve the location at which initialization is occurring. |
| 371 | SourceLocation getLocation() const { return Locations[0]; } |
| 372 | |
| 373 | /// \brief Retrieve the source range that covers the initialization. |
| 374 | SourceRange getRange() const { |
Douglas Gregor | 71d1740 | 2009-12-15 00:01:57 +0000 | [diff] [blame] | 375 | return SourceRange(Locations[0], Locations[2]); |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | /// \brief Retrieve the location of the equal sign for copy initialization |
| 379 | /// (if present). |
| 380 | SourceLocation getEqualLoc() const { |
| 381 | assert(Kind == SIK_Copy && "Only copy initialization has an '='"); |
| 382 | return Locations[1]; |
| 383 | } |
| 384 | |
| 385 | /// \brief Retrieve the source range containing the locations of the open |
| 386 | /// and closing parentheses for value and direct initializations. |
| 387 | SourceRange getParenRange() const { |
| 388 | assert((getKind() == IK_Direct || Kind == SIK_Value) && |
| 389 | "Only direct- and value-initialization have parentheses"); |
| 390 | return SourceRange(Locations[1], Locations[2]); |
| 391 | } |
| 392 | }; |
| 393 | |
| 394 | /// \brief Describes the sequence of initializations required to initialize |
| 395 | /// a given object or reference with a set of arguments. |
| 396 | class InitializationSequence { |
| 397 | public: |
| 398 | /// \brief Describes the kind of initialization sequence computed. |
Douglas Gregor | 71d1740 | 2009-12-15 00:01:57 +0000 | [diff] [blame] | 399 | /// |
| 400 | /// FIXME: Much of this information is in the initialization steps... why is |
| 401 | /// it duplicated here? |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 402 | enum SequenceKind { |
| 403 | /// \brief A failed initialization sequence. The failure kind tells what |
| 404 | /// happened. |
| 405 | FailedSequence = 0, |
| 406 | |
| 407 | /// \brief A dependent initialization, which could not be |
| 408 | /// type-checked due to the presence of dependent types or |
| 409 | /// dependently-type expressions. |
| 410 | DependentSequence, |
| 411 | |
Douglas Gregor | 4a520a2 | 2009-12-14 17:27:33 +0000 | [diff] [blame] | 412 | /// \brief A user-defined conversion sequence. |
| 413 | UserDefinedConversion, |
| 414 | |
Douglas Gregor | 51c56d6 | 2009-12-14 20:49:26 +0000 | [diff] [blame] | 415 | /// \brief A constructor call. |
Douglas Gregor | a6ca650 | 2009-12-14 20:57:13 +0000 | [diff] [blame] | 416 | ConstructorInitialization, |
Douglas Gregor | 51c56d6 | 2009-12-14 20:49:26 +0000 | [diff] [blame] | 417 | |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 418 | /// \brief A reference binding. |
Douglas Gregor | d87b61f | 2009-12-10 17:56:55 +0000 | [diff] [blame] | 419 | ReferenceBinding, |
| 420 | |
| 421 | /// \brief List initialization |
Douglas Gregor | 71d1740 | 2009-12-15 00:01:57 +0000 | [diff] [blame] | 422 | ListInitialization, |
| 423 | |
| 424 | /// \brief Zero-initialization. |
Douglas Gregor | 99a2e60 | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 425 | ZeroInitialization, |
| 426 | |
| 427 | /// \brief No initialization required. |
| 428 | NoInitialization, |
| 429 | |
| 430 | /// \brief Standard conversion sequence. |
Douglas Gregor | 18ef5e2 | 2009-12-18 05:02:21 +0000 | [diff] [blame] | 431 | StandardConversion, |
| 432 | |
| 433 | /// \brief C conversion sequence. |
Eli Friedman | cfdc81a | 2009-12-19 08:11:05 +0000 | [diff] [blame] | 434 | CAssignment, |
| 435 | |
| 436 | /// \brief String initialization |
| 437 | StringInit |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 438 | }; |
| 439 | |
| 440 | /// \brief Describes the kind of a particular step in an initialization |
| 441 | /// sequence. |
| 442 | enum StepKind { |
| 443 | /// \brief Resolve the address of an overloaded function to a specific |
| 444 | /// function declaration. |
| 445 | SK_ResolveAddressOfOverloadedFunction, |
| 446 | /// \brief Perform a derived-to-base cast, producing an rvalue. |
| 447 | SK_CastDerivedToBaseRValue, |
| 448 | /// \brief Perform a derived-to-base cast, producing an lvalue. |
| 449 | SK_CastDerivedToBaseLValue, |
| 450 | /// \brief Reference binding to an lvalue. |
| 451 | SK_BindReference, |
| 452 | /// \brief Reference binding to a temporary. |
| 453 | SK_BindReferenceToTemporary, |
Douglas Gregor | 523d46a | 2010-04-18 07:40:54 +0000 | [diff] [blame] | 454 | /// \brief An optional copy of a temporary object to another |
| 455 | /// temporary object, which is permitted (but not required) by |
| 456 | /// C++98/03 but not C++0x. |
| 457 | SK_ExtraneousCopyToTemporary, |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 458 | /// \brief Perform a user-defined conversion, either via a conversion |
| 459 | /// function or via a constructor. |
| 460 | SK_UserConversion, |
| 461 | /// \brief Perform a qualification conversion, producing an rvalue. |
| 462 | SK_QualificationConversionRValue, |
| 463 | /// \brief Perform a qualification conversion, producing an lvalue. |
| 464 | SK_QualificationConversionLValue, |
| 465 | /// \brief Perform an implicit conversion sequence. |
Douglas Gregor | d87b61f | 2009-12-10 17:56:55 +0000 | [diff] [blame] | 466 | SK_ConversionSequence, |
| 467 | /// \brief Perform list-initialization |
Douglas Gregor | 51c56d6 | 2009-12-14 20:49:26 +0000 | [diff] [blame] | 468 | SK_ListInitialization, |
| 469 | /// \brief Perform initialization via a constructor. |
Douglas Gregor | 71d1740 | 2009-12-15 00:01:57 +0000 | [diff] [blame] | 470 | SK_ConstructorInitialization, |
| 471 | /// \brief Zero-initialize the object |
Douglas Gregor | 18ef5e2 | 2009-12-18 05:02:21 +0000 | [diff] [blame] | 472 | SK_ZeroInitialization, |
| 473 | /// \brief C assignment |
Eli Friedman | cfdc81a | 2009-12-19 08:11:05 +0000 | [diff] [blame] | 474 | SK_CAssignment, |
| 475 | /// \brief Initialization by string |
| 476 | SK_StringInit |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 477 | }; |
| 478 | |
| 479 | /// \brief A single step in the initialization sequence. |
| 480 | class Step { |
| 481 | public: |
| 482 | /// \brief The kind of conversion or initialization step we are taking. |
| 483 | StepKind Kind; |
| 484 | |
| 485 | // \brief The type that results from this initialization. |
| 486 | QualType Type; |
| 487 | |
| 488 | union { |
| 489 | /// \brief When Kind == SK_ResolvedOverloadedFunction or Kind == |
| 490 | /// SK_UserConversion, the function that the expression should be |
| 491 | /// resolved to or the conversion function to call, respectively. |
John McCall | b13b737 | 2010-02-01 03:16:54 +0000 | [diff] [blame] | 492 | /// |
| 493 | /// Always a FunctionDecl. |
| 494 | /// For conversion decls, the naming class is the source type. |
| 495 | /// For construct decls, the naming class is the target type. |
John McCall | 9aa472c | 2010-03-19 07:35:19 +0000 | [diff] [blame] | 496 | struct { |
| 497 | FunctionDecl *Function; |
| 498 | DeclAccessPair FoundDecl; |
| 499 | } Function; |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 500 | |
| 501 | /// \brief When Kind = SK_ConversionSequence, the implicit conversion |
| 502 | /// sequence |
| 503 | ImplicitConversionSequence *ICS; |
| 504 | }; |
| 505 | |
| 506 | void Destroy(); |
| 507 | }; |
| 508 | |
| 509 | private: |
| 510 | /// \brief The kind of initialization sequence computed. |
| 511 | enum SequenceKind SequenceKind; |
| 512 | |
| 513 | /// \brief Steps taken by this initialization. |
| 514 | llvm::SmallVector<Step, 4> Steps; |
| 515 | |
| 516 | public: |
| 517 | /// \brief Describes why initialization failed. |
| 518 | enum FailureKind { |
| 519 | /// \brief Too many initializers provided for a reference. |
| 520 | FK_TooManyInitsForReference, |
| 521 | /// \brief Array must be initialized with an initializer list. |
| 522 | FK_ArrayNeedsInitList, |
| 523 | /// \brief Array must be initialized with an initializer list or a |
| 524 | /// string literal. |
| 525 | FK_ArrayNeedsInitListOrStringLiteral, |
| 526 | /// \brief Cannot resolve the address of an overloaded function. |
| 527 | FK_AddressOfOverloadFailed, |
| 528 | /// \brief Overloading due to reference initialization failed. |
| 529 | FK_ReferenceInitOverloadFailed, |
| 530 | /// \brief Non-const lvalue reference binding to a temporary. |
| 531 | FK_NonConstLValueReferenceBindingToTemporary, |
| 532 | /// \brief Non-const lvalue reference binding to an lvalue of unrelated |
| 533 | /// type. |
| 534 | FK_NonConstLValueReferenceBindingToUnrelated, |
| 535 | /// \brief Rvalue reference binding to an lvalue. |
| 536 | FK_RValueReferenceBindingToLValue, |
| 537 | /// \brief Reference binding drops qualifiers. |
| 538 | FK_ReferenceInitDropsQualifiers, |
| 539 | /// \brief Reference binding failed. |
| 540 | FK_ReferenceInitFailed, |
| 541 | /// \brief Implicit conversion failed. |
Douglas Gregor | d87b61f | 2009-12-10 17:56:55 +0000 | [diff] [blame] | 542 | FK_ConversionFailed, |
| 543 | /// \brief Too many initializers for scalar |
| 544 | FK_TooManyInitsForScalar, |
| 545 | /// \brief Reference initialization from an initializer list |
| 546 | FK_ReferenceBindingToInitList, |
| 547 | /// \brief Initialization of some unused destination type with an |
| 548 | /// initializer list. |
Douglas Gregor | 4a520a2 | 2009-12-14 17:27:33 +0000 | [diff] [blame] | 549 | FK_InitListBadDestinationType, |
| 550 | /// \brief Overloading for a user-defined conversion failed. |
Douglas Gregor | 51c56d6 | 2009-12-14 20:49:26 +0000 | [diff] [blame] | 551 | FK_UserConversionOverloadFailed, |
| 552 | /// \brief Overloaded for initialization by constructor failed. |
Douglas Gregor | 99a2e60 | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 553 | FK_ConstructorOverloadFailed, |
| 554 | /// \brief Default-initialization of a 'const' object. |
Douglas Gregor | 72a43bb | 2010-05-20 22:12:02 +0000 | [diff] [blame] | 555 | FK_DefaultInitOfConst, |
| 556 | /// \brief Initialization of an incomplete type. |
| 557 | FK_Incomplete |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 558 | }; |
| 559 | |
| 560 | private: |
| 561 | /// \brief The reason why initialization failued. |
| 562 | FailureKind Failure; |
| 563 | |
| 564 | /// \brief The failed result of overload resolution. |
| 565 | OverloadingResult FailedOverloadResult; |
| 566 | |
| 567 | /// \brief The candidate set created when initialization failed. |
| 568 | OverloadCandidateSet FailedCandidateSet; |
Douglas Gregor | a41a8c5 | 2010-04-22 00:20:18 +0000 | [diff] [blame] | 569 | |
| 570 | /// \brief Prints a follow-up note that highlights the location of |
| 571 | /// the initialized entity, if it's remote. |
| 572 | void PrintInitLocationNote(Sema &S, const InitializedEntity &Entity); |
| 573 | |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 574 | public: |
| 575 | /// \brief Try to perform initialization of the given entity, creating a |
| 576 | /// record of the steps required to perform the initialization. |
| 577 | /// |
| 578 | /// The generated initialization sequence will either contain enough |
| 579 | /// information to diagnose |
| 580 | /// |
| 581 | /// \param S the semantic analysis object. |
| 582 | /// |
| 583 | /// \param Entity the entity being initialized. |
| 584 | /// |
| 585 | /// \param Kind the kind of initialization being performed. |
| 586 | /// |
| 587 | /// \param Args the argument(s) provided for initialization. |
| 588 | /// |
| 589 | /// \param NumArgs the number of arguments provided for initialization. |
| 590 | InitializationSequence(Sema &S, |
| 591 | const InitializedEntity &Entity, |
| 592 | const InitializationKind &Kind, |
| 593 | Expr **Args, |
| 594 | unsigned NumArgs); |
| 595 | |
| 596 | ~InitializationSequence(); |
| 597 | |
| 598 | /// \brief Perform the actual initialization of the given entity based on |
| 599 | /// the computed initialization sequence. |
| 600 | /// |
| 601 | /// \param S the semantic analysis object. |
| 602 | /// |
| 603 | /// \param Entity the entity being initialized. |
| 604 | /// |
| 605 | /// \param Kind the kind of initialization being performed. |
| 606 | /// |
| 607 | /// \param Args the argument(s) provided for initialization, ownership of |
| 608 | /// which is transfered into the routine. |
| 609 | /// |
Douglas Gregor | d87b61f | 2009-12-10 17:56:55 +0000 | [diff] [blame] | 610 | /// \param ResultType if non-NULL, will be set to the type of the |
| 611 | /// initialized object, which is the type of the declaration in most |
| 612 | /// cases. However, when the initialized object is a variable of |
| 613 | /// incomplete array type and the initializer is an initializer |
| 614 | /// list, this type will be set to the completed array type. |
| 615 | /// |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 616 | /// \returns an expression that performs the actual object initialization, if |
| 617 | /// the initialization is well-formed. Otherwise, emits diagnostics |
| 618 | /// and returns an invalid expression. |
| 619 | Action::OwningExprResult Perform(Sema &S, |
| 620 | const InitializedEntity &Entity, |
| 621 | const InitializationKind &Kind, |
Douglas Gregor | d87b61f | 2009-12-10 17:56:55 +0000 | [diff] [blame] | 622 | Action::MultiExprArg Args, |
| 623 | QualType *ResultType = 0); |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 624 | |
| 625 | /// \brief Diagnose an potentially-invalid initialization sequence. |
| 626 | /// |
| 627 | /// \returns true if the initialization sequence was ill-formed, |
| 628 | /// false otherwise. |
| 629 | bool Diagnose(Sema &S, |
| 630 | const InitializedEntity &Entity, |
| 631 | const InitializationKind &Kind, |
| 632 | Expr **Args, unsigned NumArgs); |
| 633 | |
| 634 | /// \brief Determine the kind of initialization sequence computed. |
| 635 | enum SequenceKind getKind() const { return SequenceKind; } |
| 636 | |
| 637 | /// \brief Set the kind of sequence computed. |
| 638 | void setSequenceKind(enum SequenceKind SK) { SequenceKind = SK; } |
| 639 | |
| 640 | /// \brief Determine whether the initialization sequence is valid. |
| 641 | operator bool() const { return SequenceKind != FailedSequence; } |
| 642 | |
| 643 | typedef llvm::SmallVector<Step, 4>::const_iterator step_iterator; |
| 644 | step_iterator step_begin() const { return Steps.begin(); } |
| 645 | step_iterator step_end() const { return Steps.end(); } |
| 646 | |
Douglas Gregor | b70cf44 | 2010-03-26 20:14:36 +0000 | [diff] [blame] | 647 | /// \brief Determine whether this initialization is a direct reference |
| 648 | /// binding (C++ [dcl.init.ref]). |
| 649 | bool isDirectReferenceBinding() const; |
| 650 | |
| 651 | /// \brief Determine whether this initialization failed due to an ambiguity. |
| 652 | bool isAmbiguous() const; |
| 653 | |
Douglas Gregor | d6e44a3 | 2010-04-16 22:09:46 +0000 | [diff] [blame] | 654 | /// \brief Determine whether this initialization is direct call to a |
| 655 | /// constructor. |
| 656 | bool isConstructorInitialization() const; |
| 657 | |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 658 | /// \brief Add a new step in the initialization that resolves the address |
| 659 | /// of an overloaded function to a specific function declaration. |
| 660 | /// |
| 661 | /// \param Function the function to which the overloaded function reference |
| 662 | /// resolves. |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 663 | void AddAddressOverloadResolutionStep(FunctionDecl *Function, |
| 664 | DeclAccessPair Found); |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 665 | |
| 666 | /// \brief Add a new step in the initialization that performs a derived-to- |
| 667 | /// base cast. |
| 668 | /// |
| 669 | /// \param BaseType the base type to which we will be casting. |
| 670 | /// |
| 671 | /// \param IsLValue true if the result of this cast will be treated as |
| 672 | /// an lvalue. |
| 673 | void AddDerivedToBaseCastStep(QualType BaseType, bool IsLValue); |
| 674 | |
| 675 | /// \brief Add a new step binding a reference to an object. |
| 676 | /// |
Douglas Gregor | 523d46a | 2010-04-18 07:40:54 +0000 | [diff] [blame] | 677 | /// \param BindingTemporary True if we are binding a reference to a temporary |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 678 | /// object (thereby extending its lifetime); false if we are binding to an |
| 679 | /// lvalue or an lvalue treated as an rvalue. |
Douglas Gregor | 523d46a | 2010-04-18 07:40:54 +0000 | [diff] [blame] | 680 | /// |
| 681 | /// \param UnnecessaryCopy True if we should check for a copy |
| 682 | /// constructor for a completely unnecessary but |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 683 | void AddReferenceBindingStep(QualType T, bool BindingTemporary); |
Douglas Gregor | 523d46a | 2010-04-18 07:40:54 +0000 | [diff] [blame] | 684 | |
| 685 | /// \brief Add a new step that makes an extraneous copy of the input |
| 686 | /// to a temporary of the same class type. |
| 687 | /// |
| 688 | /// This extraneous copy only occurs during reference binding in |
| 689 | /// C++98/03, where we are permitted (but not required) to introduce |
| 690 | /// an extra copy. At a bare minimum, we must check that we could |
| 691 | /// call the copy constructor, and produce a diagnostic if the copy |
| 692 | /// constructor is inaccessible or no copy constructor matches. |
| 693 | // |
| 694 | /// \param T The type of the temporary being created. |
| 695 | void AddExtraneousCopyToTemporary(QualType T); |
| 696 | |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 697 | /// \brief Add a new step invoking a conversion function, which is either |
| 698 | /// a constructor or a conversion function. |
John McCall | b13b737 | 2010-02-01 03:16:54 +0000 | [diff] [blame] | 699 | void AddUserConversionStep(FunctionDecl *Function, |
John McCall | 9aa472c | 2010-03-19 07:35:19 +0000 | [diff] [blame] | 700 | DeclAccessPair FoundDecl, |
John McCall | b13b737 | 2010-02-01 03:16:54 +0000 | [diff] [blame] | 701 | QualType T); |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 702 | |
| 703 | /// \brief Add a new step that performs a qualification conversion to the |
| 704 | /// given type. |
| 705 | void AddQualificationConversionStep(QualType Ty, bool IsLValue); |
| 706 | |
| 707 | /// \brief Add a new step that applies an implicit conversion sequence. |
| 708 | void AddConversionSequenceStep(const ImplicitConversionSequence &ICS, |
| 709 | QualType T); |
Douglas Gregor | d87b61f | 2009-12-10 17:56:55 +0000 | [diff] [blame] | 710 | |
| 711 | /// \brief Add a list-initialiation step |
| 712 | void AddListInitializationStep(QualType T); |
| 713 | |
Douglas Gregor | 71d1740 | 2009-12-15 00:01:57 +0000 | [diff] [blame] | 714 | /// \brief Add a constructor-initialization step. |
Douglas Gregor | 51c56d6 | 2009-12-14 20:49:26 +0000 | [diff] [blame] | 715 | void AddConstructorInitializationStep(CXXConstructorDecl *Constructor, |
John McCall | b13b737 | 2010-02-01 03:16:54 +0000 | [diff] [blame] | 716 | AccessSpecifier Access, |
Douglas Gregor | 51c56d6 | 2009-12-14 20:49:26 +0000 | [diff] [blame] | 717 | QualType T); |
Douglas Gregor | 71d1740 | 2009-12-15 00:01:57 +0000 | [diff] [blame] | 718 | |
| 719 | /// \brief Add a zero-initialization step. |
| 720 | void AddZeroInitializationStep(QualType T); |
Douglas Gregor | 51c56d6 | 2009-12-14 20:49:26 +0000 | [diff] [blame] | 721 | |
Douglas Gregor | 18ef5e2 | 2009-12-18 05:02:21 +0000 | [diff] [blame] | 722 | /// \brief Add a C assignment step. |
| 723 | // |
| 724 | // FIXME: It isn't clear whether this should ever be needed; |
| 725 | // ideally, we would handle everything needed in C in the common |
| 726 | // path. However, that isn't the case yet. |
| 727 | void AddCAssignmentStep(QualType T); |
| 728 | |
Eli Friedman | cfdc81a | 2009-12-19 08:11:05 +0000 | [diff] [blame] | 729 | /// \brief Add a string init step. |
| 730 | void AddStringInitStep(QualType T); |
| 731 | |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 732 | /// \brief Note that this initialization sequence failed. |
| 733 | void SetFailed(FailureKind Failure) { |
| 734 | SequenceKind = FailedSequence; |
| 735 | this->Failure = Failure; |
| 736 | } |
| 737 | |
| 738 | /// \brief Note that this initialization sequence failed due to failed |
| 739 | /// overload resolution. |
| 740 | void SetOverloadFailure(FailureKind Failure, OverloadingResult Result); |
| 741 | |
| 742 | /// \brief Retrieve a reference to the candidate set when overload |
| 743 | /// resolution fails. |
| 744 | OverloadCandidateSet &getFailedCandidateSet() { |
| 745 | return FailedCandidateSet; |
| 746 | } |
| 747 | |
| 748 | /// \brief Determine why initialization failed. |
| 749 | FailureKind getFailureKind() const { |
| 750 | assert(getKind() == FailedSequence && "Not an initialization failure!"); |
| 751 | return Failure; |
| 752 | } |
Douglas Gregor | de4b1d8 | 2010-01-29 19:14:02 +0000 | [diff] [blame] | 753 | |
| 754 | /// \brief Dump a representation of this initialization sequence to |
| 755 | /// the given stream, for debugging purposes. |
| 756 | void dump(llvm::raw_ostream &OS) const; |
| 757 | |
| 758 | /// \brief Dump a representation of this initialization sequence to |
| 759 | /// standard error, for debugging purposes. |
| 760 | void dump() const; |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 761 | }; |
| 762 | |
| 763 | } // end namespace clang |
| 764 | |
| 765 | #endif // LLVM_CLANG_SEMA_INIT_H |