diff --git a/src/ComputeSharp.SourceGenerators/IComputeShaderDataLoaderGenerator.cs b/src/ComputeSharp.SourceGenerators/IComputeShaderDataLoaderGenerator.cs index 66bcaf40..bc1b3312 100644 --- a/src/ComputeSharp.SourceGenerators/IComputeShaderDataLoaderGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/IComputeShaderDataLoaderGenerator.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics.Contracts; using System.Linq; @@ -31,6 +32,19 @@ namespace ComputeSharp.SourceGenerators from structDeclaration in tree.GetRoot().DescendantNodes().OfType() select structDeclaration).ToImmutableArray(); + // Type attributes + AttributeListSyntax[] attributes = new[] + { + AttributeList(SingletonSeparatedList( + Attribute(IdentifierName("EditorBrowsable")).AddArgumentListArguments( + AttributeArgument(ParseExpression("EditorBrowsableState.Never"))))), + AttributeList(SingletonSeparatedList( + Attribute(IdentifierName("Obsolete")).AddArgumentListArguments( + AttributeArgument(LiteralExpression( + SyntaxKind.StringLiteralExpression, + Literal("This type is not intended to be used directly by user code")))))) + }; + foreach (StructDeclarationSyntax structDeclaration in structDeclarations) { SemanticModel semanticModel = context.Compilation.GetSemanticModel(structDeclaration.SyntaxTree); @@ -69,7 +83,7 @@ namespace ComputeSharp.SourceGenerators ClassDeclaration("DispatchDataLoader").AddModifiers( Token(SyntaxKind.InternalKeyword), Token(SyntaxKind.StaticKeyword), - Token(SyntaxKind.PartialKeyword)).AddMembers( + Token(SyntaxKind.PartialKeyword)).AddAttributeLists(attributes).AddMembers( MethodDeclaration( PredefinedType(Token(SyntaxKind.IntKeyword)), Identifier("LoadDispatchData")).AddAttributeLists( @@ -87,10 +101,14 @@ namespace ComputeSharp.SourceGenerators Parameter(Identifier("shader")).WithModifiers(TokenList(Token(SyntaxKind.InKeyword))).WithType(shaderType), Parameter(Identifier("r0")).AddModifiers(Token(SyntaxKind.RefKeyword)).WithType(PredefinedType(Token(SyntaxKind.ULongKeyword))), Parameter(Identifier("r1")).AddModifiers(Token(SyntaxKind.RefKeyword)).WithType(PredefinedType(Token(SyntaxKind.ByteKeyword)))) - .WithBody(block)))) + .WithBody(block))) + .WithNamespaceKeyword(Token(TriviaList(Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true))), SyntaxKind.NamespaceKeyword, TriviaList()))) .NormalizeWhitespace() .ToFullString(); + // Clear the attribute list to avoid duplicates + attributes = Array.Empty(); + // Add the method source attribute context.AddSource(structDeclarationSymbol.GetGeneratedFileName(), SourceText.From(source, Encoding.UTF8)); } diff --git a/src/ComputeSharp.SourceGenerators/IComputeShaderHashCodeGenerator.cs b/src/ComputeSharp.SourceGenerators/IComputeShaderHashCodeGenerator.cs index 654e3f7f..ae194820 100644 --- a/src/ComputeSharp.SourceGenerators/IComputeShaderHashCodeGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/IComputeShaderHashCodeGenerator.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics.Contracts; using System.Linq; @@ -29,6 +30,19 @@ namespace ComputeSharp.SourceGenerators from structDeclaration in tree.GetRoot().DescendantNodes().OfType() select structDeclaration).ToImmutableArray(); + // Type attributes + AttributeListSyntax[] attributes = new[] + { + AttributeList(SingletonSeparatedList( + Attribute(IdentifierName("EditorBrowsable")).AddArgumentListArguments( + AttributeArgument(ParseExpression("EditorBrowsableState.Never"))))), + AttributeList(SingletonSeparatedList( + Attribute(IdentifierName("Obsolete")).AddArgumentListArguments( + AttributeArgument(LiteralExpression( + SyntaxKind.StringLiteralExpression, + Literal("This type is not intended to be used directly by user code")))))) + }; + foreach (StructDeclarationSyntax structDeclaration in structDeclarations) { SemanticModel semanticModel = context.Compilation.GetSemanticModel(structDeclaration.SyntaxTree); @@ -68,7 +82,7 @@ namespace ComputeSharp.SourceGenerators ClassDeclaration("HashCodeProvider").AddModifiers( Token(SyntaxKind.InternalKeyword), Token(SyntaxKind.StaticKeyword), - Token(SyntaxKind.PartialKeyword)).AddMembers( + Token(SyntaxKind.PartialKeyword)).AddAttributeLists(attributes).AddMembers( MethodDeclaration( PredefinedType(Token(SyntaxKind.IntKeyword)), Identifier("CombineHash")).AddAttributeLists( @@ -88,6 +102,9 @@ namespace ComputeSharp.SourceGenerators .NormalizeWhitespace() .ToFullString(); + // Clear the attribute list to avoid duplicates + attributes = Array.Empty(); + // Add the method source attribute context.AddSource(structDeclarationSymbol.GetGeneratedFileName(), SourceText.From(source, Encoding.UTF8)); }