From dedfbd87287d877f51588b8522993bd03cb9dff7 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 5 Dec 2023 22:40:29 +0100 Subject: [PATCH] Use primary constructor in ShaderSourceRewriter --- .../SyntaxRewriters/ShaderSourceRewriter.cs | 76 ++++++++----------- 1 file changed, 31 insertions(+), 45 deletions(-) diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs index 5d51696c..f771423e 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs @@ -19,42 +19,65 @@ namespace ComputeSharp.SourceGeneration.SyntaxRewriters; /// /// A custom type that processes C# methods to convert to HLSL compliant code. /// -internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter +/// The type symbol for the shader type. +/// The instance for the target syntax tree. +/// The set of discovered custom types. +/// The set of discovered and processed static methods. +/// The collection of discovered instance methods for custom struct types. +/// The collection of discovered constructors for custom struct types. +/// The collection of discovered constant definitions. +/// The collection of discovered static field definitions. +/// The collection of produced instances. +/// The value for the current operation. +/// Whether or not the current instance is processing a shader entry point. +internal sealed partial class ShaderSourceRewriter( + INamedTypeSymbol shaderType, + SemanticModelProvider semanticModel, + ICollection discoveredTypes, + IDictionary staticMethods, + IDictionary instanceMethods, + IDictionary constructors, + IDictionary constantDefinitions, + IDictionary staticFieldDefinitions, + ImmutableArrayBuilder diagnostics, + CancellationToken token, + bool isEntryPoint = false) + : HlslSourceRewriter(semanticModel, discoveredTypes, constantDefinitions, staticFieldDefinitions, diagnostics, token) { /// /// The type symbol for the shader type. /// - private readonly INamedTypeSymbol shaderType; + private readonly INamedTypeSymbol shaderType = shaderType; /// /// The collection of discovered static methods. /// - private readonly IDictionary staticMethods; + private readonly IDictionary staticMethods = staticMethods; /// /// The collection of discovered instance methods for custom struct types. /// - private readonly IDictionary instanceMethods; + private readonly IDictionary instanceMethods = instanceMethods; /// /// The collection of discovered constructors for custom struct types. /// - private readonly IDictionary constructors; + private readonly IDictionary constructors = constructors; /// /// The collection of processed local functions in the current tree. /// - private readonly Dictionary localFunctions; + private readonly Dictionary localFunctions = []; /// /// The list of implicit variables to declare at the start of the body. /// - private readonly List implicitVariables; + private readonly List implicitVariables = []; /// /// Whether or not the current instance is processing a shader entry point. /// - private readonly bool isEntryPoint; + private readonly bool isEntryPoint = isEntryPoint; /// /// The identifier of the current , @@ -67,43 +90,6 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter /// private int localFunctionDepth; - /// - /// Creates a new instance with the specified parameters. - /// - /// The type symbol for the shader type. - /// The instance for the target syntax tree. - /// The set of discovered custom types. - /// The set of discovered and processed static methods. - /// The collection of discovered instance methods for custom struct types. - /// The collection of discovered constructors for custom struct types. - /// The collection of discovered constant definitions. - /// The collection of discovered static field definitions. - /// The collection of produced instances. - /// The value for the current operation. - /// Whether or not the current instance is processing a shader entry point. - public ShaderSourceRewriter( - INamedTypeSymbol shaderType, - SemanticModelProvider semanticModel, - ICollection discoveredTypes, - IDictionary staticMethods, - IDictionary instanceMethods, - IDictionary constructors, - IDictionary constantDefinitions, - IDictionary staticFieldDefinitions, - ImmutableArrayBuilder diagnostics, - CancellationToken token, - bool isEntryPoint = false) - : base(semanticModel, discoveredTypes, constantDefinitions, staticFieldDefinitions, diagnostics, token) - { - this.shaderType = shaderType; - this.staticMethods = staticMethods; - this.instanceMethods = instanceMethods; - this.constructors = constructors; - this.localFunctions = []; - this.implicitVariables = []; - this.isEntryPoint = isEntryPoint; - } - /// /// Gets the collection of processed local functions in the current tree. ///