1 |
3
|
krennw
|
/**
|
2 |
|
|
*
|
3 |
|
|
* OOAS Compiler (Deprecated)
|
4 |
|
|
*
|
5 |
|
|
* Copyright 2015, Institute for Software Technology, Graz University of
|
6 |
|
|
* Technology. Portions are copyright 2015 by the AIT Austrian Institute
|
7 |
|
|
* of Technology. All rights reserved.
|
8 |
|
|
*
|
9 |
|
|
* SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
|
10 |
|
|
*
|
11 |
|
|
* Please notice that this version of the OOAS compiler is considered de-
|
12 |
|
|
* precated. Only the Java version is maintained.
|
13 |
|
|
*
|
14 |
|
|
* Contributors:
|
15 |
|
|
* Willibald Krenn (TU Graz/AIT)
|
16 |
|
|
* Stefan Tiran (TU Graz/AIT)
|
17 |
|
|
*/
|
18 |
|
|
|
19 |
|
|
using System;
|
20 |
|
|
using System.Collections.Generic;
|
21 |
|
|
using System.Text;
|
22 |
|
|
|
23 |
|
|
namespace TUG.Mogentes.Codegen
|
24 |
|
|
{
|
25 |
|
|
/// <summary>
|
26 |
|
|
/// Class that is used as text buffer during code emission
|
27 |
|
|
/// </summary>
|
28 |
|
|
public class OoaCodeEmitter
|
29 |
|
|
{
|
30 |
|
|
private StringBuilder output;
|
31 |
|
|
private int indentLevel;
|
32 |
|
|
private int indentTabWidth;
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
public OoaCodeEmitter()
|
36 |
|
|
{
|
37 |
|
|
indentLevel = 0;
|
38 |
|
|
indentTabWidth = 4;
|
39 |
|
|
output = new StringBuilder();
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
public void Indent()
|
43 |
|
|
{
|
44 |
|
|
for (int i = 0; i < indentLevel * indentTabWidth; i++)
|
45 |
|
|
output.Append(" ");
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
public void Append(int num)
|
49 |
|
|
{
|
50 |
|
|
output.Append(num);
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
public void Append(string text)
|
54 |
|
|
{
|
55 |
|
|
output.Append(text);
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
public void AppendLineIncIndent(string text)
|
59 |
|
|
{
|
60 |
|
|
indentLevel++;
|
61 |
|
|
this.AppendLine(text);
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
public void AppendLineDecIndent(string text)
|
65 |
|
|
{
|
66 |
|
|
if (indentLevel > 0)
|
67 |
|
|
{
|
68 |
|
|
indentLevel--;
|
69 |
|
|
output.Remove(output.Length - indentTabWidth, indentTabWidth);
|
70 |
|
|
}
|
71 |
|
|
this.AppendLine(text);
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
|
75 |
|
|
public void AppendLine(string text)
|
76 |
|
|
{
|
77 |
|
|
output.AppendLine(text);
|
78 |
|
|
Indent();
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
public void AppendLine()
|
82 |
|
|
{
|
83 |
|
|
output.AppendLine();
|
84 |
|
|
Indent();
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
public void IncIndent()
|
90 |
|
|
{
|
91 |
|
|
indentLevel++;
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
public void DecIndent()
|
95 |
|
|
{
|
96 |
|
|
indentLevel--;
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
public void Clear()
|
100 |
|
|
{
|
101 |
|
|
output = new StringBuilder();
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
public override string ToString()
|
106 |
|
|
{
|
107 |
|
|
return output.ToString();
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
}
|
111 |
|
|
} |