using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
namespace ComputeSharp.SourceGenerators;
///
public sealed partial class ShaderMethodSourceGenerator
{
///
/// An that selects candidate nodes to process.
///
private sealed class SyntaxReceiver : ISyntaxContextReceiver
{
///
/// The list of info gathered during exploration.
///
private readonly List- gatheredInfo = new();
///
/// Gets the collection of gathered info to process.
///
public IReadOnlyCollection
- GatheredInfo => this.gatheredInfo;
///
public void OnVisitSyntaxNode(GeneratorSyntaxContext context)
{
if (context.Node is MethodDeclarationSyntax { AttributeLists: { Count: > 0 } } methodDeclaration &&
context.SemanticModel.GetDeclaredSymbol(methodDeclaration) is IMethodSymbol methodSymbol &&
context.SemanticModel.Compilation.GetTypeByMetadataName(typeof(ShaderMethodAttribute).FullName) is INamedTypeSymbol attributeSymbol &&
methodSymbol.GetAttributes().Any(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, attributeSymbol)))
{
this.gatheredInfo.Add(new Item(methodDeclaration, methodSymbol));
}
}
///
/// A model for a group of item representing a discovered method to process.
///
/// The instance for the target method declaration.
/// The instance for .
public sealed record Item(MethodDeclarationSyntax MethodDeclaration, IMethodSymbol MethodSymbol);
}
}