5 namespace CodeGeneration {
17 #region WriteComment()
25 this.WriteComment(0, msg);
29 this.WriteLine(
"{0}// {1}", this.Indentation(indent), msg);
33 #region Write() & WriteLine() & indentation
38 public void WriteLine(
int indent,
string format, params Object[] obj) {
39 this.WriteIndentation(indent);
40 this.WriteLine(format, obj);
43 public void WriteLine(
string format, params Object[] obj) {
44 this.output.WriteLine(format, obj);
46 debugMemoryLog.AppendFormat(format, obj);
47 debugMemoryLog.AppendLine();
52 public void Write(
string format, params Object[] obj) {
53 this.output.Write(format, obj);
55 debugMemoryLog.AppendFormat(format, obj);
60 public void Write(
int indent,
string format, params Object[] obj) {
61 this.WriteIndentation(indent);
62 this.Write(format, obj);
65 public void Write(
int indent,
string str) {
66 this.WriteIndentation(indent);
72 this.output.Write(str);
74 debugMemoryLog.Append(str);
79 this.Write(indent, str);
89 this.output.WriteLine();
91 debugMemoryLog.AppendLine();
97 this.Write(this.Indentation(indent));
100 private string Indentation(
int indent) {
101 return indent > 0 ?
" ".PadLeft(indent * 3) :
"";
106 this.WriteLine(
".assembly extern mscorlib {}");
107 this.WriteLine(
".assembly {0} {{}}", fileName);
110 #region WriteClassVisibility
116 this.Write(indent,
".class ");
118 if ( ( mask &
Modifier.Public ) != 0 )
119 this.
Write(
"public ");
121 if ( ( mask &
Modifier.Internal ) != 0 )
122 this.
Write(
"private ");
124 if ( ( mask &
Modifier.Abstract ) != 0 )
125 this.
Write(
"abstract ");
126 else if ( ( mask &
Modifier.Static ) != 0 )
127 this.
Write(
"abstract sealed ");
133 this.WriteLine(
".module {0}.exe", fileName);
137 this.WriteCloseBrace();
138 this.WriteComment(
"End of class " + className);
142 #region WriteLNInterfaceHeader()
163 this.Write(indent,
".class interface ");
165 if ( ( mask &
Modifier.Public ) != 0 )
166 this.
Write(
"public abstract ");
168 if ( ( mask &
Modifier.Internal ) != 0 )
169 this.
Write(
"private abstract ");
171 this.Write(
"auto ansi {0} ", name);
174 this.Write(
"implements ");
175 for (
int i = 0; i < type.InterfaceList.Count - 1; i++ ) {
178 this.Write(
"[mscorlib]");
179 this.Write(
"{0}, ", type.InterfaceList[i].FullName);
182 this.Write(
"[mscorlib]");
184 this.Write(
"{0}", type.InterfaceList[type.InterfaceList.Count - 1].FullName);
219 internal void WriteField(
int indent,
string name,
FieldType type,
bool constantField) {
220 Modifier mask = type.MemberInfo.ModifierMask;
222 this.Write(indent,
".field ");
224 if ( ( mask &
Modifier.Public ) != 0 )
225 this.
Write(
"public ");
227 if ( ( mask &
Modifier.Private ) != 0 )
228 this.
Write(
"private ");
230 if ( ( mask & (
Modifier.Protected |
Modifier.Internal ) ) == ( Modifier.Protected | Modifier.Internal ) )
231 this.Write(
"famorassem ");
233 if ( ( mask &
Modifier.Internal ) != 0 )
234 this.
Write(
"assembly ");
235 if ( ( mask &
Modifier.Protected ) != 0 )
236 this.
Write(
"family ");
238 if ( ( mask &
Modifier.Static ) != 0 )
239 this.
Write(
"static ");
240 else if ( constantField )
241 this.Write(
"static literal ");
244 this.WriteType(TypeVariable.NewTypeVariable);
246 this.WriteType(type.FieldTypeExpression);
247 this.Write(
" {0}", name);
255 this.Write(
" = {0}(", type.ILType());
266 this.Write(type.ILType());
271 #region WriteNamespace()
280 this.Write(
".namespace {0}", name);
285 #region OpenBrace & CloseBrace()
292 this.Write(indent,
"}");
296 this.WriteCloseBrace(0);
299 this.WriteCloseBrace(indent);
304 this.Write(indent,
"{");
308 this.WriteOpenBrace(0);
311 this.WriteOpenBrace(indent);
317 #region WriteEntryPoint()
320 this.Write(
".entrypoint");
325 #region WriteAuxiliarLocalVariable()
333 this.Write(
".locals init({0} {1})", type, id);
void WriteLine(int indent, string format, params Object[] obj)
Writes a line terminator in the text stream
void WriteModule(string fileName)
void Write(string format, params Object[] obj)
void Write(int indent, string str)
virtual void WriteComment(string msg)
Writes the specified message.
virtual void WriteAuxiliarLocalVariable(string id, string type)
Writes the information of local variables.
void Write(int indent, string format, params Object[] obj)
Represents a interface type.
Abstract class that represents all different types.
Represents a generic type expression
System.Text.StringBuilder StringBuilder
void WriteLineOpenBrace(int indent)
virtual void WriteLNInterfaceHeader(int indent, string name, InterfaceType type)
Writes the interface header
void WriteCloseBrace(int indent)
Writes the termination token. Requires the output text would be formatted, with tabs for example...
void WriteLineCloseBrace(int indent)
ILStatementsCodeGeneration(TextWriter output)
virtual void WriteComment(int indent, string msg)
TypeExpression FieldTypeExpression
Gets the field type.
List< InterfaceType > InterfaceList
Gets the list of interfaces
Modifier
Indicates differents modifiers to use in class (only public, internal or static), fields or methods...
void WriteIndentation(int indent)
StringBuilder debugMemoryLog
void WriteEndOfClass(string className)
virtual void WriteEntryPoint()
void WriteLine(int indent, string str)
void WriteOpenBrace(int indent)
virtual void WriteClassVisibility(int indent, string name, ClassType type)
void WriteLine(string format, params Object[] obj)
void WriteLNAssemblyDirective(string fileName)
void WriteNamespace(string name)
Writes the namespace header.
void WriteLine(string str)