Move domain specific code to HlslKnownTypes
このコミットが含まれているのは:
1 親
5f58823305
コミット
ae717681c4
6ファイル変更
+70
-60
検索条件に一致するファイルはありません
@@ -1,10 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ComputeSharp.SourceGenerators.Mappings;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.Extensions;
|
||||
|
||||
@@ -16,10 +12,9 @@ internal static class ISymbolExtensions
|
||||
/// <summary>
|
||||
/// A custom <see cref="SymbolDisplayFormat"/> instance with fully qualified style, without global::.
|
||||
/// </summary>
|
||||
public static readonly SymbolDisplayFormat FullyQualifiedWithoutGlobalFormat = new(
|
||||
globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Omitted,
|
||||
typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces,
|
||||
genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters);
|
||||
public static readonly SymbolDisplayFormat FullyQualifiedWithoutGlobalFormat =
|
||||
SymbolDisplayFormat.FullyQualifiedFormat
|
||||
.WithGlobalNamespaceStyle(SymbolDisplayGlobalNamespaceStyle.Omitted);
|
||||
|
||||
/// <summary>
|
||||
/// A custom <see cref="SymbolDisplayFormat"/> instance with fully qualified style, without global:: and parameters.
|
||||
@@ -29,6 +24,16 @@ internal static class ISymbolExtensions
|
||||
.WithMemberOptions(SymbolDisplayMemberOptions.IncludeContainingType)
|
||||
.WithParameterOptions(SymbolDisplayParameterOptions.None);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the fully qualified name for a given symbol.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The input <see cref="ISymbol"/> instance.</param>
|
||||
/// <returns>The fully qualified name for <paramref name="symbol"/>.</returns>
|
||||
public static string GetFullyQualifiedName(this ISymbol symbol)
|
||||
{
|
||||
return symbol.ToDisplayString(FullyQualifiedWithoutGlobalFormat);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full metadata name for a given <see cref="ITypeSymbol"/> instance.
|
||||
/// </summary>
|
||||
@@ -111,24 +116,4 @@ internal static class ISymbolExtensions
|
||||
{
|
||||
return symbol.GetFullMetadataName().Replace('`', '-').Replace('+', '.');
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tracks an <see cref="ITypeSymbol"/> instance and returns an HLSL compatible <see cref="TypeSyntax"/> object.
|
||||
/// </summary>
|
||||
/// <param name="typeSymbol">The input <see cref="ITypeSymbol"/> instance to process.</param>
|
||||
/// <param name="discoveredTypes">The collection of currently discovered types.</param>
|
||||
/// <returns>A <see cref="SyntaxNode"/> instance that represents a type compatible with HLSL.</returns>
|
||||
public static TypeSyntax TrackType(this ITypeSymbol typeSymbol, ICollection<INamedTypeSymbol> discoveredTypes)
|
||||
{
|
||||
string typeName = typeSymbol.ToDisplayString(FullyQualifiedWithoutGlobalFormat);
|
||||
|
||||
discoveredTypes.Add((INamedTypeSymbol)typeSymbol);
|
||||
|
||||
if (HlslKnownTypes.TryGetMappedName(typeName, out string? mappedName))
|
||||
{
|
||||
return ParseTypeName(mappedName!);
|
||||
}
|
||||
|
||||
return ParseTypeName(typeName.ToHlslIdentifierName());
|
||||
}
|
||||
}
|
||||
@@ -365,6 +365,26 @@ internal static class HlslKnownTypes
|
||||
return KnownHlslTypes.TryGetValue(originalName, out mappedName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tracks an <see cref="ITypeSymbol"/> instance and returns an HLSL compatible type name.
|
||||
/// </summary>
|
||||
/// <param name="typeSymbol">The input <see cref="ITypeSymbol"/> instance to process.</param>
|
||||
/// <param name="discoveredTypes">The collection of currently discovered types.</param>
|
||||
/// <returns>A type name that represents a type compatible with HLSL.</returns>
|
||||
public static string TrackType(ITypeSymbol typeSymbol, ICollection<INamedTypeSymbol> discoveredTypes)
|
||||
{
|
||||
string typeName = typeSymbol.GetFullyQualifiedName();
|
||||
|
||||
discoveredTypes.Add((INamedTypeSymbol)typeSymbol);
|
||||
|
||||
if (TryGetMappedName(typeName, out string? mappedName))
|
||||
{
|
||||
return mappedName!;
|
||||
}
|
||||
|
||||
return typeName.ToHlslIdentifierName();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sequence of unique custom types from a collection of discovered types.
|
||||
/// </summary>
|
||||
|
||||
@@ -429,7 +429,7 @@ internal sealed class ShaderSourceRewriter : HlslSourceRewriter
|
||||
// Track and rewrite the discarded declaration
|
||||
if (SemanticModel.For(node).GetOperation(node.Expression) is IDiscardOperation operation)
|
||||
{
|
||||
TypeSyntax typeSyntax = operation.Type!.TrackType(DiscoveredTypes);
|
||||
TypeSyntax typeSyntax = ParseTypeName(HlslKnownTypes.TrackType(operation.Type!, DiscoveredTypes));
|
||||
string identifier = $"__implicit{this.implicitVariables.Count}";
|
||||
|
||||
// Add the variable to the list of implicit declarations
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする