@@ -121,6 +121,18 @@ public Dictionary<
121121 /// modifying the original configuration object. It is used in the same way.
122122 /// </summary>
123123 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 = [ ] ;
124136 }
125137
126138 /// <summary>
@@ -259,6 +271,7 @@ public async Task InitializeAsync(IModContext ctx, CancellationToken ct = defaul
259271 job . SupportedApiProfiles = supportedApiProfiles ;
260272
261273 var profiles = supportedApiProfiles . SelectMany ( x => x . Value ) . Select ( x => x . Profile ) . ToHashSet ( ) ;
274+
262275 job . Vendors =
263276 [
264277 .. xml . Element ( "registry" )
@@ -281,6 +294,10 @@ .. xml.Element("registry")
281294 . Select ( name => name . Value . Split ( '_' ) [ 1 ] . ToUpper ( ) ) ?? Enumerable . Empty < string > ( )
282295 ] ;
283296
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+
284301 ReadGroups ( xml , job , job . Vendors ) ;
285302
286303 foreach ( var typeElement in xml . Elements ( "registry" ) . Elements ( "types" ) . Elements ( "type" ) )
@@ -303,7 +320,7 @@ public async Task ExecuteAsync(IModContext ctx, CancellationToken ct = default)
303320 var proj = ctx . SourceProject ;
304321
305322 // Rewrite phase 1
306- var rewriter1 = new EnumRewriterPhase1 ( jobData , logger ) ;
323+ var rewriter1 = new RewriterPhase1 ( jobData , logger ) ;
307324 foreach ( var docId in proj ? . DocumentIds ?? [ ] )
308325 {
309326 var doc = proj ! . GetDocument ( docId ) ?? throw new InvalidOperationException ( "Document missing" ) ;
@@ -326,7 +343,7 @@ public async Task ExecuteAsync(IModContext ctx, CancellationToken ct = default)
326343 }
327344
328345 // Rewrite phase 2
329- var rewriter2 = new EnumRewriterPhase2 ( jobData , rewriter1 ) ;
346+ var rewriter2 = new RewriterPhase2 ( jobData , rewriter1 ) ;
330347 foreach ( var docId in proj ? . DocumentIds ?? [ ] )
331348 {
332349 var doc = proj ! . GetDocument ( docId ) ?? throw new InvalidOperationException ( "Document missing" ) ;
@@ -1694,14 +1711,16 @@ jobKey is null
16941711 private static partial Regex EndingsNotToTrim ( ) ;
16951712
16961713 /// <summary>
1714+ /// This rewriter focuses on adding missing enums.
1715+ /// <para/>
16971716 /// Extracts enum constants that are defined as fields and moves them to their actual enum types.
16981717 /// Begins renaming FlagBits enums to Flags.
16991718 /// </summary>
17001719 /// <remarks>
17011720 /// This rewriter is split into two phases because NamespaceFromSyntaxNode breaks due to
17021721 /// the FieldDeclarationSyntax being modified.
17031722 /// </remarks>
1704- private class EnumRewriterPhase1 ( JobData job , ILogger logger ) : CSharpSyntaxRewriter
1723+ private class RewriterPhase1 ( JobData job , ILogger logger ) : CSharpSyntaxRewriter
17051724 {
17061725 /// <summary>
17071726 /// 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
19271946 /// Finishes renaming FlagBits enums to Flags.
19281947 /// Marks bitmask enums with the [Flags] attribute.
19291948 /// Replaces uint/ulong with the actual enum type for FlagBits/Flags types.
1949+ /// Removes deprecated aliases.
19301950 /// </summary>
1931- private class EnumRewriterPhase2 ( JobData job , EnumRewriterPhase1 phase1 ) : CSharpSyntaxRewriter ( true )
1951+ private class RewriterPhase2 ( JobData job , RewriterPhase1 phase1 ) : CSharpSyntaxRewriter ( true )
19321952 {
19331953 public override SyntaxNode ? VisitIdentifierName ( IdentifierNameSyntax node ) => IdentifierName ( node . Identifier . ToString ( ) . Replace ( "FlagBits" , "Flags" ) ) ;
19341954
19351955 public override SyntaxNode ? VisitEnumDeclaration ( EnumDeclarationSyntax node )
19361956 {
19371957 var identifier = node . Identifier . ToString ( ) ;
19381958
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+
19391967 if ( job . Groups . TryGetValue ( identifier , out var group ) && group . KnownBitmask )
19401968 {
19411969 // Add [Flags] attribute
@@ -1951,22 +1979,47 @@ private class EnumRewriterPhase2(JobData job, EnumRewriterPhase1 phase1) : CShar
19511979
19521980 public override SyntaxNode ? VisitFieldDeclaration ( FieldDeclarationSyntax node )
19531981 {
1954- if ( ! TryGetManagedEnumType ( node . AttributeLists , out var managedName ) )
1982+ if ( node . Declaration . Variables . Any ( v => job . DeprecatedAliases . Contains ( v . Identifier . ValueText ) ) )
19551983 {
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 ;
19572009 }
19582010
1959- return base . VisitFieldDeclaration ( node . WithDeclaration ( node . Declaration . WithType ( ParseTypeName ( managedName ) ) ) ) ;
2011+ return base . VisitPropertyDeclaration ( node ) ;
19602012 }
19612013
19622014 public override SyntaxNode ? VisitParameter ( ParameterSyntax node )
19632015 {
1964- if ( ! TryGetManagedEnumType ( node . AttributeLists , out var managedName ) )
2016+ if ( TryGetManagedEnumType ( node . AttributeLists , out var managedName ) )
19652017 {
1966- return base . VisitParameter ( node ) ;
2018+ node = node . WithType ( ParseTypeName ( managedName ) ) ;
19672019 }
19682020
1969- return base . VisitParameter ( node . WithType ( ParseTypeName ( managedName ) ) ) ;
2021+ return base . VisitParameter ( node ) ;
2022+
19702023 }
19712024
19722025 /// <summary>
0 commit comments