@@ -121,6 +121,18 @@ public Dictionary<
121
121
/// modifying the original configuration object. It is used in the same way.
122
122
/// </summary>
123
123
public Dictionary < string , string > TypeMap { get ; init ; } = [ ] ;
124
+
125
+ /// <summary>
126
+ /// This tracks a set of enum members marked with the deprecated="aliased" attribute.
127
+ /// These are removed from the generated bindings.
128
+ /// </summary>
129
+ /// <remarks>
130
+ /// At the time this was added, only Vulkan seems to use the deprecated="aliased" attribute.
131
+ /// These names tend to cause name collisions after names are prettified so removing these
132
+ /// prevents these issues. This can cause API breakages, but because these are aliases,
133
+ /// these are easily solvable breakages.
134
+ /// </remarks>
135
+ public HashSet < string > DeprecatedAliases = [ ] ;
124
136
}
125
137
126
138
/// <summary>
@@ -259,6 +271,7 @@ public async Task InitializeAsync(IModContext ctx, CancellationToken ct = defaul
259
271
job . SupportedApiProfiles = supportedApiProfiles ;
260
272
261
273
var profiles = supportedApiProfiles . SelectMany ( x => x . Value ) . Select ( x => x . Profile ) . ToHashSet ( ) ;
274
+
262
275
job . Vendors =
263
276
[
264
277
.. xml . Element ( "registry" )
@@ -281,6 +294,10 @@ .. xml.Element("registry")
281
294
. Select ( name => name . Value . Split ( '_' ) [ 1 ] . ToUpper ( ) ) ?? Enumerable . Empty < string > ( )
282
295
] ;
283
296
297
+ job . DeprecatedAliases = xml . Descendants ( )
298
+ . Where ( x => x . Attribute ( "deprecated" ) ? . Value == "aliased" && x . Attribute ( "name" ) != null )
299
+ . Select ( x => x . Attribute ( "name" ) ! . Value ) . ToHashSet ( ) ;
300
+
284
301
ReadGroups ( xml , job , job . Vendors ) ;
285
302
286
303
foreach ( var typeElement in xml . Elements ( "registry" ) . Elements ( "types" ) . Elements ( "type" ) )
@@ -303,7 +320,7 @@ public async Task ExecuteAsync(IModContext ctx, CancellationToken ct = default)
303
320
var proj = ctx . SourceProject ;
304
321
305
322
// Rewrite phase 1
306
- var rewriter1 = new EnumRewriterPhase1 ( jobData , logger ) ;
323
+ var rewriter1 = new RewriterPhase1 ( jobData , logger ) ;
307
324
foreach ( var docId in proj ? . DocumentIds ?? [ ] )
308
325
{
309
326
var doc = proj ! . GetDocument ( docId ) ?? throw new InvalidOperationException ( "Document missing" ) ;
@@ -326,7 +343,7 @@ public async Task ExecuteAsync(IModContext ctx, CancellationToken ct = default)
326
343
}
327
344
328
345
// Rewrite phase 2
329
- var rewriter2 = new EnumRewriterPhase2 ( jobData , rewriter1 ) ;
346
+ var rewriter2 = new RewriterPhase2 ( jobData , rewriter1 ) ;
330
347
foreach ( var docId in proj ? . DocumentIds ?? [ ] )
331
348
{
332
349
var doc = proj ! . GetDocument ( docId ) ?? throw new InvalidOperationException ( "Document missing" ) ;
@@ -1694,14 +1711,16 @@ jobKey is null
1694
1711
private static partial Regex EndingsNotToTrim ( ) ;
1695
1712
1696
1713
/// <summary>
1714
+ /// This rewriter focuses on adding missing enums.
1715
+ /// <para/>
1697
1716
/// Extracts enum constants that are defined as fields and moves them to their actual enum types.
1698
1717
/// Begins renaming FlagBits enums to Flags.
1699
1718
/// </summary>
1700
1719
/// <remarks>
1701
1720
/// This rewriter is split into two phases because NamespaceFromSyntaxNode breaks due to
1702
1721
/// the FieldDeclarationSyntax being modified.
1703
1722
/// </remarks>
1704
- private class EnumRewriterPhase1 ( JobData job , ILogger logger ) : CSharpSyntaxRewriter
1723
+ private class RewriterPhase1 ( JobData job , ILogger logger ) : CSharpSyntaxRewriter
1705
1724
{
1706
1725
/// <summary>
1707
1726
/// Tracks enum groups that already exist in the project, prior to the generation of missing enums.
@@ -1927,15 +1946,24 @@ private class EnumRewriterPhase1(JobData job, ILogger logger) : CSharpSyntaxRewr
1927
1946
/// Finishes renaming FlagBits enums to Flags.
1928
1947
/// Marks bitmask enums with the [Flags] attribute.
1929
1948
/// Replaces uint/ulong with the actual enum type for FlagBits/Flags types.
1949
+ /// Removes deprecated aliases.
1930
1950
/// </summary>
1931
- private class EnumRewriterPhase2 ( JobData job , EnumRewriterPhase1 phase1 ) : CSharpSyntaxRewriter ( true )
1951
+ private class RewriterPhase2 ( JobData job , RewriterPhase1 phase1 ) : CSharpSyntaxRewriter ( true )
1932
1952
{
1933
1953
public override SyntaxNode ? VisitIdentifierName ( IdentifierNameSyntax node ) => IdentifierName ( node . Identifier . ToString ( ) . Replace ( "FlagBits" , "Flags" ) ) ;
1934
1954
1935
1955
public override SyntaxNode ? VisitEnumDeclaration ( EnumDeclarationSyntax node )
1936
1956
{
1937
1957
var identifier = node . Identifier . ToString ( ) ;
1938
1958
1959
+ if ( node . Members . Any ( m => job . DeprecatedAliases . Contains ( m . Identifier . ValueText ) ) )
1960
+ {
1961
+ // Remove deprecated aliases
1962
+ node = node . WithMembers ( [
1963
+ ..node . Members . Where ( m => ! job . DeprecatedAliases . Contains ( m . Identifier . ValueText ) )
1964
+ ] ) ;
1965
+ }
1966
+
1939
1967
if ( job . Groups . TryGetValue ( identifier , out var group ) && group . KnownBitmask )
1940
1968
{
1941
1969
// Add [Flags] attribute
@@ -1951,22 +1979,47 @@ private class EnumRewriterPhase2(JobData job, EnumRewriterPhase1 phase1) : CShar
1951
1979
1952
1980
public override SyntaxNode ? VisitFieldDeclaration ( FieldDeclarationSyntax node )
1953
1981
{
1954
- if ( ! TryGetManagedEnumType ( node . AttributeLists , out var managedName ) )
1982
+ if ( node . Declaration . Variables . Any ( v => job . DeprecatedAliases . Contains ( v . Identifier . ValueText ) ) )
1955
1983
{
1956
- return base . VisitFieldDeclaration ( node ) ;
1984
+ // Remove deprecated aliases
1985
+ node = node . WithDeclaration ( node . Declaration . WithVariables ( [
1986
+ ..node . Declaration . Variables . Where ( v => ! job . DeprecatedAliases . Contains ( v . Identifier . ValueText ) )
1987
+ ] ) ) ;
1988
+
1989
+ if ( node . Declaration . Variables . Count == 0 )
1990
+ {
1991
+ return null ;
1992
+ }
1993
+ }
1994
+
1995
+ if ( TryGetManagedEnumType ( node . AttributeLists , out var managedName ) )
1996
+ {
1997
+ node = node . WithDeclaration ( node . Declaration . WithType ( ParseTypeName ( managedName ) ) ) ;
1998
+ }
1999
+
2000
+ return base . VisitFieldDeclaration ( node ) ;
2001
+
2002
+ }
2003
+
2004
+ public override SyntaxNode ? VisitPropertyDeclaration ( PropertyDeclarationSyntax node )
2005
+ {
2006
+ if ( job . DeprecatedAliases . Contains ( node . Identifier . ValueText ) )
2007
+ {
2008
+ return null ;
1957
2009
}
1958
2010
1959
- return base . VisitFieldDeclaration ( node . WithDeclaration ( node . Declaration . WithType ( ParseTypeName ( managedName ) ) ) ) ;
2011
+ return base . VisitPropertyDeclaration ( node ) ;
1960
2012
}
1961
2013
1962
2014
public override SyntaxNode ? VisitParameter ( ParameterSyntax node )
1963
2015
{
1964
- if ( ! TryGetManagedEnumType ( node . AttributeLists , out var managedName ) )
2016
+ if ( TryGetManagedEnumType ( node . AttributeLists , out var managedName ) )
1965
2017
{
1966
- return base . VisitParameter ( node ) ;
2018
+ node = node . WithType ( ParseTypeName ( managedName ) ) ;
1967
2019
}
1968
2020
1969
- return base . VisitParameter ( node . WithType ( ParseTypeName ( managedName ) ) ) ;
2021
+ return base . VisitParameter ( node ) ;
2022
+
1970
2023
}
1971
2024
1972
2025
/// <summary>
0 commit comments