@@ -244,6 +244,10 @@ class DeclAttribute : public AttributeBase {
244244 SWIFT_INLINE_BITFIELD (LifetimeAttr, DeclAttribute, 1 ,
245245 isUnderscored : 1
246246 );
247+
248+ SWIFT_INLINE_BITFIELD (NonexhaustiveAttr, DeclAttribute, NumNonexhaustiveModeBits,
249+ mode : NumNonexhaustiveModeBits
250+ );
247251 } Bits;
248252 // clang-format on
249253
@@ -3334,6 +3338,35 @@ class ABIAttr : public DeclAttribute {
33343338 }
33353339};
33363340
3341+ // / Defines a @nonexhaustive attribute.
3342+ class NonexhaustiveAttr : public DeclAttribute {
3343+ public:
3344+ NonexhaustiveAttr (SourceLoc atLoc, SourceRange range, NonexhaustiveMode mode,
3345+ bool implicit = false )
3346+ : DeclAttribute(DeclAttrKind::Nonexhaustive, atLoc, range, implicit) {
3347+ Bits.NonexhaustiveAttr .mode = unsigned (mode);
3348+ }
3349+
3350+ NonexhaustiveAttr (NonexhaustiveMode mode)
3351+ : NonexhaustiveAttr(SourceLoc(), SourceRange(), mode) {}
3352+
3353+ NonexhaustiveMode getMode () const {
3354+ return NonexhaustiveMode (Bits.NonexhaustiveAttr .mode );
3355+ }
3356+
3357+ static bool classof (const DeclAttribute *DA) {
3358+ return DA->getKind () == DeclAttrKind::Nonexhaustive;
3359+ }
3360+
3361+ NonexhaustiveAttr *clone (ASTContext &ctx) const {
3362+ return new (ctx) NonexhaustiveAttr (AtLoc, Range, getMode (), isImplicit ());
3363+ }
3364+
3365+ bool isEquivalent (const NonexhaustiveAttr *other, Decl *attachedTo) const {
3366+ return getMode () == other->getMode ();
3367+ }
3368+ };
3369+
33373370// / Attributes that may be applied to declarations.
33383371class DeclAttributes {
33393372 // / Linked list of declaration attributes.
0 commit comments