diff --git a/src/ComputeSharp.Core.SourceGenerators/AutoConstructorGenerator.cs b/src/ComputeSharp.Core.SourceGenerators/AutoConstructorGenerator.cs index 81f28367..9b84bdcc 100644 --- a/src/ComputeSharp.Core.SourceGenerators/AutoConstructorGenerator.cs +++ b/src/ComputeSharp.Core.SourceGenerators/AutoConstructorGenerator.cs @@ -21,17 +21,16 @@ public sealed class AutoConstructorGenerator : IIncrementalGenerator public void Initialize(IncrementalGeneratorInitializationContext context) { // Get all declared struct symbols with the [AutoConstructor] attribute - IncrementalValuesProvider structDeclarations = + IncrementalValuesProvider structSymbols = context.SyntaxProvider - .CreateSyntaxProvider( + .ForAttributeWithMetadataName( + typeof(AutoConstructorAttribute).FullName, static (node, token) => node is StructDeclarationSyntax structDeclaration, - static (context, token) => (INamedTypeSymbol?)context.SemanticModel.GetDeclaredSymbol(context.Node, token)) - .Where(static symbol => symbol is not null && - symbol.GetAttributes().Any(static a => a.AttributeClass?.ToDisplayString() == typeof(AutoConstructorAttribute).FullName))!; + static (context, token) => (INamedTypeSymbol)context.TargetSymbol); // Get the type hierarchy and fields info IncrementalValuesProvider<(HierarchyInfo Left, ConstructorInfo Right)> constructorInfo = - structDeclarations + structSymbols .Select(static (item, token) => (Hierarchy: HierarchyInfo.From(item), Info: Ctor.GetData(item))) .Where(static item => !item.Info.Parameters.IsEmpty) .WithComparers(HierarchyInfo.Comparer.Default, ConstructorInfo.Comparer.Default); diff --git a/src/ComputeSharp.Core.SourceGenerators/ComputeSharp.Core.SourceGenerators.csproj b/src/ComputeSharp.Core.SourceGenerators/ComputeSharp.Core.SourceGenerators.csproj index 65673a59..ba8c712b 100644 --- a/src/ComputeSharp.Core.SourceGenerators/ComputeSharp.Core.SourceGenerators.csproj +++ b/src/ComputeSharp.Core.SourceGenerators/ComputeSharp.Core.SourceGenerators.csproj @@ -63,7 +63,7 @@ - + diff --git a/src/ComputeSharp.Core/ComputeSharp.Core.targets b/src/ComputeSharp.Core/ComputeSharp.Core.targets index c67a4d3f..d73b83ab 100644 --- a/src/ComputeSharp.Core/ComputeSharp.Core.targets +++ b/src/ComputeSharp.Core/ComputeSharp.Core.targets @@ -7,7 +7,7 @@ - + @(ComputeSharpCoreCurrentCompilerAssemblyIdentity->'%(Version)') - true + true - + diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj index 872389bd..75dddcbb 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj +++ b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj @@ -96,7 +96,7 @@ - + diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.cs index 6e1d2ad4..fb64cfa0 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.cs @@ -21,18 +21,16 @@ public sealed partial class D2DPixelShaderSourceGenerator : IIncrementalGenerato public void Initialize(IncrementalGeneratorInitializationContext context) { // Get all method declarations with the [D2DPixelShaderSource] attribute - IncrementalValuesProvider<(MethodDeclarationSyntax Syntax, IMethodSymbol Symbol)> methodSymbols = + IncrementalValuesProvider<(MethodDeclarationSyntax Syntax, IMethodSymbol Symbol)> methodDeclarationsAndSymbols = context.SyntaxProvider - .CreateSyntaxProvider( - static (node, _) => node is MethodDeclarationSyntax { Parent: ClassDeclarationSyntax, AttributeLists.Count: > 0 }, - static (context, _) => ( - (MethodDeclarationSyntax)context.Node, - Symbol: (IMethodSymbol)context.SemanticModel.GetDeclaredSymbol(context.Node)!)) - .Where(static pair => pair.Symbol.HasAttributeWithFullyQualifiedName("ComputeSharp.D2D1.D2DPixelShaderSourceAttribute")); + .ForAttributeWithMetadataName( + typeof(D2DPixelShaderSourceAttribute).FullName, + static (node, token) => node is MethodDeclarationSyntax, + static (context, token) => ((MethodDeclarationSyntax)context.TargetNode, (IMethodSymbol)context.TargetSymbol)); // Gather info for all annotated methods IncrementalValuesProvider<(HierarchyInfo Hierarchy, HlslShaderMethodSourceInfo Source, ImmutableArray Diagnostics)> shaderInfoWithErrors = - methodSymbols + methodDeclarationsAndSymbols .Select(static (item, _) => { ImmutableArray.Builder diagnostics = ImmutableArray.CreateBuilder(); diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs index a838ae1e..537ff7f4 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs @@ -13,7 +13,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; -#pragma warning disable CS0618, RS1024 +#pragma warning disable CS0618 namespace ComputeSharp.D2D1.SourceGenerators; diff --git a/src/ComputeSharp.D2D1/ComputeSharp.D2D1.targets b/src/ComputeSharp.D2D1/ComputeSharp.D2D1.targets index 5d93c4cf..3f5e6f84 100644 --- a/src/ComputeSharp.D2D1/ComputeSharp.D2D1.targets +++ b/src/ComputeSharp.D2D1/ComputeSharp.D2D1.targets @@ -7,7 +7,7 @@ - + @(ComputeSharpD2D1CurrentCompilerAssemblyIdentity->'%(Version)') - true + true - + @@ -38,7 +38,7 @@ - + diff --git a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj index 404c9496..9e9e3ce2 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj +++ b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj @@ -86,7 +86,7 @@ - + diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs index 364da166..8f7b86c7 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs @@ -8,7 +8,7 @@ using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; -#pragma warning disable CS0618, RS1024 +#pragma warning disable CS0618 namespace ComputeSharp.SourceGenerators; diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs index a2c6f83b..020a1e84 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs @@ -15,7 +15,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; -#pragma warning disable CS0618, RS1024 +#pragma warning disable CS0618 namespace ComputeSharp.SourceGenerators; diff --git a/src/ComputeSharp.SourceGenerators/ShaderMethodSourceGenerator.cs b/src/ComputeSharp.SourceGenerators/ShaderMethodSourceGenerator.cs index 5b2d8520..e7323701 100644 --- a/src/ComputeSharp.SourceGenerators/ShaderMethodSourceGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/ShaderMethodSourceGenerator.cs @@ -15,7 +15,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using static ComputeSharp.SourceGenerators.Helpers.SyntaxFactoryHelper; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; -#pragma warning disable CS0618, RS1024 +#pragma warning disable CS0618 namespace ComputeSharp.SourceGenerators; @@ -29,19 +29,16 @@ public sealed partial class ShaderMethodSourceGenerator : IIncrementalGenerator public void Initialize(IncrementalGeneratorInitializationContext context) { // Get all declared methods (including global function declarations) with the [ShaderMethod] attribute - IncrementalValuesProvider<(CSharpSyntaxNode Syntax, IMethodSymbol Symbol)> structDeclarations = + IncrementalValuesProvider<(MethodDeclarationSyntax Syntax, IMethodSymbol Symbol)> methodDeclarationsAndSymbols = context.SyntaxProvider - .CreateSyntaxProvider( + .ForAttributeWithMetadataName( + typeof(ShaderMethodAttribute).FullName, static (node, token) => node is MethodDeclarationSyntax { AttributeLists.Count: > 0 } or LocalFunctionStatementSyntax { Parent: GlobalStatementSyntax { Parent: CompilationUnitSyntax }, AttributeLists.Count: > 0 }, - static (context, token) => ( - Syntax: (CSharpSyntaxNode)context.Node, - Symbol: (IMethodSymbol?)context.SemanticModel.GetDeclaredSymbol(context.Node, token))) - .Where(static item => item.Symbol is not null && - item.Symbol.GetAttributes().Any(static a => a.AttributeClass?.ToDisplayString() == typeof(ShaderMethodAttribute).FullName))!; + static (context, token) => ((MethodDeclarationSyntax)context.TargetNode, (IMethodSymbol)context.TargetSymbol)); // Get the source info for each method IncrementalValuesProvider> methodSourceInfoWithErrors = - structDeclarations + methodDeclarationsAndSymbols .Combine(context.CompilationProvider) .Select(static (item, token) => { diff --git a/src/ComputeSharp/ComputeSharp.targets b/src/ComputeSharp/ComputeSharp.targets index e2fa4629..ad3ba1cc 100644 --- a/src/ComputeSharp/ComputeSharp.targets +++ b/src/ComputeSharp/ComputeSharp.targets @@ -7,7 +7,7 @@ - + @(ComputeSharpCurrentCompilerAssemblyIdentity->'%(Version)') - true + true - + @@ -38,7 +38,7 @@ - + diff --git a/tests/ComputeSharp.Tests.SourceGenerators/ComputeSharp.Tests.SourceGenerators.csproj b/tests/ComputeSharp.Tests.SourceGenerators/ComputeSharp.Tests.SourceGenerators.csproj index 48e5464a..65337e0a 100644 --- a/tests/ComputeSharp.Tests.SourceGenerators/ComputeSharp.Tests.SourceGenerators.csproj +++ b/tests/ComputeSharp.Tests.SourceGenerators/ComputeSharp.Tests.SourceGenerators.csproj @@ -9,7 +9,7 @@ - +