source: branches/xpascal/Generator.pas

Last change on this file was 224, checked in by chronos, 11 months ago
  • Modified: Code cleanup.
File size: 1.4 KB
Line 
1unit Generator;
2
3interface
4
5uses
6 Classes, SysUtils, strutils, Source;
7
8type
9
10 { TGenerator }
11
12 TGenerator = class
13 private
14 FIndent: Integer;
15 procedure SetIndent(AValue: Integer);
16 public
17 Name: string;
18 FileExt: string;
19 Output: string;
20 Prog: TProgram;
21 procedure AddText(Text: string);
22 procedure AddTextLine(Text: string = '');
23 procedure Generate; virtual;
24 constructor Create; virtual;
25 destructor Destroy; override;
26 property Indent: Integer read FIndent write SetIndent;
27 end;
28
29 TGeneratorClass = class of TGenerator;
30
31
32implementation
33
34procedure TGenerator.SetIndent(AValue: Integer);
35var
36 ToRemove: string;
37 RemoveIndex: Integer;
38begin
39 if FIndent = AValue then Exit;
40 if AValue > FIndent then begin
41 Output := Output + DupeString(' ', AValue - FIndent);
42 end else
43 if AValue < FIndent then begin
44 RemoveIndex := Length(Output) - (FIndent - AValue) * 2;
45 ToRemove := Copy(Output, RemoveIndex + 1, MaxInt);
46 if ToRemove = DupeString(' ', FIndent - AValue) then
47 Output := Copy(Output, 1, RemoveIndex);
48 end;
49 FIndent := AValue;
50end;
51
52procedure TGenerator.AddText(Text: string);
53begin
54 Output := Output + Text;
55end;
56
57procedure TGenerator.AddTextLine(Text: string);
58begin
59 AddText(Text + LineEnding + DupeString(' ', Indent));
60end;
61
62procedure TGenerator.Generate;
63begin
64end;
65
66constructor TGenerator.Create;
67begin
68end;
69
70destructor TGenerator.Destroy;
71begin
72 inherited;
73end;
74
75end.
76
Note: See TracBrowser for help on using the repository browser.