@@ -182,6 +182,7 @@ enum class DeclKind : uint8_t;
182
182
// / Represents one declaration attribute.
183
183
class DeclAttribute : public AttributeBase {
184
184
friend class DeclAttributes ;
185
+
185
186
protected:
186
187
union {
187
188
uint64_t OpaqueBits;
@@ -261,84 +262,65 @@ class DeclAttribute : public AttributeBase {
261
262
Bits.DeclAttribute .Invalid = false ;
262
263
}
263
264
265
+ private:
266
+ // NOTE: We cannot use DeclKind due to layering. Even if we could, there is no
267
+ // guarantee that the first DeclKind starts at zero. This is only used to
268
+ // build "OnXYZ" flags.
269
+ enum class DeclKindIndex : unsigned {
270
+ #define DECL (Name, _ ) Name,
271
+ #define LAST_DECL (Name ) Last_Decl = Name
272
+ #include " swift/AST/DeclNodes.def"
273
+ };
274
+
264
275
public:
265
- enum DeclAttrOptions {
276
+ enum DeclAttrOptions : uint64_t {
277
+ // There is one entry for each DeclKind, and some higher level buckets
278
+ // below. These are used in Attr.def to control which kinds of declarations
279
+ // an attribute can be attached to.
280
+ #define DECL (Name, _ ) On##Name = 1ull << unsigned (DeclKindIndex::Name),
281
+ #include " swift/AST/DeclNodes.def"
282
+
283
+ // More coarse-grained aggregations for use in Attr.def.
284
+ OnOperator = 0
285
+ #define DECL (Name, _ )
286
+ #define OPERATOR_DECL (Name, _ ) |On##Name
287
+ #include " swift/AST/DeclNodes.def"
288
+ ,
289
+
290
+ OnAnyDecl = 0
291
+ #define DECL (Name, _ ) |On##Name
292
+ #include " swift/AST/DeclNodes.def"
293
+ ,
294
+
266
295
// / True if multiple instances of this attribute are allowed on a single
267
296
// / declaration.
268
- AllowMultipleAttributes = 1 << 0 ,
297
+ AllowMultipleAttributes = 1ull << ( unsigned (DeclKindIndex::Last_Decl) + 1 ) ,
269
298
270
299
// / True if this is a decl modifier - i.e., that it should not be spelled
271
300
// / with an @.
272
- DeclModifier = 1 << 1 ,
301
+ DeclModifier = 1ull << ( unsigned (DeclKindIndex::Last_Decl) + 2 ) ,
273
302
274
303
// / True if this is a long attribute that should be printed on its own line.
275
304
// /
276
305
// / Currently has no effect on DeclModifier attributes.
277
- LongAttribute = 1 << 2 ,
306
+ LongAttribute = 1ull << ( unsigned (DeclKindIndex::Last_Decl) + 3 ) ,
278
307
279
308
// / True if this shouldn't be serialized.
280
- NotSerialized = 1 << 3 ,
309
+ NotSerialized = 1ull << ( unsigned (DeclKindIndex::Last_Decl) + 4 ) ,
281
310
282
311
// / True if this attribute is only valid when parsing a .sil file.
283
- SILOnly = 1 << 4 ,
312
+ SILOnly = 1ull << ( unsigned (DeclKindIndex::Last_Decl) + 5 ) ,
284
313
285
314
// / The attribute should be reported by parser as unknown.
286
- RejectByParser = 1 << 5 ,
315
+ RejectByParser = 1ull << ( unsigned (DeclKindIndex::Last_Decl) + 6 ) ,
287
316
288
317
// / Whether client code cannot use the attribute.
289
- UserInaccessible = 1 << 6 ,
290
-
291
- // There is one entry for each DeclKind here, and some higher level buckets
292
- // down below. These are used in Attr.def to control which kinds of
293
- // declarations an attribute can be attached to.
294
- OnPrecedenceGroup = 1 << 7 ,
295
- OnImport = 1 << 8 ,
296
- OnExtension = 1 << 9 ,
297
- OnPatternBinding = 1 << 10 ,
298
- OnEnumCase = 1 << 11 ,
299
- OnTopLevelCode = 1 << 12 ,
300
- OnIfConfig = 1 << 13 ,
301
- OnInfixOperator = 1 << 14 , // "infix operator"
302
- OnPrefixOperator = 1 << 15 , // "prefix operator"
303
- OnPostfixOperator = 1 << 16 , // "postfix operator"
304
-
305
- OnEnum = 1 << 17 ,
306
- OnStruct = 1 << 18 ,
307
- OnClass = 1 << 19 ,
308
- OnProtocol = 1 << 20 ,
309
- OnTypeAlias = 1 << 21 ,
310
- OnVar = 1 << 22 ,
311
- OnSubscript = 1 << 23 ,
312
-
313
- OnConstructor = 1 << 24 ,
314
- OnDestructor = 1 << 25 ,
315
- OnFunc = 1 << 26 ,
316
- OnAccessor = OnFunc,
317
- OnEnumElement = 1 << 27 ,
318
-
319
- OnGenericTypeParam = 1 << 28 ,
320
- OnAssociatedType = 1 << 29 ,
321
- OnParam = 1 << 30 ,
322
- OnModule = 1 << 31 ,
323
-
324
- // Cannot have any attributes.
325
- OnMissingMember = 0 ,
326
- OnPoundDiagnostic = 0 ,
327
-
328
- // More coarse-grained aggregations for use in Attr.def.
329
- OnOperator = OnInfixOperator|OnPrefixOperator|OnPostfixOperator,
330
-
331
- OnAnyDecl = OnImport|OnExtension|OnPatternBinding|OnEnumCase|
332
- OnTopLevelCode|OnIfConfig|OnInfixOperator|OnPrefixOperator|
333
- OnPostfixOperator|OnEnum|OnStruct|OnClass|OnProtocol|
334
- OnTypeAlias|OnVar|OnSubscript|OnConstructor|OnDestructor|
335
- OnFunc|OnEnumElement|OnGenericTypeParam|OnAssociatedType|
336
- OnParam|OnPrecedenceGroup
318
+ UserInaccessible = 1ull << (unsigned (DeclKindIndex::Last_Decl) + 7 ),
337
319
};
338
320
339
- static unsigned getOptions (DeclAttrKind DK);
321
+ static uint64_t getOptions (DeclAttrKind DK);
340
322
341
- unsigned getOptions () const {
323
+ uint64_t getOptions () const {
342
324
return getOptions (getKind ());
343
325
}
344
326
0 commit comments