Fully enable D2D1 generator to run on indented text writer

このコミットが含まれているのは:
Sergio Pedri committed 2023-09-30 01:34:04 +02:00
1 親 6accd17c9f
コミット 5d859266d8
12ファイル変更
+241 -164

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

+4 -2
ファイルの表示
@@ -61,9 +61,8 @@ internal sealed class IndentedTextWriter : IDisposable
{
this.builder = builder;
this.currentIndentationLevel = 0;
this.currentIndentation = DefaultIndentation;
this.currentIndentation = "";
this.availableIndentations = new string[4];
this.availableIndentations[0] = "";
for (int i = 1, n = this.availableIndentations.Length; i < n; i++)
@@ -158,11 +157,14 @@ internal sealed class IndentedTextWriter : IDisposable
{
// There are no new lines left, so the content can be written as a single line
WriteRawText(content);
break;
}
else
{
// Write the current line
WriteRawText(content[..newLineIndex]);
WriteLine();
// Move past the new line character (the result could be an empty span)
content = content[(newLineIndex + 1)..];
+49
ファイルの表示
@@ -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>
+15
ファイルの表示
@@ -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>