@@ -45,37 +45,60 @@ class alignas(8) TypeRepr {
45
45
TypeRepr (const TypeRepr&) = delete ;
46
46
void operator =(const TypeRepr&) = delete ;
47
47
48
- // / \brief The subclass of TypeRepr that this is.
49
- unsigned Kind : 6 ;
48
+ class TypeReprBitfields {
49
+ friend class TypeRepr ;
50
+ // / The subclass of TypeRepr that this is.
51
+ unsigned Kind : 6 ;
52
+
53
+ // / Whether this type representation is known to contain an invalid
54
+ // / type.
55
+ unsigned Invalid : 1 ;
56
+
57
+ // / Whether this type representation had a warning emitted related to it.
58
+ // / This is a hack related to how we resolve type exprs multiple times in
59
+ // / generic contexts.
60
+ unsigned Warned : 1 ;
61
+ };
62
+ enum { NumTypeReprBits = 8 };
63
+ class TupleTypeReprBitfields {
64
+ friend class TupleTypeRepr ;
65
+ unsigned : NumTypeReprBits;
66
+ // HasNames, HasLabels?
67
+ unsigned NameStatus : 2 ;
68
+ // Whether this tuple has '...' and its position.
69
+ unsigned HasEllipsis : 1 ;
70
+ };
50
71
51
- // / Whether this type representation is known to contain an invalid
52
- // / type.
53
- unsigned Invalid : 1 ;
72
+ protected:
73
+ union {
74
+ TypeReprBitfields TypeReprBits;
75
+ TupleTypeReprBitfields TupleTypeReprBits;
76
+ };
54
77
55
- // / Whether this type representation had a warning emitted related to it.
56
- // / This is a hack related to how we resolve type exprs multiple times in
57
- // / generic contexts.
58
- unsigned Warned : 1 ;
78
+ TypeRepr (TypeReprKind K) {
79
+ TypeReprBits.Kind = static_cast <unsigned >(K);
80
+ TypeReprBits.Invalid = false ;
81
+ TypeReprBits.Warned = false ;
82
+ }
59
83
84
+ private:
60
85
SourceLoc getLocImpl () const { return getStartLoc (); }
61
86
62
- protected:
63
- TypeRepr (TypeReprKind K)
64
- : Kind (static_cast <unsigned >(K)), Invalid (false ), Warned (false ) {}
65
-
66
87
public:
67
- TypeReprKind getKind () const { return static_cast <TypeReprKind>(Kind); }
88
+ TypeReprKind getKind () const {
89
+ return static_cast <TypeReprKind>(TypeReprBits.Kind );
90
+ }
68
91
69
92
// / Is this type representation known to be invalid?
70
- bool isInvalid () const { return Invalid; }
93
+ bool isInvalid () const { return TypeReprBits. Invalid ; }
71
94
72
95
// / Note that this type representation describes an invalid type.
73
- void setInvalid () { Invalid = true ; }
96
+ void setInvalid () { TypeReprBits. Invalid = true ; }
74
97
75
98
// / If a warning is produced about this type repr, keep track of that so we
76
99
// / don't emit another one upon further reanalysis.
77
- bool isWarnedAbout () const { return Warned; }
78
- void setWarned () { Warned = true ; }
100
+ bool isWarnedAbout () const { return TypeReprBits. Warned ; }
101
+ void setWarned () { TypeReprBits. Warned = true ; }
79
102
80
103
// / Get the representative location for pointing at this type.
81
104
SourceLoc getLoc () const ;
@@ -556,21 +579,21 @@ class TupleTypeRepr final : public TypeRepr,
556
579
NotNamed = 0 ,
557
580
HasNames = 1 ,
558
581
HasLabels = 2
559
- } NameStatus : 2 ;
560
- bool HasEllipsis : 1 ;
582
+ };
561
583
562
584
size_t numTrailingObjects (OverloadToken<TypeRepr *>) const {
563
585
return NumElements;
564
586
}
565
587
size_t numTrailingObjects (OverloadToken<Identifier>) const {
566
- return NameStatus >= HasNames ? NumElements : 0 ;
588
+ return TupleTypeReprBits. NameStatus >= HasNames ? NumElements : 0 ;
567
589
}
568
590
size_t numTrailingObjects (OverloadToken<SourceLoc>) const {
569
- switch (NameStatus) {
591
+ switch (TupleTypeReprBits. NameStatus ) {
570
592
case NotNamed: return 0 ;
571
593
case HasNames: return NumElements;
572
594
case HasLabels: return NumElements + NumElements;
573
595
}
596
+ llvm_unreachable (" all cases should have been handled" );
574
597
}
575
598
576
599
TupleTypeRepr (ArrayRef<TypeRepr *> Elements, SourceRange Parens,
@@ -581,8 +604,12 @@ class TupleTypeRepr final : public TypeRepr,
581
604
public:
582
605
583
606
unsigned getNumElements () const { return NumElements; }
584
- bool hasElementNames () const { return NameStatus >= HasNames; }
585
- bool hasUnderscoreLocs () const { return NameStatus == HasLabels; }
607
+ bool hasElementNames () const {
608
+ return TupleTypeReprBits.NameStatus >= HasNames;
609
+ }
610
+ bool hasUnderscoreLocs () const {
611
+ return TupleTypeReprBits.NameStatus == HasLabels;
612
+ }
586
613
587
614
ArrayRef<TypeRepr *> getElements () const {
588
615
return { getTrailingObjects<TypeRepr *>(), NumElements };
@@ -622,19 +649,19 @@ class TupleTypeRepr final : public TypeRepr,
622
649
}
623
650
624
651
SourceRange getParens () const { return Parens; }
652
+
653
+ bool hasEllipsis () const { return TupleTypeReprBits.HasEllipsis ; }
625
654
SourceLoc getEllipsisLoc () const {
626
- return HasEllipsis ?
655
+ return hasEllipsis () ?
627
656
getTrailingObjects<SourceLocAndIdx>()[0 ].first : SourceLoc ();
628
657
}
629
658
unsigned getEllipsisIndex () const {
630
- return HasEllipsis ?
659
+ return hasEllipsis () ?
631
660
getTrailingObjects<SourceLocAndIdx>()[0 ].second : NumElements;
632
661
}
633
- bool hasEllipsis () const { return HasEllipsis; }
634
-
635
662
void removeEllipsis () {
636
- if (HasEllipsis ) {
637
- HasEllipsis = false ;
663
+ if (hasEllipsis () ) {
664
+ TupleTypeReprBits. HasEllipsis = false ;
638
665
getTrailingObjects<SourceLocAndIdx>()[0 ] = {SourceLoc (), NumElements};
639
666
}
640
667
}
0 commit comments