Skip to content

Commit 1192c96

Browse files
committed
[AST] Introduce DeclAttrKind::Last_DeclAttr et al.
Instead of using dummy `_counting_KAK_*` global symbols, use `LAST_DECL_ATTR` metaprogramming technique to determine the number of enum values. This align with other "kind" enum e.g. `DeclKind`.
1 parent 92e70ef commit 1192c96

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

include/swift/AST/AttrKind.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,29 +132,25 @@ enum : unsigned { NumExternKindBits =
132132

133133
enum class DeclAttrKind : unsigned {
134134
#define DECL_ATTR(_, CLASS, ...) CLASS,
135+
#define LAST_DECL_ATTR(CLASS) Last_DeclAttr = CLASS,
135136
#include "swift/AST/DeclAttr.def"
136137
};
137138

138139
enum : unsigned {
139-
#define DECL_ATTR(_, C, ...) _counting_DAK_##C,
140-
#include "swift/AST/DeclAttr.def"
141-
NumDeclAttrKinds,
142-
143-
NumDeclAttrKindBits = countBitsUsed(NumDeclAttrKinds - 1)
140+
NumDeclAttrKinds = static_cast<unsigned>(DeclAttrKind::Last_DeclAttr) + 1,
141+
NumDeclAttrKindBits = countBitsUsed(NumDeclAttrKinds - 1),
144142
};
145143

146144
// Define enumerators for each type attribute, e.g. TypeAttrKind::Weak.
147145
enum class TypeAttrKind {
148146
#define TYPE_ATTR(_, CLASS) CLASS,
147+
#define LAST_TYPE_ATTR(CLASS) Last_TypeAttr = CLASS,
149148
#include "swift/AST/TypeAttr.def"
150149
};
151150

152151
enum : unsigned {
153-
#define TYPE_ATTR(_, C) _counting_TAK_##C,
154-
#include "swift/AST/TypeAttr.def"
155-
NumTypeAttrKinds,
156-
157-
NumTypeAttrKindBits = countBitsUsed(NumTypeAttrKinds - 1)
152+
NumTypeAttrKinds = static_cast<unsigned>(TypeAttrKind::Last_TypeAttr) + 1,
153+
NumTypeAttrKindBits = countBitsUsed(NumTypeAttrKinds - 1),
158154
};
159155

160156
} // end namespace swift

include/swift/AST/DeclAttr.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
DECL_ATTR_ALIAS(SPELLING, CLASS)
4343
#endif
4444

45+
#ifndef LAST_DECL_ATTR
46+
#define LAST_DECL_ATTR(CLASS)
47+
#endif
4548

4649
// Declaration Attributes and Modifers
4750
DECL_ATTR(_silgen_name, SILGenName,
@@ -482,10 +485,12 @@ SIMPLE_DECL_ATTR(_noExistentials, NoExistentials,
482485
SIMPLE_DECL_ATTR(_noObjCBridging, NoObjCBridging,
483486
OnAbstractFunction | OnSubscript | UserInaccessible | ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
484487
155)
488+
LAST_DECL_ATTR(NoObjCBridging)
485489

486490
#undef DECL_ATTR_ALIAS
487491
#undef CONTEXTUAL_DECL_ATTR_ALIAS
488492
#undef SIMPLE_DECL_ATTR
489493
#undef CONTEXTUAL_SIMPLE_DECL_ATTR
490494
#undef DECL_ATTR
491495
#undef CONTEXTUAL_DECL_ATTR
496+
#undef LAST_DECL_ATTR

include/swift/AST/TypeAttr.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
#define SIMPLE_TYPE_ATTR(SPELLING, CLASS) TYPE_ATTR(SPELLING, CLASS)
4747
#endif
4848

49+
#ifndef LAST_TYPE_ATTR
50+
#define LAST_TYPE_ATTR(CLASS)
51+
#endif
52+
4953
// Type attributes
5054
SIMPLE_TYPE_ATTR(autoclosure, Autoclosure)
5155
TYPE_ATTR(convention, Convention)
@@ -105,7 +109,10 @@ SIMPLE_SIL_TYPE_ATTR(isolated, Isolated)
105109
SIMPLE_SIL_TYPE_ATTR(thin, Thin)
106110
SIMPLE_SIL_TYPE_ATTR(thick, Thick)
107111

112+
LAST_TYPE_ATTR(Thick)
113+
108114
#undef SIMPLE_SIL_TYPE_ATTR
109115
#undef SIMPLE_TYPE_ATTR
110116
#undef SIL_TYPE_ATTR
111117
#undef TYPE_ATTR
118+
#undef LAST_TYPE_ATTR

0 commit comments

Comments
 (0)