@@ -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
@@ -3500,6 +3509,36 @@ class ABIAttr : public DeclAttribute {
3500
3509
}
3501
3510
};
3502
3511
3512
+ // / Defines a @nonexhaustive attribute.
3513
+ class NonexhaustiveAttr : public DeclAttribute {
3514
+ public:
3515
+ NonexhaustiveAttr (SourceLoc atLoc, SourceRange range, NonexhaustiveMode mode,
3516
+ bool implicit = false )
3517
+ : DeclAttribute(DeclAttrKind::Nonexhaustive, atLoc, range, implicit) {
3518
+ Bits.NonexhaustiveAttr .mode = unsigned (mode);
3519
+ }
3520
+
3521
+ NonexhaustiveAttr (NonexhaustiveMode mode)
3522
+ : NonexhaustiveAttr(SourceLoc(), SourceRange(), mode) {}
3523
+
3524
+ NonexhaustiveMode getMode () const {
3525
+ return NonexhaustiveMode (Bits.NonexhaustiveAttr .mode );
3526
+ }
3527
+
3528
+ static bool classof (const DeclAttribute *DA) {
3529
+ return DA->getKind () == DeclAttrKind::Nonexhaustive;
3530
+ }
3531
+
3532
+ NonexhaustiveAttr *clone (ASTContext &ctx) const {
3533
+ return new (ctx) NonexhaustiveAttr (AtLoc, Range, getMode (), isImplicit ());
3534
+ }
3535
+
3536
+ bool isEquivalent (const NonexhaustiveAttr *other, Decl *attachedTo) const {
3537
+ return getMode () == other->getMode ();
3538
+ }
3539
+ };
3540
+
3541
+
3503
3542
// / The kind of unary operator, if any.
3504
3543
enum class UnaryOperatorKind : uint8_t { None, Prefix, Postfix };
3505
3544
0 commit comments