using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using ComputeSharp.SourceGenerators.Extensions;
namespace ComputeSharp.SourceGenerators.Models;
///
/// A model for extracted info on a processed HLSL method.
///
/// The metadata name for the method.
/// The meethod entry point.
/// The discovered declared types.
/// The discovered defined constants.
/// The dependent captured methods.
internal sealed record HlslMethodSourceInfo(
string MetadataName,
string EntryPoint,
ImmutableArray<(string Name, string Definition)> DefinedTypes,
ImmutableArray<(string Name, string Value)> DefinedConstants,
ImmutableArray<(string Signature, string Definition)> DependentMethods)
{
///
/// An implementation for .
///
public sealed class Comparer : IEqualityComparer
{
///
/// The singleton instance.
///
public static Comparer Default { get; } = new();
///
public bool Equals(HlslMethodSourceInfo? x, HlslMethodSourceInfo? y)
{
if (x is null && y is null)
{
return true;
}
if (x is null || y is null)
{
return false;
}
if (ReferenceEquals(x, y))
{
return true;
}
return
x.MetadataName == y.MetadataName &&
x.EntryPoint == y.EntryPoint &&
x.DefinedTypes.SequenceEqual(y.DefinedTypes) &&
x.DefinedConstants.SequenceEqual(y.DefinedConstants) &&
x.DependentMethods.SequenceEqual(y.DependentMethods);
}
///
public int GetHashCode(HlslMethodSourceInfo obj)
{
HashCode hashCode = default;
hashCode.Add(obj.MetadataName);
hashCode.Add(obj.EntryPoint);
hashCode.AddRange(obj.DefinedTypes);
hashCode.AddRange(obj.DefinedConstants);
hashCode.AddRange(obj.DependentMethods);
return hashCode.ToHashCode();
}
}
}