2022-05-31 22:12:46 +02:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Horizon.Generators
|
|
|
|
|
{
|
|
|
|
|
class CodeGenerator
|
|
|
|
|
{
|
2023-01-18 23:25:16 +01:00
|
|
|
|
private const int IndentLength = 4;
|
|
|
|
|
|
2022-05-31 22:12:46 +02:00
|
|
|
|
private readonly StringBuilder _sb;
|
2023-01-18 23:25:16 +01:00
|
|
|
|
private int _currentIndentCount;
|
2022-05-31 22:12:46 +02:00
|
|
|
|
|
|
|
|
|
public CodeGenerator()
|
|
|
|
|
{
|
|
|
|
|
_sb = new StringBuilder();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void EnterScope(string header = null)
|
|
|
|
|
{
|
|
|
|
|
if (header != null)
|
|
|
|
|
{
|
|
|
|
|
AppendLine(header);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AppendLine("{");
|
|
|
|
|
IncreaseIndentation();
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
|
public void LeaveScope(string suffix = "")
|
2022-05-31 22:12:46 +02:00
|
|
|
|
{
|
|
|
|
|
DecreaseIndentation();
|
2023-01-04 23:15:45 +01:00
|
|
|
|
AppendLine($"}}{suffix}");
|
2022-05-31 22:12:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void IncreaseIndentation()
|
|
|
|
|
{
|
2023-01-18 23:25:16 +01:00
|
|
|
|
_currentIndentCount++;
|
2022-05-31 22:12:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DecreaseIndentation()
|
|
|
|
|
{
|
2023-01-18 23:25:16 +01:00
|
|
|
|
if (_currentIndentCount - 1 >= 0)
|
|
|
|
|
{
|
|
|
|
|
_currentIndentCount--;
|
|
|
|
|
}
|
2022-05-31 22:12:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AppendLine()
|
|
|
|
|
{
|
|
|
|
|
_sb.AppendLine();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AppendLine(string text)
|
|
|
|
|
{
|
2023-01-18 23:25:16 +01:00
|
|
|
|
_sb.Append(' ', IndentLength * _currentIndentCount);
|
|
|
|
|
_sb.AppendLine(text);
|
2022-05-31 22:12:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return _sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|