CodeGenerator.cs
1 using System.Text; 2 3 namespace Ryujinx.Horizon.Kernel.Generators 4 { 5 class CodeGenerator 6 { 7 private const string Indent = " "; 8 private readonly StringBuilder _sb; 9 private string _currentIndent; 10 11 public CodeGenerator() 12 { 13 _sb = new StringBuilder(); 14 } 15 16 public void EnterScope(string header = null) 17 { 18 if (header != null) 19 { 20 AppendLine(header); 21 } 22 23 AppendLine("{"); 24 IncreaseIndentation(); 25 } 26 27 public void LeaveScope() 28 { 29 DecreaseIndentation(); 30 AppendLine("}"); 31 } 32 33 public void IncreaseIndentation() 34 { 35 _currentIndent += Indent; 36 } 37 38 public void DecreaseIndentation() 39 { 40 _currentIndent = _currentIndent.Substring(0, _currentIndent.Length - Indent.Length); 41 } 42 43 public void AppendLine() 44 { 45 _sb.AppendLine(); 46 } 47 48 public void AppendLine(string text) 49 { 50 _sb.AppendLine(_currentIndent + text); 51 } 52 53 public override string ToString() 54 { 55 return _sb.ToString(); 56 } 57 } 58 }