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 | |
---|
1 | unit UCompiler;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | SysUtils, Generics.Collections, UAnalyzer, UTarget;
|
---|
7 |
|
---|
8 | type
|
---|
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 |
|
---|
25 | implementation
|
---|
26 |
|
---|
27 | procedure TCompiler.Compile;
|
---|
28 | begin
|
---|
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');
|
---|
34 | end;
|
---|
35 |
|
---|
36 | procedure TCompiler.RegisterTarget(TargetClass: TTargetClass);
|
---|
37 | begin
|
---|
38 | SupportedTargets.Add(TargetClass.Create);
|
---|
39 | if not Assigned(Target) then
|
---|
40 | Target := SupportedTargets.Last;
|
---|
41 | end;
|
---|
42 |
|
---|
43 | constructor TCompiler.Create;
|
---|
44 | begin
|
---|
45 | SupportedTargets := TObjectList<TTarget>.Create;
|
---|
46 | SupportedAnalyzers := TObjectList<TAnalyzer>.Create;
|
---|
47 | end;
|
---|
48 |
|
---|
49 | destructor TCompiler.Destroy;
|
---|
50 | begin
|
---|
51 | SupportedTargets.Free;
|
---|
52 | SupportedAnalyzers.Free;
|
---|
53 | inherited;
|
---|
54 | end;
|
---|
55 |
|
---|
56 | procedure TCompiler.RegisterAnalyzer(AnalyzerClass: TAnalyzerClass);
|
---|
57 | begin
|
---|
58 | SupportedAnalyzers.Add(AnalyzerClass.Create);
|
---|
59 | if not Assigned(Analyzer) then
|
---|
60 | Analyzer := SupportedAnalyzers.Last;
|
---|
61 | end;
|
---|
62 |
|
---|
63 | end.
|
---|
Note:
See
TracBrowser
for help on using the repository browser.