diff --git a/src/Generator/Generators/Template.cs b/src/Generator/Generators/Template.cs index 8ae9145c..6cc466d5 100644 --- a/src/Generator/Generators/Template.cs +++ b/src/Generator/Generators/Template.cs @@ -1,76 +1,26 @@ -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Cxxi.Generators +namespace Cxxi.Generators { - public abstract class TextTemplate + public abstract class TextTemplate : TextGenerator { private const uint DefaultIndent = 4; private const uint MaxIndent = 80; - public Generator Generator { get; set; } - public DriverOptions DriverOptions { get; set; } + public Driver Driver { get; set; } + public DriverOptions Options { get; set; } public Library Library { get; set; } public ILibrary Transform; - public TranslationUnit Module { get; set; } + public TranslationUnit unit { get; set; } public abstract string FileExtension { get; } - protected abstract void Generate(); - - protected StringBuilder Builder; - protected Stack CurrentIndent; - - private bool isStartOfLine; - - protected TextTemplate() - { - Builder = new StringBuilder(); - CurrentIndent = new Stack(); - isStartOfLine = true; - } - - public void Write(string msg, params object[] args) - { - if (isStartOfLine) - Builder.Append(new string(' ', (int)CurrentIndent.Sum(u => u))); - - if (args.Length > 0) - msg = string.Format(msg, args); - - if (msg.Length > 0) - isStartOfLine = false; - - Builder.Append(msg); - } - - public void WriteLine(string msg, params object[] args) - { - Write(msg, args); - NewLine(); - } - - public void NewLine() - { - Builder.AppendLine(string.Empty); - isStartOfLine = true; - } - - public void PushIndent(uint indent = DefaultIndent) - { - CurrentIndent.Push(indent); - } - - public void PopIndent() - { - CurrentIndent.Pop(); - } + public abstract void Generate(); - public override string ToString() + protected TextTemplate(Driver driver, TranslationUnit unit) { - Builder.Clear(); - Generate(); - return Builder.ToString(); + Driver = driver; + Options = driver.Options; + Library = driver.Library; + Transform = driver.Transform; + this.unit = unit; } } } \ No newline at end of file