@@ -136,6 +136,11 @@ enum : unsigned {
136
136
InheritActorContextModifier::Last_InheritActorContextKind))
137
137
};
138
138
139
+ enum : unsigned {
140
+ NumNonexhaustiveModeBits = countBitsUsed (
141
+ static_cast <unsigned >(NonexhaustiveMode::Last_NonexhaustiveMode))
142
+ };
143
+
139
144
enum : unsigned { NumDeclAttrKindBits = countBitsUsed (NumDeclAttrKinds - 1 ) };
140
145
141
146
enum : unsigned { NumTypeAttrKindBits = countBitsUsed (NumTypeAttrKinds - 1 ) };
@@ -277,6 +282,10 @@ class DeclAttribute : public AttributeBase {
277
282
SWIFT_INLINE_BITFIELD (LifetimeAttr, DeclAttribute, 1 ,
278
283
isUnderscored : 1
279
284
);
285
+
286
+ SWIFT_INLINE_BITFIELD (NonexhaustiveAttr, DeclAttribute, NumNonexhaustiveModeBits,
287
+ mode : NumNonexhaustiveModeBits
288
+ );
280
289
} Bits;
281
290
// clang-format on
282
291
@@ -3506,6 +3515,36 @@ class ABIAttr : public DeclAttribute {
3506
3515
}
3507
3516
};
3508
3517
3518
+ // / Defines a @nonexhaustive attribute.
3519
+ class NonexhaustiveAttr : public DeclAttribute {
3520
+ public:
3521
+ NonexhaustiveAttr (SourceLoc atLoc, SourceRange range, NonexhaustiveMode mode,
3522
+ bool implicit = false )
3523
+ : DeclAttribute(DeclAttrKind::Nonexhaustive, atLoc, range, implicit) {
3524
+ Bits.NonexhaustiveAttr .mode = unsigned (mode);
3525
+ }
3526
+
3527
+ NonexhaustiveAttr (NonexhaustiveMode mode)
3528
+ : NonexhaustiveAttr(SourceLoc(), SourceRange(), mode) {}
3529
+
3530
+ NonexhaustiveMode getMode () const {
3531
+ return NonexhaustiveMode (Bits.NonexhaustiveAttr .mode );
3532
+ }
3533
+
3534
+ static bool classof (const DeclAttribute *DA) {
3535
+ return DA->getKind () == DeclAttrKind::Nonexhaustive;
3536
+ }
3537
+
3538
+ NonexhaustiveAttr *clone (ASTContext &ctx) const {
3539
+ return new (ctx) NonexhaustiveAttr (AtLoc, Range, getMode (), isImplicit ());
3540
+ }
3541
+
3542
+ bool isEquivalent (const NonexhaustiveAttr *other, Decl *attachedTo) const {
3543
+ return getMode () == other->getMode ();
3544
+ }
3545
+ };
3546
+
3547
+
3509
3548
// / The kind of unary operator, if any.
3510
3549
enum class UnaryOperatorKind : uint8_t { None, Prefix, Postfix };
3511
3550
0 commit comments