Fully enable D2D1 generator to run on indented text writer
このコミットが含まれているのは:
1 親
6accd17c9f
コミット
5d859266d8
12ファイル変更
+241
-164
検索条件に一致するファイルはありません
@@ -42,6 +42,55 @@ internal sealed partial record HierarchyInfo(string FullyQualifiedMetadataName,
|
||||
hierarchy.ToImmutable());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes syntax for the current hierarchy into a target writer.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of state to pass to callbacks.</typeparam>
|
||||
/// <param name="state">The input state to pass to callbacks.</param>
|
||||
/// <param name="writer">The target <see cref="IndentedTextWriter"/> instance to write text to.</param>
|
||||
/// <param name="memberCallbacks">The callbacks to use to write members into the declared type.</param>
|
||||
public void WriteSyntax<T>(T state, IndentedTextWriter writer, ReadOnlySpan<IndentedTextWriter.Callback<T>> memberCallbacks)
|
||||
{
|
||||
// Write the generated file header
|
||||
writer.WriteLine("// <auto-generated/>");
|
||||
writer.WriteLine("#pragma warning disable");
|
||||
writer.WriteLine();
|
||||
|
||||
// Declare the file scoped namespace, if needed
|
||||
if (Namespace.Length > 0)
|
||||
{
|
||||
writer.WriteLine($"namespace {Namespace};");
|
||||
writer.WriteLine();
|
||||
}
|
||||
|
||||
// Declare all the opening types until the inner-most one
|
||||
for (int i = Hierarchy.Length - 1; i >= 0; i--)
|
||||
{
|
||||
writer.WriteLine($$"""/// <inheritdoc cref="{{Hierarchy[i].QualifiedName}}"/>""");
|
||||
writer.WriteLine($$"""partial {{Hierarchy[i].GetTypeKeyword()}} {{Hierarchy[i].QualifiedName}}""");
|
||||
writer.WriteLine($$"""{""");
|
||||
writer.IncreaseIndent();
|
||||
}
|
||||
|
||||
// Generate all nested members
|
||||
for (int i = 0; i < memberCallbacks.Length; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
writer.WriteLine();
|
||||
}
|
||||
|
||||
memberCallbacks[i](state, writer);
|
||||
}
|
||||
|
||||
// Close all scopes and reduce the indentation
|
||||
for (int i = 0; i < Hierarchy.Length; i++)
|
||||
{
|
||||
writer.DecreaseIndent();
|
||||
writer.WriteLine("}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the fully qualified type name for the current instance.
|
||||
/// </summary>
|
||||
|
||||
@@ -13,6 +13,21 @@ namespace ComputeSharp.SourceGeneration.Models;
|
||||
/// <param name="IsRecord">Whether the type is a record type.</param>
|
||||
internal sealed record TypeInfo(string QualifiedName, TypeKind Kind, bool IsRecord)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the keyword for the current type kind.
|
||||
/// </summary>
|
||||
/// <returns>The keyword for the current type kind.</returns>
|
||||
public string GetTypeKeyword()
|
||||
{
|
||||
return Kind switch
|
||||
{
|
||||
TypeKind.Struct => "struct",
|
||||
TypeKind.Interface => "interface",
|
||||
TypeKind.Class when IsRecord => "record",
|
||||
_ => "class"
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="TypeDeclarationSyntax"/> instance for the current info.
|
||||
/// </summary>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする