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 IComputeShaderSourceGenerator
{
///
/// 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 StructDeclarationSyntax structDeclaration &&
context.SemanticModel.GetDeclaredSymbol(structDeclaration) is INamedTypeSymbol structSymbol &&
structSymbol.Interfaces.Any(static interfaceSymbol =>
interfaceSymbol.Name == nameof(IComputeShader) ||
interfaceSymbol is { IsGenericType: true, Name: nameof(IPixelShader) }))
{
this.gatheredInfo.Add(new Item(structDeclaration, structSymbol));
}
}
///
/// A model for a group of item representing a discovered type to process.
///
/// The instance for the target struct declaration.
/// The instance for .
public sealed record Item(StructDeclarationSyntax StructDeclaration, INamedTypeSymbol StructSymbol);
}
}
}