Fix blocks not being printed when wrapped in AssignmentExpressions

This commit is contained in:
HoLLy 2019-11-23 22:23:24 +01:00
Родитель c55d5b98da
Коммит f8249a5ef0
4 изменённых файлов: 19 добавлений и 6 удалений

Просмотреть файл

@ -141,17 +141,17 @@ namespace WasmLib.Decompilation
}
// TODO: support comments
if (expression is GenericExpression ge && ge.Block1 != null) {
if (expression is IHasBlocks blocks && blocks.Block1 != null) {
output.WriteLine(new string('\t', tabCount) + stringRepresentation + " {");
OutputAsCode(ge.Block1, output, tabCount + 1, varCounts);
OutputAsCode(blocks.Block1, output, tabCount + 1, varCounts);
if (ge.Block2 == null) {
if (blocks.Block2 == null) {
output.WriteLine(new string('\t', tabCount) + "}");
}
else {
output.WriteLine(new string('\t', tabCount) + "} else {");
OutputAsCode(ge.Block2, output, tabCount + 1, varCounts);
OutputAsCode(blocks.Block2, output, tabCount + 1, varCounts);
output.WriteLine(new string('\t', tabCount) + "}");
}
}

Просмотреть файл

@ -1,13 +1,16 @@
using Rivers;
using WasmLib.FileFormat;
using WasmLib.Utils;
namespace WasmLib.Decompilation.SourceCode
{
public class AssignmentExpression : IExpression
public class AssignmentExpression : IExpression, IHasBlocks
{
public IExpression BaseExpression { get; }
public VariableReferenceExpression Reference { get; }
public string Name { get; }
public Graph? Block1 => (BaseExpression as IHasBlocks)?.Block1;
public Graph? Block2 => (BaseExpression as IHasBlocks)?.Block2;
public AssignmentExpression(IExpression baseExpression, ValueKind type, int index)
{

Просмотреть файл

@ -5,7 +5,7 @@ using WasmLib.Utils;
namespace WasmLib.Decompilation.SourceCode
{
public class GenericExpression : IExpression
public class GenericExpression : IExpression, IHasBlocks
{
public IntermediateInstruction BaseInstruction { get; }
public IExpression[]? Parameters { get; }

Просмотреть файл

@ -0,0 +1,10 @@
using Rivers;
namespace WasmLib.Decompilation.SourceCode
{
public interface IHasBlocks
{
Graph? Block1 { get; }
Graph? Block2 { get; }
}
}