1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | #ifndef LLVM_CLANG_SEMA_INITIALIZATION_H |
14 | #define LLVM_CLANG_SEMA_INITIALIZATION_H |
15 | |
16 | #include "clang/AST/ASTContext.h" |
17 | #include "clang/AST/Attr.h" |
18 | #include "clang/AST/Decl.h" |
19 | #include "clang/AST/DeclAccessPair.h" |
20 | #include "clang/AST/DeclarationName.h" |
21 | #include "clang/AST/Expr.h" |
22 | #include "clang/AST/Type.h" |
23 | #include "clang/Basic/IdentifierTable.h" |
24 | #include "clang/Basic/LLVM.h" |
25 | #include "clang/Basic/LangOptions.h" |
26 | #include "clang/Basic/SourceLocation.h" |
27 | #include "clang/Basic/Specifiers.h" |
28 | #include "clang/Sema/Overload.h" |
29 | #include "clang/Sema/Ownership.h" |
30 | #include "llvm/ADT/ArrayRef.h" |
31 | #include "llvm/ADT/SmallVector.h" |
32 | #include "llvm/ADT/StringRef.h" |
33 | #include "llvm/ADT/iterator_range.h" |
34 | #include "llvm/Support/Casting.h" |
35 | #include <cassert> |
36 | #include <cstdint> |
37 | #include <string> |
38 | |
39 | namespace clang { |
40 | |
41 | class APValue; |
42 | class CXXBaseSpecifier; |
43 | class CXXConstructorDecl; |
44 | class ObjCMethodDecl; |
45 | class Sema; |
46 | |
47 | |
48 | class alignas(8) InitializedEntity { |
49 | public: |
50 | |
51 | enum EntityKind { |
52 | |
53 | EK_Variable, |
54 | |
55 | |
56 | EK_Parameter, |
57 | |
58 | |
59 | EK_Result, |
60 | |
61 | |
62 | EK_StmtExprResult, |
63 | |
64 | |
65 | |
66 | EK_Exception, |
67 | |
68 | |
69 | |
70 | EK_Member, |
71 | |
72 | |
73 | EK_ArrayElement, |
74 | |
75 | |
76 | |
77 | EK_New, |
78 | |
79 | |
80 | EK_Temporary, |
81 | |
82 | |
83 | EK_Base, |
84 | |
85 | |
86 | EK_Delegating, |
87 | |
88 | |
89 | |
90 | EK_VectorElement, |
91 | |
92 | |
93 | |
94 | EK_BlockElement, |
95 | |
96 | |
97 | |
98 | EK_LambdaToBlockConversionBlockElement, |
99 | |
100 | |
101 | |
102 | EK_ComplexElement, |
103 | |
104 | |
105 | |
106 | EK_LambdaCapture, |
107 | |
108 | |
109 | |
110 | EK_CompoundLiteralInit, |
111 | |
112 | |
113 | |
114 | EK_RelatedResult, |
115 | |
116 | |
117 | |
118 | EK_Parameter_CF_Audited, |
119 | |
120 | |
121 | |
122 | EK_Binding, |
123 | |
124 | |
125 | |
126 | |
127 | }; |
128 | |
129 | private: |
130 | |
131 | EntityKind Kind; |
132 | |
133 | |
134 | |
135 | const InitializedEntity *Parent = nullptr; |
136 | |
137 | |
138 | QualType Type; |
139 | |
140 | |
141 | mutable unsigned ManglingNumber = 0; |
142 | |
143 | struct LN { |
144 | |
145 | |
146 | |
147 | |
148 | unsigned Location; |
149 | |
150 | |
151 | |
152 | bool NRVO; |
153 | }; |
154 | |
155 | struct VD { |
156 | |
157 | ValueDecl *VariableOrMember; |
158 | |
159 | |
160 | |
161 | |
162 | bool IsImplicitFieldInit; |
163 | |
164 | |
165 | |
166 | bool IsDefaultMemberInit; |
167 | }; |
168 | |
169 | struct C { |
170 | |
171 | IdentifierInfo *VarID; |
172 | |
173 | |
174 | unsigned Location; |
175 | }; |
176 | |
177 | union { |
178 | |
179 | VD Variable; |
180 | |
181 | |
182 | |
183 | ObjCMethodDecl *MethodDecl; |
184 | |
185 | |
186 | |
187 | uintptr_t Parameter; |
188 | |
189 | |
190 | |
191 | TypeSourceInfo *TypeInfo; |
192 | |
193 | struct LN LocAndNRVO; |
194 | |
195 | |
196 | |
197 | |
198 | uintptr_t Base; |
199 | |
200 | |
201 | |
202 | |
203 | unsigned Index; |
204 | |
205 | struct C Capture; |
206 | }; |
207 | |
208 | InitializedEntity() = default; |
209 | |
210 | |
211 | InitializedEntity(VarDecl *Var, EntityKind EK = EK_Variable) |
212 | : Kind(EK), Type(Var->getType()), Variable{Var, false, false} {} |
213 | |
214 | |
215 | |
216 | |
217 | InitializedEntity(EntityKind Kind, SourceLocation Loc, QualType Type, |
218 | bool NRVO = false) |
219 | : Kind(Kind), Type(Type) { |
220 | LocAndNRVO.Location = Loc.getRawEncoding(); |
221 | LocAndNRVO.NRVO = NRVO; |
222 | } |
223 | |
224 | |
225 | InitializedEntity(FieldDecl *Member, const InitializedEntity *Parent, |
226 | bool Implicit, bool DefaultMemberInit) |
227 | : Kind(EK_Member), Parent(Parent), Type(Member->getType()), |
228 | Variable{Member, Implicit, DefaultMemberInit} {} |
229 | |
230 | |
231 | InitializedEntity(ASTContext &Context, unsigned Index, |
232 | const InitializedEntity &Parent); |
233 | |
234 | |
235 | InitializedEntity(IdentifierInfo *VarID, QualType FieldType, SourceLocation Loc) |
236 | : Kind(EK_LambdaCapture), Type(FieldType) { |
237 | Capture.VarID = VarID; |
238 | Capture.Location = Loc.getRawEncoding(); |
239 | } |
240 | |
241 | public: |
242 | |
243 | static InitializedEntity InitializeVariable(VarDecl *Var) { |
244 | return InitializedEntity(Var); |
245 | } |
246 | |
247 | |
248 | static InitializedEntity InitializeParameter(ASTContext &Context, |
249 | const ParmVarDecl *Parm) { |
250 | return InitializeParameter(Context, Parm, Parm->getType()); |
251 | } |
252 | |
253 | |
254 | |
255 | static InitializedEntity InitializeParameter(ASTContext &Context, |
256 | const ParmVarDecl *Parm, |
257 | QualType Type) { |
258 | bool Consumed = (Context.getLangOpts().ObjCAutoRefCount && |
259 | Parm->hasAttr<NSConsumedAttr>()); |
260 | |
261 | InitializedEntity Entity; |
262 | Entity.Kind = EK_Parameter; |
263 | Entity.Type = |
264 | Context.getVariableArrayDecayedType(Type.getUnqualifiedType()); |
265 | Entity.Parent = nullptr; |
266 | Entity.Parameter |
267 | = (static_cast<uintptr_t>(Consumed) | reinterpret_cast<uintptr_t>(Parm)); |
268 | return Entity; |
269 | } |
270 | |
271 | |
272 | |
273 | static InitializedEntity InitializeParameter(ASTContext &Context, |
274 | QualType Type, |
275 | bool Consumed) { |
276 | InitializedEntity Entity; |
277 | Entity.Kind = EK_Parameter; |
278 | Entity.Type = Context.getVariableArrayDecayedType(Type); |
279 | Entity.Parent = nullptr; |
280 | Entity.Parameter = (Consumed); |
281 | return Entity; |
282 | } |
283 | |
284 | |
285 | static InitializedEntity InitializeResult(SourceLocation ReturnLoc, |
286 | QualType Type, bool NRVO) { |
287 | return InitializedEntity(EK_Result, ReturnLoc, Type, NRVO); |
288 | } |
289 | |
290 | static InitializedEntity InitializeStmtExprResult(SourceLocation ReturnLoc, |
291 | QualType Type) { |
292 | return InitializedEntity(EK_StmtExprResult, ReturnLoc, Type); |
293 | } |
294 | |
295 | static InitializedEntity InitializeBlock(SourceLocation BlockVarLoc, |
296 | QualType Type, bool NRVO) { |
297 | return InitializedEntity(EK_BlockElement, BlockVarLoc, Type, NRVO); |
298 | } |
299 | |
300 | static InitializedEntity InitializeLambdaToBlock(SourceLocation BlockVarLoc, |
301 | QualType Type, bool NRVO) { |
302 | return InitializedEntity(EK_LambdaToBlockConversionBlockElement, |
303 | BlockVarLoc, Type, NRVO); |
304 | } |
305 | |
306 | |
307 | static InitializedEntity InitializeException(SourceLocation ThrowLoc, |
308 | QualType Type, bool NRVO) { |
309 | return InitializedEntity(EK_Exception, ThrowLoc, Type, NRVO); |
310 | } |
311 | |
312 | |
313 | static InitializedEntity InitializeNew(SourceLocation NewLoc, QualType Type) { |
314 | return InitializedEntity(EK_New, NewLoc, Type); |
315 | } |
316 | |
317 | |
318 | static InitializedEntity InitializeTemporary(QualType Type) { |
319 | return InitializeTemporary(nullptr, Type); |
320 | } |
321 | |
322 | |
323 | static InitializedEntity InitializeTemporary(TypeSourceInfo *TypeInfo) { |
324 | return InitializeTemporary(TypeInfo, TypeInfo->getType()); |
325 | } |
326 | |
327 | |
328 | static InitializedEntity InitializeTemporary(TypeSourceInfo *TypeInfo, |
329 | QualType Type) { |
330 | InitializedEntity Result(EK_Temporary, SourceLocation(), Type); |
331 | Result.TypeInfo = TypeInfo; |
332 | return Result; |
333 | } |
334 | |
335 | |
336 | static InitializedEntity InitializeRelatedResult(ObjCMethodDecl *MD, |
337 | QualType Type) { |
338 | InitializedEntity Result(EK_RelatedResult, SourceLocation(), Type); |
339 | Result.MethodDecl = MD; |
340 | return Result; |
341 | } |
342 | |
343 | |
344 | static InitializedEntity |
345 | InitializeBase(ASTContext &Context, const CXXBaseSpecifier *Base, |
346 | bool IsInheritedVirtualBase, |
347 | const InitializedEntity *Parent = nullptr); |
348 | |
349 | |
350 | static InitializedEntity InitializeDelegation(QualType Type) { |
351 | return InitializedEntity(EK_Delegating, SourceLocation(), Type); |
352 | } |
353 | |
354 | |
355 | static InitializedEntity |
356 | InitializeMember(FieldDecl *Member, |
357 | const InitializedEntity *Parent = nullptr, |
358 | bool Implicit = false) { |
359 | return InitializedEntity(Member, Parent, Implicit, false); |
360 | } |
361 | |
362 | |
363 | static InitializedEntity |
364 | InitializeMember(IndirectFieldDecl *Member, |
365 | const InitializedEntity *Parent = nullptr, |
366 | bool Implicit = false) { |
367 | return InitializedEntity(Member->getAnonField(), Parent, Implicit, false); |
368 | } |
369 | |
370 | |
371 | static InitializedEntity |
372 | InitializeMemberFromDefaultMemberInitializer(FieldDecl *Member) { |
373 | return InitializedEntity(Member, nullptr, false, true); |
374 | } |
375 | |
376 | |
377 | static InitializedEntity InitializeElement(ASTContext &Context, |
378 | unsigned Index, |
379 | const InitializedEntity &Parent) { |
380 | return InitializedEntity(Context, Index, Parent); |
381 | } |
382 | |
383 | |
384 | static InitializedEntity InitializeBinding(VarDecl *Binding) { |
385 | return InitializedEntity(Binding, EK_Binding); |
386 | } |
387 | |
388 | |
389 | static InitializedEntity InitializeLambdaCapture(IdentifierInfo *VarID, |
390 | QualType FieldType, |
391 | SourceLocation Loc) { |
392 | return InitializedEntity(VarID, FieldType, Loc); |
393 | } |
394 | |
395 | |
396 | static InitializedEntity InitializeCompoundLiteralInit(TypeSourceInfo *TSI) { |
397 | InitializedEntity Result(EK_CompoundLiteralInit, SourceLocation(), |
398 | TSI->getType()); |
399 | Result.TypeInfo = TSI; |
400 | return Result; |
401 | } |
402 | |
403 | |
404 | EntityKind getKind() const { return Kind; } |
405 | |
406 | |
407 | |
408 | |
409 | const InitializedEntity *getParent() const { return Parent; } |
410 | |
411 | |
412 | QualType getType() const { return Type; } |
413 | |
414 | |
415 | |
416 | TypeSourceInfo *getTypeSourceInfo() const { |
417 | if (Kind == EK_Temporary || Kind == EK_CompoundLiteralInit) |
418 | return TypeInfo; |
419 | |
420 | return nullptr; |
421 | } |
422 | |
423 | |
424 | DeclarationName getName() const; |
425 | |
426 | |
427 | |
428 | ValueDecl *getDecl() const; |
429 | |
430 | |
431 | ObjCMethodDecl *getMethodDecl() const { return MethodDecl; } |
432 | |
433 | |
434 | |
435 | bool allowsNRVO() const; |
436 | |
437 | bool isParameterKind() const { |
438 | return (getKind() == EK_Parameter || |
439 | getKind() == EK_Parameter_CF_Audited); |
440 | } |
441 | |
442 | |
443 | |
444 | bool isParameterConsumed() const { |
445 | (0) . __assert_fail ("isParameterKind() && \"Not a parameter\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/Initialization.h", 445, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(isParameterKind() && "Not a parameter"); |
446 | return (Parameter & 1); |
447 | } |
448 | |
449 | |
450 | const CXXBaseSpecifier *getBaseSpecifier() const { |
451 | (0) . __assert_fail ("getKind() == EK_Base && \"Not a base specifier\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/Initialization.h", 451, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getKind() == EK_Base && "Not a base specifier"); |
452 | return reinterpret_cast<const CXXBaseSpecifier *>(Base & ~0x1); |
453 | } |
454 | |
455 | |
456 | bool isInheritedVirtualBase() const { |
457 | (0) . __assert_fail ("getKind() == EK_Base && \"Not a base specifier\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/Initialization.h", 457, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getKind() == EK_Base && "Not a base specifier"); |
458 | return Base & 0x1; |
459 | } |
460 | |
461 | |
462 | bool isVariableLengthArrayNew() const { |
463 | return getKind() == EK_New && dyn_cast_or_null<IncompleteArrayType>( |
464 | getType()->getAsArrayTypeUnsafe()); |
465 | } |
466 | |
467 | |
468 | |
469 | bool isImplicitMemberInitializer() const { |
470 | return getKind() == EK_Member && Variable.IsImplicitFieldInit; |
471 | } |
472 | |
473 | |
474 | |
475 | bool isDefaultMemberInitializer() const { |
476 | return getKind() == EK_Member && Variable.IsDefaultMemberInit; |
477 | } |
478 | |
479 | |
480 | |
481 | SourceLocation getReturnLoc() const { |
482 | (0) . __assert_fail ("getKind() == EK_Result && \"No 'return' location!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/Initialization.h", 482, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getKind() == EK_Result && "No 'return' location!"); |
483 | return SourceLocation::getFromRawEncoding(LocAndNRVO.Location); |
484 | } |
485 | |
486 | |
487 | |
488 | SourceLocation getThrowLoc() const { |
489 | (0) . __assert_fail ("getKind() == EK_Exception && \"No 'throw' location!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/Initialization.h", 489, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getKind() == EK_Exception && "No 'throw' location!"); |
490 | return SourceLocation::getFromRawEncoding(LocAndNRVO.Location); |
491 | } |
492 | |
493 | |
494 | |
495 | unsigned getElementIndex() const { |
496 | assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement || |
497 | getKind() == EK_ComplexElement); |
498 | return Index; |
499 | } |
500 | |
501 | |
502 | |
503 | void setElementIndex(unsigned Index) { |
504 | assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement || |
505 | getKind() == EK_ComplexElement); |
506 | this->Index = Index; |
507 | } |
508 | |
509 | |
510 | StringRef getCapturedVarName() const { |
511 | (0) . __assert_fail ("getKind() == EK_LambdaCapture && \"Not a lambda capture!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/Initialization.h", 511, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getKind() == EK_LambdaCapture && "Not a lambda capture!"); |
512 | return Capture.VarID->getName(); |
513 | } |
514 | |
515 | |
516 | |
517 | SourceLocation getCaptureLoc() const { |
518 | (0) . __assert_fail ("getKind() == EK_LambdaCapture && \"Not a lambda capture!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/Initialization.h", 518, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getKind() == EK_LambdaCapture && "Not a lambda capture!"); |
519 | return SourceLocation::getFromRawEncoding(Capture.Location); |
520 | } |
521 | |
522 | void setParameterCFAudited() { |
523 | Kind = EK_Parameter_CF_Audited; |
524 | } |
525 | |
526 | unsigned allocateManglingNumber() const { return ++ManglingNumber; } |
527 | |
528 | |
529 | |
530 | void dump() const; |
531 | |
532 | private: |
533 | unsigned dumpImpl(raw_ostream &OS) const; |
534 | }; |
535 | |
536 | |
537 | |
538 | |
539 | class InitializationKind { |
540 | public: |
541 | |
542 | enum InitKind { |
543 | |
544 | IK_Direct, |
545 | |
546 | |
547 | IK_DirectList, |
548 | |
549 | |
550 | IK_Copy, |
551 | |
552 | |
553 | IK_Default, |
554 | |
555 | |
556 | IK_Value |
557 | }; |
558 | |
559 | private: |
560 | |
561 | enum InitContext { |
562 | |
563 | IC_Normal, |
564 | |
565 | |
566 | IC_ExplicitConvs, |
567 | |
568 | |
569 | IC_Implicit, |
570 | |
571 | |
572 | IC_StaticCast, |
573 | |
574 | |
575 | IC_CStyleCast, |
576 | |
577 | |
578 | IC_FunctionalCast |
579 | }; |
580 | |
581 | |
582 | InitKind Kind : 8; |
583 | |
584 | |
585 | InitContext Context : 8; |
586 | |
587 | |
588 | SourceLocation Locations[3]; |
589 | |
590 | InitializationKind(InitKind Kind, InitContext Context, SourceLocation Loc1, |
591 | SourceLocation Loc2, SourceLocation Loc3) |
592 | : Kind(Kind), Context(Context) { |
593 | Locations[0] = Loc1; |
594 | Locations[1] = Loc2; |
595 | Locations[2] = Loc3; |
596 | } |
597 | |
598 | public: |
599 | |
600 | static InitializationKind CreateDirect(SourceLocation InitLoc, |
601 | SourceLocation LParenLoc, |
602 | SourceLocation RParenLoc) { |
603 | return InitializationKind(IK_Direct, IC_Normal, |
604 | InitLoc, LParenLoc, RParenLoc); |
605 | } |
606 | |
607 | static InitializationKind CreateDirectList(SourceLocation InitLoc) { |
608 | return InitializationKind(IK_DirectList, IC_Normal, InitLoc, InitLoc, |
609 | InitLoc); |
610 | } |
611 | |
612 | static InitializationKind CreateDirectList(SourceLocation InitLoc, |
613 | SourceLocation LBraceLoc, |
614 | SourceLocation RBraceLoc) { |
615 | return InitializationKind(IK_DirectList, IC_Normal, InitLoc, LBraceLoc, |
616 | RBraceLoc); |
617 | } |
618 | |
619 | |
620 | |
621 | static InitializationKind CreateCast(SourceRange TypeRange) { |
622 | return InitializationKind(IK_Direct, IC_StaticCast, TypeRange.getBegin(), |
623 | TypeRange.getBegin(), TypeRange.getEnd()); |
624 | } |
625 | |
626 | |
627 | static InitializationKind CreateCStyleCast(SourceLocation StartLoc, |
628 | SourceRange TypeRange, |
629 | bool InitList) { |
630 | |
631 | |
632 | return InitializationKind(InitList ? IK_DirectList : IK_Direct, |
633 | IC_CStyleCast, StartLoc, TypeRange.getBegin(), |
634 | TypeRange.getEnd()); |
635 | } |
636 | |
637 | |
638 | static InitializationKind CreateFunctionalCast(SourceRange TypeRange, |
639 | bool InitList) { |
640 | return InitializationKind(InitList ? IK_DirectList : IK_Direct, |
641 | IC_FunctionalCast, TypeRange.getBegin(), |
642 | TypeRange.getBegin(), TypeRange.getEnd()); |
643 | } |
644 | |
645 | |
646 | static InitializationKind CreateCopy(SourceLocation InitLoc, |
647 | SourceLocation EqualLoc, |
648 | bool AllowExplicitConvs = false) { |
649 | return InitializationKind(IK_Copy, |
650 | AllowExplicitConvs? IC_ExplicitConvs : IC_Normal, |
651 | InitLoc, EqualLoc, EqualLoc); |
652 | } |
653 | |
654 | |
655 | static InitializationKind CreateDefault(SourceLocation InitLoc) { |
656 | return InitializationKind(IK_Default, IC_Normal, InitLoc, InitLoc, InitLoc); |
657 | } |
658 | |
659 | |
660 | static InitializationKind CreateValue(SourceLocation InitLoc, |
661 | SourceLocation LParenLoc, |
662 | SourceLocation RParenLoc, |
663 | bool isImplicit = false) { |
664 | return InitializationKind(IK_Value, isImplicit ? IC_Implicit : IC_Normal, |
665 | InitLoc, LParenLoc, RParenLoc); |
666 | } |
667 | |
668 | |
669 | |
670 | static InitializationKind CreateForInit(SourceLocation Loc, bool DirectInit, |
671 | Expr *Init) { |
672 | if (!Init) return CreateDefault(Loc); |
673 | if (!DirectInit) |
674 | return CreateCopy(Loc, Init->getBeginLoc()); |
675 | if (isa<InitListExpr>(Init)) |
676 | return CreateDirectList(Loc, Init->getBeginLoc(), Init->getEndLoc()); |
677 | return CreateDirect(Loc, Init->getBeginLoc(), Init->getEndLoc()); |
678 | } |
679 | |
680 | |
681 | InitKind getKind() const { |
682 | return Kind; |
683 | } |
684 | |
685 | |
686 | bool isExplicitCast() const { |
687 | return Context >= IC_StaticCast; |
688 | } |
689 | |
690 | |
691 | bool isCStyleOrFunctionalCast() const { |
692 | return Context >= IC_CStyleCast; |
693 | } |
694 | |
695 | |
696 | bool isCStyleCast() const { |
697 | return Context == IC_CStyleCast; |
698 | } |
699 | |
700 | |
701 | bool isFunctionalCast() const { |
702 | return Context == IC_FunctionalCast; |
703 | } |
704 | |
705 | |
706 | |
707 | |
708 | bool isImplicitValueInit() const { return Context == IC_Implicit; } |
709 | |
710 | |
711 | SourceLocation getLocation() const { return Locations[0]; } |
712 | |
713 | |
714 | SourceRange getRange() const { |
715 | return SourceRange(Locations[0], Locations[2]); |
716 | } |
717 | |
718 | |
719 | |
720 | SourceLocation getEqualLoc() const { |
721 | (0) . __assert_fail ("Kind == IK_Copy && \"Only copy initialization has an '='\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/Initialization.h", 721, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Kind == IK_Copy && "Only copy initialization has an '='"); |
722 | return Locations[1]; |
723 | } |
724 | |
725 | bool isCopyInit() const { return Kind == IK_Copy; } |
726 | |
727 | |
728 | |
729 | bool AllowExplicit() const { return !isCopyInit(); } |
730 | |
731 | |
732 | |
733 | |
734 | |
735 | bool allowExplicitConversionFunctionsInRefBinding() const { |
736 | return !isCopyInit() || Context == IC_ExplicitConvs; |
737 | } |
738 | |
739 | |
740 | |
741 | bool hasParenOrBraceRange() const { |
742 | return Kind == IK_Direct || Kind == IK_Value || Kind == IK_DirectList; |
743 | } |
744 | |
745 | |
746 | |
747 | |
748 | SourceRange getParenOrBraceRange() const { |
749 | (0) . __assert_fail ("hasParenOrBraceRange() && \"Only direct, value, and direct-list \" \"initialization have parentheses or \" \"braces\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/Initialization.h", 751, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(hasParenOrBraceRange() && "Only direct, value, and direct-list " |
750 | (0) . __assert_fail ("hasParenOrBraceRange() && \"Only direct, value, and direct-list \" \"initialization have parentheses or \" \"braces\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/Initialization.h", 751, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "initialization have parentheses or " |
751 | (0) . __assert_fail ("hasParenOrBraceRange() && \"Only direct, value, and direct-list \" \"initialization have parentheses or \" \"braces\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/Initialization.h", 751, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "braces"); |
752 | return SourceRange(Locations[1], Locations[2]); |
753 | } |
754 | }; |
755 | |
756 | |
757 | |
758 | class InitializationSequence { |
759 | public: |
760 | |
761 | enum SequenceKind { |
762 | |
763 | |
764 | FailedSequence = 0, |
765 | |
766 | |
767 | |
768 | |
769 | DependentSequence, |
770 | |
771 | |
772 | NormalSequence |
773 | }; |
774 | |
775 | |
776 | |
777 | enum StepKind { |
778 | |
779 | |
780 | SK_ResolveAddressOfOverloadedFunction, |
781 | |
782 | |
783 | SK_CastDerivedToBaseRValue, |
784 | |
785 | |
786 | SK_CastDerivedToBaseXValue, |
787 | |
788 | |
789 | SK_CastDerivedToBaseLValue, |
790 | |
791 | |
792 | SK_BindReference, |
793 | |
794 | |
795 | SK_BindReferenceToTemporary, |
796 | |
797 | |
798 | |
799 | |
800 | , |
801 | |
802 | |
803 | |
804 | SK_FinalCopy, |
805 | |
806 | |
807 | |
808 | SK_UserConversion, |
809 | |
810 | |
811 | SK_QualificationConversionRValue, |
812 | |
813 | |
814 | SK_QualificationConversionXValue, |
815 | |
816 | |
817 | SK_QualificationConversionLValue, |
818 | |
819 | |
820 | SK_AtomicConversion, |
821 | |
822 | |
823 | SK_LValueToRValue, |
824 | |
825 | |
826 | SK_ConversionSequence, |
827 | |
828 | |
829 | SK_ConversionSequenceNoNarrowing, |
830 | |
831 | |
832 | SK_ListInitialization, |
833 | |
834 | |
835 | SK_UnwrapInitList, |
836 | |
837 | |
838 | SK_RewrapInitList, |
839 | |
840 | |
841 | SK_ConstructorInitialization, |
842 | |
843 | |
844 | |
845 | SK_ConstructorInitializationFromList, |
846 | |
847 | |
848 | SK_ZeroInitialization, |
849 | |
850 | |
851 | SK_CAssignment, |
852 | |
853 | |
854 | SK_StringInit, |
855 | |
856 | |
857 | |
858 | SK_ObjCObjectConversion, |
859 | |
860 | |
861 | SK_ArrayLoopIndex, |
862 | |
863 | |
864 | SK_ArrayLoopInit, |
865 | |
866 | |
867 | SK_ArrayInit, |
868 | |
869 | |
870 | SK_GNUArrayInit, |
871 | |
872 | |
873 | |
874 | SK_ParenthesizedArrayInit, |
875 | |
876 | |
877 | SK_PassByIndirectCopyRestore, |
878 | |
879 | |
880 | SK_PassByIndirectRestore, |
881 | |
882 | |
883 | SK_ProduceObjCObject, |
884 | |
885 | |
886 | SK_StdInitializerList, |
887 | |
888 | |
889 | |
890 | SK_StdInitializerListConstructorCall, |
891 | |
892 | |
893 | SK_OCLSamplerInit, |
894 | |
895 | |
896 | SK_OCLZeroOpaqueType |
897 | }; |
898 | |
899 | |
900 | class Step { |
901 | public: |
902 | |
903 | StepKind Kind; |
904 | |
905 | |
906 | QualType Type; |
907 | |
908 | struct F { |
909 | bool HadMultipleCandidates; |
910 | FunctionDecl *Function; |
911 | DeclAccessPair FoundDecl; |
912 | }; |
913 | |
914 | union { |
915 | |
916 | |
917 | |
918 | |
919 | |
920 | |
921 | |
922 | |
923 | |
924 | |
925 | struct F Function; |
926 | |
927 | |
928 | |
929 | ImplicitConversionSequence *ICS; |
930 | |
931 | |
932 | |
933 | InitListExpr *WrappingSyntacticList; |
934 | }; |
935 | |
936 | void Destroy(); |
937 | }; |
938 | |
939 | private: |
940 | |
941 | enum SequenceKind SequenceKind; |
942 | |
943 | |
944 | SmallVector<Step, 4> Steps; |
945 | |
946 | public: |
947 | |
948 | enum FailureKind { |
949 | |
950 | FK_TooManyInitsForReference, |
951 | |
952 | |
953 | FK_ParenthesizedListInitForReference, |
954 | |
955 | |
956 | FK_ArrayNeedsInitList, |
957 | |
958 | |
959 | |
960 | FK_ArrayNeedsInitListOrStringLiteral, |
961 | |
962 | |
963 | |
964 | FK_ArrayNeedsInitListOrWideStringLiteral, |
965 | |
966 | |
967 | FK_NarrowStringIntoWideCharArray, |
968 | |
969 | |
970 | FK_WideStringIntoCharArray, |
971 | |
972 | |
973 | |
974 | FK_IncompatWideStringIntoWideChar, |
975 | |
976 | |
977 | FK_PlainStringIntoUTF8Char, |
978 | |
979 | |
980 | FK_UTF8StringIntoPlainChar, |
981 | |
982 | |
983 | FK_ArrayTypeMismatch, |
984 | |
985 | |
986 | FK_NonConstantArrayInit, |
987 | |
988 | |
989 | FK_AddressOfOverloadFailed, |
990 | |
991 | |
992 | FK_ReferenceInitOverloadFailed, |
993 | |
994 | |
995 | FK_NonConstLValueReferenceBindingToTemporary, |
996 | |
997 | |
998 | FK_NonConstLValueReferenceBindingToBitfield, |
999 | |
1000 | |
1001 | FK_NonConstLValueReferenceBindingToVectorElement, |
1002 | |
1003 | |
1004 | |
1005 | FK_NonConstLValueReferenceBindingToUnrelated, |
1006 | |
1007 | |
1008 | FK_RValueReferenceBindingToLValue, |
1009 | |
1010 | |
1011 | FK_ReferenceInitDropsQualifiers, |
1012 | |
1013 | |
1014 | FK_ReferenceInitFailed, |
1015 | |
1016 | |
1017 | FK_ConversionFailed, |
1018 | |
1019 | |
1020 | FK_ConversionFromPropertyFailed, |
1021 | |
1022 | |
1023 | FK_TooManyInitsForScalar, |
1024 | |
1025 | |
1026 | FK_ParenthesizedListInitForScalar, |
1027 | |
1028 | |
1029 | FK_ReferenceBindingToInitList, |
1030 | |
1031 | |
1032 | |
1033 | FK_InitListBadDestinationType, |
1034 | |
1035 | |
1036 | FK_UserConversionOverloadFailed, |
1037 | |
1038 | |
1039 | FK_ConstructorOverloadFailed, |
1040 | |
1041 | |
1042 | FK_ListConstructorOverloadFailed, |
1043 | |
1044 | |
1045 | FK_DefaultInitOfConst, |
1046 | |
1047 | |
1048 | FK_Incomplete, |
1049 | |
1050 | |
1051 | FK_VariableLengthArrayHasInitializer, |
1052 | |
1053 | |
1054 | FK_ListInitializationFailed, |
1055 | |
1056 | |
1057 | |
1058 | FK_PlaceholderType, |
1059 | |
1060 | |
1061 | |
1062 | FK_AddressOfUnaddressableFunction, |
1063 | |
1064 | |
1065 | FK_ExplicitConstructor, |
1066 | }; |
1067 | |
1068 | private: |
1069 | |
1070 | FailureKind Failure; |
1071 | |
1072 | |
1073 | OverloadingResult FailedOverloadResult; |
1074 | |
1075 | |
1076 | OverloadCandidateSet FailedCandidateSet; |
1077 | |
1078 | |
1079 | QualType FailedIncompleteType; |
1080 | |
1081 | |
1082 | |
1083 | std::string ZeroInitializationFixit; |
1084 | SourceLocation ZeroInitializationFixitLoc; |
1085 | |
1086 | public: |
1087 | |
1088 | |
1089 | void SetZeroInitializationFixit(const std::string& Fixit, SourceLocation L) { |
1090 | ZeroInitializationFixit = Fixit; |
1091 | ZeroInitializationFixitLoc = L; |
1092 | } |
1093 | |
1094 | private: |
1095 | |
1096 | |
1097 | void PrintInitLocationNote(Sema &S, const InitializedEntity &Entity); |
1098 | |
1099 | public: |
1100 | |
1101 | |
1102 | |
1103 | |
1104 | |
1105 | |
1106 | |
1107 | |
1108 | |
1109 | |
1110 | |
1111 | |
1112 | |
1113 | |
1114 | |
1115 | |
1116 | |
1117 | |
1118 | |
1119 | InitializationSequence(Sema &S, |
1120 | const InitializedEntity &Entity, |
1121 | const InitializationKind &Kind, |
1122 | MultiExprArg Args, |
1123 | bool TopLevelOfInitList = false, |
1124 | bool TreatUnavailableAsInvalid = true); |
1125 | void InitializeFrom(Sema &S, const InitializedEntity &Entity, |
1126 | const InitializationKind &Kind, MultiExprArg Args, |
1127 | bool TopLevelOfInitList, bool TreatUnavailableAsInvalid); |
1128 | |
1129 | ~InitializationSequence(); |
1130 | |
1131 | |
1132 | |
1133 | |
1134 | |
1135 | |
1136 | |
1137 | |
1138 | |
1139 | |
1140 | |
1141 | |
1142 | |
1143 | |
1144 | |
1145 | |
1146 | |
1147 | |
1148 | |
1149 | |
1150 | |
1151 | |
1152 | ExprResult Perform(Sema &S, |
1153 | const InitializedEntity &Entity, |
1154 | const InitializationKind &Kind, |
1155 | MultiExprArg Args, |
1156 | QualType *ResultType = nullptr); |
1157 | |
1158 | |
1159 | |
1160 | |
1161 | |
1162 | bool Diagnose(Sema &S, |
1163 | const InitializedEntity &Entity, |
1164 | const InitializationKind &Kind, |
1165 | ArrayRef<Expr *> Args); |
1166 | |
1167 | |
1168 | enum SequenceKind getKind() const { return SequenceKind; } |
1169 | |
1170 | |
1171 | void setSequenceKind(enum SequenceKind SK) { SequenceKind = SK; } |
1172 | |
1173 | |
1174 | explicit operator bool() const { return !Failed(); } |
1175 | |
1176 | |
1177 | bool Failed() const { return SequenceKind == FailedSequence; } |
1178 | |
1179 | using step_iterator = SmallVectorImpl<Step>::const_iterator; |
1180 | |
1181 | step_iterator step_begin() const { return Steps.begin(); } |
1182 | step_iterator step_end() const { return Steps.end(); } |
1183 | |
1184 | using step_range = llvm::iterator_range<step_iterator>; |
1185 | |
1186 | step_range steps() const { return {step_begin(), step_end()}; } |
1187 | |
1188 | |
1189 | |
1190 | bool isDirectReferenceBinding() const; |
1191 | |
1192 | |
1193 | bool isAmbiguous() const; |
1194 | |
1195 | |
1196 | |
1197 | bool isConstructorInitialization() const; |
1198 | |
1199 | |
1200 | |
1201 | |
1202 | |
1203 | |
1204 | |
1205 | |
1206 | bool endsWithNarrowing(ASTContext &Ctx, const Expr *Initializer, |
1207 | bool *isInitializerConstant, |
1208 | APValue *ConstantValue) const; |
1209 | |
1210 | |
1211 | |
1212 | |
1213 | |
1214 | |
1215 | void AddAddressOverloadResolutionStep(FunctionDecl *Function, |
1216 | DeclAccessPair Found, |
1217 | bool HadMultipleCandidates); |
1218 | |
1219 | |
1220 | |
1221 | |
1222 | |
1223 | |
1224 | |
1225 | |
1226 | void AddDerivedToBaseCastStep(QualType BaseType, |
1227 | ExprValueKind Category); |
1228 | |
1229 | |
1230 | |
1231 | |
1232 | |
1233 | |
1234 | void AddReferenceBindingStep(QualType T, bool BindingTemporary); |
1235 | |
1236 | |
1237 | |
1238 | |
1239 | |
1240 | |
1241 | |
1242 | |
1243 | |
1244 | |
1245 | |
1246 | void (QualType T); |
1247 | |
1248 | |
1249 | |
1250 | void AddFinalCopy(QualType T); |
1251 | |
1252 | |
1253 | |
1254 | void AddUserConversionStep(FunctionDecl *Function, |
1255 | DeclAccessPair FoundDecl, |
1256 | QualType T, |
1257 | bool HadMultipleCandidates); |
1258 | |
1259 | |
1260 | |
1261 | void AddQualificationConversionStep(QualType Ty, |
1262 | ExprValueKind Category); |
1263 | |
1264 | |
1265 | |
1266 | void AddAtomicConversionStep(QualType Ty); |
1267 | |
1268 | |
1269 | |
1270 | |
1271 | |
1272 | void AddLValueToRValueStep(QualType Ty); |
1273 | |
1274 | |
1275 | void AddConversionSequenceStep(const ImplicitConversionSequence &ICS, |
1276 | QualType T, bool TopLevelOfInitList = false); |
1277 | |
1278 | |
1279 | void AddListInitializationStep(QualType T); |
1280 | |
1281 | |
1282 | |
1283 | |
1284 | |
1285 | |
1286 | void AddConstructorInitializationStep(DeclAccessPair FoundDecl, |
1287 | CXXConstructorDecl *Constructor, |
1288 | QualType T, |
1289 | bool HadMultipleCandidates, |
1290 | bool FromInitList, bool AsInitList); |
1291 | |
1292 | |
1293 | void AddZeroInitializationStep(QualType T); |
1294 | |
1295 | |
1296 | |
1297 | |
1298 | |
1299 | |
1300 | void AddCAssignmentStep(QualType T); |
1301 | |
1302 | |
1303 | void AddStringInitStep(QualType T); |
1304 | |
1305 | |
1306 | |
1307 | void AddObjCObjectConversionStep(QualType T); |
1308 | |
1309 | |
1310 | void AddArrayInitLoopStep(QualType T, QualType EltTy); |
1311 | |
1312 | |
1313 | void AddArrayInitStep(QualType T, bool IsGNUExtension); |
1314 | |
1315 | |
1316 | void AddParenthesizedArrayInitStep(QualType T); |
1317 | |
1318 | |
1319 | void AddPassByIndirectCopyRestoreStep(QualType T, bool shouldCopy); |
1320 | |
1321 | |
1322 | |
1323 | void AddProduceObjCObjectStep(QualType T); |
1324 | |
1325 | |
1326 | |
1327 | void AddStdInitializerListConstructionStep(QualType T); |
1328 | |
1329 | |
1330 | |
1331 | void AddOCLSamplerInitStep(QualType T); |
1332 | |
1333 | |
1334 | |
1335 | void AddOCLZeroOpaqueTypeStep(QualType T); |
1336 | |
1337 | |
1338 | |
1339 | void AddOCLIntelSubgroupAVCZeroInitStep(QualType T); |
1340 | |
1341 | |
1342 | |
1343 | void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic); |
1344 | |
1345 | |
1346 | void SetFailed(FailureKind Failure) { |
1347 | SequenceKind = FailedSequence; |
1348 | this->Failure = Failure; |
1349 | (0) . __assert_fail ("(Failure != FK_Incomplete || !FailedIncompleteType.isNull()) && \"Incomplete type failure requires a type!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/Initialization.h", 1350, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert((Failure != FK_Incomplete || !FailedIncompleteType.isNull()) && |
1350 | (0) . __assert_fail ("(Failure != FK_Incomplete || !FailedIncompleteType.isNull()) && \"Incomplete type failure requires a type!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/Initialization.h", 1350, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Incomplete type failure requires a type!"); |
1351 | } |
1352 | |
1353 | |
1354 | |
1355 | void SetOverloadFailure(FailureKind Failure, OverloadingResult Result); |
1356 | |
1357 | |
1358 | |
1359 | OverloadCandidateSet &getFailedCandidateSet() { |
1360 | return FailedCandidateSet; |
1361 | } |
1362 | |
1363 | |
1364 | |
1365 | OverloadingResult getFailedOverloadResult() const { |
1366 | return FailedOverloadResult; |
1367 | } |
1368 | |
1369 | |
1370 | |
1371 | void setIncompleteTypeFailure(QualType IncompleteType) { |
1372 | FailedIncompleteType = IncompleteType; |
1373 | SetFailed(FK_Incomplete); |
1374 | } |
1375 | |
1376 | |
1377 | FailureKind getFailureKind() const { |
1378 | (0) . __assert_fail ("Failed() && \"Not an initialization failure!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/Initialization.h", 1378, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Failed() && "Not an initialization failure!"); |
1379 | return Failure; |
1380 | } |
1381 | |
1382 | |
1383 | |
1384 | void dump(raw_ostream &OS) const; |
1385 | |
1386 | |
1387 | |
1388 | void dump() const; |
1389 | }; |
1390 | |
1391 | } |
1392 | |
1393 | #endif |
1394 | |