Initial version of custom type declarations

このコミットが含まれているのは:
Sergio Pedri committed 2020-11-29 15:55:58 +01:00
1 親 83d64d4db8
コミット ba135ef76d
4ファイル変更
+104 -32

検索条件に一致するファイルはありません

+35 -1
ファイルの表示
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using ComputeSharp.SourceGenerators.Extensions;
using Microsoft.CodeAnalysis;
namespace ComputeSharp.SourceGenerators.Mappings
{
@@ -37,7 +39,8 @@ namespace ComputeSharp.SourceGenerators.Mappings
[typeof(double).FullName] = "double",
[typeof(Double2).FullName] = "double2",
[typeof(Double3).FullName] = "double3",
[typeof(Double4).FullName] = "double4"
[typeof(Double4).FullName] = "double4",
[typeof(ThreadIds).FullName] = "uint3",
};
/// <summary>
@@ -73,5 +76,36 @@ namespace ComputeSharp.SourceGenerators.Mappings
{
return KnownTypes.TryGetValue(originalName, out mappedName);
}
/// <summary>
/// Gets the sequence of unique custom types from a collection of discovered types.
/// </summary>
/// <param name="discoveredTypes">The input collection of discovered types.</param>
/// <returns>The list of unique custom types.</returns>
public static IEnumerable<INamedTypeSymbol> GetCustomTypes(IEnumerable<INamedTypeSymbol> discoveredTypes)
{
// Local function to recursively gather nested types
static void ExploreTypes(INamedTypeSymbol type, HashSet<INamedTypeSymbol> customTypes)
{
if (KnownTypes.ContainsKey(type.GetFullMetadataName())) return;
customTypes.Add(type);
foreach (var field in type.GetMembers().OfType<IFieldSymbol>())
{
ExploreTypes((INamedTypeSymbol)field.Type, customTypes);
}
}
HashSet<INamedTypeSymbol> customTypes = new(SymbolEqualityComparer.Default);
// Explore all input types and their nested types
foreach (INamedTypeSymbol type in discoveredTypes)
{
ExploreTypes(type, customTypes);
}
return customTypes;
}
}
}