24
24
#include " llvm/ADT/SmallVector.h"
25
25
#include " llvm/ADT/TinyPtrVector.h"
26
26
#include " llvm/Support/Allocator.h"
27
+ #include " llvm/Support/Registry.h"
27
28
#include " llvm/Support/VersionTuple.h"
28
29
#include < cassert>
29
30
#include < cstddef>
@@ -37,6 +38,72 @@ class Decl;
37
38
class Expr ;
38
39
class IdentifierInfo ;
39
40
class LangOptions ;
41
+ class ParsedAttr ;
42
+ class Sema ;
43
+
44
+ struct ParsedAttrInfo {
45
+ // / Corresponds to the Kind enum.
46
+ unsigned AttrKind : 16 ;
47
+ // / The number of required arguments of this attribute.
48
+ unsigned NumArgs : 4 ;
49
+ // / The number of optional arguments of this attributes.
50
+ unsigned OptArgs : 4 ;
51
+ // / True if the parsing does not match the semantic content.
52
+ unsigned HasCustomParsing : 1 ;
53
+ // / True if this attribute is only available for certain targets.
54
+ unsigned IsTargetSpecific : 1 ;
55
+ // / True if this attribute applies to types.
56
+ unsigned IsType : 1 ;
57
+ // / True if this attribute applies to statements.
58
+ unsigned IsStmt : 1 ;
59
+ // / True if this attribute has any spellings that are known to gcc.
60
+ unsigned IsKnownToGCC : 1 ;
61
+ // / True if this attribute is supported by #pragma clang attribute.
62
+ unsigned IsSupportedByPragmaAttribute : 1 ;
63
+ // / The syntaxes supported by this attribute and how they're spelled.
64
+ struct Spelling {
65
+ AttributeCommonInfo::Syntax Syntax;
66
+ std::string NormalizedFullName;
67
+ };
68
+ std::vector<Spelling> Spellings;
69
+
70
+ ParsedAttrInfo (AttributeCommonInfo::Kind AttrKind =
71
+ AttributeCommonInfo::UnknownAttribute)
72
+ : AttrKind(AttrKind), NumArgs(0 ), OptArgs(0 ), HasCustomParsing(0 ),
73
+ IsTargetSpecific (0 ), IsType(0 ), IsStmt(0 ), IsKnownToGCC(0 ),
74
+ IsSupportedByPragmaAttribute(0 ) {}
75
+
76
+ virtual ~ParsedAttrInfo () = default ;
77
+
78
+ // / Check if this attribute appertains to D, and issue a diagnostic if not.
79
+ virtual bool diagAppertainsToDecl (Sema &S, const ParsedAttr &Attr,
80
+ const Decl *D) const {
81
+ return true ;
82
+ }
83
+ // / Check if this attribute is allowed by the language we are compiling, and
84
+ // / issue a diagnostic if not.
85
+ virtual bool diagLangOpts (Sema &S, const ParsedAttr &Attr) const {
86
+ return true ;
87
+ }
88
+ // / Check if this attribute is allowed when compiling for the given target.
89
+ virtual bool existsInTarget (const TargetInfo &Target) const {
90
+ return true ;
91
+ }
92
+ // / Convert the spelling index of Attr to a semantic spelling enum value.
93
+ virtual unsigned
94
+ spellingIndexToSemanticSpelling (const ParsedAttr &Attr) const {
95
+ return UINT_MAX;
96
+ }
97
+ // / Populate Rules with the match rules of this attribute.
98
+ virtual void getPragmaAttributeMatchRules (
99
+ llvm::SmallVectorImpl<std::pair<attr::SubjectMatchRule, bool >> &Rules,
100
+ const LangOptions &LangOpts) const {
101
+ }
102
+
103
+ static const ParsedAttrInfo &get (const AttributeCommonInfo &A);
104
+ };
105
+
106
+ typedef llvm::Registry<ParsedAttrInfo> ParsedAttrInfoRegistry;
40
107
41
108
// / Represents information about a change in availability for
42
109
// / an entity, which is part of the encoding of the 'availability'
@@ -181,6 +248,8 @@ class ParsedAttr final
181
248
182
249
const Expr *MessageExpr;
183
250
251
+ const ParsedAttrInfo &Info;
252
+
184
253
ArgsUnion *getArgsBuffer () { return getTrailingObjects<ArgsUnion>(); }
185
254
ArgsUnion const *getArgsBuffer () const {
186
255
return getTrailingObjects<ArgsUnion>();
@@ -207,7 +276,8 @@ class ParsedAttr final
207
276
EllipsisLoc (ellipsisLoc), NumArgs(numArgs), Invalid(false ),
208
277
UsedAsTypeAttr(false ), IsAvailability(false ),
209
278
IsTypeTagForDatatype(false ), IsProperty(false ), HasParsedType(false ),
210
- HasProcessingCache(false ), IsPragmaClangAttribute(false ) {
279
+ HasProcessingCache(false ), IsPragmaClangAttribute(false ),
280
+ Info(ParsedAttrInfo::get(*this )) {
211
281
if (numArgs)
212
282
memcpy (getArgsBuffer (), args, numArgs * sizeof (ArgsUnion));
213
283
}
@@ -225,7 +295,8 @@ class ParsedAttr final
225
295
NumArgs(1 ), Invalid(false ), UsedAsTypeAttr(false ), IsAvailability(true ),
226
296
IsTypeTagForDatatype(false ), IsProperty(false ), HasParsedType(false ),
227
297
HasProcessingCache(false ), IsPragmaClangAttribute(false ),
228
- UnavailableLoc(unavailable), MessageExpr(messageExpr) {
298
+ UnavailableLoc(unavailable), MessageExpr(messageExpr),
299
+ Info(ParsedAttrInfo::get(*this )) {
229
300
ArgsUnion PVal (Parm);
230
301
memcpy (getArgsBuffer (), &PVal, sizeof (ArgsUnion));
231
302
new (getAvailabilityData ()) detail::AvailabilityData (
@@ -242,7 +313,7 @@ class ParsedAttr final
242
313
NumArgs(3 ), Invalid(false ), UsedAsTypeAttr(false ),
243
314
IsAvailability(false ), IsTypeTagForDatatype(false ), IsProperty(false ),
244
315
HasParsedType(false ), HasProcessingCache(false ),
245
- IsPragmaClangAttribute(false ) {
316
+ IsPragmaClangAttribute(false ), Info(ParsedAttrInfo::get(* this )) {
246
317
ArgsUnion *Args = getArgsBuffer ();
247
318
Args[0 ] = Parm1;
248
319
Args[1 ] = Parm2;
@@ -259,7 +330,7 @@ class ParsedAttr final
259
330
NumArgs(1 ), Invalid(false ), UsedAsTypeAttr(false ),
260
331
IsAvailability(false ), IsTypeTagForDatatype(true ), IsProperty(false ),
261
332
HasParsedType(false ), HasProcessingCache(false ),
262
- IsPragmaClangAttribute(false ) {
333
+ IsPragmaClangAttribute(false ), Info(ParsedAttrInfo::get(* this )) {
263
334
ArgsUnion PVal (ArgKind);
264
335
memcpy (getArgsBuffer (), &PVal, sizeof (ArgsUnion));
265
336
detail::TypeTagForDatatypeData &ExtraData = getTypeTagForDatatypeDataSlot ();
@@ -277,7 +348,7 @@ class ParsedAttr final
277
348
NumArgs(0 ), Invalid(false ), UsedAsTypeAttr(false ),
278
349
IsAvailability(false ), IsTypeTagForDatatype(false ), IsProperty(false ),
279
350
HasParsedType(true ), HasProcessingCache(false ),
280
- IsPragmaClangAttribute(false ) {
351
+ IsPragmaClangAttribute(false ), Info(ParsedAttrInfo::get(* this )) {
281
352
new (&getTypeBuffer ()) ParsedType (typeArg);
282
353
}
283
354
@@ -291,7 +362,7 @@ class ParsedAttr final
291
362
NumArgs(0 ), Invalid(false ), UsedAsTypeAttr(false ),
292
363
IsAvailability(false ), IsTypeTagForDatatype(false ), IsProperty(true ),
293
364
HasParsedType(false ), HasProcessingCache(false ),
294
- IsPragmaClangAttribute(false ) {
365
+ IsPragmaClangAttribute(false ), Info(ParsedAttrInfo::get(* this )) {
295
366
new (&getPropertyDataBuffer ()) detail::PropertyData (getterId, setterId);
296
367
}
297
368
@@ -534,7 +605,10 @@ class ParsedAttr final
534
605
}
535
606
}
536
607
537
- AttributeCommonInfo::Kind getKind () const { return getParsedKind (); }
608
+ AttributeCommonInfo::Kind getKind () const {
609
+ return AttributeCommonInfo::Kind (Info.AttrKind );
610
+ }
611
+ const ParsedAttrInfo &getInfo () const { return Info; }
538
612
};
539
613
540
614
class AttributePool ;
0 commit comments