Update ID2D1Shader interface and generator

このコミットが含まれているのは:
Sergio Pedri committed 2023-09-27 15:03:06 +02:00
1 親 01b32fd0ad
コミット 8edc54748f
8ファイル変更
+28 -22

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

@@ -16,18 +16,25 @@ partial class ID2D1ShaderGenerator
/// <summary>
/// Creates a <see cref="PropertyDeclarationSyntax"/> instance for the <c>EffectDisplayName</c> property.
/// </summary>
/// <param name="effectDisplayName">The input effect display name value.</param>
/// <param name="effectDisplayName">The input effect display name value, if available.</param>
/// <returns>The resulting <see cref="PropertyDeclarationSyntax"/> instance for the <c>EffectDisplayName</c> property.</returns>
public static PropertyDeclarationSyntax GetSyntax(string effectDisplayName)
public static PropertyDeclarationSyntax GetSyntax(string? effectDisplayName)
{
// Get the expression: either a string literal, or just null
ExpressionSyntax displayNameExpression = effectDisplayName switch
{
{ } => LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(effectDisplayName)),
_ => LiteralExpression(SyntaxKind.NullLiteralExpression)
};
// This code produces a method declaration as follows:
//
// readonly string global::ComputeSharp.D2D1.__Internals.ID2D1Shader.EffectDisplayName => "<EFFECT_DISPLAY_NAME>";
// readonly string? global::ComputeSharp.D2D1.__Internals.ID2D1Shader.EffectDisplayName => <EFFECT_DISPLAY_NAME>;
return
PropertyDeclaration(PredefinedType(Token(SyntaxKind.StringKeyword)), Identifier(nameof(EffectDisplayName)))
PropertyDeclaration(NullableType(PredefinedType(Token(SyntaxKind.StringKeyword))), Identifier(nameof(EffectDisplayName)))
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.D2D1.__Internals.{nameof(ID2D1Shader)}")))
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
.WithExpressionBody(ArrowExpressionClause(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(effectDisplayName))))
.WithExpressionBody(ArrowExpressionClause(displayNameExpression))
.WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
}
}
@@ -1,6 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using ComputeSharp.D2D1.SourceGenerators.Helpers;
using ComputeSharp.SourceGeneration.Extensions;
using Microsoft.CodeAnalysis;
namespace ComputeSharp.D2D1.SourceGenerators;
@@ -18,15 +17,15 @@ partial class ID2D1ShaderGenerator
/// </summary>
/// <param name="compilation">The input <see cref="Compilation"/> object currently in use.</param>
/// <param name="structDeclarationSymbol">The <see cref="INamedTypeSymbol"/> for the shader type in use.</param>
/// <returns>The resulting effect display name.</returns>
public static string GetInfo(Compilation compilation, INamedTypeSymbol structDeclarationSymbol)
/// <returns>The resulting effect display name, if available.</returns>
public static string? GetInfo(Compilation compilation, INamedTypeSymbol structDeclarationSymbol)
{
if (TryGetDefinedEffectDisplayName(compilation, structDeclarationSymbol, out string? effectDisplayName))
{
return effectDisplayName;
}
return structDeclarationSymbol.GetFullyQualifiedMetadataName();
return null;
}
/// <summary>
+2 -2
ファイルの表示
@@ -58,7 +58,7 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
token.ThrowIfCancellationRequested();
// EffectDisplayName info
string effectDisplayName = EffectDisplayName.GetInfo(context.SemanticModel.Compilation, typeSymbol);
string? effectDisplayName = EffectDisplayName.GetInfo(context.SemanticModel.Compilation, typeSymbol);
token.ThrowIfCancellationRequested();
@@ -149,7 +149,7 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
.Select(static (item, _) => item.Diagnostcs));
// Get the EffectDisplayName info (hierarchy and effect display name)
IncrementalValuesProvider<(HierarchyInfo Hierarchy, string EffectDisplayName)> effectDisplayNameInfo =
IncrementalValuesProvider<(HierarchyInfo Hierarchy, string? EffectDisplayName)> effectDisplayNameInfo =
shaderInfoWithErrors
.Select(static (item, _) => (item.Hierarchy, item.EffectDisplayName));
+2 -2
ファイルの表示
@@ -8,7 +8,7 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models;
/// </summary>
/// <param name="Hierarchy">The hierarchy info for the shader type.</param>
/// <param name="EffectId">The effect id info for the shader type.</param>
/// <param name="EffectDisplayName">The effect display name for the shader type.</param>
/// <param name="EffectDisplayName">The effect display name for the shader type, if available.</param>
/// <param name="DispatchData">The gathered shader dispatch data.</param>
/// <param name="InputTypes">The gathered input types for the shader.</param>
/// <param name="ResourceTextureDescriptions">The gathered resource texture descriptions for the shader.</param>
@@ -20,7 +20,7 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models;
internal sealed record D2D1ShaderInfo(
HierarchyInfo Hierarchy,
EffectIdInfo EffectId,
string EffectDisplayName,
string? EffectDisplayName,
DispatchDataInfo DispatchData,
InputTypesInfo InputTypes,
ResourceTextureDescriptionsInfo ResourceTextureDescriptions,