CodeGenerator.cs 1.2 KB

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