@@ -110,6 +110,36 @@ class BracketOptions {
110110 }
111111};
112112
113+ // / A union of DeclAttrKind and TypeAttrKind.
114+ class AnyAttrKind {
115+ unsigned kind : 31 ;
116+ unsigned isType : 1 ;
117+
118+ public:
119+ AnyAttrKind (TypeAttrKind K) : kind(static_cast <unsigned >(K)), isType(1 ) {
120+ static_assert (TAK_Count < UINT_MAX, " TypeAttrKind is > 31 bits" );
121+ }
122+ AnyAttrKind (DeclAttrKind K) : kind(static_cast <unsigned >(K)), isType(0 ) {
123+ static_assert (DAK_Count < UINT_MAX, " DeclAttrKind is > 31 bits" );
124+ }
125+ AnyAttrKind () : kind(TAK_Count), isType(1 ) {}
126+ AnyAttrKind (const AnyAttrKind &) = default ;
127+
128+ // / Returns the TypeAttrKind, or TAK_Count if this is not a type attribute.
129+ TypeAttrKind type () const {
130+ return isType ? static_cast <TypeAttrKind>(kind) : TAK_Count;
131+ }
132+ // / Returns the DeclAttrKind, or DAK_Count if this is not a decl attribute.
133+ DeclAttrKind decl () const {
134+ return isType ? DAK_Count : static_cast <DeclAttrKind>(kind);
135+ }
136+
137+ bool operator ==(AnyAttrKind K) const {
138+ return kind == K.kind && isType == K.isType ;
139+ }
140+ bool operator !=(AnyAttrKind K) const { return !(*this == K); }
141+ };
142+
113143// / Options for printing AST nodes.
114144// /
115145// / A default-constructed PrintOptions is suitable for printing to users;
@@ -225,12 +255,12 @@ struct PrintOptions {
225255 bool PrintUserInaccessibleAttrs = true ;
226256
227257 // / List of attribute kinds that should not be printed.
228- std::vector<DeclAttrKind > ExcludeAttrList =
258+ std::vector<AnyAttrKind > ExcludeAttrList =
229259 { DAK_Transparent, DAK_Effects, DAK_FixedLayout };
230260
231261 // / List of attribute kinds that should be printed exclusively.
232262 // / Empty means allow all.
233- std::vector<DeclAttrKind > ExclusiveAttrList;
263+ std::vector<AnyAttrKind > ExclusiveAttrList;
234264
235265 // / Whether to print function @convention attribute on function types.
236266 bool PrintFunctionRepresentationAttrs = true ;
@@ -326,6 +356,16 @@ struct PrintOptions {
326356
327357 BracketOptions BracketOptions;
328358
359+ bool excludeAttrKind (AnyAttrKind K) const {
360+ if (std::any_of (ExcludeAttrList.begin (), ExcludeAttrList.end (),
361+ [K](AnyAttrKind other) { return other == K; }))
362+ return true ;
363+ if (!ExclusiveAttrList.empty ())
364+ return std::none_of (ExclusiveAttrList.begin (), ExclusiveAttrList.end (),
365+ [K](AnyAttrKind other) { return other == K; });
366+ return false ;
367+ }
368+
329369 // / Retrieve the set of options for verbose printing to users.
330370 static PrintOptions printVerbose () {
331371 PrintOptions result;
0 commit comments