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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345 | ------------------------------------------------------------------------------
-- --
-- OCARINA COMPONENTS --
-- --
-- OCARINA.GENERATORS.PO_QOS_ADA.NAMESPACES --
-- --
-- B o d y --
-- --
-- Copyright (C) 2006-2007, GET-Telecom Paris. --
-- --
-- Ocarina is free software; you can redistribute it and/or modify --
-- it under terms of the GNU General Public License as published by the --
-- Free Software Foundation; either version 2, or (at your option) any --
-- later version. Ocarina is distributed in the hope that it will be --
-- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. You should have received a copy of the --
-- GNU General Public License distributed with Ocarina; see file COPYING. --
-- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth --
-- Floor, Boston, MA 02111-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- Ocarina is maintained by the Ocarina team --
-- (ocarina-users@listes.enst.fr) --
-- --
------------------------------------------------------------------------------
with Ocarina.Nodes;
with Ocarina.Nutils;
with Ocarina.Entities.Components;
with Ocarina.Generators.Utils;
with Ocarina.Generators.Properties;
with Ocarina.Generators.Messages;
with Ocarina.Generators.PO_QoS_Ada.Mapping;
with Ocarina.Generators.PO_QoS_Ada.Runtime;
with Ocarina.Generators.Ada_Tree.Nutils;
with Ocarina.Generators.Ada_Tree.Nodes;
with Ocarina.Generators.Ada_Values;
package body Ocarina.Generators.PO_QoS_Ada.Namespaces is
use Ocarina.Nodes;
use Ocarina.Entities.Components;
use Ocarina.Generators.Utils;
use Ocarina.Generators.Properties;
use Ocarina.Generators.Messages;
use Ocarina.Generators.PO_QoS_Ada.Mapping;
use Ocarina.Generators.PO_QoS_Ada.Runtime;
use Ocarina.Generators.Ada_Tree.Nutils;
use Ocarina.Generators.Ada_Values;
package AAN renames Ocarina.Nodes;
package AAU renames Ocarina.Nutils;
package ADN renames Ocarina.Generators.Ada_Tree.Nodes;
package ADU renames Ocarina.Generators.Ada_Tree.Nutils;
------------------
-- Package_Spec --
------------------
package body Package_Spec is
procedure Visit_Architecture_Instance (E : Node_Id);
procedure Visit_Component_Instance (E : Node_Id);
procedure Visit_System_Instance (E : Node_Id);
procedure Visit_Process_Instance (E : Node_Id);
procedure Visit_Thread_Instance (E : Node_Id);
procedure Visit_Namespace_Instance (E : Node_Id);
procedure Visit_Data_Instance (E : Node_Id);
procedure Visit_Subprogram_Instance (E : Node_Id);
Current_Architecture_Instance : Node_Id;
-- Points to the root of the instance tree
Current_Process_Instance : Node_Id;
-- Points to the current visited AADL process instance
function Get_Ada_Unit (E : Node_Id) return Node_Id;
pragma Inline (Get_Ada_Unit);
-- Return the Ada unit inside which the data or subprogram
-- component E has to be generated.
function Protected_Type_Routines
(E : Node_Id;
Components : List_Id)
return List_Id;
-- Declares the routines corresponding to a protected AADL data
-- component. Components is pre-built list of Ada component
-- declaration corresponding to the data subcomponents.
------------------
-- Get_Ada_Unit --
------------------
function Get_Ada_Unit (E : Node_Id) return Node_Id is
N : Node_Id;
P : Node_Id;
U : Node_Id;
begin
pragma Assert (Utils.Is_Data (E) or else Utils.Is_Subprogram (E));
N := Namespace (E);
P := ADN.Namespaces_Node
(Backend_Node
(Bind_Two_Nodes
(N, Current_Process_Instance)));
U := ADN.Distributed_Application_Unit (P);
return U;
end Get_Ada_Unit;
-----------
-- Visit --
-----------
procedure Visit (E : Node_Id) is
begin
case Kind (E) is
when K_Architecture_Instance =>
Visit_Architecture_Instance (E);
when K_Component_Instance =>
Visit_Component_Instance (E);
when K_Namespace_Instance =>
Visit_Namespace_Instance (E);
when others =>
null;
end case;
end Visit;
---------------------------------
-- Visit_Architecture_Instance --
---------------------------------
procedure Visit_Architecture_Instance (E : Node_Id) is
begin
Current_Architecture_Instance := E;
Visit (Root_System (E));
end Visit_Architecture_Instance;
------------------------------
-- Visit_Component_Instance --
------------------------------
procedure Visit_Component_Instance (E : Node_Id) is
Cathegory : constant Component_Category
:= Get_Category_Of_Component (E);
begin
case Cathegory is
when CC_System =>
Visit_System_Instance (E);
when CC_Process =>
Visit_Process_Instance (E);
when CC_Thread =>
Visit_Thread_Instance (E);
when CC_Data =>
Visit_Data_Instance (E);
when CC_Subprogram =>
Visit_Subprogram_Instance (E);
when others =>
null;
end case;
end Visit_Component_Instance;
-------------------------
-- Visit_Data_Instance --
-------------------------
procedure Visit_Data_Instance (E : Node_Id) is
U : constant Node_Id := Get_Ada_Unit (E);
Data_Type : Supported_Data_Type;
N : Node_Id;
S : Node_Id;
begin
-- Push the Ada unit correspoding to the AADL namespace
Push_Entity (U);
Set_Namespaces_Spec;
-- Do not generate Ada type more than once
if No (Get_Handling (E, By_Name, H_Ada_Namespaces_Spec)) then
-- FIXME: For now, strings and arrays are unsupported
-- The code generation for the following types is not yet
-- supported: Arrays and bounded strings.
Data_Type := Get_Data_Type (E);
case Data_Type is
when Data_Integer =>
N := Make_Full_Type_Declaration
(Defining_Identifier => Map_Ada_Defining_Identifier (E),
Type_Definition => Make_Derived_Type_Definition
(RE (RE_Integer)));
when Data_Float =>
N := Make_Full_Type_Declaration
(Defining_Identifier => Map_Ada_Defining_Identifier (E),
Type_Definition => Make_Derived_Type_Definition
(RE (RE_Float_2)));
when Data_Fixed =>
declare
Data_Digits : constant Unsigned_Long_Long
:= Get_Data_Digits (E);
Data_Scale : constant Unsigned_Long_Long
:= Get_Data_Scale (E);
begin
if Data_Digits /= 0 and then Data_Scale /= 0 then
N := Make_Full_Type_Declaration
(Defining_Identifier => Map_Ada_Defining_Identifier
(E),
Type_Definition => Make_Decimal_Type_Definition
(Data_Digits,
Data_Scale));
else
if Data_Digits = 0 then
Display_Located_Error
(Loc (E),
"Missing the digit number of fixed point type!",
Fatal => True);
end if;
if Data_Scale = 0 then
Display_Located_Error
(Loc (E),
"Missing the scale of fixed point type!",
Fatal => True);
end if;
end if;
end;
when Data_Boolean =>
N := Make_Full_Type_Declaration
(Defining_Identifier => Map_Ada_Defining_Identifier (E),
Type_Definition => Make_Derived_Type_Definition
(RE (RE_Boolean_2)));
when Data_Character =>
N := Make_Full_Type_Declaration
(Defining_Identifier => Map_Ada_Defining_Identifier (E),
Type_Definition => Make_Derived_Type_Definition
(RE (RE_Character_2)));
when Data_Wide_Character =>
N := Make_Full_Type_Declaration
(Defining_Identifier => Map_Ada_Defining_Identifier (E),
Type_Definition => Make_Derived_Type_Definition
(RE (RE_Wide_Character_2)));
when Data_String =>
-- Bounded string data types require special
-- handling: we don't map string to the
-- 'Standard.String' type since this is an
-- unconstrained type and would prevent us to build
-- data structures (buffers, records) with it. So
-- we use the Ada.Strings.Bounded packages
N := Make_Package_Instantiation
(Defining_Identifier => Map_Package_Identifier (E),
Generic_Package => RU
(RU_Ada_Strings_Bounded_Generic_Bounded_Length),
Parameter_List => Make_List_Id
(Make_Literal
(New_Integer_Value
(Get_Data_Length (E),
1,
10))));
Append_Node_To_List (N, ADN.Visible_Part (Current_Package));
N := Make_Full_Type_Declaration
(Defining_Identifier => Map_Ada_Defining_Identifier (E),
Type_Definition => Make_Derived_Type_Definition
(Make_Selected_Component
(Map_Package_Identifier (E),
Make_Defining_Identifier (TN (T_Bounded_String)))));
when Data_Wide_String =>
-- Bounded wide string data types require special
-- handling: we don't map string to the
-- 'Standard.Wide_String' type since this is an
-- unconstrained type and would prevent us to build
-- data structures (buffers, records) with it. So
-- we use the Ada.Strings.Wide_Bounded packages
N := Make_Package_Instantiation
(Defining_Identifier => Map_Package_Identifier (E),
Generic_Package => RU
(RU_Ada_Strings_Wide_Bounded_Generic_Bounded_Length),
Parameter_List => Make_List_Id
(Make_Literal
(New_Integer_Value
(Get_Data_Length (E),
1,
10))));
Append_Node_To_List (N, ADN.Visible_Part (Current_Package));
N := Make_Full_Type_Declaration
(Defining_Identifier => Map_Ada_Defining_Identifier (E),
Type_Definition => Make_Derived_Type_Definition
(Make_Selected_Component
(Map_Package_Identifier (E),
Make_Defining_Identifier
(TN (T_Bounded_Wide_String)))));
Display_Located_Error
(Loc (E),
"Bounded wide strings not supported yet!",
Fatal => True);
when Data_Array =>
Display_Located_Error
(Loc (E),
"Bounded arrays not supported yet!",
Fatal => True);
when Data_Record | Data_With_Accessors =>
declare
Components : constant List_Id := New_List
(ADN.K_Component_List);
Conc_Proto : constant
Supported_Concurrency_Control_Protocol :=
Get_Concurrency_Protocol (E);
C : Node_Id := First_Node (Subcomponents (E));
L : List_Id;
begin
-- Build the component list
while Present (C) loop
-- Generate the Ada type corresponding to the
-- subcomponent.
Visit (Corresponding_Instance (C));
-- Make the record or private type component
N := Make_Component_Declaration
(Defining_Identifier => Map_Ada_Defining_Identifier
(C),
Subtype_Indication => Map_Ada_Data_Type_Designator
(Corresponding_Instance (C)));
Append_Node_To_List (N, Components);
C := Next_Node (C);
end loop;
if Data_Type = Data_Record
and then Conc_Proto = Concurrency_NoneSpecified
then
-- Simple record type
N := Make_Full_Type_Declaration
(Defining_Identifier => Map_Ada_Defining_Identifier
(E),
Type_Definition => Make_Record_Type_Definition
(Make_Record_Definition
(Components)));
elsif Conc_Proto = Concurrency_Protected_Access then
-- Protected type
L := Protected_Type_Routines (E, Components);
-- The first element of the list L is the
-- protected type declaration.
N := ADN.First_Node (L);
else
Display_Located_Error
(Loc (E),
"Unsupported concurrency protocol "
& Conc_Proto'Img,
Fatal => True);
end if;
end;
when others =>
Display_Located_Error
(Loc (E), "Unsupported data type!", Fatal => True);
end case;
-- Mark the data type as being handled.
Set_Handling (E, By_Name, H_Ada_Namespaces_Spec, N);
-- In the case of a data type with accessor, visit the
-- parameters of its features subprograms. It is
-- important to do this *after* marking the type as
-- handled, to avoid endless loops and *before* adding
-- the type declaration to the package statements because
-- the declaration order of type is important in Ada. In
-- parallel, we visit the subprograms to create their
-- specs
if Data_Type = Data_With_Accessors then
S := First_Node (Features (E));
while Present (S) loop
Visit (Corresponding_Instance (S));
S := Next_Node (S);
end loop;
end if;
-- Append the type declaration to the package spec
Append_Node_To_List (N, ADN.Visible_Part (Current_Package));
end if;
-- Bind the type to its mapping
Bind_AADL_To_Type_Definition
(Identifier (E),
Get_Handling (E, By_Name, H_Ada_Namespaces_Spec));
Pop_Entity; -- U
end Visit_Data_Instance;
------------------------------
-- Visit_Namespace_Instance --
------------------------------
procedure Visit_Namespace_Instance (E : Node_Id) is
U : constant Node_Id := Map_QoS_Unit (E, Current_Process_Instance);
pragma Unreferenced (U); -- Not read
begin
null;
end Visit_Namespace_Instance;
----------------------------
-- Visit_Process_Instance --
----------------------------
procedure Visit_Process_Instance (E : Node_Id) is
P : constant Node_Id := Map_QoS_Node (E);
U : Node_Id;
pragma Unreferenced (U);
N : Node_Id;
S : Node_Id;
begin
Current_Process_Instance := E;
Push_Entity (P);
-- It is important to push P before creating U
U := Map_QoS_Unit (E);
-- Do not push U. We just need to ensure the creation of the
-- main subprogram node before the namespace node.
-- We begin by visiting all the namespaces of the current
-- architecture instance. Note that this is necessary for
-- creating the empty packages corresponding to each
-- namespace instance. It is important to do this after
-- pushing the entity corresponding to the node at the top
-- of the entity stack so that the namespace packages would
-- be attched to the current node. Note also that generating
-- an empty package for each namespace does not necessarily
-- imply the generation of a source file. Only the packages
-- that contain declarations (depending on the current node)
-- will be generated.
-- Visit the unnamed namespace of the current archirtecture
-- instance.
if Present (Unnamed_Namespace (Current_Architecture_Instance)) then
Visit (Unnamed_Namespace (Current_Architecture_Instance));
else
-- This is an instantiation error
Display_Located_Error
(Loc (Current_Architecture_Instance),
"This AADL architecture has no unnamed namespace",
Fatal => True);
end if;
-- Visit all the namespace instances of the architecture
-- instance.
if
not AAU.Is_Empty (AAN.Namespaces (Current_Architecture_Instance))
then
N := First_Node (AAN.Namespaces (Current_Architecture_Instance));
while Present (N) loop
Visit (N);
N := Next_Node (N);
end loop;
end if;
-- After creating the package declarations, we need to set,
-- for each package declaration generating from a namespace
-- instance, its corresponding parent package
-- declaration. This has to be done *after* creating all
-- package declarations because in AADL, we can declare a
-- child package *before* it parent. This has to be done
-- only for the namespaces corresponding to AADL packages
-- (the unnamed namespace has no parent).
if
not AAU.Is_Empty (AAN.Namespaces (Current_Architecture_Instance))
then
N := First_Node (AAN.Namespaces (Current_Architecture_Instance));
while Present (N) loop
declare
Pkg_Dcl : constant Node_Id := ADN.Namespaces_Node
(Backend_Node
(Bind_Two_Nodes
(N,
Current_Process_Instance)));
Parent_Id : constant Node_Id := ADN.Parent_Unit_Name
(ADN.Defining_Identifier (Pkg_Dcl));
begin
if Present (Pkg_Dcl) then
ADN.Set_Parent (Pkg_Dcl, Get_Bound_Package (Parent_Id));
end if;
end;
N := Next_Node (N);
end loop;
end if;
-- Now that all the namespace packages are created, we visit
-- recursively all the subcomponents of the process and map
-- them to their corresponding packages.
-- Start recording all handlings because we want to reset
-- them for each node.
Start_Recording_Handlings;
if not AAU.Is_Empty (Subcomponents (E)) then
S := First_Node (Subcomponents (E));
while Present (S) loop
-- Visit the corresponding component instance
Visit (Corresponding_Instance (S));
S := Next_Node (S);
end loop;
end if;
-- After all the entities are generated in the namespaces
-- packages, we must ensure that, for each package P.Q, the
-- parent spec P is generated even if P has no declarations.
if
not AAU.Is_Empty (AAN.Namespaces (Current_Architecture_Instance))
then
N := First_Node (AAN.Namespaces (Current_Architecture_Instance));
while Present (N) loop
declare
Pkg_Dcl : constant Node_Id := ADN.Namespaces_Node
(Backend_Node
(Bind_Two_Nodes
(N,
Current_Process_Instance)));
Parent_Dcl : Node_Id;
Parent_Spec : Node_Id;
begin
Parent_Dcl := ADN.Parent (Pkg_Dcl);
while Present (Parent_Dcl) loop
Parent_Spec := ADN.Package_Specification (Parent_Dcl);
if ADU.Is_Empty (ADN.Visible_Part (Parent_Spec)) and then
ADU.Is_Empty (ADN.Private_Part (Parent_Spec))
then
Append_Node_To_List
(Message_Comment
("This package specification has to be generated"
& " because it has at least one child package"),
ADN.Visible_Part (Parent_Spec));
end if;
Parent_Dcl := ADN.Parent (Parent_Dcl);
end loop;
end;
N := Next_Node (N);
end loop;
end if;
-- Reset all the recorded handlings
Reset_Handlings;
Pop_Entity; -- P
end Visit_Process_Instance;
-------------------------------
-- Visit_Subprogram_Instance --
-------------------------------
procedure Visit_Subprogram_Instance (E : Node_Id) is
U : constant Node_Id := Get_Ada_Unit (E);
N : Node_Id;
F : Node_Id;
Call_Seq : Node_Id;
Spg_Call : Node_Id;
begin
-- Declare all necessary data types
if not AAU.Is_Empty (Features (E)) then
F := First_Node (Features (E));
while Present (F) loop
if Kind (F) = K_Port_Spec_Instance then
Display_Located_Error
(Loc (F),
"Port features in subprogram are not supported",
Fatal => True);
end if;
if Present (Corresponding_Instance (F)) then
Visit (Corresponding_Instance (F));
end if;
F := Next_Node (F);
end loop;
end if;
if No (Get_Handling (E, By_Name, H_Ada_Namespaces_Spec)) then
-- Push the Ada unit correspoding to the AADL namespace
Push_Entity (U);
Set_Namespaces_Spec;
N := Map_Ada_Subprogram_Spec (E);
Append_Node_To_List (N, ADN.Visible_Part (Current_Package));
-- Mark the data type as being handled
Set_Handling (E, By_Name, H_Ada_Namespaces_Spec, N);
-- If the subprogram is hybrid, generate extra
-- declarations.
if Get_Subprogram_Kind (E) = Subprogram_Hybrid_Ada_95 then
-- The status record type declaration
N := Map_Ada_Subprogram_Status (E);
Append_Node_To_List (N, ADN.Visible_Part (Current_Package));
-- The subprogram access type
N := Map_Ada_Call_Seq_Access (E);
Append_Node_To_List (N, ADN.Visible_Part (Current_Package));
Call_Seq := First_Node (Calls (E));
while Present (Call_Seq) loop
-- For each call sequence create a subprogram spec
N := Map_Ada_Call_Seq_Subprogram_Spec (E, Call_Seq);
Append_Node_To_List (N, ADN.Visible_Part (Current_Package));
Call_Seq := Next_Node (Call_Seq);
end loop;
end if;
Pop_Entity; -- U
end if;
Bind_AADL_To_Subprogram
(Identifier (E),
Get_Handling (E, By_Name, H_Ada_Namespaces_Spec));
-- Visit all the call sequences of the subprogram
if not AAU.Is_Empty (Calls (E)) then
Call_Seq := First_Node (Calls (E));
while Present (Call_Seq) loop
-- For each call sequence visit all the called
-- subprograms.
if not AAU.Is_Empty (Subprogram_Calls (Call_Seq)) then
Spg_Call := First_Node (Subprogram_Calls (Call_Seq));
while Present (Spg_Call) loop
Visit (Corresponding_Instance (Spg_Call));
Spg_Call := Next_Node (Spg_Call);
end loop;
end if;
Call_Seq := Next_Node (Call_Seq);
end loop;
end if;
end Visit_Subprogram_Instance;
---------------------------
-- Visit_System_Instance --
---------------------------
procedure Visit_System_Instance (E : Node_Id) is
D : Node_Id;
S : Node_Id;
begin
D := Map_Distributed_Application (E);
Push_Entity (D);
if not AAU.Is_Empty (Subcomponents (E)) then
S := First_Node (Subcomponents (E));
while Present (S) loop
-- Visit the corresponding component instance
Visit (Corresponding_Instance (S));
S := Next_Node (S);
end loop;
end if;
Pop_Entity;
end Visit_System_Instance;
---------------------------
-- Visit_Thread_Instance --
---------------------------
procedure Visit_Thread_Instance (E : Node_Id) is
Call_Seq : Node_Id;
Spg_Call : Node_Id;
F : Node_Id;
begin
-- Visit all the thread features
if not AAU.Is_Empty (Features (E)) then
F := First_Node (Features (E));
while Present (F) loop
Visit (Corresponding_Instance (F));
F := Next_Node (F);
end loop;
end if;
-- Visit all the call sequences of the thread
if not AAU.Is_Empty (Calls (E)) then
Call_Seq := First_Node (Calls (E));
while Present (Call_Seq) loop
-- For each call sequence visit all the called
-- subprograms.
if not AAU.Is_Empty (Subprogram_Calls (Call_Seq)) then
Spg_Call := First_Node (Subprogram_Calls (Call_Seq));
while Present (Spg_Call) loop
Visit (Corresponding_Instance (Spg_Call));
Spg_Call := Next_Node (Spg_Call);
end loop;
end if;
Call_Seq := Next_Node (Call_Seq);
end loop;
end if;
end Visit_Thread_Instance;
-----------------------------
-- Protected_Type_Routines --
-----------------------------
function Protected_Type_Routines
(E : Node_Id;
Components : List_Id)
return List_id
is
Routines : constant List_Id := New_List (ADN.K_Statement_List);
N : Node_Id;
A : Node_Id;
Accessor : Name_Id;
begin
-- Declare the private type in the package visible part
-- (which is the Routines list)
N := Make_Full_Type_Declaration
(Defining_Identifier => Map_Ada_Defining_Identifier (E),
Type_Definition => Make_Private_Type_Definition);
Append_Node_To_List (N, Routines);
-- Decalre the full type in the parivate part of the package
-- Add mutex field to the component list
N := Make_Object_Declaration
(Defining_Identifier => Make_Defining_Identifier (VN (V_Mutex)),
Object_Definition => RE (RE_Mutex_Access));
Append_Node_To_List (N, Components);
N := Make_Full_Type_Declaration
(Defining_Identifier => Map_Ada_Defining_Identifier (E),
Type_Definition => Make_Record_Type_Definition
(Make_Record_Definition
(Components)));
Append_Node_To_List (N, ADN.Private_Part (Current_Package));
-- Specification of the subprogram that builds one instance
-- of the protected type.
N := Make_Subprogram_Specification
(Make_Defining_Identifier (SN (S_Build)),
Make_List_Id
(Make_Parameter_Specification
(Make_Defining_Identifier (PN (P_Self)),
Map_Ada_Defining_Identifier (E),
Mode_Out)));
Append_Node_To_List (N, Routines);
Bind_AADL_To_Build (Identifier (E), N);
-- For each field, create an accessor subprogram
-- specification.
A := First_Node (Subcomponents (E));
while Present (A) loop
-- Setter spec
Accessor := Add_Prefix_To_Name
("Set_", To_Ada_Name (Name (Identifier (A))));
N := Make_Subprogram_Specification
(Make_Defining_Identifier (Accessor),
Make_List_Id
(Make_Parameter_Specification
(Make_Defining_Identifier (PN (P_Self)),
Map_Ada_Defining_Identifier (E),
Mode_Inout),
Make_Parameter_Specification
(Make_Defining_Identifier (PN (P_Value)),
Map_Ada_Data_Type_Designator
(Corresponding_Instance (A)))));
Append_Node_To_List (N, Routines);
Bind_AADL_To_Set (Identifier (A), N);
-- Getter spec
Accessor := Add_Prefix_To_Name
("Get_", To_Ada_Name (Name (Identifier (A))));
N := Make_Subprogram_Specification
(Make_Defining_Identifier (Accessor),
Make_List_Id
(Make_Parameter_Specification
(Make_Defining_Identifier (PN (P_Self)),
Map_Ada_Defining_Identifier (E),
Mode_In),
Make_Parameter_Specification
(Make_Defining_Identifier (PN (P_Value)),
Map_Ada_Data_Type_Designator
(Corresponding_Instance (A)),
Mode_Out)));
Append_Node_To_List (N, Routines);
Bind_AADL_To_Get (Identifier (A), N);
A := Next_Node (A);
end loop;
return Routines;
end Protected_Type_Routines;
end Package_Spec;
------------------
-- Package_Body --
------------------
package body Package_Body is
procedure Visit_Architecture_Instance (E : Node_Id);
procedure Visit_Component_Instance (E : Node_Id);
procedure Visit_System_Instance (E : Node_Id);
procedure Visit_Process_Instance (E : Node_Id);
procedure Visit_Thread_Instance (E : Node_Id);
procedure Visit_Data_Instance (E : Node_Id);
procedure Visit_Subprogram_Instance (E : Node_Id);
Current_Process_Instance : Node_Id;
-- Points to the current visited AADL process instance
function Get_Ada_Unit (E : Node_Id) return Node_Id;
pragma Inline (Get_Ada_Unit);
-- Return the Ada unit inside which the data or subprogram
-- component E has to be generated.
function Protected_Type_Routines (E : Node_Id) return List_Id;
-- Declares the routines corresponding to a protected AADL data
-- component. Components is pre-built list of Ada component
-- declaration corresponding to the data subcomponents.
------------------
-- Get_Ada_Unit --
------------------
function Get_Ada_Unit (E : Node_Id) return Node_Id is
N : Node_Id;
P : Node_Id;
U : Node_Id;
begin
pragma Assert (Utils.Is_Data (E) or else Utils.Is_Subprogram (E));
N := Namespace (E);
P := ADN.Namespaces_Node
(Backend_Node
(Bind_Two_Nodes
(N, Current_Process_Instance)));
U := ADN.Distributed_Application_Unit (P);
return U;
end Get_Ada_Unit;
-----------
-- Visit --
-----------
procedure Visit (E : Node_Id) is
begin
case Kind (E) is
when K_Architecture_Instance =>
Visit_Architecture_Instance (E);
when K_Component_Instance =>
Visit_Component_Instance (E);
when others =>
null;
end case;
end Visit;
---------------------------------
-- Visit_Architecture_Instance --
---------------------------------
procedure Visit_Architecture_Instance (E : Node_Id) is
begin
Visit (Root_System (E));
end Visit_Architecture_Instance;
------------------------------
-- Visit_Component_Instance --
------------------------------
procedure Visit_Component_Instance (E : Node_Id) is
Cathegory : constant Component_Category
:= Get_Category_Of_Component (E);
begin
case Cathegory is
when CC_System =>
Visit_System_Instance (E);
when CC_Process =>
Visit_Process_Instance (E);
when CC_Thread =>
Visit_Thread_Instance (E);
when CC_Data =>
Visit_Data_Instance (E);
when CC_Subprogram =>
Visit_Subprogram_Instance (E);
when others =>
null;
end case;
end Visit_Component_Instance;
-------------------------
-- Visit_Data_Instance --
-------------------------
procedure Visit_Data_Instance (E : Node_Id) is
U : constant Node_Id := Get_Ada_Unit (E);
Data_Type : Supported_Data_Type;
N : Node_Id;
begin
-- Push the Ada unit correspoding to the AADL namespace
Push_Entity (U);
Set_Namespaces_Body;
if No (Get_Handling (E, By_Name, H_Ada_Namespaces_Body)) then
Data_Type := Get_Data_Type (E);
case Data_Type is
when Data_With_Accessors | Data_Record =>
declare
Conc_Proto : constant
Supported_Concurrency_Control_Protocol :=
Get_Concurrency_Protocol (E);
C : Node_Id := First_Node (Subcomponents (E));
L : List_Id;
S : Node_Id;
begin
-- Visit the subcomponents
while Present (C) loop
Visit (Corresponding_Instance (C));
C := Next_Node (C);
end loop;
if Conc_Proto = Concurrency_Protected_Access then
-- Protected type
L := Protected_Type_Routines (E);
N := ADN.First_Node (L);
Append_Node_To_List
(N, ADN.Statements (Current_Package));
end if;
-- Mark the data type as being handled
Set_Handling (E, By_Name, H_Ada_Namespaces_Body, E);
-- Bodies of the subprogram features. It is
-- important to do this *after* marking the type
-- as being visited to avoid endless recursion.
if Data_Type = Data_With_Accessors then
S := First_Node (Features (E));
while Present (S) loop
Visit (Corresponding_Instance (S));
S := Next_Node (S);
end loop;
end if;
end;
when others =>
null;
end case;
end if;
Pop_Entity; -- U
end Visit_Data_Instance;
----------------------------
-- Visit_Process_Instance --
----------------------------
procedure Visit_Process_Instance (E : Node_Id) is
S : Node_Id;
begin
Current_Process_Instance := E;
-- Visit recursively all the subcomponents of the process
-- and map them to their corresponding packages.
-- Start recording all handlings because we want to reset
-- them for each node.
Start_Recording_Handlings;
if not AAU.Is_Empty (Subcomponents (E)) then
S := First_Node (Subcomponents (E));
while Present (S) loop
-- Visit the corresponding component instance
Visit (Corresponding_Instance (S));
S := Next_Node (S);
end loop;
end if;
-- Reset all the recorded handlings
Reset_Handlings;
end Visit_Process_Instance;
-------------------------------
-- Visit_Subprogram_Instance --
-------------------------------
procedure Visit_Subprogram_Instance (E : Node_Id) is
U : constant Node_Id := Get_Ada_Unit (E);
N : Node_Id;
F : Node_Id;
Call_Seq : Node_Id;
Spg_Call : Node_Id;
begin
-- Declare all necessary data types
if not AAU.Is_Empty (Features (E)) then
F := First_Node (Features (E));
while Present (F) loop
if Present (Corresponding_Instance (F)) then
Visit (Corresponding_Instance (F));
end if;
F := Next_Node (F);
end loop;
end if;
-- Generate the body of the subprogram
if No (Get_Handling (E, By_Name, H_Ada_Namespaces_Body)) then
Push_Entity (U);
Set_Namespaces_Body;
N := Map_Ada_Subprogram_Body (E);
Append_Node_To_List (N, ADN.Statements (Current_Package));
-- Mark the data type as being handled
Set_Handling (E, By_Name, H_Ada_Namespaces_Body, N);
-- If the subprogram is hybrid, generate extra entities
if Get_Subprogram_Kind (E) = Subprogram_Hybrid_Ada_95 then
Call_Seq := First_Node (Calls (E));
while Present (Call_Seq) loop
-- For each call sequence create a subprogram body
N := Map_Ada_Call_Seq_Subprogram_Body (E, Call_Seq);
Append_Node_To_List (N, ADN.Statements (Current_Package));
Call_Seq := Next_Node (Call_Seq);
end loop;
end if;
end if;
-- Visit all the call sequences of the subprogram
if not AAU.Is_Empty (Calls (E)) then
Call_Seq := First_Node (Calls (E));
while Present (Call_Seq) loop
-- For each call sequence visit all the called
-- subprograms.
if not AAU.Is_Empty (Subprogram_Calls (Call_Seq)) then
Spg_Call := First_Node (Subprogram_Calls (Call_Seq));
while Present (Spg_Call) loop
Visit (Corresponding_Instance (Spg_Call));
Spg_Call := Next_Node (Spg_Call);
end loop;
end if;
Call_Seq := Next_Node (Call_Seq);
end loop;
end if;
end Visit_Subprogram_Instance;
---------------------------
-- Visit_System_Instance --
---------------------------
procedure Visit_System_Instance (E : Node_Id) is
S : Node_Id;
begin
Push_Entity (QoS_Distributed_Application_Root);
if not AAU.Is_Empty (Subcomponents (E)) then
S := First_Node (Subcomponents (E));
while Present (S) loop
-- Visit the corresponding component instance
Visit (Corresponding_Instance (S));
S := Next_Node (S);
end loop;
end if;
Pop_Entity; -- QoS_Distributed_Application_Root
end Visit_System_Instance;
---------------------------
-- Visit_Thread_Instance --
---------------------------
procedure Visit_Thread_Instance (E : Node_Id) is
Call_Seq : Node_Id;
Spg_Call : Node_Id;
F : Node_Id;
begin
-- Visit all the thread features
if not AAU.Is_Empty (Features (E)) then
F := First_Node (Features (E));
while Present (F) loop
Visit (Corresponding_Instance (F));
F := Next_Node (F);
end loop;
end if;
-- Visit all the call sequences of the thread
if not AAU.Is_Empty (Calls (E)) then
Call_Seq := First_Node (Calls (E));
while Present (Call_Seq) loop
-- For each call sequence visit all the called
-- subprograms.
if not AAU.Is_Empty (Subprogram_Calls (Call_Seq)) then
Spg_Call := First_Node (Subprogram_Calls (Call_Seq));
while Present (Spg_Call) loop
Visit (Corresponding_Instance (Spg_Call));
Spg_Call := Next_Node (Spg_Call);
end loop;
end if;
Call_Seq := Next_Node (Call_Seq);
end loop;
end if;
end Visit_Thread_Instance;
-----------------------------
-- Protected_Type_Routines --
-----------------------------
function Protected_Type_Routines (E : Node_Id) return List_Id is
Routines : constant List_Id := New_List (ADN.K_Statement_List);
N : Node_Id;
A : Node_Id;
Spec : Node_Id;
Statements : List_Id;
begin
-- Builder implementation
Spec := ADN.Build_Node (Backend_Node (Identifier (E)));
Statements := New_List (ADN.K_Statement_List);
N := Make_Subprogram_Call
(RE (RE_Create_2),
Make_List_Id
(Make_Selected_Component
(Make_Defining_Identifier (PN (P_Self)),
Make_Defining_Identifier (VN (V_Mutex)))));
Append_Node_To_List (N, Statements);
N := Make_Subprogram_Implementation (Spec, No_List, Statements);
Append_Node_To_List (N, Routines);
A := First_Node (Subcomponents (E));
while Present (A) loop
-- Setter implementation
Spec := ADN.Set_Node (Backend_Node (Identifier (A)));
Statements := New_List (ADN.K_Statement_List);
N := Make_Subprogram_Call
(RE (RE_Enter),
Make_List_Id
(Make_Selected_Component
(Make_Defining_Identifier (PN (P_Self)),
Make_Defining_Identifier (VN (V_Mutex)))));
Append_Node_To_List (N, Statements);
N := Make_Assignment_Statement
(Make_Selected_Component
(Make_Defining_Identifier (PN (P_Self)),
Map_Ada_Defining_Identifier (A)),
Make_Defining_Identifier (PN (P_Value)));
ADU.Append_Node_To_List (N, Statements);
N := Make_Subprogram_Call
(RE (RE_Leave),
Make_List_Id
(Make_Selected_Component
(Make_Defining_Identifier (PN (P_Self)),
Make_Defining_Identifier (VN (V_Mutex)))));
Append_Node_To_List (N, Statements);
N := Make_Subprogram_Implementation (Spec, No_List, Statements);
ADU.Append_Node_To_List (N, Routines);
-- Getter implementation
Spec := ADN.Get_Node (Backend_Node (Identifier (A)));
Statements := New_List (ADN.K_Statement_List);
N := Make_Subprogram_Call
(RE (RE_Enter),
Make_List_Id
(Make_Selected_Component
(Make_Defining_Identifier (PN (P_Self)),
Make_Defining_Identifier (VN (V_Mutex)))));
Append_Node_To_List (N, Statements);
N := Make_Assignment_Statement
(Make_Defining_Identifier (PN (P_Value)),
Make_Selected_Component
(Make_Defining_Identifier (PN (P_Self)),
Map_Ada_Defining_Identifier (A)));
ADU.Append_Node_To_List (N, Statements);
N := Make_Subprogram_Call
(RE (RE_Leave),
Make_List_Id
(Make_Selected_Component
(Make_Defining_Identifier (PN (P_Self)),
Make_Defining_Identifier (VN (V_Mutex)))));
Append_Node_To_List (N, Statements);
N := Make_Subprogram_Implementation (Spec, No_List, Statements);
ADU.Append_Node_To_List (N, Routines);
A := Next_Node (A);
end loop;
return Routines;
end Protected_Type_Routines;
end Package_Body;
end Ocarina.Generators.PO_QoS_Ada.Namespaces;
|