Move all generated types into private namespace

このコミットが含まれているのは:
Sergio Pedri committed 2023-09-30 01:34:04 +02:00
1 親 3439d3ec05
コミット 4917d67d7d
10ファイル変更
+189 -56

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

@@ -39,7 +39,7 @@ partial class ID2D1ShaderGenerator
// Get a reference to the data through the generated native layout type
writer.WriteLine();
writer.WriteLine("ref readonly ConstantBuffer buffer = ref global::System.Runtime.CompilerServices.Unsafe.As<byte, ConstantBuffer>(ref global::System.Runtime.InteropServices.MemoryMarshal.GetReference(data));");
writer.WriteLine("ref readonly global::ComputeSharp.D2D1.Generated.ConstantBuffer buffer = ref global::System.Runtime.CompilerServices.Unsafe.As<byte, global::ComputeSharp.D2D1.Generated.ConstantBuffer>(ref global::System.Runtime.InteropServices.MemoryMarshal.GetReference(data));");
// Generate loading statements for each captured field
foreach (FieldInfo fieldInfo in info.Fields)
@@ -31,7 +31,7 @@ partial class ID2D1ShaderGenerator
}
else
{
writer.WriteLine("Data.InputDescriptions;");
writer.WriteLine("global::ComputeSharp.D2D1.Generated.Data.InputDescriptions;");
}
}
@@ -40,7 +40,11 @@ partial class ID2D1ShaderGenerator
/// </summary>
/// <param name="info">The input <see cref="D2D1ShaderInfo"/> instance with gathered shader info.</param>
/// <param name="callbacks">The registered callbacks to generate additional types.</param>
public static void RegisterAdditionalTypeSyntax(D2D1ShaderInfo info, ImmutableArrayBuilder<IndentedTextWriter.Callback<D2D1ShaderInfo>> callbacks)
/// <param name="usingDirectives">The using directives needed by the generated code.</param>
public static void RegisterAdditionalTypeSyntax(
D2D1ShaderInfo info,
ImmutableArrayBuilder<IndentedTextWriter.Callback<D2D1ShaderInfo>> callbacks,
ImmutableHashSetBuilder<string> usingDirectives)
{
// If there are no necessary data members, stop here
if (info.InputDescriptions.IsEmpty &&
@@ -49,13 +53,20 @@ partial class ID2D1ShaderGenerator
return;
}
usingDirectives.Add("global::System.CodeDom.Compiler");
usingDirectives.Add("global::System.Diagnostics");
usingDirectives.Add("global::System.Diagnostics.CodeAnalysis");
AddAdditionalDataMemberUsingDirectives(info, usingDirectives);
ResourceTextureDescriptions.AddAdditionalDataMemberUsingDirectives(info, usingDirectives);
// Declare the additional data type
static void Callback(D2D1ShaderInfo info, IndentedTextWriter writer)
{
writer.WriteLine($$"""/// <summary>""");
writer.WriteLine($$"""/// A container type for additional data needed by the shader.""");
writer.WriteLine($$"""/// </summary>""");
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator), useFullyQualifiedTypeNames: false);
writer.WriteLine($$"""file static class Data""");
using (writer.WriteBlock())
@@ -80,6 +91,22 @@ partial class ID2D1ShaderGenerator
callbacks.Add(Callback);
}
/// <summary>
/// Adds any using directives for the additional data member, if needed.
/// </summary>
/// <param name="info">The input <see cref="D2D1ShaderInfo"/> instance with gathered shader info.</param>
/// <param name="usingDirectives">The using directives needed by the generated code.</param>
public static void AddAdditionalDataMemberUsingDirectives(D2D1ShaderInfo info, ImmutableHashSetBuilder<string> usingDirectives)
{
if (info.InputDescriptions.IsEmpty)
{
return;
}
usingDirectives.Add("global::ComputeSharp.D2D1");
usingDirectives.Add("global::ComputeSharp.D2D1.Interop");
}
/// <summary>
/// Registers a callback to generate an additional data member, if needed.
/// </summary>
@@ -96,15 +123,15 @@ partial class ID2D1ShaderGenerator
// Declare the shared array with input descriptions
static void Callback(D2D1ShaderInfo info, IndentedTextWriter writer)
{
writer.WriteLine("""/// <summary>The singleton <see cref="global::ComputeSharp.D2D1.Interop.D2D1InputDescription"/> array instance.</summary>""");
writer.WriteLine("""public static readonly global::ComputeSharp.D2D1.Interop.D2D1InputDescription[] InputDescriptions = """);
writer.WriteLine("""/// <summary>The singleton <see cref="D2D1InputDescription"/> array instance.</summary>""");
writer.WriteLine("""public static readonly D2D1InputDescription[] InputDescriptions = """);
writer.WriteLine("""{""");
writer.IncreaseIndent();
// Initialize all input descriptions
writer.WriteInitializationExpressions(info.InputDescriptions.AsSpan(), static (description, writer) =>
{
writer.Write($$"""new global::ComputeSharp.D2D1.Interop.D2D1InputDescription({{description.Index}}, global::ComputeSharp.D2D1.D2D1Filter.{{description.Filter}}) { LevelOfDetailCount = {{description.LevelOfDetailCount}} }""");
writer.Write($$"""new D2D1InputDescription({{description.Index}}, D2D1Filter.{{description.Filter}}) { LevelOfDetailCount = {{description.LevelOfDetailCount}} }""");
});
writer.DecreaseIndent();
@@ -29,7 +29,7 @@ partial class ID2D1ShaderGenerator
}
else
{
writer.WriteLine("InputTypesMemoryManager.Instance.Memory;");
writer.WriteLine("global::ComputeSharp.D2D1.Generated.InputTypesMemoryManager.Instance.Memory;");
}
}
@@ -38,7 +38,11 @@ partial class ID2D1ShaderGenerator
/// </summary>
/// <param name="info">The input <see cref="D2D1ShaderInfo"/> instance with gathered shader info.</param>
/// <param name="callbacks">The registered callbacks to generate additional types.</param>
public static void RegisterAdditionalTypeSyntax(D2D1ShaderInfo info, ImmutableArrayBuilder<IndentedTextWriter.Callback<D2D1ShaderInfo>> callbacks)
/// <param name="usingDirectives">The using directives needed by the generated code.</param>
public static void RegisterAdditionalTypeSyntax(
D2D1ShaderInfo info,
ImmutableArrayBuilder<IndentedTextWriter.Callback<D2D1ShaderInfo>> callbacks,
ImmutableHashSetBuilder<string> usingDirectives)
{
// If there are no inputs, no memory manager is needed
if (info.InputTypes.IsEmpty)
@@ -46,14 +50,23 @@ partial class ID2D1ShaderGenerator
return;
}
usingDirectives.Add("global::System");
usingDirectives.Add("global::System.Buffers");
usingDirectives.Add("global::System.CodeDom.Compiler");
usingDirectives.Add("global::System.Diagnostics");
usingDirectives.Add("global::System.Diagnostics.CodeAnalysis");
usingDirectives.Add("global::System.Runtime.CompilerServices");
usingDirectives.Add("global::System.Runtime.InteropServices");
usingDirectives.Add("global::ComputeSharp.D2D1.Interop");
// Declare the InputTypesMemoryManager custom memory manager type
static void Callback(D2D1ShaderInfo info, IndentedTextWriter writer)
{
writer.WriteLine($$"""/// <summary>""");
writer.WriteLine($$"""/// A <see cref="global::System.Buffers.MemoryManager{T}"/> implementation to get the input types.""");
writer.WriteLine($$"""/// A <see cref="MemoryManager{T}"/> implementation to get the input types.""");
writer.WriteLine($$"""/// </summary>""");
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
writer.WriteLine($$"""file sealed class InputTypesMemoryManager : global::System.Buffers.MemoryManager<global::ComputeSharp.D2D1.Interop.D2D1PixelShaderInputType>""");
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator), useFullyQualifiedTypeNames: false);
writer.WriteLine($$"""file sealed class InputTypesMemoryManager : MemoryManager<D2D1PixelShaderInputType>""");
using (writer.WriteBlock())
{
@@ -64,14 +77,14 @@ partial class ID2D1ShaderGenerator
// RVA field
writer.WriteLine();
writer.WriteLine("/// <summary>The RVA data with the input type info.</summary>");
writer.WriteLine("private static global::System.ReadOnlySpan<global::ComputeSharp.D2D1.Interop.D2D1PixelShaderInputType> Data => new[]");
writer.WriteLine("private static global::System.ReadOnlySpan<D2D1PixelShaderInputType> Data => new[]");
writer.WriteLine("{");
writer.IncreaseIndent();
// Input types, one per line in the RVA field initializer
writer.WriteInitializationExpressions(info.InputTypes.AsSpan(), static (type, writer) =>
{
writer.Write("global::ComputeSharp.D2D1.Interop.D2D1PixelShaderInputType.");
writer.Write("D2D1PixelShaderInputType.");
writer.Write(type == 0 ? "Simple" : "Complex");
});
@@ -83,22 +96,22 @@ partial class ID2D1ShaderGenerator
// Add the remaining members for the memory manager
writer.WriteLine("""
/// <inheritdoc/>
public override unsafe global::System.Span<global::ComputeSharp.D2D1.Interop.D2D1PixelShaderInputType> GetSpan()
public override unsafe Span<D2D1PixelShaderInputType> GetSpan()
{
return new(global::System.Runtime.CompilerServices.Unsafe.AsPointer(ref global::System.Runtime.InteropServices.MemoryMarshal.GetReference(Data)), Data.Length);
return new(Unsafe.AsPointer(ref MemoryMarshal.GetReference(Data)), Data.Length);
}
/// <inheritdoc/>
public override global::System.Memory<global::ComputeSharp.D2D1.Interop.D2D1PixelShaderInputType> Memory
public override Memory<D2D1PixelShaderInputType> Memory
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => CreateMemory(Data.Length);
}
/// <inheritdoc/>
public override unsafe global::System.Buffers.MemoryHandle Pin(int elementIndex)
public override unsafe MemoryHandle Pin(int elementIndex)
{
return new(global::System.Runtime.CompilerServices.Unsafe.AsPointer(ref global::System.Runtime.CompilerServices.Unsafe.AsRef(in Data[elementIndex])), pinnable: this);
return new(Unsafe.AsPointer(ref Unsafe.AsRef(in Data[elementIndex])), pinnable: this);
}
/// <inheritdoc/>
@@ -63,7 +63,7 @@ partial class ID2D1ShaderGenerator
}
else
{
writer.WriteLine("HlslBytecodeMemoryManager.Instance.Memory;");
writer.WriteLine("global::ComputeSharp.D2D1.Generated.HlslBytecodeMemoryManager.Instance.Memory;");
}
}
@@ -72,7 +72,11 @@ partial class ID2D1ShaderGenerator
/// </summary>
/// <param name="info">The input <see cref="D2D1ShaderInfo"/> instance with gathered shader info.</param>
/// <param name="callbacks">The registered callbacks to generate additional types.</param>
public static void RegisterAdditionalTypeSyntax(D2D1ShaderInfo info, ImmutableArrayBuilder<IndentedTextWriter.Callback<D2D1ShaderInfo>> callbacks)
/// <param name="usingDirectives">The using directives needed by the generated code.</param>
public static void RegisterAdditionalTypeSyntax(
D2D1ShaderInfo info,
ImmutableArrayBuilder<IndentedTextWriter.Callback<D2D1ShaderInfo>> callbacks,
ImmutableHashSetBuilder<string> usingDirectives)
{
// If there is no bytecode, no memory manager is needed
if (info.HlslInfo is not HlslBytecodeInfo.Success)
@@ -80,14 +84,22 @@ partial class ID2D1ShaderGenerator
return;
}
usingDirectives.Add("global::System");
usingDirectives.Add("global::System.Buffers");
usingDirectives.Add("global::System.CodeDom.Compiler");
usingDirectives.Add("global::System.Diagnostics");
usingDirectives.Add("global::System.Diagnostics.CodeAnalysis");
usingDirectives.Add("global::System.Runtime.CompilerServices");
usingDirectives.Add("global::System.Runtime.InteropServices");
// Declare the HlslBytecodeMemoryManager custom memory manager type
static void Callback(D2D1ShaderInfo info, IndentedTextWriter writer)
{
writer.WriteLine($$"""/// <summary>""");
writer.WriteLine($$"""/// <see cref="global::System.Buffers.MemoryManager{T}"/> implementation to get the HLSL bytecode.""");
writer.WriteLine($$"""/// <see cref="MemoryManager{T}"/> implementation to get the HLSL bytecode.""");
writer.WriteLine($$"""/// </summary>""");
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
writer.WriteLine($$"""file sealed class HlslBytecodeMemoryManager : global::System.Buffers.MemoryManager<byte>""");
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator), useFullyQualifiedTypeNames: false);
writer.WriteLine($$"""file sealed class HlslBytecodeMemoryManager : MemoryManager<byte>""");
using (writer.WriteBlock())
{
@@ -98,7 +110,7 @@ partial class ID2D1ShaderGenerator
// RVA field (with the compiled HLSL bytecode, on a single line)
writer.WriteLine();
writer.WriteLine("/// <summary>The RVA data with the HLSL bytecode.</summary>");
writer.Write("private static global::System.ReadOnlySpan<byte> Data => new byte[] { ");
writer.Write("private static ReadOnlySpan<byte> Data => new byte[] { ");
SyntaxFormattingHelper.WriteByteArrayInitializationExpressions(((HlslBytecodeInfo.Success)info.HlslInfo).Bytecode.AsSpan(), writer);
@@ -108,22 +120,22 @@ partial class ID2D1ShaderGenerator
// Add the remaining members for the memory manager
writer.WriteLine("""
/// <inheritdoc/>
public override unsafe global::System.Span<byte> GetSpan()
public override unsafe Span<byte> GetSpan()
{
return new(global::System.Runtime.CompilerServices.Unsafe.AsPointer(ref global::System.Runtime.InteropServices.MemoryMarshal.GetReference(Data)), Data.Length);
return new(Unsafe.AsPointer(ref MemoryMarshal.GetReference(Data)), Data.Length);
}
/// <inheritdoc/>
public override global::System.Memory<byte> Memory
public override Memory<byte> Memory
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => CreateMemory(Data.Length);
}
/// <inheritdoc/>
public override unsafe global::System.Buffers.MemoryHandle Pin(int elementIndex)
public override unsafe MemoryHandle Pin(int elementIndex)
{
return new(global::System.Runtime.CompilerServices.Unsafe.AsPointer(ref global::System.Runtime.CompilerServices.Unsafe.AsRef(in Data[elementIndex])), pinnable: this);
return new(Unsafe.AsPointer(ref Unsafe.AsRef(in Data[elementIndex])), pinnable: this);
}
/// <inheritdoc/>
@@ -31,7 +31,7 @@ partial class ID2D1ShaderGenerator
}
else
{
writer.WriteLine("ConstantBuffer buffer;");
writer.WriteLine("global::ComputeSharp.D2D1.Generated.ConstantBuffer buffer;");
// Generate loading statements for each captured field
foreach (FieldInfo fieldInfo in info.Fields)
@@ -71,7 +71,11 @@ partial class ID2D1ShaderGenerator
/// </summary>
/// <param name="info">The input <see cref="D2D1ShaderInfo"/> instance with gathered shader info.</param>
/// <param name="callbacks">The registered callbacks to generate additional types.</param>
public static void RegisterAdditionalTypeSyntax(D2D1ShaderInfo info, ImmutableArrayBuilder<IndentedTextWriter.Callback<D2D1ShaderInfo>> callbacks)
/// <param name="usingDirectives">The using directives needed by the generated code.</param>
public static void RegisterAdditionalTypeSyntax(
D2D1ShaderInfo info,
ImmutableArrayBuilder<IndentedTextWriter.Callback<D2D1ShaderInfo>> callbacks,
ImmutableHashSetBuilder<string> usingDirectives)
{
// If there are no fields, there is no need for a constant buffer type
if (info.Fields.IsEmpty)
@@ -79,6 +83,11 @@ partial class ID2D1ShaderGenerator
return;
}
usingDirectives.Add("global::System.CodeDom.Compiler");
usingDirectives.Add("global::System.Diagnostics");
usingDirectives.Add("global::System.Diagnostics.CodeAnalysis");
usingDirectives.Add("global::System.Runtime.InteropServices");
// Declare the ConstantBuffer type
static void Callback(D2D1ShaderInfo info, IndentedTextWriter writer)
{
@@ -87,8 +96,8 @@ partial class ID2D1ShaderGenerator
writer.WriteLine($$"""/// <summary>""");
writer.WriteLine($$"""/// A type representing the constant buffer native layout for <see cref="{{fullyQualifiedTypeName}}"/>.""");
writer.WriteLine($$"""/// </summary>""");
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
writer.WriteLine($$"""[global::System.Runtime.InteropServices.StructLayout(global::System.Runtime.InteropServices.LayoutKind.Explicit, Size = {{info.ConstantBufferSizeInBytes}})]""");
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator), useFullyQualifiedTypeNames: false);
writer.WriteLine($$"""[StructLayout(LayoutKind.Explicit, Size = {{info.ConstantBufferSizeInBytes}})]""");
writer.WriteLine($$"""file struct ConstantBuffer""");
using (writer.WriteBlock())
@@ -102,14 +111,14 @@ partial class ID2D1ShaderGenerator
// Append a field as a global::ComputeSharp.Bool value (will use the implicit conversion from bool values)
writer.WriteLine($$"""/// <inheritdoc cref="{{fullyQualifiedTypeName}}.{{string.Join(".", primitive.FieldPath)}}"/>""");
writer.WriteLine($$"""[global::System.Runtime.InteropServices.FieldOffset({{primitive.Offset}})]""");
writer.WriteLine($$"""[FieldOffset({{primitive.Offset}})]""");
writer.WriteLine($$"""public global::ComputeSharp.Bool {{string.Join("_", primitive.FieldPath)}};""");
break;
case FieldInfo.Primitive primitive:
// Append primitive fields of other types with their mapped names
writer.WriteLine($$"""/// <inheritdoc cref="{{fullyQualifiedTypeName}}.{{string.Join(".", primitive.FieldPath)}}"/>""");
writer.WriteLine($$"""[global::System.Runtime.InteropServices.FieldOffset({{primitive.Offset}})]""");
writer.WriteLine($$"""[FieldOffset({{primitive.Offset}})]""");
writer.WriteLine($$"""public {{HlslKnownTypes.GetMappedName(primitive.TypeName)}} {{string.Join("_", primitive.FieldPath)}};""");
break;
@@ -120,8 +129,9 @@ partial class ID2D1ShaderGenerator
// Declare a field for every row of the matrix type
for (int j = 0; j < matrix.Rows; j++)
{
writer.WriteLineIf(j > 0);
writer.WriteLine($$"""/// <summary>Row {j} of <see cref="{{fullyQualifiedTypeName}}.{{string.Join(".", matrix.FieldPath)}}"/>.</summary>""");
writer.WriteLine($$"""[global::System.Runtime.InteropServices.FieldOffset({{matrix.Offsets[j]}})]""");
writer.WriteLine($$"""[FieldOffset({{matrix.Offsets[j]}})]""");
writer.WriteLine($$"""public {{rowTypeName}} {{fieldNamePrefix}}_{{j}};""");
}
@@ -31,10 +31,25 @@ partial class ID2D1ShaderGenerator
}
else
{
writer.WriteLine("Data.ResourceTextureDescriptions;");
writer.WriteLine("global::ComputeSharp.D2D1.Generated.Data.ResourceTextureDescriptions;");
}
}
/// <summary>
/// Adds any using directives for the additional data member, if needed.
/// </summary>
/// <param name="info">The input <see cref="D2D1ShaderInfo"/> instance with gathered shader info.</param>
/// <param name="usingDirectives">The using directives needed by the generated code.</param>
public static void AddAdditionalDataMemberUsingDirectives(D2D1ShaderInfo info, ImmutableHashSetBuilder<string> usingDirectives)
{
if (info.ResourceTextureDescriptions.IsEmpty)
{
return;
}
usingDirectives.Add("global::ComputeSharp.D2D1.Interop");
}
/// <summary>
/// Registers a callback to generate an additional data member, if needed.
/// </summary>
@@ -51,15 +66,15 @@ partial class ID2D1ShaderGenerator
// Declare the shared array with resource texture descriptions
static void Callback(D2D1ShaderInfo info, IndentedTextWriter writer)
{
writer.WriteLine("""/// <summary>The singleton <see cref="global::ComputeSharp.D2D1.Interop.D2D1ResourceTextureDescription"/> array instance.</summary>""");
writer.WriteLine("""public static readonly global::ComputeSharp.D2D1.Interop.D2D1ResourceTextureDescription[] ResourceTextureDescriptions =""");
writer.WriteLine("""/// <summary>The singleton <see cref="D2D1ResourceTextureDescription"/> array instance.</summary>""");
writer.WriteLine("""public static readonly D2D1ResourceTextureDescription[] ResourceTextureDescriptions =""");
writer.WriteLine("""{""");
writer.IncreaseIndent();
// Initialize all resource texture descriptions
writer.WriteInitializationExpressions(info.ResourceTextureDescriptions.AsSpan(), static (description, writer) =>
{
writer.Write($"new global::ComputeSharp.D2D1.Interop.D2D1ResourceTextureDescription({description.Index}, {description.Rank})");
writer.Write($"new D2D1ResourceTextureDescription({description.Index}, {description.Rank})");
});
writer.DecreaseIndent();
+30 -6
ファイルの表示
@@ -216,21 +216,45 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
declaredMembers.Add(LoadDispatchData.WriteSyntax);
using ImmutableArrayBuilder<IndentedTextWriter.Callback<D2D1ShaderInfo>> additionalTypes = ImmutableArrayBuilder<IndentedTextWriter.Callback<D2D1ShaderInfo>>.Rent();
using ImmutableHashSetBuilder<string> usingDirectives = ImmutableHashSetBuilder<string>.Rent();
LoadDispatchData.RegisterAdditionalTypeSyntax(item, additionalTypes);
InputDescriptions.RegisterAdditionalTypeSyntax(item, additionalTypes);
InputTypes.RegisterAdditionalTypeSyntax(item, additionalTypes);
LoadBytecode.RegisterAdditionalTypeSyntax(item, additionalTypes);
LoadDispatchData.RegisterAdditionalTypeSyntax(item, additionalTypes, usingDirectives);
InputDescriptions.RegisterAdditionalTypeSyntax(item, additionalTypes, usingDirectives);
InputTypes.RegisterAdditionalTypeSyntax(item, additionalTypes, usingDirectives);
LoadBytecode.RegisterAdditionalTypeSyntax(item, additionalTypes, usingDirectives);
using IndentedTextWriter writer = IndentedTextWriter.Rent();
item.Hierarchy.WriteSyntax(item, writer, declaredMembers.WrittenSpan);
foreach (IndentedTextWriter.Callback<D2D1ShaderInfo> additionalType in additionalTypes.WrittenSpan)
// If any generated types are needed, they go into a separate namespace
// This allows the code to use using directives without any conflicts.
if (additionalTypes.Count > 0)
{
writer.WriteLine();
writer.WriteLine("namespace ComputeSharp.D2D1.Generated");
additionalType(item, writer);
using (writer.WriteBlock())
{
// Add the System directives first, in the correct order
foreach (string usingDirective in usingDirectives.AsEnumerable().Where(static name => name.StartsWith("global::System")).OrderBy(static name => name))
{
writer.WriteLine($"using {usingDirective};");
}
// Add the other directives, also sorted in the correct order
foreach (string usingDirective in usingDirectives.AsEnumerable().Where(static name => !name.StartsWith("global::System")).OrderBy(static name => name))
{
writer.WriteLine($"using {usingDirective};");
}
foreach (IndentedTextWriter.Callback<D2D1ShaderInfo> callback in additionalTypes.WrittenSpan)
{
writer.WriteLine();
callback(item, writer);
}
}
}
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.g.cs", writer.ToString());
+1
ファイルの表示
@@ -21,6 +21,7 @@
<Compile Include="$(MSBuildThisFileDirectory)helpers\DynamicCache{TKey,TValue}.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\EquatableArray{T}.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\HashCode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\ImmutableHashSetBuilder{T}.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\ImmutableArrayBuilder{T}.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\IndentedTextWriter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\ObjectPool{T}.cs" />
+27 -4
ファイルの表示
@@ -18,11 +18,34 @@ internal static class IndentedTextWriterExtensions
/// </summary>
/// <param name="writer">The <see cref="IndentedTextWriter"/> instance to write into.</param>
/// <param name="generatorType">The type of the running generator.</param>
public static void WriteGeneratedAttributes(this IndentedTextWriter writer, Type generatorType)
/// <param name="useFullyQualifiedTypeNames">Whether to use fully qualified type names or not.</param>
public static void WriteGeneratedAttributes(this IndentedTextWriter writer, Type generatorType, bool useFullyQualifiedTypeNames = true)
{
writer.WriteLine($$"""[global::System.CodeDom.Compiler.GeneratedCode("{{generatorType.FullName}}", "{{generatorType.Assembly.GetName().Version}}")]""");
writer.WriteLine($$"""[global::System.Diagnostics.DebuggerNonUserCode]""");
writer.WriteLine($$"""[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]""");
if (useFullyQualifiedTypeNames)
{
writer.WriteLine($$"""[global::System.CodeDom.Compiler.GeneratedCode("{{generatorType.FullName}}", "{{generatorType.Assembly.GetName().Version}}")]""");
writer.WriteLine($$"""[global::System.Diagnostics.DebuggerNonUserCode]""");
writer.WriteLine($$"""[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]""");
}
else
{
writer.WriteLine($$"""[GeneratedCode("{{generatorType.FullName}}", "{{generatorType.Assembly.GetName().Version}}")]""");
writer.WriteLine($$"""[DebuggerNonUserCode]""");
writer.WriteLine($$"""[ExcludeFromCodeCoverage]""");
}
}
/// <summary>
/// Writes a new line into the target writer depending on an input condition.
/// </summary>
/// <param name="writer">The <see cref="IndentedTextWriter"/> instance to write into.</param>
/// <param name="condition">The condition to use to decide whether or not to write a new line.</param>
public static void WriteLineIf(this IndentedTextWriter writer, bool condition)
{
if (condition)
{
writer.WriteLine();
}
}
/// <summary>
+11 -3
ファイルの表示
@@ -56,11 +56,12 @@ internal sealed partial record HierarchyInfo(string FullyQualifiedMetadataName,
writer.WriteLine("#pragma warning disable");
writer.WriteLine();
// Declare the file scoped namespace, if needed
// Declare the namespace, if needed
if (Namespace.Length > 0)
{
writer.WriteLine($"namespace {Namespace};");
writer.WriteLine();
writer.WriteLine($"namespace {Namespace}");
writer.WriteLine("{");
writer.IncreaseIndent();
}
// Declare all the opening types until the inner-most one
@@ -81,6 +82,13 @@ internal sealed partial record HierarchyInfo(string FullyQualifiedMetadataName,
writer.DecreaseIndent();
writer.WriteLine("}");
}
// Close the namespace scope as well, if needed
if (Namespace.Length > 0)
{
writer.DecreaseIndent();
writer.WriteLine("}");
}
}
/// <summary>