Handle InputTypes generation for no inputs
このコミットが含まれているのは:
1 親
41ca3a0b1d
コミット
5829bfe9ec
2ファイル変更
+25
-11
検索条件に一致するファイルはありません
+23
-9
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using ComputeSharp.D2D1.__Internals;
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
@@ -20,15 +21,32 @@ partial class ID2D1ShaderGenerator
|
||||
/// Creates a <see cref="MethodDeclarationSyntax"/> instance for the <c>InputTypes</c> property.
|
||||
/// </summary>
|
||||
/// <param name="inputTypes">The input types for the shader.</param>
|
||||
/// <param name="additionalType">An additional <see cref="TypeDeclarationSyntax"/> instance needed by the generated code.</param>
|
||||
/// <param name="additionalTypes">Any additional <see cref="TypeDeclarationSyntax"/> instances needed by the generated code, if needed.</param>
|
||||
/// <returns>The resulting <see cref="MemberDeclarationSyntax"/> instance for the <c>InputTypes</c> property.</returns>
|
||||
public static PropertyDeclarationSyntax GetSyntax(ImmutableArray<uint> inputTypes, out TypeDeclarationSyntax additionalType)
|
||||
public static PropertyDeclarationSyntax GetSyntax(ImmutableArray<uint> inputTypes, out TypeDeclarationSyntax[] additionalTypes)
|
||||
{
|
||||
additionalType = GetMemoryManagerDeclaration(inputTypes);
|
||||
ExpressionSyntax memoryExpression;
|
||||
|
||||
// If there are no inputs, simply return a default expression.
|
||||
// Otherwise, declare the memory manager and access it.
|
||||
if (inputTypes.Length == 0)
|
||||
{
|
||||
memoryExpression = LiteralExpression(SyntaxKind.DefaultLiteralExpression, Token(SyntaxKind.DefaultKeyword));
|
||||
additionalTypes = Array.Empty<TypeDeclarationSyntax>();
|
||||
}
|
||||
else
|
||||
{
|
||||
memoryExpression = MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName("InputTypesMemoryManager"),
|
||||
IdentifierName("Memory"));
|
||||
|
||||
additionalTypes = new TypeDeclarationSyntax[] { GetMemoryManagerDeclaration(inputTypes) };
|
||||
}
|
||||
|
||||
// This code produces a method declaration as follows:
|
||||
//
|
||||
// readonly uint global::ComputeSharp.D2D1.__Internals.ID2D1Shader.InputTypes => InputTypesMemoryManager.Memory;
|
||||
// readonly uint global::ComputeSharp.D2D1.__Internals.ID2D1Shader.InputTypes => <MEMORY_EXPRESSION>;
|
||||
return
|
||||
PropertyDeclaration(
|
||||
GenericName(Identifier("global::System.ReadOnlyMemory"))
|
||||
@@ -36,11 +54,7 @@ partial class ID2D1ShaderGenerator
|
||||
Identifier(nameof(InputTypes)))
|
||||
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.D2D1.__Internals.{nameof(ID2D1Shader)}")))
|
||||
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
|
||||
.WithExpressionBody(ArrowExpressionClause(
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName("InputTypesMemoryManager"),
|
||||
IdentifierName("Memory"))))
|
||||
.WithExpressionBody(ArrowExpressionClause(memoryExpression))
|
||||
.WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
|
||||
}
|
||||
|
||||
|
||||
@@ -265,8 +265,8 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
|
||||
// Generate the InputTypes properties
|
||||
context.RegisterSourceOutput(inputTypesInfo, static (context, item) =>
|
||||
{
|
||||
MemberDeclarationSyntax inputTypesProperty = InputTypes.GetSyntax(item.InputTypes.InputTypes, out TypeDeclarationSyntax additionalType);
|
||||
CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMember(item.Hierarchy, inputTypesProperty, canUseSkipLocalsInit: false, additionalMemberDeclarations: additionalType);
|
||||
MemberDeclarationSyntax inputTypesProperty = InputTypes.GetSyntax(item.InputTypes.InputTypes, out TypeDeclarationSyntax[] additionalTypes);
|
||||
CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMember(item.Hierarchy, inputTypesProperty, canUseSkipLocalsInit: false, additionalMemberDeclarations: additionalTypes);
|
||||
|
||||
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(InputTypes)}.g.cs", compilationUnit.GetText(Encoding.UTF8));
|
||||
});
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする