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