/** * * OOAS Compiler (Deprecated) * * Copyright 2015, Institute for Software Technology, Graz University of * Technology. Portions are copyright 2015 by the AIT Austrian Institute * of Technology. All rights reserved. * * SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED. * * Please notice that this version of the OOAS compiler is considered de- * precated. Only the Java version is maintained. * * Contributors: * Willibald Krenn (TU Graz/AIT) * Stefan Tiran (TU Graz/AIT) */ using System; using System.Collections.Generic; using System.Text; namespace TUG.Mogentes.Codegen { /// /// Class that is used as text buffer during code emission /// public class OoaCodeEmitter { private StringBuilder output; private int indentLevel; private int indentTabWidth; public OoaCodeEmitter() { indentLevel = 0; indentTabWidth = 4; output = new StringBuilder(); } public void Indent() { for (int i = 0; i < indentLevel * indentTabWidth; i++) output.Append(" "); } public void Append(int num) { output.Append(num); } public void Append(string text) { output.Append(text); } public void AppendLineIncIndent(string text) { indentLevel++; this.AppendLine(text); } public void AppendLineDecIndent(string text) { if (indentLevel > 0) { indentLevel--; output.Remove(output.Length - indentTabWidth, indentTabWidth); } this.AppendLine(text); } public void AppendLine(string text) { output.AppendLine(text); Indent(); } public void AppendLine() { output.AppendLine(); Indent(); } public void IncIndent() { indentLevel++; } public void DecIndent() { indentLevel--; } public void Clear() { output = new StringBuilder(); } public override string ToString() { return output.ToString(); } } }