Add and adopt IndentedTextWriterExtensions
このコミットが含まれているのは:
1 親
5d859266d8
コミット
eba861e20e
7ファイル変更
+76
-43
検索条件に一致するファイルはありません
+5
-9
@@ -1,6 +1,9 @@
|
||||
using ComputeSharp.D2D1.SourceGenerators.Models;
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
|
||||
#pragma warning disable IDE0053
|
||||
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -99,17 +102,10 @@ partial class ID2D1ShaderGenerator
|
||||
writer.IncreaseIndent();
|
||||
|
||||
// Initialize all input descriptions
|
||||
for (int i = 0; i < info.InputDescriptions.Length; i++)
|
||||
writer.WriteInitializationExpressions(info.InputDescriptions.AsSpan(), static (description, writer) =>
|
||||
{
|
||||
InputDescription description = info.InputDescriptions[i];
|
||||
|
||||
writer.Write($$"""new global::ComputeSharp.D2D1.Interop.D2D1InputDescription({{description.Index}}, global::ComputeSharp.D2D1.D2D1Filter.{{description.Filter}}) { LevelOfDetailCount = {{description.LevelOfDetailCount}} }""");
|
||||
|
||||
if (i < info.InputDescriptions.Length - 1)
|
||||
{
|
||||
writer.WriteLine(",");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
writer.DecreaseIndent();
|
||||
writer.WriteLine();
|
||||
|
||||
+4
-8
@@ -1,4 +1,5 @@
|
||||
using ComputeSharp.D2D1.SourceGenerators.Models;
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
@@ -68,16 +69,11 @@ partial class ID2D1ShaderGenerator
|
||||
writer.IncreaseIndent();
|
||||
|
||||
// Input types, one per line in the RVA field initializer
|
||||
for (int i = 0; i < info.InputTypes.Length; i++)
|
||||
writer.WriteInitializationExpressions(info.InputTypes.AsSpan(), static (type, writer) =>
|
||||
{
|
||||
writer.Write("global::ComputeSharp.D2D1.Interop.D2D1PixelShaderInputType.");
|
||||
writer.Write(info.InputTypes[i] == 0 ? "Simple" : "Complex");
|
||||
|
||||
if (i < info.InputTypes.Length - 1)
|
||||
{
|
||||
writer.WriteLine(",");
|
||||
}
|
||||
}
|
||||
writer.Write(type == 0 ? "Simple" : "Complex");
|
||||
});
|
||||
|
||||
writer.DecreaseIndent();
|
||||
writer.WriteLine();
|
||||
|
||||
+4
-8
@@ -1,4 +1,5 @@
|
||||
using ComputeSharp.D2D1.SourceGenerators.Models;
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
using ComputeSharp.SourceGeneration.Mappings;
|
||||
|
||||
@@ -93,14 +94,9 @@ partial class ID2D1ShaderGenerator
|
||||
using (writer.WriteBlock())
|
||||
{
|
||||
// Declare fields for every mapped item from the shader layout
|
||||
for (int i = 0; i < info.Fields.Length; i++)
|
||||
writer.WriteLineSeparatedMembers(info.Fields.AsSpan(), (field, writer) =>
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
writer.WriteLine();
|
||||
}
|
||||
|
||||
switch (info.Fields[i])
|
||||
switch (field)
|
||||
{
|
||||
case FieldInfo.Primitive { TypeName: "System.Boolean" } primitive:
|
||||
|
||||
@@ -131,7 +127,7 @@ partial class ID2D1ShaderGenerator
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-9
@@ -1,6 +1,9 @@
|
||||
using ComputeSharp.D2D1.SourceGenerators.Models;
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
|
||||
#pragma warning disable IDE0053
|
||||
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -52,17 +55,10 @@ partial class ID2D1ShaderGenerator
|
||||
writer.IncreaseIndent();
|
||||
|
||||
// Initialize all resource texture descriptions
|
||||
for (int i = 0; i < info.ResourceTextureDescriptions.Length; i++)
|
||||
writer.WriteInitializationExpressions(info.ResourceTextureDescriptions.AsSpan(), static (description, writer) =>
|
||||
{
|
||||
ResourceTextureDescription description = info.ResourceTextureDescriptions[i];
|
||||
|
||||
writer.Write($"new global::ComputeSharp.D2D1.Interop.D2D1ResourceTextureDescription({description.Index}, {description.Rank})");
|
||||
|
||||
if (i < info.ResourceTextureDescriptions.Length - 1)
|
||||
{
|
||||
writer.WriteLine(",");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
writer.DecreaseIndent();
|
||||
writer.WriteLine();
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Extensions\CompilationExtensions.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Extensions\DiagnosticsExtensions.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Extensions\IMethodSymbolExtensions.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Extensions\IndentedTextWriterExtensions.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Extensions\IPropertySymbolExtensions.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Extensions\IFieldSymbolExtensions.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ITypeSymbolExtensions.cs" />
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
|
||||
namespace ComputeSharp.SourceGeneration.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for the <see cref="IndentedTextWriter"/> type.
|
||||
/// </summary>
|
||||
internal static class IndentedTextWriterExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes a series of members separated by one line between each of them.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of input items to process.</typeparam>
|
||||
/// <param name="writer">The <see cref="IndentedTextWriter"/> instance to write into.</param>
|
||||
/// <param name="items">The input items to process.</param>
|
||||
/// <param name="callback">The <see cref="IndentedTextWriter.Callback{T}"/> instance to invoke for each item.</param>
|
||||
public static void WriteLineSeparatedMembers<T>(
|
||||
this IndentedTextWriter writer,
|
||||
ReadOnlySpan<T> items,
|
||||
IndentedTextWriter.Callback<T> callback)
|
||||
{
|
||||
for (int i = 0; i < items.Length; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
writer.WriteLine();
|
||||
}
|
||||
|
||||
callback(items[i], writer);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a series of initialization expressions separated by a comma between each of them.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of input items to process.</typeparam>
|
||||
/// <param name="writer">The <see cref="IndentedTextWriter"/> instance to write into.</param>
|
||||
/// <param name="items">The input items to process.</param>
|
||||
/// <param name="callback">The <see cref="IndentedTextWriter.Callback{T}"/> instance to invoke for each item.</param>
|
||||
public static void WriteInitializationExpressions<T>(
|
||||
this IndentedTextWriter writer,
|
||||
ReadOnlySpan<T> items,
|
||||
IndentedTextWriter.Callback<T> callback)
|
||||
{
|
||||
for (int i = 0; i < items.Length; i++)
|
||||
{
|
||||
callback(items[i], writer);
|
||||
|
||||
if (i < items.Length - 1)
|
||||
{
|
||||
writer.WriteLine(",");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,15 +73,7 @@ internal sealed partial record HierarchyInfo(string FullyQualifiedMetadataName,
|
||||
}
|
||||
|
||||
// Generate all nested members
|
||||
for (int i = 0; i < memberCallbacks.Length; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
writer.WriteLine();
|
||||
}
|
||||
|
||||
memberCallbacks[i](state, writer);
|
||||
}
|
||||
writer.WriteLineSeparatedMembers(memberCallbacks, (callback, writer) => callback(state, writer));
|
||||
|
||||
// Close all scopes and reduce the indentation
|
||||
for (int i = 0; i < Hierarchy.Length; i++)
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする