-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathRoutineMapping.pas
More file actions
164 lines (150 loc) · 4.04 KB
/
RoutineMapping.pas
File metadata and controls
164 lines (150 loc) · 4.04 KB
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
unit RoutineMapping;
interface
uses
Classes, Types, SysUtils, Generics.Collections, VarMapping;
type
TParameter = class
private
FName: string;
FTypeName: string;
FAccess: string;
public
property Name: string read FName write FName;
property TypeName: string read FTypeName write FTypeName;
property Access: string read FAccess write FAccess;
end;
TRoutineMapping = class(TVarMapping)
private
FParameters: TObjectList<TParameter>;
FLocals: TObjectList<TParameter>;
procedure ReadParametersFromLine(ALine: string);
procedure ReadLocalsFromLine(ALine: string);
protected
function GetText(): string; override;
public
constructor Create();
destructor Destroy(); override;
procedure ReadFromLine(ALine: string); override;
property Parameters: TObjectList<TParameter> read FParameters;
property Locals: TObjectList<TParameter> read FLocals;
end;
implementation
uses
StrUtils;
{ TRoutineMapping }
constructor TRoutineMapping.Create;
begin
inherited;
FIsPossibleBreakPoint := True;
FParameters := TObjectList<TParameter>.Create();
FLocals := TObjectList<TParameter>.Create();
end;
destructor TRoutineMapping.Destroy;
begin
FParameters.Free;
FLocals.Free;
inherited;
end;
function TRoutineMapping.GetText: string;
var
LParameter: TParameter;
i: Integer;
begin
Result := inherited + '%';
for i := 0 to FParameters.Count - 1 do
begin
LParameter := FParameters.Items[i];
Result := Result + LParameter.Name + ',' + LParameter.TypeName + ',' + LParameter.Access;
if i < FParameters.Count - 1 then
begin
Result := Result + '#';
end;
end;
Result := Result + '%';
for i := 0 to FLocals.Count - 1 do
begin
LParameter := FLocals.Items[i];
Result := Result + LParameter.Name + ',' + LParameter.TypeName + ',' + LParameter.Access;
if i < FLocals.Count - 1 then
begin
Result := Result + '#';
end;
end;
end;
procedure TRoutineMapping.ReadFromLine(ALine: string);
var
LLines: TStringDynArray;
begin
LLines := SplitString(ALine, '%');
if Length(LLines) = 3 then
begin
inherited ReadFromLine(LLines[0]);
ReadParametersFromLine(LLines[1]);
ReadLocalsFromLine(LLines[2]);
end
else
begin
raise Exception.Create('Expected 3 Toplevel elements in TRoutineMapping but found ' + IntToStr(Length(LLines)));
end;
end;
procedure TRoutineMapping.ReadLocalsFromLine(ALine: string);
var
LLines, LData: TStringDynArray;
LLine: string;
LParameter: TParameter;
begin
LLines := SplitString(ALine, '#');
if Length(LLines) > 0 then
begin
for LLine in LLines do
begin
LParameter := TParameter.Create();
try
LData := SplitString(LLine, ',');
if Length(LData) = 3 then
begin
LParameter.Name := LData[0];
LParameter.TypeName := LData[1];
LParameter.Access := LData[2];
end
else
begin
raise Exception.Create('Expected 3 elements for reading TParameter as Local but found ' + IntToStr(Length(LData)));
end;
finally
FLocals.Add(LParameter);
end;
end;
end;
end;
procedure TRoutineMapping.ReadParametersFromLine(ALine: string);
var
LLines, LData: TStringDynArray;
LLine: string;
LParameter: TParameter;
begin
LLines := SplitString(ALine, '#');
if Length(LLines) > 0 then
begin
for LLine in LLines do
begin
LParameter := TParameter.Create();
try
LData := SplitString(LLine, ',');
if Length(LData) = 3 then
begin
LParameter.Name := LData[0];
LParameter.TypeName := LData[1];
LParameter.Access := LData[2];
end
else
begin
raise Exception.Create('Expected 3 elements for reading TParameter as Parameter but found ' + IntToStr(Length(LData)));
end;
finally
FParameters.Add(LParameter);
end;
end;
end;
end;
end.