aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Horizon.Kernel.Generators/CodeGenerator.cs
blob: 80a33c66cf9e9722b3587d840e65dce17f44d77d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System.Text;

namespace Ryujinx.Horizon.Generators
{
    class CodeGenerator
    {
        private const string Indent = "    ";
        private readonly StringBuilder _sb;
        private string _currentIndent;

        public CodeGenerator()
        {
            _sb = new StringBuilder();
        }

        public void EnterScope(string header = null)
        {
            if (header != null)
            {
                AppendLine(header);
            }

            AppendLine("{");
            IncreaseIndentation();
        }

        public void LeaveScope()
        {
            DecreaseIndentation();
            AppendLine("}");
        }

        public void IncreaseIndentation()
        {
            _currentIndent += Indent;
        }

        public void DecreaseIndentation()
        {
            _currentIndent = _currentIndent.Substring(0, _currentIndent.Length - Indent.Length);
        }

        public void AppendLine()
        {
            _sb.AppendLine();
        }

        public void AppendLine(string text)
        {
            _sb.AppendLine(_currentIndent + text);
        }

        public override string ToString()
        {
            return _sb.ToString();
        }
    }
}