diff --git a/src/MLIR.Generators/DialectSourceEmitter.cs b/src/MLIR.Generators/DialectSourceEmitter.cs index a5be8dc..3f33b88 100644 --- a/src/MLIR.Generators/DialectSourceEmitter.cs +++ b/src/MLIR.Generators/DialectSourceEmitter.cs @@ -224,7 +224,7 @@ private static void AppendOperationBodySyntaxClass(StringBuilder builder, Operat builder.AppendLine(" return false;"); builder.AppendLine(" }"); builder.AppendLine(); - builder.AppendLine(" public override void WriteTo(Text.SyntaxWriter writer, int indentLevel, System.Action writeRegion)"); + builder.AppendLine(" public override void WriteTo(Text.SyntaxWriter writer, int indentLevel)"); builder.AppendLine(" {"); foreach (var field in fields) { diff --git a/src/MLIR/Syntax/BlockArgumentSyntax.cs b/src/MLIR/Syntax/BlockArgumentSyntax.cs index e94ea0f..b21455d 100644 --- a/src/MLIR/Syntax/BlockArgumentSyntax.cs +++ b/src/MLIR/Syntax/BlockArgumentSyntax.cs @@ -56,7 +56,12 @@ public bool TryGetRawType(out RawSyntaxText? rawType) /// public RawSyntaxText RawType => TypeSyntax.GetRawText(); - internal void WriteTo(SyntaxWriter writer, string defaultLeadingTrivia) + /// + /// Writes this block argument to the supplied syntax writer. + /// + /// The syntax writer to write to. + /// The fallback leading trivia to use when syntax does not carry explicit trivia. + public void WriteTo(SyntaxWriter writer, string defaultLeadingTrivia) { writer.WriteToken(NameToken, defaultLeadingTrivia); writer.WriteToken(ColonToken, string.Empty); diff --git a/src/MLIR/Syntax/BlockSyntax.cs b/src/MLIR/Syntax/BlockSyntax.cs index bd3dd6d..799c3b6 100644 --- a/src/MLIR/Syntax/BlockSyntax.cs +++ b/src/MLIR/Syntax/BlockSyntax.cs @@ -1,7 +1,6 @@ namespace MLIR.Syntax; using System.Collections.Generic; -using System; using MLIR.Text; /// @@ -72,10 +71,14 @@ public BlockSyntax( /// public string Label => LabelToken.Text; - internal void WriteTo( + /// + /// Writes this block to the supplied syntax writer. + /// + /// The syntax writer to write to. + /// The indentation level of the containing region. + public void WriteTo( SyntaxWriter writer, - int regionIndentLevel, - Action writeOperation) + int regionIndentLevel) { // Synthetic entry blocks are a parser implementation detail. Omit their labels when // printing unless the block carries arguments that require an explicit header. @@ -108,7 +111,7 @@ internal void WriteTo( var operationIndentLevel = blockHasExplicitLabel ? regionIndentLevel + 2 : regionIndentLevel + 1; foreach (var operation in Operations) { - writeOperation(writer, operation, operationIndentLevel, "\n"); + writer.WriteOperation(operation, operationIndentLevel, "\n"); } } diff --git a/src/MLIR/Syntax/GenericOperationBodySyntax.cs b/src/MLIR/Syntax/GenericOperationBodySyntax.cs index 03126d3..12df9a9 100644 --- a/src/MLIR/Syntax/GenericOperationBodySyntax.cs +++ b/src/MLIR/Syntax/GenericOperationBodySyntax.cs @@ -77,7 +77,7 @@ public override bool TryGetGenericBody(out GenericOperationBodySyntax? genericBo } /// - public override void WriteTo(Text.SyntaxWriter writer, int indentLevel, System.Action writeRegion) + public override void WriteTo(Text.SyntaxWriter writer, int indentLevel) { writer.WriteToken(OperandList.OpenToken!.Value, string.Empty); for (var i = 0; i < OperandList.Count; i++) @@ -110,7 +110,7 @@ public override void WriteTo(Text.SyntaxWriter writer, int indentLevel, System.A foreach (var region in Regions) { - writeRegion(writer, region, indentLevel); + writer.WriteRegion(region, indentLevel); } if (Attributes.OpenToken != null) diff --git a/src/MLIR/Syntax/ModuleSyntax.cs b/src/MLIR/Syntax/ModuleSyntax.cs index fb0a3f6..35a6c6a 100644 --- a/src/MLIR/Syntax/ModuleSyntax.cs +++ b/src/MLIR/Syntax/ModuleSyntax.cs @@ -32,7 +32,11 @@ public ModuleSyntax(IReadOnlyList operations) /// public SyntaxToken EndOfFileToken { get; } = endOfFileToken; - internal void WriteTo(SyntaxWriter writer) + /// + /// Writes this module to the supplied syntax writer. + /// + /// The syntax writer to write to. + public void WriteTo(SyntaxWriter writer) { for (var i = 0; i < Operations.Count; i++) { diff --git a/src/MLIR/Syntax/OperationBodySyntax.cs b/src/MLIR/Syntax/OperationBodySyntax.cs index 6c31228..aeeb0e2 100644 --- a/src/MLIR/Syntax/OperationBodySyntax.cs +++ b/src/MLIR/Syntax/OperationBodySyntax.cs @@ -35,5 +35,5 @@ public GenericOperationBodySyntax GetGenericBody() /// /// Writes the operation body to the supplied syntax writer. /// - public abstract void WriteTo(Text.SyntaxWriter writer, int indentLevel, System.Action writeRegion); + public abstract void WriteTo(Text.SyntaxWriter writer, int indentLevel); } diff --git a/src/MLIR/Syntax/OperationSyntax.cs b/src/MLIR/Syntax/OperationSyntax.cs index e59b199..dde5bf0 100644 --- a/src/MLIR/Syntax/OperationSyntax.cs +++ b/src/MLIR/Syntax/OperationSyntax.cs @@ -1,7 +1,6 @@ namespace MLIR.Syntax; using System.Collections.Generic; -using System; using MLIR.Text; /// @@ -221,11 +220,16 @@ public bool TryGetRawTypeSignature(out RawSyntaxText? rawTypeSignature) /// public bool HasCustomAssemblyBody => Body is not GenericOperationBodySyntax; - internal void WriteTo( + /// + /// Writes this operation to the supplied syntax writer. + /// + /// The syntax writer to write to. + /// The indentation level to use when indentation is synthesized. + /// The fallback leading trivia to use when syntax does not carry explicit trivia. + public void WriteTo( SyntaxWriter writer, int indentLevel, - string defaultLeadingTrivia, - Action writeRegion) + string defaultLeadingTrivia) { if (ResultTokens.Count > 0) { @@ -247,7 +251,7 @@ internal void WriteTo( writer.WriteToken(NameToken, defaultLeadingTrivia, indentLevel); } - Body.WriteTo(writer, indentLevel, writeRegion); + Body.WriteTo(writer, indentLevel); } private static IReadOnlyList CreateValueTokens(IReadOnlyList values) diff --git a/src/MLIR/Syntax/RegionSyntax.cs b/src/MLIR/Syntax/RegionSyntax.cs index f7515b2..f3cb627 100644 --- a/src/MLIR/Syntax/RegionSyntax.cs +++ b/src/MLIR/Syntax/RegionSyntax.cs @@ -1,7 +1,6 @@ namespace MLIR.Syntax; using System.Collections.Generic; -using System; using MLIR.Text; /// @@ -39,16 +38,20 @@ public RegionSyntax(IReadOnlyList blocks) /// public SyntaxToken CloseBraceToken { get; } = closeBraceToken; - internal void WriteTo( + /// + /// Writes this region to the supplied syntax writer. + /// + /// The syntax writer to write to. + /// The indentation level of the containing operation. + public void WriteTo( SyntaxWriter writer, - int indentLevel, - Action writeOperation) + int indentLevel) { writer.WriteToken(OpenBraceToken, " "); foreach (var block in Blocks) { - block.WriteTo(writer, indentLevel, writeOperation); + block.WriteTo(writer, indentLevel); } writer.WriteToken(CloseBraceToken, "\n", indentLevel); diff --git a/src/MLIR/Text/SyntaxWriter.cs b/src/MLIR/Text/SyntaxWriter.cs index 46c8a90..a2e349f 100644 --- a/src/MLIR/Text/SyntaxWriter.cs +++ b/src/MLIR/Text/SyntaxWriter.cs @@ -1,6 +1,5 @@ namespace MLIR.Text; -using System; using System.Text; using MLIR.Syntax; @@ -60,8 +59,7 @@ public void WriteModule(ModuleSyntax module) /// The fallback leading trivia to use when syntax does not carry explicit trivia. public void WriteOperation(OperationSyntax operation, int indentLevel, string defaultLeadingTrivia) { - operation.WriteTo(this, indentLevel, defaultLeadingTrivia, static (writer, region, innerIndentLevel) => - writer.WriteRegion(region, innerIndentLevel)); + operation.WriteTo(this, indentLevel, defaultLeadingTrivia); } /// @@ -71,8 +69,7 @@ public void WriteOperation(OperationSyntax operation, int indentLevel, string de /// The indentation level of the containing operation. public void WriteRegion(RegionSyntax region, int indentLevel) { - region.WriteTo(this, indentLevel, static (writer, operation, operationIndentLevel, operationLeadingTrivia) => - writer.WriteOperation(operation, operationIndentLevel, operationLeadingTrivia)); + region.WriteTo(this, indentLevel); } /// @@ -82,8 +79,7 @@ public void WriteRegion(RegionSyntax region, int indentLevel) /// The indentation level of the containing region. public void WriteBlock(BlockSyntax block, int regionIndentLevel) { - block.WriteTo(this, regionIndentLevel, static (writer, operation, operationIndentLevel, operationLeadingTrivia) => - writer.WriteOperation(operation, operationIndentLevel, operationLeadingTrivia)); + block.WriteTo(this, regionIndentLevel); } /// diff --git a/tests/MLIR.Generators.Tests/DialectGeneratorTests.cs b/tests/MLIR.Generators.Tests/DialectGeneratorTests.cs index d0de9d0..b9850df 100644 --- a/tests/MLIR.Generators.Tests/DialectGeneratorTests.cs +++ b/tests/MLIR.Generators.Tests/DialectGeneratorTests.cs @@ -103,7 +103,7 @@ public void GeneratesOperationBodySyntaxClassForDeclarativeAssemblyFormat() Assert.Contains("return false;", registrationSource); // WriteTo is implemented. - Assert.Contains("public override void WriteTo(Text.SyntaxWriter writer, int indentLevel, System.Action writeRegion)", registrationSource); + Assert.Contains("public override void WriteTo(Text.SyntaxWriter writer, int indentLevel)", registrationSource); } [Fact] diff --git a/tests/MLIR.Tests/ConstructionTests.cs b/tests/MLIR.Tests/ConstructionTests.cs index 8d1e5b9..129cef0 100644 --- a/tests/MLIR.Tests/ConstructionTests.cs +++ b/tests/MLIR.Tests/ConstructionTests.cs @@ -40,7 +40,7 @@ public override bool TryGetGenericBody(out GenericOperationBodySyntax? genericBo return true; } - public override void WriteTo(SyntaxWriter writer, int indentLevel, System.Action writeRegion) + public override void WriteTo(SyntaxWriter writer, int indentLevel) { writer.WriteRaw(Value, " "); writer.WriteToken(ColonToken, " "); diff --git a/tests/MLIR.Tests/ParsingTests.cs b/tests/MLIR.Tests/ParsingTests.cs index 7a32cfa..2e2f3a6 100644 --- a/tests/MLIR.Tests/ParsingTests.cs +++ b/tests/MLIR.Tests/ParsingTests.cs @@ -39,7 +39,7 @@ public override bool TryGetGenericBody(out GenericOperationBodySyntax? genericBo return true; } - public override void WriteTo(SyntaxWriter writer, int indentLevel, System.Action writeRegion) + public override void WriteTo(SyntaxWriter writer, int indentLevel) { writer.WriteRaw(value, " "); writer.WriteToken(this.genericBody.TypeSignatureColonToken ?? new SyntaxToken(":"), " "); diff --git a/tests/MLIR.Tests/SemanticTests.cs b/tests/MLIR.Tests/SemanticTests.cs index 9c109c3..44805e8 100644 --- a/tests/MLIR.Tests/SemanticTests.cs +++ b/tests/MLIR.Tests/SemanticTests.cs @@ -57,7 +57,7 @@ public override bool TryGetGenericBody(out GenericOperationBodySyntax? genericBo return true; } - public override void WriteTo(SyntaxWriter writer, int indentLevel, System.Action writeRegion) + public override void WriteTo(SyntaxWriter writer, int indentLevel) { writer.WriteRaw(Value, " "); writer.WriteToken(ColonToken, " ");