@@ -136,6 +136,11 @@ enum : unsigned {
136136 InheritActorContextModifier::Last_InheritActorContextKind))
137137};
138138
139+ enum : unsigned {
140+ NumNonexhaustiveModeBits = countBitsUsed (
141+ static_cast <unsigned >(NonexhaustiveMode::Last_NonexhaustiveMode))
142+ };
143+
139144enum : unsigned { NumDeclAttrKindBits = countBitsUsed (NumDeclAttrKinds - 1 ) };
140145
141146enum : unsigned { NumTypeAttrKindBits = countBitsUsed (NumTypeAttrKinds - 1 ) };
@@ -277,6 +282,10 @@ class DeclAttribute : public AttributeBase {
277282 SWIFT_INLINE_BITFIELD (LifetimeAttr, DeclAttribute, 1 ,
278283 isUnderscored : 1
279284 );
285+
286+ SWIFT_INLINE_BITFIELD (NonexhaustiveAttr, DeclAttribute, NumNonexhaustiveModeBits,
287+ mode : NumNonexhaustiveModeBits
288+ );
280289 } Bits;
281290 // clang-format on
282291
@@ -3500,6 +3509,36 @@ class ABIAttr : public DeclAttribute {
35003509 }
35013510};
35023511
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+
35033542// / The kind of unary operator, if any.
35043543enum class UnaryOperatorKind : uint8_t { None, Prefix, Postfix };
35053544
0 commit comments