source: branches/dcomp/CmdLine/Compiler/UCompiler.pas

Last change on this file was 93, checked in by chronos, 8 years ago
  • Modified: Use generic lists in supported analyzers and parsers.
  • Fixed: Build under Delphi.
File size: 1.4 KB
Line 
1unit UCompiler;
2
3interface
4
5uses
6 SysUtils, Generics.Collections, UAnalyzer, UTarget;
7
8type
9
10 { TCompiler }
11
12 TCompiler = class
13 SupportedAnalyzers: TObjectList<TAnalyzer>;
14 SupportedTargets: TObjectList<TTarget>;
15 Analyzer: TAnalyzer;
16 Target: TTarget;
17 MainSourceFile: string;
18 procedure Compile;
19 procedure RegisterTarget(TargetClass: TTargetClass);
20 procedure RegisterAnalyzer(AnalyzerClass: TAnalyzerClass);
21 constructor Create;
22 destructor Destroy; override;
23 end;
24
25implementation
26
27procedure TCompiler.Compile;
28begin
29 if Assigned(Analyzer) then Analyzer.Analyze
30 else raise Exception.Create('Undefined analyzer');
31 if Assigned(Target) then Target.Produce
32 else raise Exception.Create('Undefined target');
33 WriteLn('Compile');
34end;
35
36procedure TCompiler.RegisterTarget(TargetClass: TTargetClass);
37begin
38 SupportedTargets.Add(TargetClass.Create);
39 if not Assigned(Target) then
40 Target := SupportedTargets.Last;
41end;
42
43constructor TCompiler.Create;
44begin
45 SupportedTargets := TObjectList<TTarget>.Create;
46 SupportedAnalyzers := TObjectList<TAnalyzer>.Create;
47end;
48
49destructor TCompiler.Destroy;
50begin
51 SupportedTargets.Free;
52 SupportedAnalyzers.Free;
53 inherited;
54end;
55
56procedure TCompiler.RegisterAnalyzer(AnalyzerClass: TAnalyzerClass);
57begin
58 SupportedAnalyzers.Add(AnalyzerClass.Create);
59 if not Assigned(Analyzer) then
60 Analyzer := SupportedAnalyzers.Last;
61end;
62
63end.
Note: See TracBrowser for help on using the repository browser.