@@ -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
@@ -3506,6 +3515,36 @@ class ABIAttr : public DeclAttribute {
35063515 }
35073516};
35083517
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+
35093548// / The kind of unary operator, if any.
35103549enum class UnaryOperatorKind : uint8_t { None, Prefix, Postfix };
35113550
0 commit comments