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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328 | with Ada.Containers.Hashed_Maps;
with Ada.Containers.Ordered_Sets;
with Ada.Strings.Wide_Fixed;
with Ada.Strings.Wide_Hash;
with Ada.Unchecked_Conversion;
with Asis.Compilation_Units;
with Asis.Declarations;
with Asis.Elements;
with Asis.Text;
with League.Characters.Latin;
with League.Strings.Hash;
package body Documentation_Generator.Database is
function Hash
(Item : Asis.Compilation_Unit) return Ada.Containers.Hash_Type;
function Hash (Item : Asis.Element) return Ada.Containers.Hash_Type;
function Is_Less
(Left : not null Type_Access; Right : not null Type_Access) return Boolean;
function Is_Less
(Left : not null Module_Access;
Right : not null Module_Access) return Boolean;
package Module_Sets is
new Ada.Containers.Ordered_Sets (Module_Access, Is_Less);
package Compilation_Unit_Maps is
new Ada.Containers.Hashed_Maps
(Asis.Compilation_Unit,
Compilation_Unit_Access,
Hash,
Asis.Compilation_Units.Is_Equal);
-- League.Strings.Hash,
-- League.Strings."=");
package Type_Declaration_Maps is
new Ada.Containers.Hashed_Maps
(Asis.Element, Type_Access, Hash, Asis.Elements.Is_Equal);
package Type_Declaration_Sets is
new Ada.Containers.Ordered_Sets (Type_Access, Is_Less);
Compilation_Units : Compilation_Unit_Maps.Map;
All_Modules : Module_Sets.Set;
Type_Declarations : Type_Declaration_Maps.Map;
All_Type_Declarations : Type_Declaration_Sets.Set;
----------------------
-- Compilation_Unit --
----------------------
function Compilation_Unit
(Self : Type_Information'Class) return Compilation_Unit_Access is
begin
return Lookup (Asis.Elements.Enclosing_Compilation_Unit (Self.Element));
end Compilation_Unit;
------------
-- Create --
------------
function Create
(Unit : Asis.Compilation_Unit;
Module : not null Module_Access) return Compilation_Unit_Access
is
Aux : constant Compilation_Unit_Access := Lookup (Unit);
begin
Aux.Module := Module;
return Aux;
end Create;
------------
-- Create --
------------
function Create
(Name : League.Strings.Universal_String;
Short_Description : League.Strings.Universal_String) return Module_Access
is
Aux : constant Module_Access
:= new Module_Information'
(Name => Name,
Short_Description => Short_Description);
begin
All_Modules.Insert (Aux);
return Aux;
end Create;
-----------------
-- Description --
-----------------
function Description
(Self : Type_Information'Class) return League.Strings.Universal_String
is
Lines : constant Asis.Text.Line_List
:= Asis.Text.Lines
(Self.Element,
Asis.Text.Last_Line_Number (Self.Element) + 1,
Asis.Text.Compilation_Unit_Span (Self.Element).Last_Line);
Aux : League.Strings.Universal_String;
begin
-- Extract text description from the comment starting immidiately after
-- last line of type declaration.
for J in Lines'Range loop
declare
Line : constant Asis.Program_Text
:= Asis.Text.Line_Image (Lines (J));
Comment : constant Asis.Program_Text
:= Asis.Text.Comment_Image (Lines (J));
Delimiter : constant Natural
:= Ada.Strings.Wide_Fixed.Index (Comment, "-");
begin
exit when Line'Length = 0;
if Delimiter /= 0 then
if Delimiter + 4 > Comment'Last then
Aux.Append (League.Characters.Latin.Line_Feed);
Aux.Append (League.Characters.Latin.Line_Feed);
elsif not Aux.Is_Empty then
Aux.Append (' ');
end if;
Aux.Append
(League.Strings.From_UTF_16_Wide_String
(Comment (Delimiter + 4 .. Comment'Last)));
end if;
end;
end loop;
return Aux;
end Description;
----------
-- Hash --
----------
function Hash
(Item : Asis.Compilation_Unit) return Ada.Containers.Hash_Type is
begin
return
Ada.Strings.Wide_Hash (Asis.Compilation_Units.Unit_Full_Name (Item));
end Hash;
----------
-- Hash --
----------
function Hash (Item : Asis.Element) return Ada.Containers.Hash_Type is
function To_Hash_Type is
new Ada.Unchecked_Conversion
(Asis.ASIS_Integer, Ada.Containers.Hash_Type);
begin
return To_Hash_Type (Asis.Elements.Hash (Item));
end Hash;
-------------
-- Is_Less --
-------------
function Is_Less
(Left : not null Module_Access;
Right : not null Module_Access) return Boolean
is
use type League.Strings.Universal_String;
begin
return Left.Name < Right.Name;
end Is_Less;
-------------
-- Is_Less --
-------------
function Is_Less
(Left : not null Type_Access; Right : not null Type_Access) return Boolean
is
use type League.Strings.Sort_Key;
L : constant League.Strings.Sort_Key := Left.Name.To_Lowercase.Collation;
R : constant League.Strings.Sort_Key := Right.Name.To_Lowercase.Collation;
begin
return L < R;
end Is_Less;
-------------
-- Iterate --
-------------
procedure Iterate
(Process : not null access procedure (Module : not null Module_Access))
is
Position : Module_Sets.Cursor := All_Modules.First;
begin
while Module_Sets.Has_Element (Position) loop
Process (Module_Sets.Element (Position));
Module_Sets.Next (Position);
end loop;
end Iterate;
-------------
-- Iterate --
-------------
procedure Iterate
(Process : not null access procedure (The_Type : not null Type_Access))
is
Position : Type_Declaration_Sets.Cursor := All_Type_Declarations.First;
begin
while Type_Declaration_Sets.Has_Element (Position) loop
Process (Type_Declaration_Sets.Element (Position));
Type_Declaration_Sets.Next (Position);
end loop;
end Iterate;
------------
-- Lookup --
------------
function Lookup
(Unit : Asis.Compilation_Unit) return Compilation_Unit_Access is
begin
if not Compilation_Units.Contains (Unit) then
Compilation_Units.Insert
(Unit,
new Compilation_Unit_Information'
(Unit => Unit,
Module => null));
end if;
return Compilation_Units.Element (Unit);
end Lookup;
------------
-- Lookup --
------------
function Lookup (Declaration : Asis.Element) return Type_Access is
Aux : Type_Access;
begin
if not Type_Declarations.Contains (Declaration) then
Aux := new Type_Information'(Element => Declaration);
Type_Declarations.Insert (Declaration, Aux);
All_Type_Declarations.Insert (Aux);
end if;
return Type_Declarations.Element (Declaration);
end Lookup;
------------
-- Module --
------------
function Module (Self : Type_Information'Class) return Module_Access is
begin
return Self.Compilation_Unit.Module;
end Module;
----------
-- Name --
----------
function Name
(Self : Compilation_Unit_Information'Class)
return League.Strings.Universal_String is
begin
return
League.Strings.From_UTF_16_Wide_String
(Asis.Compilation_Units.Unit_Full_Name (Self.Unit));
end Name;
----------
-- Name --
----------
function Name
(Self : Module_Information'Class) return League.Strings.Universal_String is
begin
return Self.Name;
end Name;
----------
-- Name --
----------
function Name
(Self : Type_Information'Class) return League.Strings.Universal_String
is
Names : constant Asis.Defining_Name_List
:= Asis.Declarations.Names (Self.Element);
begin
return
League.Strings.From_UTF_16_Wide_String
(Asis.Declarations.Defining_Name_Image (Names (Names'First)));
end Name;
-----------------------
-- Short_Description --
-----------------------
function Short_Description
(Self : Module_Information'Class) return League.Strings.Universal_String is
begin
return Self.Short_Description;
end Short_Description;
end Documentation_Generator.Database;
|