-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfiguration-step_3a.adb
340 lines (273 loc) · 12.8 KB
/
configuration-step_3a.adb
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
329
330
331
332
333
334
335
336
337
338
339
340
------------------------------------------------------------------------------
-- --
-- Ada User Repository Annex (AURA) --
-- ANNEXI-STRAYLINE Reference Implementation --
-- --
-- Command Line Interface --
-- --
-- ------------------------------------------------------------------------ --
-- --
-- Copyright (C) 2020, ANNEXI-STRAYLINE Trans-Human Ltd. --
-- All rights reserved. --
-- --
-- Original Contributors: --
-- * Richard Wai (ANNEXI-STRAYLINE) --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- --
-- * Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A --
-- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
with Ada.Containers;
with Ada.Characters.Conversions;
with Specification_Scanner; use Specification_Scanner;
separate (Configuration)
procedure Step_3a (Target: in out Subsystem) is
use type Ada.Containers.Count_Type;
package ACC renames Ada.Characters.Conversions;
package Subsystems renames Registrar.Subsystems;
Config_Tree: Declaration_Trees.Tree;
-- We now expect the Configuration unit to be present
Config_Unit: constant Library_Unit
:= Reg_Qs.Lookup_Unit (Config_Unit_Name (Target));
-- Utilities
function Find_In_Branch (Root: in Declaration_Trees.Cursor;
Name: in Wide_Wide_String)
return Declaration_Trees.Cursor;
-- Searches for an entity Name within the branch rooted at Root - i.e.
-- only within the immediate children of Root
function Find_Package_In_Branch (Root: in Declaration_Trees.Cursor;
Name: in Wide_Wide_String)
return Declaration_Trees.Cursor;
-- Invokes Find_In_Branch for Root and Name, and then asserts that
-- the entity (if any) denoted by Name is a non-generic package
procedure Load_Names (Package_Root: in Declaration_Trees.Cursor;
List : in out Subsystems.Configuration_Vector);
-- Load names expected to be given the root cursor of a package entity.
-- Load names then iterates over the immediate children of that package
-- entity, isolating constant String objects, and appending their names
-- to List.
-- Stages
procedure Process_Build;
procedure Process_Ada_Package (Build_Root: in Declaration_Trees.Cursor);
procedure Process_C_Package (Build_Root: in Declaration_Trees.Cursor);
procedure Process_Codepaths;
procedure Process_Information;
--------------------
-- Find_In_Branch --
--------------------
function Find_In_Branch (Root: in Declaration_Trees.Cursor;
Name: in Wide_Wide_String)
return Declaration_Trees.Cursor
is
use Declaration_Trees;
Index: Cursor := First_Child (Root);
begin
while Index /= No_Element loop
if WWU.To_Wide_Wide_String (Config_Tree(Index).Name) = Name then
return Index;
end if;
Index := Next_Sibling (Index);
end loop;
return No_Element;
end Find_In_Branch;
----------------------------
-- Find_Package_In_Branch --
----------------------------
function Find_Package_In_Branch (Root: in Declaration_Trees.Cursor;
Name: in Wide_Wide_String)
return Declaration_Trees.Cursor
is
use Declaration_Trees;
PC: constant Cursor := Find_In_Branch (Root, Name);
begin
if PC = No_Element then
return PC;
end if;
declare
PE: Declared_Entity renames Config_Tree(PC);
begin
Assert (Check => PE.Kind = Package_Declaration
and then not PE.Is_Generic,
Message => ACC.To_String (WWU.To_Wide_Wide_String (PE.Name))
& " shall be a non-generic package declaration." );
return PC;
end;
end Find_Package_In_Branch;
----------------
-- Load_Names --
----------------
procedure Load_Names (Package_Root: in Declaration_Trees.Cursor;
List : in out Subsystems.Configuration_Vector)
is
use Declaration_Trees;
Index: Cursor := First_Child (Package_Root);
begin
while Index /= No_Element loop
declare
Ent: Declared_Entity renames Config_Tree(Index);
begin
if Ent.Kind = Object_Declaration
and then Ent.Is_Constant
and then WWU.To_Wide_Wide_String (Ent.Subtype_Mark) = "string"
then
List.Append ((Name => Ent.Name,
Value => UBS.Null_Unbounded_String));
end if;
Index := Next_Sibling (Index);
end;
end loop;
end Load_Names;
-------------------
-- Process_Build --
-------------------
procedure Process_Build is
use Declaration_Trees;
Build_Root: constant Cursor
:= Find_Package_In_Branch (Root => First_Child (Config_Tree.Root),
Name => "build");
begin
if Build_Root = No_Element then
return;
end if;
-- Load the External_Libraries, if present
declare
P: constant Cursor
:= Find_Package_In_Branch (Root => Build_Root,
Name => "external_libraries");
begin
if P /= No_Element then
Load_Names
(Package_Root => P,
List => Target.Configuration.External_Libraries);
end if;
end;
Process_Ada_Package (Build_Root);
Process_C_Package (Build_Root);
end Process_Build;
-------------------------
-- Process_Ada_Package --
-------------------------
procedure Process_Ada_Package (Build_Root: in Declaration_Trees.Cursor) is
use Declaration_Trees;
Ada_Root: constant Cursor
:= Find_Package_In_Branch (Root => Build_Root,
Name => "ada");
Comp_Opt: Cursor;
begin
if Ada_Root /= No_Element then
Comp_Opt := Find_Package_In_Branch (Root => Ada_Root,
Name => "compiler_options");
if Comp_Opt /= No_Element then
Load_Names (Package_Root => Comp_Opt,
List => Target.Configuration.Ada_Compiler_Opts);
end if;
end if;
end Process_Ada_Package;
-----------------------
-- Process_C_Package --
-----------------------
procedure Process_C_Package (Build_Root: in Declaration_Trees.Cursor) is
use Declaration_Trees;
C_Root: constant Cursor
:= Find_Package_In_Branch (Root => Build_Root,
Name => "c");
Comp_Opt: Cursor;
CPP_Defs: Cursor;
begin
if C_Root /= No_Element then
Comp_Opt := Find_Package_In_Branch (Root => C_Root,
Name => "compiler_options");
if Comp_Opt /= No_Element then
Load_Names (Package_Root => Comp_Opt,
List => Target.Configuration.C_Compiler_Opts);
end if;
CPP_Defs
:= Find_Package_In_Branch (Root => C_Root,
Name => "preprocessor_definitions");
if CPP_Defs /= No_Element then
Load_Names (Package_Root => CPP_Defs,
List => Target.Configuration.C_Definitions);
end if;
end if;
end Process_C_Package;
-----------------------
-- Process_Codepaths --
-----------------------
procedure Process_Codepaths is
use Declaration_Trees;
CP_Root: constant Cursor
:= Find_Package_In_Branch (Root => First_Child (Config_Tree.Root),
Name => "codepaths");
begin
if CP_Root /= No_Element then
Assert (Check => Target.Name.To_String /= "aura",
Message => "Root Configuration (AURA.Root) shall not "
& "have a codepaths package");
Load_Names (Package_Root => CP_Root,
List => Target.Configuration.Codepaths);
end if;
end Process_Codepaths;
-------------------------
-- Process_Information --
-------------------------
procedure Process_Information is
use Declaration_Trees;
Info_Root: constant Cursor
:= Find_Package_In_Branch (Root => First_Child (Config_Tree.Root),
Name => "information");
begin
if Info_Root /= No_Element then
Load_Names (Package_Root => Info_Root,
List => Target.Configuration.Codepaths);
end if;
end Process_Information;
begin
Target.Configuration
:= (others => Subsystems.Configuration_Vectors.Empty_Vector);
Scan_Package_Spec (Unit => Config_Unit,
Unit_Tree => Config_Tree);
Process_Build; -- Includes Ada and C packages
Process_Codepaths;
Process_Information;
-- Now we have a sense of which packages are in the configuration unit, and
-- which objects need to be exported from the loader program, executed in
-- Step 3b
-- However if we *know* we don't have anything to load, then we can skip
-- right to step 4. This can happen when the configuration file is empty.
if Target.Configuration.External_Libraries.Length = 0
and then Target.Configuration.Ada_Compiler_Opts.Length = 0
and then Target.Configuration.C_Compiler_Opts.Length = 0
and then Target.Configuration.C_Definitions.Length = 0
and then Target.Configuration.Codepaths.Length = 0
and then Target.Configuration.Information.Length = 0
then
Step_4 (Target);
else
Step_3b (Target);
end if;
end Step_3a;