From 6fbcf21f74fc24b237e383ba36e8bb0c209fa32c Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 10 Jul 2021 23:17:26 +0200 Subject: [PATCH] Switched source generated files to only use LF line endings --- .../AutoConstructorGenerator.cs | 2 +- ...derGenerator.CreateBuildHlslStringMethod.cs | 18 +++++++++--------- .../IShaderGenerator.cs | 2 +- .../ShaderMethodSourceGenerator.cs | 6 +++--- .../SyntaxRewriters/ShaderSourceRewriter.cs | 2 +- .../AutoConstructorGeneratorTests.cs | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/ComputeSharp.SourceGenerators/AutoConstructorGenerator.cs b/src/ComputeSharp.SourceGenerators/AutoConstructorGenerator.cs index 395f1b22..8d31d254 100644 --- a/src/ComputeSharp.SourceGenerators/AutoConstructorGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/AutoConstructorGenerator.cs @@ -101,7 +101,7 @@ namespace ComputeSharp.SourceGenerators var source = CompilationUnit().AddMembers( NamespaceDeclaration(IdentifierName(namespaceName)).AddMembers(typeDeclarationSyntax)) - .NormalizeWhitespace() + .NormalizeWhitespace(eol: "\n") .ToFullString(); // Add the partial type diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslStringMethod.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslStringMethod.cs index c5cad728..05a12ef3 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslStringMethod.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslStringMethod.cs @@ -228,7 +228,7 @@ namespace ComputeSharp.SourceGenerators constantDefinitions, context); - string? assignment = staticFieldRewriter.Visit(variableDeclarator)?.NormalizeWhitespace().ToFullString(); + string? assignment = staticFieldRewriter.Visit(variableDeclarator)?.NormalizeWhitespace(eol: "\n").ToFullString(); yield return (mapping ?? fieldSymbol.Name, typeDeclaration, assignment); } @@ -350,8 +350,8 @@ namespace ComputeSharp.SourceGenerators // Emit the extracted local functions first foreach (var localFunction in shaderSourceRewriter.LocalFunctions) { - methods.Add(localFunction.Value.NormalizeWhitespace().ToFullString()); - declarations.Add(localFunction.Value.AsDefinition().NormalizeWhitespace().ToFullString()); + methods.Add(localFunction.Value.NormalizeWhitespace(eol: "\n").ToFullString()); + declarations.Add(localFunction.Value.AsDefinition().NormalizeWhitespace(eol: "\n").ToFullString()); } // If the method is the shader entry point, do additional processing @@ -363,20 +363,20 @@ namespace ComputeSharp.SourceGenerators false => new ExecuteMethodRewriter.Pixel(shaderSourceRewriter).Visit(processedMethod)! }; - entryPoint = processedMethod.NormalizeWhitespace().ToFullString(); + entryPoint = processedMethod.NormalizeWhitespace(eol: "\n").ToFullString(); } else { - methods.Add(processedMethod.NormalizeWhitespace().ToFullString()); - declarations.Add(processedMethod.AsDefinition().NormalizeWhitespace().ToFullString()); + methods.Add(processedMethod.NormalizeWhitespace(eol: "\n").ToFullString()); + declarations.Add(processedMethod.AsDefinition().NormalizeWhitespace(eol: "\n").ToFullString()); } } // Process static methods as well foreach (MethodDeclarationSyntax staticMethod in staticMethods.Values) { - methods.Add(staticMethod.NormalizeWhitespace().ToFullString()); - declarations.Add(staticMethod.AsDefinition().NormalizeWhitespace().ToFullString()); + methods.Add(staticMethod.NormalizeWhitespace(eol: "\n").ToFullString()); + declarations.Add(staticMethod.AsDefinition().NormalizeWhitespace(eol: "\n").ToFullString()); } return (entryPoint!, methods, declarations, isSamplerUsed); @@ -431,7 +431,7 @@ namespace ComputeSharp.SourceGenerators // Insert the trailing ; right after the closing bracket (after normalization) yield return structDeclaration - .NormalizeWhitespace() + .NormalizeWhitespace(eol: "\n") .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)) .ToFullString(); } diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs index 56e71574..23d30bbd 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs @@ -150,7 +150,7 @@ namespace ComputeSharp.SourceGenerators UsingDirective(IdentifierName("ComputeSharp.__Internals"))).AddMembers( NamespaceDeclaration(IdentifierName(namespaceName)).AddMembers(typeDeclarationSyntax) .WithNamespaceKeyword(Token(TriviaList(Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true))), SyntaxKind.NamespaceKeyword, TriviaList()))) - .NormalizeWhitespace() + .NormalizeWhitespace(eol: "\n") .ToFullString(); // Add the method source attribute diff --git a/src/ComputeSharp.SourceGenerators/ShaderMethodSourceGenerator.cs b/src/ComputeSharp.SourceGenerators/ShaderMethodSourceGenerator.cs index 573afef0..d73d1d92 100644 --- a/src/ComputeSharp.SourceGenerators/ShaderMethodSourceGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/ShaderMethodSourceGenerator.cs @@ -87,7 +87,7 @@ namespace ComputeSharp.SourceGenerators AttributeArgument(NestedArrayExpression(Array.Empty()))))) // TODO .WithOpenBracketToken(Token(TriviaList(Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true))), SyntaxKind.OpenBracketToken, TriviaList())) .WithTarget(AttributeTargetSpecifier(Token(SyntaxKind.AssemblyKeyword)))) - .NormalizeWhitespace() + .NormalizeWhitespace(eol: "\n") .ToFullString(); // Add the method source attribute @@ -120,7 +120,7 @@ namespace ComputeSharp.SourceGenerators .Visit(methodDeclaration)! .WithIdentifier(Identifier(ShaderMethodSourceAttribute.InvokeMethodIdentifier)) .WithoutTrivia() - .NormalizeWhitespace() + .NormalizeWhitespace(eol: "\n") .ToFullString(); List localFunctions = new(shaderSourceRewriter.LocalFunctions.Count); @@ -128,7 +128,7 @@ namespace ComputeSharp.SourceGenerators // Emit the extracted local functions foreach (var localFunction in shaderSourceRewriter.LocalFunctions) { - localFunctions.Add(localFunction.Value.NormalizeWhitespace().ToFullString()); + localFunctions.Add(localFunction.Value.NormalizeWhitespace(eol: "\n").ToFullString()); } return (targetMethod, localFunctions); diff --git a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs index 43fe3386..cd0c7d32 100644 --- a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs +++ b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs @@ -406,7 +406,7 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters ShaderSourceRewriter shaderSourceRewriter = new(SemanticModel, DiscoveredTypes, this.staticMethods, ConstantDefinitions, Context); MethodDeclarationSyntax methodNode = (MethodDeclarationSyntax)method.DeclaringSyntaxReferences[0].GetSyntax(), - processedMethod = shaderSourceRewriter.Visit(methodNode)!.NormalizeWhitespace().WithoutTrivia(); + processedMethod = shaderSourceRewriter.Visit(methodNode)!.NormalizeWhitespace(eol: "\n").WithoutTrivia(); this.staticMethods.Add(method, processedMethod.WithIdentifier(Identifier(methodIdentifier))); } diff --git a/tests/ComputeSharp.Tests.SourceGenerators/AutoConstructorGeneratorTests.cs b/tests/ComputeSharp.Tests.SourceGenerators/AutoConstructorGeneratorTests.cs index 1e46d676..92a4e006 100644 --- a/tests/ComputeSharp.Tests.SourceGenerators/AutoConstructorGeneratorTests.cs +++ b/tests/ComputeSharp.Tests.SourceGenerators/AutoConstructorGeneratorTests.cs @@ -75,7 +75,7 @@ namespace ComputeSharp.Tests.SourceGenerators /// The input source to process. /// The target index to check in the resulting output. /// The expected body to compare with the generated code. - private void VerifyGeneratedMethodLines(string source, int index, string expectedBody) + private static void VerifyGeneratedMethodLines(string source, int index, string expectedBody) where TGenerator : class, ISourceGenerator, new() { SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(source); @@ -97,8 +97,8 @@ namespace ComputeSharp.Tests.SourceGenerators string outputBody = outputCompilation.SyntaxTrees.Skip(index + 1).First().ToString(); string[] - outputLines = outputBody.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries), - expectedLines = expectedBody.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + outputLines = outputBody.Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries), + expectedLines = expectedBody.Replace("\r", "").Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); Assert.AreEqual(expectedLines.Length, outputLines.Length);