forked from epi/cito-old
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSourceGenerator.cs
890 lines (802 loc) · 19.2 KB
/
SourceGenerator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
// SourceGenerator.cs - base class for code generators
//
// Copyright (C) 2011-2013 Piotr Fusik
//
// This file is part of CiTo, see http://cito.sourceforge.net
//
// CiTo is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// CiTo is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with CiTo. If not, see http://www.gnu.org/licenses/
using System;
using System.Globalization;
using System.IO;
namespace Foxoft.Ci
{
public delegate TextWriter TextWriterFactory(string filename);
public abstract class SourceGenerator : ICiStatementVisitor
{
public string OutputFile;
public TextWriterFactory CreateTextWriter = CreateFileWriter;
TextWriter Writer;
protected int Indent = 0;
bool AtLineStart = true;
static TextWriter CreateFileWriter(string filename)
{
TextWriter w = File.CreateText(filename);
w.NewLine = "\n";
return w;
}
void StartLine()
{
if (this.AtLineStart) {
for (int i = 0; i < this.Indent; i++)
this.Writer.Write('\t');
this.AtLineStart = false;
}
}
/// <summary>
/// Writes the ToString() value of the object
/// </summary>
protected void Write(object value)
{
StartLine();
if (value is float)
{
float f = (float)value;
this.Writer.Write(f.ToString(CultureInfo.InvariantCulture));//always dot as decimal seperator
}
else
{
this.Writer.Write(value.ToString());
}
}
protected static string ToCamelCase(string s)
{
return char.ToLowerInvariant(s[0]) + s.Substring(1);
}
protected void WriteCamelCase(string s)
{
StartLine();
this.Writer.Write(char.ToLowerInvariant(s[0]));
this.Writer.Write(s.Substring(1));
}
protected void WriteUppercaseWithUnderscores(string s)
{
StartLine();
bool first = true;
foreach (char c in s) {
if (char.IsUpper(c) && !first) {
this.Writer.Write('_');
this.Writer.Write(c);
}
else
this.Writer.Write(char.ToUpperInvariant(c));
first = false;
}
}
protected void WriteLowercaseWithUnderscores(string s)
{
StartLine();
bool first = true;
foreach (char c in s) {
if (char.IsUpper(c)) {
if (!first)
this.Writer.Write('_');
this.Writer.Write(char.ToLowerInvariant(c));
}
else
this.Writer.Write(c);
first = false;
}
}
protected void WriteLine()
{
this.Writer.WriteLine();
this.AtLineStart = true;
}
protected void WriteLine(string s)
{
StartLine();
this.Writer.WriteLine(s);
this.AtLineStart = true;
}
protected void WriteLine(string format, params object[] args)
{
StartLine();
this.Writer.WriteLine(format, args);
this.AtLineStart = true;
}
#region JavaDoc
void WriteDoc(string text)
{
foreach (char c in text) {
switch (c) {
case '&': Write("&"); break;
case '<': Write("<"); break;
case '>': Write(">"); break;
case '\n': WriteLine(); Write(" * "); break;
default: Write(c); break;
}
}
}
void Write(CiDocPara para)
{
foreach (CiDocInline inline in para.Children) {
CiDocText text = inline as CiDocText;
if (text != null) {
WriteDoc(text.Text);
continue;
}
CiDocCode code = inline as CiDocCode;
if (code != null) {
Write("<code>");
WriteDoc(code.Text);
Write("</code>");
continue;
}
throw new ArgumentException(inline.GetType().Name);
}
}
void Write(CiDocBlock block)
{
CiDocList list = block as CiDocList;
if (list != null) {
WriteLine();
WriteLine(" * <ul>");
foreach (CiDocPara item in list.Items) {
Write(" * <li>");
Write(item);
WriteLine("</li>");
}
WriteLine(" * </ul>");
Write(" * ");
return;
}
Write((CiDocPara) block);
}
void WriteDontClose(CiCodeDoc doc)
{
WriteLine("/**");
Write(" * ");
Write(doc.Summary);
if (doc.Details.Length > 0) {
WriteLine();
Write(" * ");
foreach (CiDocBlock block in doc.Details)
Write(block);
}
WriteLine();
}
protected virtual void Write(CiCodeDoc doc)
{
if (doc != null) {
WriteDontClose(doc);
WriteLine(" */");
}
}
protected void WriteDoc(CiMethod method)
{
if (method.Documentation != null) {
WriteDontClose(method.Documentation);
foreach (CiParam param in method.Signature.Params) {
if (param.Documentation != null) {
Write(" * @param ");
Write(param.Name);
Write(' ');
Write(param.Documentation.Summary);
WriteLine();
}
}
WriteLine(" */");
}
}
#endregion JavaDoc
protected virtual void WriteBanner()
{
WriteLine("// Generated automatically with \"cito\". Do not edit.");
}
protected void CreateFile(string filename)
{
this.Writer = CreateTextWriter(filename);
WriteBanner();
}
protected void CloseFile()
{
this.Writer.Close();
}
protected void OpenBlock()
{
WriteLine("{");
this.Indent++;
}
protected void CloseBlock()
{
this.Indent--;
WriteLine("}");
}
protected void WriteInitializer(CiArrayType type)
{
for (; type != null; type = type.ElementType as CiArrayType) {
Write('[');
CiArrayStorageType storageType = type as CiArrayStorageType;
if (storageType != null) {
if (storageType.LengthExpr != null)
Write(storageType.LengthExpr);
else
Write(storageType.Length);
}
Write(']');
}
}
protected void WriteContent(Array array)
{
for (int i = 0; i < array.Length; i++) {
if (i > 0) {
if (i % 16 == 0) {
WriteLine(",");
Write('\t');
}
else
Write(", ");
}
WriteConst(array.GetValue(i));
}
}
protected virtual void WriteConst(object value)
{
if (value is bool)
Write((bool)value ? "true" : "false");
else if (value is byte || value is int)
Write(value);
else if (value is float)
{
Write(value);
Write('f');//f suffix for float
}
else if (value is string)
{
Write('"');
foreach (char c in (string)value)
{
WriteStringChar(c);
}
Write('"');
}
else if (value is CiEnumValue)
{
CiEnumValue ev = (CiEnumValue)value;
Write(ev.Type.Name);
Write('.');
Write(ev.Name);
}
else if (value is Array)
{
Write("{ ");
WriteContent((Array)value);
Write(" }");
}
else if (value == null)
Write("null");
else
throw new ArgumentException("unable to parse type " + value.GetType());
}
protected virtual void WriteStringChar(char c)
{
switch (c)
{
case '\t': Write("\\t"); break;
case '\r': Write("\\r"); break;
case '\n': Write("\\n"); break;
case '\\': Write("\\\\"); break;
case '\"': Write("\\\""); break;
default: Write(c); break;
}
}
protected virtual CiPriority GetPriority(CiExpr expr)
{
if (expr is CiConstExpr
|| expr is CiConstAccess
|| expr is CiVarAccess
|| expr is CiFieldAccess
|| expr is CiPropertyAccess
|| expr is CiArrayAccess
|| expr is CiMethodCall
|| expr is CiBinaryResourceExpr
|| expr is CiNewExpr) // ?
return CiPriority.Postfix;
if (expr is CiUnaryExpr
|| expr is CiCondNotExpr
|| expr is CiPostfixExpr) // ?
return CiPriority.Prefix;
if (expr is CiCoercion)
return GetPriority((CiExpr) ((CiCoercion) expr).Inner);
if (expr is CiBinaryExpr) {
switch (((CiBinaryExpr) expr).Op) {
case CiToken.Asterisk:
case CiToken.Slash:
case CiToken.Mod:
return CiPriority.Multiplicative;
case CiToken.Plus:
case CiToken.Minus:
return CiPriority.Additive;
case CiToken.ShiftLeft:
case CiToken.ShiftRight:
return CiPriority.Shift;
case CiToken.Less:
case CiToken.LessOrEqual:
case CiToken.Greater:
case CiToken.GreaterOrEqual:
return CiPriority.Ordering;
case CiToken.Equal:
case CiToken.NotEqual:
return CiPriority.Equality;
case CiToken.And:
return CiPriority.And;
case CiToken.Xor:
return CiPriority.Xor;
case CiToken.Or:
return CiPriority.Or;
case CiToken.CondAnd:
return CiPriority.CondAnd;
case CiToken.CondOr:
return CiPriority.CondOr;
default:
throw new ArgumentException(((CiBinaryExpr) expr).Op.ToString());
}
}
if (expr is CiCondExpr)
return CiPriority.CondExpr;
throw new ArgumentException(expr.GetType().Name);
}
protected void WriteChild(CiPriority parentPriority, CiExpr child)
{
if (GetPriority(child) < parentPriority) {
Write('(');
Write(child);
Write(')');
}
else
Write(child);
}
protected void WriteChild(CiExpr parent, CiExpr child)
{
WriteChild(GetPriority(parent), child);
}
protected void WriteNonAssocChild(CiPriority parentPriority, CiExpr child)
{
if (GetPriority(child) <= parentPriority) {
Write('(');
Write(child);
Write(')');
}
else
Write(child);
}
protected void WriteNonAssocChild(CiExpr parent, CiExpr child)
{
WriteNonAssocChild(GetPriority(parent), child);
}
protected void WriteSum(CiExpr left, CiExpr right)
{
Write(new CiBinaryExpr { Left = left, Op = CiToken.Plus, Right = right });
}
protected virtual void WriteName(CiConst konst)
{
Write(konst.GlobalName ?? konst.Name);
}
protected virtual void Write(CiVarAccess expr)
{
Write(expr.Var.Name);
}
protected virtual void Write(CiFieldAccess expr)
{
WriteChild(expr, expr.Obj);
Write('.');
Write(expr.Field.Name);
}
protected abstract void Write(CiPropertyAccess expr);
protected virtual void Write(CiArrayAccess expr)
{
WriteChild(expr, expr.Array);
Write('[');
Write(expr.Index);
Write(']');
}
protected virtual void WriteName(CiMethod method)
{
Write(method.Name);
}
protected virtual void WriteDelegateCall(CiExpr expr)
{
Write(expr);
}
protected void WriteMulDiv(CiPriority firstPriority, CiMethodCall expr)
{
WriteChild(firstPriority, expr.Obj);
Write(" * ");
WriteChild(CiPriority.Multiplicative, expr.Arguments[0]);
Write(" / ");
WriteNonAssocChild(CiPriority.Multiplicative, expr.Arguments[1]);
Write(')');
}
protected void WriteArguments(CiMethodCall expr)
{
Write('(');
bool first = true;
foreach (CiExpr arg in expr.Arguments)
{
if (first)
first = false;
else
Write(", ");
Write(arg);
}
Write(')');
}
protected virtual void Write(CiMethodCall expr)
{
if (expr.Method != null) {
if (expr.Obj != null)
Write(expr.Obj);
else
Write(expr.Method.Class.Name);
Write('.');
WriteName(expr.Method);
}
else
WriteDelegateCall(expr.Obj);
WriteArguments(expr);
}
void Write(CiUnaryExpr expr)
{
switch (expr.Op) {
case CiToken.Increment: Write("++"); break;
case CiToken.Decrement: Write("--"); break;
case CiToken.Minus: Write('-'); break;
case CiToken.Not: Write('~'); break;
default: throw new ArgumentException(expr.Op.ToString());
}
WriteChild(expr, expr.Inner);
}
void Write(CiCondNotExpr expr)
{
Write('!');
WriteChild(expr, expr.Inner);
}
void Write(CiPostfixExpr expr)
{
WriteChild(expr, expr.Inner);
switch (expr.Op) {
case CiToken.Increment: Write("++"); break;
case CiToken.Decrement: Write("--"); break;
default: throw new ArgumentException(expr.Op.ToString());
}
}
protected void WriteOp(CiBinaryExpr expr)
{
switch (expr.Op) {
case CiToken.Plus: Write(" + "); break;
case CiToken.Minus: Write(" - "); return;
case CiToken.Asterisk: Write(" * "); break;
case CiToken.Slash: Write(" / "); break;
case CiToken.Mod: Write(" % "); break;
case CiToken.ShiftLeft: Write(" << "); break;
case CiToken.ShiftRight: Write(" >> "); break;
case CiToken.Less: Write(" < "); break;
case CiToken.LessOrEqual: Write(" <= "); break;
case CiToken.Greater: Write(" > "); break;
case CiToken.GreaterOrEqual: Write(" >= "); break;
case CiToken.Equal: Write(" == "); break;
case CiToken.NotEqual: Write(" != "); break;
case CiToken.And: Write(" & "); break;
case CiToken.Or: Write(" | "); break;
case CiToken.Xor: Write(" ^ "); break;
case CiToken.CondAnd: Write(" && "); break;
case CiToken.CondOr: Write(" || "); break;
default: throw new ArgumentException(expr.Op.ToString());
}
}
protected virtual void Write(CiBinaryExpr expr)
{
WriteChild(expr, expr.Left);
switch (expr.Op) {
case CiToken.Plus:
case CiToken.Asterisk:
case CiToken.Less:
case CiToken.LessOrEqual:
case CiToken.Greater:
case CiToken.GreaterOrEqual:
case CiToken.Equal:
case CiToken.NotEqual:
case CiToken.And:
case CiToken.Or:
case CiToken.Xor:
case CiToken.CondAnd:
case CiToken.CondOr:
WriteOp(expr);
WriteChild(expr, expr.Right);
break;
case CiToken.Minus:
case CiToken.Slash:
case CiToken.Mod:
case CiToken.ShiftLeft:
case CiToken.ShiftRight:
WriteOp(expr);
WriteNonAssocChild(expr, expr.Right);
break;
default:
throw new ArgumentException(expr.Op.ToString());
}
}
protected virtual void Write(CiCondExpr expr)
{
WriteNonAssocChild(expr, expr.Cond);
Write(" ? ");
WriteChild(expr, expr.OnTrue);
Write(" : ");
WriteChild(expr, expr.OnFalse);
}
protected virtual void WriteName(CiBinaryResource resource)
{
Write("CiBinaryResource_");
foreach (char c in resource.Name)
Write(CiLexer.IsLetter(c) ? c : '_');
}
protected virtual void Write(CiBinaryResourceExpr expr)
{
WriteName(expr.Resource);
}
protected abstract void WriteNew(CiType type);
protected void WriteInline(CiMaybeAssign expr)
{
if (expr is CiExpr)
Write((CiExpr) expr);
else
Visit((CiAssign) expr);
}
protected virtual void Write(CiCoercion expr)
{
WriteInline(expr.Inner);
}
protected void Write(CiExpr expr)
{
if (expr is CiConstExpr)
WriteConst(((CiConstExpr) expr).Value);
else if (expr is CiConstAccess)
WriteName(((CiConstAccess) expr).Const);
else if (expr is CiVarAccess)
Write((CiVarAccess) expr);
else if (expr is CiFieldAccess)
Write((CiFieldAccess) expr);
else if (expr is CiPropertyAccess)
Write((CiPropertyAccess) expr);
else if (expr is CiArrayAccess)
Write((CiArrayAccess) expr);
else if (expr is CiMethodCall)
Write((CiMethodCall) expr);
else if (expr is CiUnaryExpr)
Write((CiUnaryExpr) expr);
else if (expr is CiCondNotExpr)
Write((CiCondNotExpr) expr);
else if (expr is CiPostfixExpr)
Write((CiPostfixExpr) expr);
else if (expr is CiBinaryExpr)
Write((CiBinaryExpr) expr);
else if (expr is CiCondExpr)
Write((CiCondExpr) expr);
else if (expr is CiBinaryResourceExpr)
Write((CiBinaryResourceExpr) expr);
else if (expr is CiNewExpr)
WriteNew(((CiNewExpr) expr).NewType);
else if (expr is CiCoercion)
Write((CiCoercion) expr);
else
throw new ArgumentException(expr.ToString());
}
protected void Write(ICiStatement[] statements, int length)
{
for (int i = 0; i < length; i++)
Write(statements[i]);
}
protected virtual void Write(ICiStatement[] statements)
{
Write(statements, statements.Length);
}
public virtual void Visit(CiBlock block)
{
OpenBlock();
Write(block.Statements);
CloseBlock();
}
protected virtual void WriteChild(ICiStatement stmt)
{
if (stmt is CiBlock) {
Write(' ');
Write((CiBlock) stmt);
}
else {
WriteLine();
this.Indent++;
Write(stmt);
this.Indent--;
}
}
public virtual void Visit(CiExpr expr)
{
Write(expr);
}
public abstract void Visit(CiVar stmt);
public virtual void Visit(CiAssign assign)
{
Write(assign.Target);
switch (assign.Op) {
case CiToken.Assign: Write(" = "); break;
case CiToken.AddAssign: Write(" += "); break;
case CiToken.SubAssign: Write(" -= "); break;
case CiToken.MulAssign: Write(" *= "); break;
case CiToken.DivAssign: Write(" /= "); break;
case CiToken.ModAssign: Write(" %= "); break;
case CiToken.ShiftLeftAssign: Write(" <<= "); break;
case CiToken.ShiftRightAssign: Write(" >>= "); break;
case CiToken.AndAssign: Write(" &= "); break;
case CiToken.OrAssign: Write(" |= "); break;
case CiToken.XorAssign: Write(" ^= "); break;
default: throw new ArgumentException(assign.Op.ToString());
}
WriteInline(assign.Source);
}
public virtual void Visit(CiDelete stmt)
{
// do nothing - assume automatic garbage collector
}
public virtual void Visit(CiBreak stmt)
{
WriteLine("break;");
}
public virtual void Visit(CiConst stmt)
{
}
public virtual void Visit(CiContinue stmt)
{
WriteLine("continue;");
}
public virtual void Visit(CiDoWhile stmt)
{
Write("do");
WriteChild(stmt.Body);
Write("while (");
Write(stmt.Cond);
WriteLine(");");
}
public virtual void Visit(CiFor stmt)
{
Write("for (");
if (stmt.Init != null)
stmt.Init.Accept(this);
Write(';');
if (stmt.Cond != null) {
Write(' ');
Write(stmt.Cond);
}
Write(';');
if (stmt.Advance != null) {
Write(' ');
stmt.Advance.Accept(this);
}
Write(')');
WriteChild(stmt.Body);
}
protected virtual void WriteIfOnTrue(CiIf stmt)
{
WriteChild(stmt.OnTrue);
}
public virtual void Visit(CiIf stmt)
{
Write("if (");
Write(stmt.Cond);
Write(')');
WriteIfOnTrue(stmt);
if (stmt.OnFalse != null) {
Write("else");
if (stmt.OnFalse is CiIf) {
Write(' ');
Write(stmt.OnFalse);
}
else
WriteChild(stmt.OnFalse);
}
}
void ICiStatementVisitor.Visit(CiNativeBlock statement)
{
Write(statement.Content);
}
public virtual void Visit(CiReturn stmt)
{
if (stmt.Value == null)
WriteLine("return;");
else {
Write("return ");
Write(stmt.Value);
WriteLine(";");
}
}
protected virtual void StartSwitch(CiSwitch stmt)
{
}
protected virtual void StartCase(ICiStatement stmt)
{
}
protected virtual void WriteFallthrough(CiExpr expr)
{
}
protected virtual void EndSwitch(CiSwitch stmt)
{
}
public virtual void Visit(CiSwitch stmt)
{
Write("switch (");
Write(stmt.Value);
WriteLine(") {");
StartSwitch(stmt);
foreach (CiCase kase in stmt.Cases) {
foreach (object value in kase.Values) {
Write("case ");
WriteConst(value);
WriteLine(":");
}
this.Indent++;
StartCase(kase.Body[0]);
Write(kase.Body);
if (kase.Fallthrough)
WriteFallthrough(kase.FallthroughTo);
this.Indent--;
}
if (stmt.DefaultBody != null) {
WriteLine("default:");
this.Indent++;
StartCase(stmt.DefaultBody[0]);
Write(stmt.DefaultBody);
this.Indent--;
}
EndSwitch(stmt);
WriteLine("}");
}
public abstract void Visit(CiThrow stmt);
public virtual void Visit(CiWhile stmt)
{
Write("while (");
Write(stmt.Cond);
Write(')');
WriteChild(stmt.Body);
}
protected void Write(ICiStatement stmt)
{
stmt.Accept(this);
if ((stmt is CiMaybeAssign || stmt is CiVar) && !this.AtLineStart)
WriteLine(";");
}
protected void OpenClass(bool isAbstract, CiClass klass, string extendsClause)
{
if (isAbstract)
Write("abstract ");
Write("class ");
Write(klass.Name);
if (klass.BaseClass != null) {
Write(extendsClause);
Write(klass.BaseClass.Name);
}
WriteLine();
OpenBlock();
}
public abstract void Write(CiProgram prog);
}
}