-
Notifications
You must be signed in to change notification settings - Fork 5
/
PascalUnit.pas
114 lines (96 loc) · 2.92 KB
/
PascalUnit.pas
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
unit PascalUnit;
interface
uses
Classes, Types, Generics.Collections, CodeElement, Lexer, WriterIntf;
type
TPascalUnit = class(TCodeElement)
private
FFooterSource: TStringList;
FInitSection: TObjectList<TCodeElement>;
FLexer: TLexer;
FUsedUnits: TStringList;
FImplementationSection: TObjectList<TCodeElement>;
function GetInterfaceSection: TObjectList<TCodeElement>;
public
constructor Create(AName: string);
destructor Destroy(); override;
procedure GetDCPUSource(AWriter: IWriter); override;
function GetImplementationElement(AName: string; AType: TCodeElementClass): TCodeElement;
function GetElementFromAll(AName: string; AType: TCodeElementClass): TCodeElement;
property FooterSource: TStringList read FFooterSource;
property InitSection: TObjectList<TCodeElement> read FInitSection;
property ImplementationSection: TObjectList<TCodeElement> read FImplementationSection;
property InterfaceSection: TObjectList<TCodeElement> read GetInterfaceSection;
property Lexer: TLexer read FLexer;
property UsedUnits: TStringList read FUsedUnits;
end;
implementation
uses
VarDeclaration, Optimizer;
{ TPascalUnit }
constructor TPascalUnit.Create(AName: string);
begin
inherited;
FFooterSource := TStringList.Create();
FInitSection := TObjectList<TCodeElement>.Create();
FImplementationSection := TObjectList<TCodeElement>.Create();
FLexer := TLexer.Create();
FUsedUnits := TStringList.Create();
end;
destructor TPascalUnit.Destroy;
begin
FFooterSource.Free;
FinitSection.Free;
FImplementationSection.Free;
FLexer.Free;
FUsedUnits.Free;
inherited;
end;
procedure TPascalUnit.GetDCPUSource;
var
LElement: TCodeElement;
begin
for LElement in FInitSection do
begin
LElement.GetDCPUSource(AWriter);
end;
for LElement in SubElements do
begin
if not (LElement is TVarDeclaration) then
begin
LElement.GetDCPUSource(AWriter);
end;
end;
for LElement in ImplementationSection do
begin
LElement.GetDCPUSource(AWriter);
end;
for LElement in SubElements do
begin
if LELement is TVarDeclaration then
begin
LElement.GetDCPUSource(AWriter);
end;
end;
AWriter.WriteList(FFooterSource);
AWriter.Write('');//one emptyline for padding, otherwhise we screw mapping...
end;
function TPascalUnit.GetElementFromAll(AName: string;
AType: TCodeElementClass): TCodeElement;
begin
Result := GetImplementationElement(AName, AType);
if not Assigned(Result) then
begin
Result := GetElement(AName, AType);
end;
end;
function TPascalUnit.GetImplementationElement(AName: string;
AType: TCodeElementClass): TCodeElement;
begin
Result := GetElementInScope(AName, AType, FImplementationSection);
end;
function TPascalUnit.GetInterfaceSection: TObjectList<TCodeElement>;
begin
Result := SubElements;
end;
end.