From 93be0343884da2344162a3e513f63d6ebd911513 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 20 Sep 2023 16:49:45 +0200 Subject: [PATCH] Rename and update source generator files --- ...nerator.CreateInputTypesProperty.Syntax.cs} | 18 +++++++++--------- ...haderGenerator.CreateInputTypesProperty.cs} | 4 ++-- .../ID2D1ShaderGenerator.cs | 14 +++++++------- .../Interfaces/__Internals/ID2D1Shader.cs | 1 - 4 files changed, 18 insertions(+), 19 deletions(-) rename src/ComputeSharp.D2D1.SourceGenerators/{ID2D1ShaderGenerator.CreateGetInputTypeMethod.Syntax.cs => ID2D1ShaderGenerator.CreateInputTypesProperty.Syntax.cs} (96%) rename src/ComputeSharp.D2D1.SourceGenerators/{ID2D1ShaderGenerator.CreateGetInputTypeMethod.cs => ID2D1ShaderGenerator.CreateInputTypesProperty.cs} (98%) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetInputTypeMethod.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInputTypesProperty.Syntax.cs similarity index 96% rename from src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetInputTypeMethod.Syntax.cs rename to src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInputTypesProperty.Syntax.cs index 0e194dc45..66612f3d6 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetInputTypeMethod.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInputTypesProperty.Syntax.cs @@ -14,24 +14,26 @@ namespace ComputeSharp.D2D1.SourceGenerators; partial class ID2D1ShaderGenerator { /// - partial class GetInputType + partial class InputTypes { /// - /// Creates a instance for the GetInputTypeMethod method. + /// Creates a instance for the InputTypes property. /// /// The input types for the shader. - /// The resulting instance for the GetInputTypeMethod method. - public static (MemberDeclarationSyntax Member, MemberDeclarationSyntax Type) GetSyntax(ImmutableArray inputTypes) + /// An additional instance needed by the generated code. + /// The resulting instance for the InputTypes property. + public static PropertyDeclarationSyntax GetSyntax(ImmutableArray inputTypes, out TypeDeclarationSyntax additionalType) { + additionalType = GetMemoryManagerDeclaration(inputTypes); + // This code produces a method declaration as follows: // // readonly uint global::ComputeSharp.D2D1.__Internals.ID2D1Shader.InputTypes => InputTypesMemoryManager.Memory; - MemberDeclarationSyntax member = + return PropertyDeclaration( GenericName(Identifier("global::System.ReadOnlyMemory")) .AddTypeArgumentListArguments(IdentifierName("global::ComputeSharp.D2D1.Interop.D2D1PixelShaderInputType")), - Identifier("InputTypes")) // TODO: use nameof() + Identifier(nameof(InputTypes))) .WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.D2D1.__Internals.{nameof(ID2D1Shader)}"))) .AddModifiers(Token(SyntaxKind.ReadOnlyKeyword)) .WithExpressionBody(ArrowExpressionClause( @@ -40,8 +42,6 @@ public static (MemberDeclarationSyntax Member, MemberDeclarationSyntax Type) Get IdentifierName("InputTypesMemoryManager"), IdentifierName("Memory")))) .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)); - - return (member, GetMemoryManagerDeclaration(inputTypes)); } /// diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetInputTypeMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInputTypesProperty.cs similarity index 98% rename from src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetInputTypeMethod.cs rename to src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInputTypesProperty.cs index 4d79a732e..7b2d19a7e 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetInputTypeMethod.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInputTypesProperty.cs @@ -12,9 +12,9 @@ namespace ComputeSharp.D2D1.SourceGenerators; partial class ID2D1ShaderGenerator { /// - /// A helper with all logic to generate the GetInputType method. + /// A helper with all logic to generate the InputTypes properties. /// - private static partial class GetInputType + private static partial class InputTypes { /// /// Extracts the input info for the current shader. diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs index 743bd7572..4e8e3b356 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs @@ -60,8 +60,8 @@ public void Initialize(IncrementalGeneratorInitializationContext context) token.ThrowIfCancellationRequested(); - // Get the input info for GetInputInfo() - GetInputType.GetInfo( + // Get the input info for InputTypes + InputTypes.GetInfo( diagnostics, typeSymbol, out int inputCount, @@ -150,18 +150,18 @@ public void Initialize(IncrementalGeneratorInitializationContext context) context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(GetInputCount)}.g.cs", compilationUnit.GetText(Encoding.UTF8)); }); - // Get the GetInputType() info (hierarchy and input types) + // Get the InputTypes info (hierarchy and input types) IncrementalValuesProvider<(HierarchyInfo Hierarchy, InputTypesInfo InputTypes)> inputTypesInfo = shaderInfoWithErrors .Select(static (item, _) => (item.Hierarchy, item.InputTypes)); - // Generate the GetInputType() methods + // Generate the InputTypes properties context.RegisterSourceOutput(inputTypesInfo, static (context, item) => { - (MemberDeclarationSyntax property, MemberDeclarationSyntax type) = GetInputType.GetSyntax(item.InputTypes.InputTypes); - CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Hierarchy, property, canUseSkipLocalsInit: false, additionalMemberDeclarations: type); + MemberDeclarationSyntax inputTypesProperty = InputTypes.GetSyntax(item.InputTypes.InputTypes, out TypeDeclarationSyntax additionalType); + CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Hierarchy, inputTypesProperty, canUseSkipLocalsInit: false, additionalMemberDeclarations: additionalType); - context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(GetInputType)}.g.cs", compilationUnit.GetText(Encoding.UTF8)); + context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(InputTypes)}.g.cs", compilationUnit.GetText(Encoding.UTF8)); }); // Get the LoadResourceTextureDescriptions() info (hierarchy and resource texture descriptions) diff --git a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs b/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs index 2427cd70d..4b15af797 100644 --- a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs +++ b/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs @@ -40,7 +40,6 @@ public interface ID2D1Shader /// /// Gets the input types for the current shader. /// - /// The input types for the current shader. [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("This method is not intended to be used directly by user code")] ReadOnlyMemory InputTypes { get; }