mirror of
https://github.com/ZuneDev/ZuneUIXTools.git
synced 2026-07-27 13:11:59 -07:00
51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using Microsoft.CodeAnalysis.CSharp;
|
|||
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
|
||
|
|
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||
|
|
|
||
|
|
namespace Microsoft.Iris.DecompXml;
|
||
|
|
|
||
|
|
internal class CodeBlockInfo
|
||
|
|
{
|
||
|
|
public CodeBlockInfo(uint startOffset, uint endOffset, SyntaxKind kind, ExpressionSyntax expression = null)
|
||
|
|
{
|
||
|
|
StartOffset = startOffset;
|
||
|
|
EndOffset = endOffset;
|
||
|
|
Kind = kind;
|
||
|
|
Expression = expression;
|
||
|
|
}
|
||
|
|
|
||
|
|
public uint StartOffset { get; init; }
|
||
|
|
|
||
|
|
public uint EndOffset { get; init; }
|
||
|
|
|
||
|
|
public SyntaxKind Kind { get; init; }
|
||
|
|
|
||
|
|
public ExpressionSyntax Expression { get; init; }
|
||
|
|
|
||
|
|
public List<StatementSyntax> Statements { get; } = [];
|
||
|
|
|
||
|
|
public void FinalizeBlock(CodeBlockInfo parentBlock)
|
||
|
|
{
|
||
|
|
var blockBody = Block(Statements);
|
||
|
|
|
||
|
|
switch (Kind)
|
||
|
|
{
|
||
|
|
case SyntaxKind.IfStatement:
|
||
|
|
var ifStatement = IfStatement(Expression, blockBody);
|
||
|
|
parentBlock.Statements.Add(ifStatement);
|
||
|
|
break;
|
||
|
|
|
||
|
|
case SyntaxKind.ElseClause:
|
||
|
|
var elseClause = ElseClause(blockBody);
|
||
|
|
var ifElseBlock = (IfStatementSyntax)parentBlock.Statements[^1];
|
||
|
|
parentBlock.Statements[^1] = ifElseBlock.WithElse(elseClause);
|
||
|
|
break;
|
||
|
|
|
||
|
|
default:
|
||
|
|
throw new System.NotImplementedException($"Unrecognized code block kind '{Kind}'");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|