blob: da6587bcca8dda96dcd7c3258ff46f7d0ea97958 [file] [log] [blame]
Douglas Gregord87b61f2009-12-10 17:56:55 +00001//===--- SemaInit.h - Semantic Analysis for Initializers --------*- C++ -*-===//
Douglas Gregor20093b42009-12-09 23:02:17 +00002//
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"
17#include "clang/AST/TypeLoc.h"
18#include "clang/Parse/Action.h"
19#include "clang/Basic/SourceLocation.h"
20#include "llvm/ADT/PointerIntPair.h"
21#include "llvm/ADT/SmallVector.h"
22#include <cassert>
23
24namespace clang {
25
26class CXXBaseSpecifier;
27class DeclaratorDecl;
28class DeclaratorInfo;
29class FieldDecl;
30class FunctionDecl;
31class ParmVarDecl;
32class Sema;
33class TypeLoc;
34class VarDecl;
35
36/// \brief Describes an entity that is being initialized.
37class InitializedEntity {
38public:
39 /// \brief Specifies the kind of entity being initialized.
40 enum EntityKind {
41 /// \brief The entity being initialized is a variable.
42 EK_Variable,
43 /// \brief The entity being initialized is a function parameter.
44 EK_Parameter,
45 /// \brief The entity being initialized is the result of a function call.
46 EK_Result,
47 /// \brief The entity being initialized is an exception object that
48 /// is being thrown.
49 EK_Exception,
50 /// \brief The entity being initialized is a temporary object.
51 EK_Temporary,
52 /// \brief The entity being initialized is a base member subobject.
53 EK_Base,
54 /// \brief The entity being initialized is a non-static data member
55 /// subobject.
Douglas Gregorcb57fb92009-12-16 06:35:08 +000056 EK_Member,
57 /// \brief The entity being initialized is an element of an array
58 /// or vector.
59 EK_ArrayOrVectorElement
Douglas Gregor20093b42009-12-09 23:02:17 +000060 };
61
62private:
63 /// \brief The kind of entity being initialized.
64 EntityKind Kind;
65
Douglas Gregorcb57fb92009-12-16 06:35:08 +000066 /// \brief If non-NULL, the parent entity in which this
67 /// initialization occurs.
68 const InitializedEntity *Parent;
69
Douglas Gregor20093b42009-12-09 23:02:17 +000070 /// \brief The type of the object or reference being initialized along with
71 /// its location information.
72 TypeLoc TL;
73
74 union {
75 /// \brief When Kind == EK_Variable, EK_Parameter, or EK_Member,
76 /// the VarDecl, ParmVarDecl, or FieldDecl, respectively.
77 DeclaratorDecl *VariableOrMember;
78
79 /// \brief When Kind == EK_Result or EK_Exception, the location of the
80 /// 'return' or 'throw' keyword, respectively. When Kind == EK_Temporary,
81 /// the location where the temporary is being created.
82 unsigned Location;
83
84 /// \brief When Kind == EK_Base, the base specifier that provides the
85 /// base class.
86 CXXBaseSpecifier *Base;
Douglas Gregorcb57fb92009-12-16 06:35:08 +000087
88 /// \brief When Kind = EK_ArrayOrVectorElement, the index of the
89 /// array or vector element being initialized.
90 unsigned Index;
Douglas Gregor20093b42009-12-09 23:02:17 +000091 };
92
93 InitializedEntity() { }
94
95 /// \brief Create the initialization entity for a variable.
96 InitializedEntity(VarDecl *Var)
Douglas Gregorcb57fb92009-12-16 06:35:08 +000097 : Kind(EK_Variable), Parent(0),
Douglas Gregor20093b42009-12-09 23:02:17 +000098 VariableOrMember(reinterpret_cast<DeclaratorDecl*>(Var))
99 {
100 InitDeclLoc();
101 }
102
103 /// \brief Create the initialization entity for a parameter.
104 InitializedEntity(ParmVarDecl *Parm)
Douglas Gregorcb57fb92009-12-16 06:35:08 +0000105 : Kind(EK_Parameter), Parent(0),
Douglas Gregor20093b42009-12-09 23:02:17 +0000106 VariableOrMember(reinterpret_cast<DeclaratorDecl*>(Parm))
107 {
108 InitDeclLoc();
109 }
110
111 /// \brief Create the initialization entity for the result of a function,
112 /// throwing an object, or performing an explicit cast.
113 InitializedEntity(EntityKind Kind, SourceLocation Loc, TypeLoc TL)
Douglas Gregorcb57fb92009-12-16 06:35:08 +0000114 : Kind(Kind), Parent(0), TL(TL), Location(Loc.getRawEncoding()) { }
Douglas Gregor20093b42009-12-09 23:02:17 +0000115
116 /// \brief Create the initialization entity for a member subobject.
Douglas Gregorcb57fb92009-12-16 06:35:08 +0000117 InitializedEntity(FieldDecl *Member, const InitializedEntity *Parent)
118 : Kind(EK_Member), Parent(Parent),
Douglas Gregor20093b42009-12-09 23:02:17 +0000119 VariableOrMember(reinterpret_cast<DeclaratorDecl*>(Member))
120 {
121 InitDeclLoc();
122 }
123
Douglas Gregorcb57fb92009-12-16 06:35:08 +0000124 /// \brief Create the initialization entity for an array element.
125 InitializedEntity(ASTContext &Context, unsigned Index,
126 const InitializedEntity &Parent);
127
Douglas Gregor20093b42009-12-09 23:02:17 +0000128 /// \brief Initialize type-location information from a declaration.
129 void InitDeclLoc();
130
131public:
132 /// \brief Create the initialization entity for a variable.
133 static InitializedEntity InitializeVariable(VarDecl *Var) {
134 return InitializedEntity(Var);
135 }
136
137 /// \brief Create the initialization entity for a parameter.
138 static InitializedEntity InitializeParameter(ParmVarDecl *Parm) {
139 return InitializedEntity(Parm);
140 }
141
142 /// \brief Create the initialization entity for the result of a function.
143 static InitializedEntity InitializeResult(SourceLocation ReturnLoc,
144 TypeLoc TL) {
145 return InitializedEntity(EK_Result, ReturnLoc, TL);
146 }
147
148 /// \brief Create the initialization entity for an exception object.
149 static InitializedEntity InitializeException(SourceLocation ThrowLoc,
150 TypeLoc TL) {
151 return InitializedEntity(EK_Exception, ThrowLoc, TL);
152 }
153
154 /// \brief Create the initialization entity for a temporary.
Douglas Gregor99a2e602009-12-16 01:38:02 +0000155 static InitializedEntity InitializeTemporary(TypeLoc TL) {
156 return InitializedEntity(EK_Temporary, SourceLocation(), TL);
Douglas Gregor20093b42009-12-09 23:02:17 +0000157 }
158
159 /// \brief Create the initialization entity for a base class subobject.
160 static InitializedEntity InitializeBase(ASTContext &Context,
161 CXXBaseSpecifier *Base);
162
Douglas Gregorcb57fb92009-12-16 06:35:08 +0000163 /// \brief Create the initialization entity for a member subobject.
164 static InitializedEntity InitializeMember(FieldDecl *Member,
165 const InitializedEntity *Parent = 0) {
166 return InitializedEntity(Member, Parent);
Douglas Gregor20093b42009-12-09 23:02:17 +0000167 }
168
Douglas Gregorcb57fb92009-12-16 06:35:08 +0000169 /// \brief Create the initialization entity for an array element.
170 static InitializedEntity InitializeElement(ASTContext &Context,
171 unsigned Index,
172 const InitializedEntity &Parent) {
173 return InitializedEntity(Context, Index, Parent);
174 }
175
Douglas Gregor20093b42009-12-09 23:02:17 +0000176 /// \brief Determine the kind of initialization.
177 EntityKind getKind() const { return Kind; }
178
Douglas Gregorcb57fb92009-12-16 06:35:08 +0000179 /// \brief Retrieve the parent of the entity being initialized, when
180 /// the initialization itself is occuring within the context of a
181 /// larger initialization.
182 const InitializedEntity *getParent() const { return Parent; }
183
Douglas Gregor20093b42009-12-09 23:02:17 +0000184 /// \brief Retrieve type being initialized.
185 TypeLoc getType() const { return TL; }
186
Douglas Gregor99a2e602009-12-16 01:38:02 +0000187 /// \brief Retrieve the name of the entity being initialized.
188 DeclarationName getName() const;
189
Douglas Gregor20093b42009-12-09 23:02:17 +0000190 /// \brief Determine the location of the 'return' keyword when initializing
191 /// the result of a function call.
192 SourceLocation getReturnLoc() const {
193 assert(getKind() == EK_Result && "No 'return' location!");
194 return SourceLocation::getFromRawEncoding(Location);
195 }
196
197 /// \brief Determine the location of the 'throw' keyword when initializing
198 /// an exception object.
199 SourceLocation getThrowLoc() const {
200 assert(getKind() == EK_Exception && "No 'throw' location!");
201 return SourceLocation::getFromRawEncoding(Location);
202 }
Douglas Gregorcb57fb92009-12-16 06:35:08 +0000203
204 /// \brief If this is already the initializer for an array or vector
205 /// element, sets the element index.
206 void setElementIndex(unsigned Index) {
207 assert(getKind() == EK_ArrayOrVectorElement);
208 this->Index = Index;
209 }
Douglas Gregor20093b42009-12-09 23:02:17 +0000210};
211
212/// \brief Describes the kind of initialization being performed, along with
213/// location information for tokens related to the initialization (equal sign,
214/// parentheses).
215class InitializationKind {
216public:
217 /// \brief The kind of initialization being performed.
218 enum InitKind {
219 IK_Direct, ///< Direct initialization
220 IK_Copy, ///< Copy initialization
221 IK_Default, ///< Default initialization
222 IK_Value ///< Value initialization
223 };
224
225private:
226 /// \brief The kind of initialization that we're storing.
227 enum StoredInitKind {
228 SIK_Direct = IK_Direct, ///< Direct initialization
229 SIK_Copy = IK_Copy, ///< Copy initialization
230 SIK_Default = IK_Default, ///< Default initialization
231 SIK_Value = IK_Value, ///< Value initialization
Douglas Gregorcb57fb92009-12-16 06:35:08 +0000232 SIK_ImplicitValue, ///< Implicit value initialization
Douglas Gregor20093b42009-12-09 23:02:17 +0000233 SIK_DirectCast, ///< Direct initialization due to a cast
234 /// \brief Direct initialization due to a C-style or functional cast.
235 SIK_DirectCStyleOrFunctionalCast
236 };
237
238 /// \brief The kind of initialization being performed.
239 StoredInitKind Kind;
240
241 /// \brief The source locations involved in the initialization.
242 SourceLocation Locations[3];
243
244 InitializationKind(StoredInitKind Kind, SourceLocation Loc1,
245 SourceLocation Loc2, SourceLocation Loc3)
246 : Kind(Kind)
247 {
248 Locations[0] = Loc1;
249 Locations[1] = Loc2;
250 Locations[2] = Loc3;
251 }
252
253public:
254 /// \brief Create a direct initialization.
255 static InitializationKind CreateDirect(SourceLocation InitLoc,
256 SourceLocation LParenLoc,
257 SourceLocation RParenLoc) {
258 return InitializationKind(SIK_Direct, InitLoc, LParenLoc, RParenLoc);
259 }
260
261 /// \brief Create a direct initialization due to a cast.
262 static InitializationKind CreateCast(SourceRange TypeRange,
263 bool IsCStyleCast) {
264 return InitializationKind(IsCStyleCast? SIK_DirectCStyleOrFunctionalCast
265 : SIK_DirectCast,
266 TypeRange.getBegin(), TypeRange.getBegin(),
267 TypeRange.getEnd());
268 }
269
270 /// \brief Create a copy initialization.
271 static InitializationKind CreateCopy(SourceLocation InitLoc,
272 SourceLocation EqualLoc) {
273 return InitializationKind(SIK_Copy, InitLoc, EqualLoc, EqualLoc);
274 }
275
276 /// \brief Create a default initialization.
277 static InitializationKind CreateDefault(SourceLocation InitLoc) {
278 return InitializationKind(SIK_Default, InitLoc, InitLoc, InitLoc);
279 }
280
281 /// \brief Create a value initialization.
282 static InitializationKind CreateValue(SourceLocation InitLoc,
283 SourceLocation LParenLoc,
Douglas Gregorcb57fb92009-12-16 06:35:08 +0000284 SourceLocation RParenLoc,
285 bool isImplicit = false) {
286 return InitializationKind(isImplicit? SIK_ImplicitValue : SIK_Value,
287 InitLoc, LParenLoc, RParenLoc);
Douglas Gregor20093b42009-12-09 23:02:17 +0000288 }
289
290 /// \brief Determine the initialization kind.
291 InitKind getKind() const {
Douglas Gregorcb57fb92009-12-16 06:35:08 +0000292 if (Kind > SIK_ImplicitValue)
Douglas Gregor20093b42009-12-09 23:02:17 +0000293 return IK_Direct;
Douglas Gregorcb57fb92009-12-16 06:35:08 +0000294 if (Kind == SIK_ImplicitValue)
295 return IK_Value;
296
Douglas Gregor20093b42009-12-09 23:02:17 +0000297 return (InitKind)Kind;
298 }
299
300 /// \brief Determine whether this initialization is an explicit cast.
301 bool isExplicitCast() const {
302 return Kind == SIK_DirectCast || Kind == SIK_DirectCStyleOrFunctionalCast;
303 }
304
305 /// \brief Determine whether this initialization is a C-style cast.
306 bool isCStyleOrFunctionalCast() const {
307 return Kind == SIK_DirectCStyleOrFunctionalCast;
308 }
Douglas Gregorcb57fb92009-12-16 06:35:08 +0000309
310 /// \brief Determine whether this initialization is an implicit
311 /// value-initialization, e.g., as occurs during aggregate
312 /// initialization.
313 bool isImplicitValueInit() const { return Kind == SIK_ImplicitValue; }
314
Douglas Gregor20093b42009-12-09 23:02:17 +0000315 /// \brief Retrieve the location at which initialization is occurring.
316 SourceLocation getLocation() const { return Locations[0]; }
317
318 /// \brief Retrieve the source range that covers the initialization.
319 SourceRange getRange() const {
Douglas Gregor71d17402009-12-15 00:01:57 +0000320 return SourceRange(Locations[0], Locations[2]);
Douglas Gregor20093b42009-12-09 23:02:17 +0000321 }
322
323 /// \brief Retrieve the location of the equal sign for copy initialization
324 /// (if present).
325 SourceLocation getEqualLoc() const {
326 assert(Kind == SIK_Copy && "Only copy initialization has an '='");
327 return Locations[1];
328 }
329
330 /// \brief Retrieve the source range containing the locations of the open
331 /// and closing parentheses for value and direct initializations.
332 SourceRange getParenRange() const {
333 assert((getKind() == IK_Direct || Kind == SIK_Value) &&
334 "Only direct- and value-initialization have parentheses");
335 return SourceRange(Locations[1], Locations[2]);
336 }
337};
338
339/// \brief Describes the sequence of initializations required to initialize
340/// a given object or reference with a set of arguments.
341class InitializationSequence {
342public:
343 /// \brief Describes the kind of initialization sequence computed.
Douglas Gregor71d17402009-12-15 00:01:57 +0000344 ///
345 /// FIXME: Much of this information is in the initialization steps... why is
346 /// it duplicated here?
Douglas Gregor20093b42009-12-09 23:02:17 +0000347 enum SequenceKind {
348 /// \brief A failed initialization sequence. The failure kind tells what
349 /// happened.
350 FailedSequence = 0,
351
352 /// \brief A dependent initialization, which could not be
353 /// type-checked due to the presence of dependent types or
354 /// dependently-type expressions.
355 DependentSequence,
356
Douglas Gregor4a520a22009-12-14 17:27:33 +0000357 /// \brief A user-defined conversion sequence.
358 UserDefinedConversion,
359
Douglas Gregor51c56d62009-12-14 20:49:26 +0000360 /// \brief A constructor call.
Douglas Gregora6ca6502009-12-14 20:57:13 +0000361 ConstructorInitialization,
Douglas Gregor51c56d62009-12-14 20:49:26 +0000362
Douglas Gregor20093b42009-12-09 23:02:17 +0000363 /// \brief A reference binding.
Douglas Gregord87b61f2009-12-10 17:56:55 +0000364 ReferenceBinding,
365
366 /// \brief List initialization
Douglas Gregor71d17402009-12-15 00:01:57 +0000367 ListInitialization,
368
369 /// \brief Zero-initialization.
Douglas Gregor99a2e602009-12-16 01:38:02 +0000370 ZeroInitialization,
371
372 /// \brief No initialization required.
373 NoInitialization,
374
375 /// \brief Standard conversion sequence.
376 StandardConversion
Douglas Gregor20093b42009-12-09 23:02:17 +0000377 };
378
379 /// \brief Describes the kind of a particular step in an initialization
380 /// sequence.
381 enum StepKind {
382 /// \brief Resolve the address of an overloaded function to a specific
383 /// function declaration.
384 SK_ResolveAddressOfOverloadedFunction,
385 /// \brief Perform a derived-to-base cast, producing an rvalue.
386 SK_CastDerivedToBaseRValue,
387 /// \brief Perform a derived-to-base cast, producing an lvalue.
388 SK_CastDerivedToBaseLValue,
389 /// \brief Reference binding to an lvalue.
390 SK_BindReference,
391 /// \brief Reference binding to a temporary.
392 SK_BindReferenceToTemporary,
393 /// \brief Perform a user-defined conversion, either via a conversion
394 /// function or via a constructor.
395 SK_UserConversion,
396 /// \brief Perform a qualification conversion, producing an rvalue.
397 SK_QualificationConversionRValue,
398 /// \brief Perform a qualification conversion, producing an lvalue.
399 SK_QualificationConversionLValue,
400 /// \brief Perform an implicit conversion sequence.
Douglas Gregord87b61f2009-12-10 17:56:55 +0000401 SK_ConversionSequence,
402 /// \brief Perform list-initialization
Douglas Gregor51c56d62009-12-14 20:49:26 +0000403 SK_ListInitialization,
404 /// \brief Perform initialization via a constructor.
Douglas Gregor71d17402009-12-15 00:01:57 +0000405 SK_ConstructorInitialization,
406 /// \brief Zero-initialize the object
407 SK_ZeroInitialization
Douglas Gregor20093b42009-12-09 23:02:17 +0000408 };
409
410 /// \brief A single step in the initialization sequence.
411 class Step {
412 public:
413 /// \brief The kind of conversion or initialization step we are taking.
414 StepKind Kind;
415
416 // \brief The type that results from this initialization.
417 QualType Type;
418
419 union {
420 /// \brief When Kind == SK_ResolvedOverloadedFunction or Kind ==
421 /// SK_UserConversion, the function that the expression should be
422 /// resolved to or the conversion function to call, respectively.
423 FunctionDecl *Function;
424
425 /// \brief When Kind = SK_ConversionSequence, the implicit conversion
426 /// sequence
427 ImplicitConversionSequence *ICS;
428 };
429
430 void Destroy();
431 };
432
433private:
434 /// \brief The kind of initialization sequence computed.
435 enum SequenceKind SequenceKind;
436
437 /// \brief Steps taken by this initialization.
438 llvm::SmallVector<Step, 4> Steps;
439
440public:
441 /// \brief Describes why initialization failed.
442 enum FailureKind {
443 /// \brief Too many initializers provided for a reference.
444 FK_TooManyInitsForReference,
445 /// \brief Array must be initialized with an initializer list.
446 FK_ArrayNeedsInitList,
447 /// \brief Array must be initialized with an initializer list or a
448 /// string literal.
449 FK_ArrayNeedsInitListOrStringLiteral,
450 /// \brief Cannot resolve the address of an overloaded function.
451 FK_AddressOfOverloadFailed,
452 /// \brief Overloading due to reference initialization failed.
453 FK_ReferenceInitOverloadFailed,
454 /// \brief Non-const lvalue reference binding to a temporary.
455 FK_NonConstLValueReferenceBindingToTemporary,
456 /// \brief Non-const lvalue reference binding to an lvalue of unrelated
457 /// type.
458 FK_NonConstLValueReferenceBindingToUnrelated,
459 /// \brief Rvalue reference binding to an lvalue.
460 FK_RValueReferenceBindingToLValue,
461 /// \brief Reference binding drops qualifiers.
462 FK_ReferenceInitDropsQualifiers,
463 /// \brief Reference binding failed.
464 FK_ReferenceInitFailed,
465 /// \brief Implicit conversion failed.
Douglas Gregord87b61f2009-12-10 17:56:55 +0000466 FK_ConversionFailed,
467 /// \brief Too many initializers for scalar
468 FK_TooManyInitsForScalar,
469 /// \brief Reference initialization from an initializer list
470 FK_ReferenceBindingToInitList,
471 /// \brief Initialization of some unused destination type with an
472 /// initializer list.
Douglas Gregor4a520a22009-12-14 17:27:33 +0000473 FK_InitListBadDestinationType,
474 /// \brief Overloading for a user-defined conversion failed.
Douglas Gregor51c56d62009-12-14 20:49:26 +0000475 FK_UserConversionOverloadFailed,
476 /// \brief Overloaded for initialization by constructor failed.
Douglas Gregor99a2e602009-12-16 01:38:02 +0000477 FK_ConstructorOverloadFailed,
478 /// \brief Default-initialization of a 'const' object.
479 FK_DefaultInitOfConst
Douglas Gregor20093b42009-12-09 23:02:17 +0000480 };
481
482private:
483 /// \brief The reason why initialization failued.
484 FailureKind Failure;
485
486 /// \brief The failed result of overload resolution.
487 OverloadingResult FailedOverloadResult;
488
489 /// \brief The candidate set created when initialization failed.
490 OverloadCandidateSet FailedCandidateSet;
491
492public:
493 /// \brief Try to perform initialization of the given entity, creating a
494 /// record of the steps required to perform the initialization.
495 ///
496 /// The generated initialization sequence will either contain enough
497 /// information to diagnose
498 ///
499 /// \param S the semantic analysis object.
500 ///
501 /// \param Entity the entity being initialized.
502 ///
503 /// \param Kind the kind of initialization being performed.
504 ///
505 /// \param Args the argument(s) provided for initialization.
506 ///
507 /// \param NumArgs the number of arguments provided for initialization.
508 InitializationSequence(Sema &S,
509 const InitializedEntity &Entity,
510 const InitializationKind &Kind,
511 Expr **Args,
512 unsigned NumArgs);
513
514 ~InitializationSequence();
515
516 /// \brief Perform the actual initialization of the given entity based on
517 /// the computed initialization sequence.
518 ///
519 /// \param S the semantic analysis object.
520 ///
521 /// \param Entity the entity being initialized.
522 ///
523 /// \param Kind the kind of initialization being performed.
524 ///
525 /// \param Args the argument(s) provided for initialization, ownership of
526 /// which is transfered into the routine.
527 ///
Douglas Gregord87b61f2009-12-10 17:56:55 +0000528 /// \param ResultType if non-NULL, will be set to the type of the
529 /// initialized object, which is the type of the declaration in most
530 /// cases. However, when the initialized object is a variable of
531 /// incomplete array type and the initializer is an initializer
532 /// list, this type will be set to the completed array type.
533 ///
Douglas Gregor20093b42009-12-09 23:02:17 +0000534 /// \returns an expression that performs the actual object initialization, if
535 /// the initialization is well-formed. Otherwise, emits diagnostics
536 /// and returns an invalid expression.
537 Action::OwningExprResult Perform(Sema &S,
538 const InitializedEntity &Entity,
539 const InitializationKind &Kind,
Douglas Gregord87b61f2009-12-10 17:56:55 +0000540 Action::MultiExprArg Args,
541 QualType *ResultType = 0);
Douglas Gregor20093b42009-12-09 23:02:17 +0000542
543 /// \brief Diagnose an potentially-invalid initialization sequence.
544 ///
545 /// \returns true if the initialization sequence was ill-formed,
546 /// false otherwise.
547 bool Diagnose(Sema &S,
548 const InitializedEntity &Entity,
549 const InitializationKind &Kind,
550 Expr **Args, unsigned NumArgs);
551
552 /// \brief Determine the kind of initialization sequence computed.
553 enum SequenceKind getKind() const { return SequenceKind; }
554
555 /// \brief Set the kind of sequence computed.
556 void setSequenceKind(enum SequenceKind SK) { SequenceKind = SK; }
557
558 /// \brief Determine whether the initialization sequence is valid.
559 operator bool() const { return SequenceKind != FailedSequence; }
560
561 typedef llvm::SmallVector<Step, 4>::const_iterator step_iterator;
562 step_iterator step_begin() const { return Steps.begin(); }
563 step_iterator step_end() const { return Steps.end(); }
564
565 /// \brief Add a new step in the initialization that resolves the address
566 /// of an overloaded function to a specific function declaration.
567 ///
568 /// \param Function the function to which the overloaded function reference
569 /// resolves.
570 void AddAddressOverloadResolutionStep(FunctionDecl *Function);
571
572 /// \brief Add a new step in the initialization that performs a derived-to-
573 /// base cast.
574 ///
575 /// \param BaseType the base type to which we will be casting.
576 ///
577 /// \param IsLValue true if the result of this cast will be treated as
578 /// an lvalue.
579 void AddDerivedToBaseCastStep(QualType BaseType, bool IsLValue);
580
581 /// \brief Add a new step binding a reference to an object.
582 ///
583 /// \param BindingTemporary true if we are binding a reference to a temporary
584 /// object (thereby extending its lifetime); false if we are binding to an
585 /// lvalue or an lvalue treated as an rvalue.
586 void AddReferenceBindingStep(QualType T, bool BindingTemporary);
587
588 /// \brief Add a new step invoking a conversion function, which is either
589 /// a constructor or a conversion function.
Eli Friedman03981012009-12-11 02:42:07 +0000590 void AddUserConversionStep(FunctionDecl *Function, QualType T);
Douglas Gregor20093b42009-12-09 23:02:17 +0000591
592 /// \brief Add a new step that performs a qualification conversion to the
593 /// given type.
594 void AddQualificationConversionStep(QualType Ty, bool IsLValue);
595
596 /// \brief Add a new step that applies an implicit conversion sequence.
597 void AddConversionSequenceStep(const ImplicitConversionSequence &ICS,
598 QualType T);
Douglas Gregord87b61f2009-12-10 17:56:55 +0000599
600 /// \brief Add a list-initialiation step
601 void AddListInitializationStep(QualType T);
602
Douglas Gregor71d17402009-12-15 00:01:57 +0000603 /// \brief Add a constructor-initialization step.
Douglas Gregor51c56d62009-12-14 20:49:26 +0000604 void AddConstructorInitializationStep(CXXConstructorDecl *Constructor,
605 QualType T);
Douglas Gregor71d17402009-12-15 00:01:57 +0000606
607 /// \brief Add a zero-initialization step.
608 void AddZeroInitializationStep(QualType T);
Douglas Gregor51c56d62009-12-14 20:49:26 +0000609
Douglas Gregor20093b42009-12-09 23:02:17 +0000610 /// \brief Note that this initialization sequence failed.
611 void SetFailed(FailureKind Failure) {
612 SequenceKind = FailedSequence;
613 this->Failure = Failure;
614 }
615
616 /// \brief Note that this initialization sequence failed due to failed
617 /// overload resolution.
618 void SetOverloadFailure(FailureKind Failure, OverloadingResult Result);
619
620 /// \brief Retrieve a reference to the candidate set when overload
621 /// resolution fails.
622 OverloadCandidateSet &getFailedCandidateSet() {
623 return FailedCandidateSet;
624 }
625
626 /// \brief Determine why initialization failed.
627 FailureKind getFailureKind() const {
628 assert(getKind() == FailedSequence && "Not an initialization failure!");
629 return Failure;
630 }
631};
632
633} // end namespace clang
634
635#endif // LLVM_CLANG_SEMA_INIT_H