From 7a3dd640b16d4d2490f8bdc0c7616a0faec1d419 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 25 Nov 2024 20:24:15 -0800 Subject: [PATCH] Always emit diagnostics directly on arguments --- .../Analyzers/InvalidD2DInputArgumentAnalyzer.cs | 6 +++--- ...st_D2DPixelShaderDescriptorGenerator_Analyzers.cs | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/InvalidD2DInputArgumentAnalyzer.cs b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/InvalidD2DInputArgumentAnalyzer.cs index 254f6a83..078c9360 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/InvalidD2DInputArgumentAnalyzer.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/InvalidD2DInputArgumentAnalyzer.cs @@ -59,7 +59,7 @@ public sealed class InvalidD2DInputArgumentAnalyzer : DiagnosticAnalyzer // Second cheap inital filter: we only care about invocations with a constant 'int' argument in first position. // While we're validating this, let's also get the 'index' parameter, since we need to validate it anyway. - if (operation.Arguments is not [{ Value.ConstantValue: { HasValue: true, Value: int index } }, ..]) + if (operation.Arguments is not [{ Value.ConstantValue: { HasValue: true, Value: int index } } firstArgument, ..]) { return; } @@ -95,7 +95,7 @@ public sealed class InvalidD2DInputArgumentAnalyzer : DiagnosticAnalyzer { context.ReportDiagnostic(Diagnostic.Create( IndexOutOfRangeForD2DIntrinsic, - operation.Syntax.GetLocation(), + firstArgument.Syntax.GetLocation(), targetMethodSymbol.Name, index, typeSymbol, @@ -106,7 +106,7 @@ public sealed class InvalidD2DInputArgumentAnalyzer : DiagnosticAnalyzer // Second validation: the input type must match context.ReportDiagnostic(Diagnostic.Create( InvalidInputTypeForD2DIntrinsic, - operation.Syntax.GetLocation(), + firstArgument.Syntax.GetLocation(), targetMethodSymbol.Name, index)); } diff --git a/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderDescriptorGenerator_Analyzers.cs b/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderDescriptorGenerator_Analyzers.cs index 778129b9..988c05b4 100644 --- a/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderDescriptorGenerator_Analyzers.cs +++ b/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderDescriptorGenerator_Analyzers.cs @@ -1307,7 +1307,7 @@ public class Test_D2DPixelShaderDescriptorGenerator_Analyzers { public float4 Execute() { - return {|CMPSD2D0083:D2D.GetInput({{index}})|}; + return D2D.GetInput({|CMPSD2D0083:{{index}}|}); } } """; @@ -1331,7 +1331,7 @@ public class Test_D2DPixelShaderDescriptorGenerator_Analyzers { public float4 Execute() { - return {|CMPSD2D0083:D2D.GetInput({{index}})|}; + return D2D.GetInput({|CMPSD2D0083:{{index}}|}); } } """; @@ -1382,10 +1382,10 @@ public class Test_D2DPixelShaderDescriptorGenerator_Analyzers { public float4 Execute() { - {|CMPSD2D0084:D2D.GetInputCoordinate(0)|}; - {|CMPSD2D0084:D2D.SampleInput(0, 0)|}; - {|CMPSD2D0084:D2D.SampleInputAtOffset(0, 0)|}; - {|CMPSD2D0084:D2D.SampleInputAtPosition(0, 0)|}; + D2D.GetInputCoordinate({|CMPSD2D0084:0|}); + D2D.SampleInput({|CMPSD2D0084:0|}, 0); + D2D.SampleInputAtOffset({|CMPSD2D0084:0|}, 0); + D2D.SampleInputAtPosition({|CMPSD2D0084:0|}, 0); return 0; }