ocarina-be_aadl-namespaces.adb 20 KB
Newer Older
1
2
3
4
5
6
7
8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--           O C A R I N A . B E _ A A D L . N A M E S P A C E S            --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--    Copyright (C) 2008-2009 Telecom ParisTech, 2010-2017 ESA & ISAE.      --
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
--                                                                          --
-- Ocarina  is free software; you can redistribute it and/or modify under   --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion. 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.                     --
--                                                                          --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception,   --
-- version 3.1, as published by the Free Software Foundation.               --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
26
--                                                                          --
jhugues's avatar
jhugues committed
27
28
--                 Ocarina is maintained by the TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
29
30
31
--                                                                          --
------------------------------------------------------------------------------

32
with Ocarina.Output;
33
34
35
36
37

with Ocarina.ME_AADL;
with Ocarina.ME_AADL.AADL_Tree.Nodes;
with Ocarina.ME_AADL.AADL_Tree.Nutils;
with Ocarina.Property_Sets;
38
with Ocarina.BE_AADL.Annexes;
39
40
with Ocarina.BE_AADL.Components;
with Ocarina.BE_AADL.Identifiers;
41
with Ocarina.BE_AADL.Properties;
42
43
44

package body Ocarina.BE_AADL.Namespaces is

45
   use Ocarina.Output;
46
47
48
49
   use Ocarina.ME_AADL;
   use Ocarina.ME_AADL.AADL_Tree.Nodes;
   use Ocarina.ME_AADL.AADL_Tree.Nutils;
   use Ocarina.Property_Sets;
50
   use Ocarina.BE_AADL.Annexes;
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
   use Ocarina.BE_AADL.Components;
   use Ocarina.BE_AADL.Properties;
   use Ocarina.BE_AADL.Identifiers;

   procedure Print_Import_Declaration (Node : Node_Id);
   procedure Print_Alias_Declaration (Node : Node_Id);

   ------------------------------------
   -- Print_Constrained_Property_Set --
   ------------------------------------

   procedure Print_Constrained_Property_Set
     (Node      : Node_Id;
      Criterion : Node_Id)
   is
66
67
      Ident     : constant Node_Id := Identifier (Node);
      List_Node : Node_Id;
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

      Someting_To_Print : Boolean := False;
   begin
      --  We do not print standard property sets.

      if not Is_User_Defined (Ident) then
         return;
      end if;

      --  First of all see whether the constraint let us some
      --  declarations to print.

      if not Is_Empty (Declarations (Node)) then
         List_Node := First_Node (Declarations (Node));

         while Present (List_Node) loop

85
86
            Someting_To_Print :=
              Is_Printable (List_Node, Criterion) or else Someting_To_Print;
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

            exit when Someting_To_Print;

            List_Node := Next_Node (List_Node);
         end loop;
      end if;

      if not Someting_To_Print then
         return;
      end if;

      Print_Tokens ((T_Property, T_Set));
      Write_Space;
      Print_Identifier (Ident);
      Write_Space;
      Print_Token (T_Is);
      Write_Eol;

      if not Is_Empty (Imports_List (Node)) then
         List_Node := First_Node (Imports_List (Node));

         while Present (List_Node) loop
            if List_Node /= First_Node (Imports_List (Node)) then
               Write_Eol;
            end if;

            Print_Import_Declaration (List_Node);

            List_Node := Next_Node (List_Node);
         end loop;

         Write_Eol;
         Write_Eol;
      end if;

      if not Is_Empty (Declarations (Node)) then
         List_Node := First_Node (Declarations (Node));
         Increment_Indentation;

         while Present (List_Node) loop
            if Is_Printable (List_Node, Criterion) then
               case Kind (List_Node) is
                  when K_Property_Definition_Declaration =>
                     Print_Property_Definition_Declaration (List_Node);

                  when K_Property_Type_Declaration =>
                     Print_Property_Type_Declaration (List_Node);

                  when K_Constant_Property_Declaration =>
                     Print_Constant_Property (List_Node);

                  when others =>
                     Node_Not_Handled (List_Node);
               end case;
            end if;

            List_Node := Next_Node (List_Node);
         end loop;

         Decrement_Indentation;
      end if;

      Write_Indentation;
      Print_Token (T_End);
      Write_Space;
      Print_Identifier (Ident);
      Print_Token (T_Semicolon);
      Write_Eol;
   end Print_Constrained_Property_Set;

   ------------------------
   -- Print_Property_Set --
   ------------------------

   procedure Print_Property_Set (Node : Node_Id) is
162
163
164
      procedure Internal_Print_Property_Set is
         new Print_Constrained_Property_Set
        (Always_Printable);
yoogx's avatar
yoogx committed
165

166
167
168
169
170
171
172
173
174
175
176
177
178
   begin
      Internal_Print_Property_Set (Node, No_Node);
   end Print_Property_Set;

   -------------------------------
   -- Print_Constrained_Package --
   -------------------------------

   procedure Print_Constrained_Package (Node : Node_Id; Criterion : Node_Id) is
      pragma Assert (Kind (Node) = K_Package_Specification);

      Pack_Identifier   : constant Node_Id := Identifier (Node);
      List_Node         : Node_Id;
179
180
181
      Someting_To_Print : Boolean          := False;
      Has_Public        : Boolean          := False;
      Has_Private       : Boolean          := False;
182
183
184
185
186
187
188
189
   begin
      --  First of all see whether the constraint let us some
      --  declarations to print.

      if not Is_Empty (Declarations (Node)) then
         List_Node := First_Node (Declarations (Node));

         while Present (List_Node) loop
190
191
            Someting_To_Print :=
              Is_Printable (List_Node, Criterion) or else Someting_To_Print;
192

193
194
            Has_Public  := Has_Public or else not Is_Private (List_Node);
            Has_Private := Has_Private or else Is_Private (List_Node);
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

            List_Node := Next_Node (List_Node);
         end loop;
      end if;

      Increment_Indentation;
      Print_Token (T_Package);
      Write_Space;
      Print_Identifier (Pack_Identifier);
      Write_Eol;

      --  Public part

      if Has_Public then
         Print_Token (T_Public);
         Write_Eol;

         List_Node := First_Node (Declarations (Node));

         while Present (List_Node) loop
            if not Is_Private (List_Node)
              and then Is_Printable (List_Node, Criterion)
            then
               case Kind (List_Node) is
                  when K_Component_Type =>
                     Print_Component_Type (List_Node);

                  when K_Component_Implementation =>
                     Print_Component_Implementation (List_Node);

                  when K_Feature_Group_Type =>
                     Print_Feature_Group_Type (List_Node);

                  when K_Name_Visibility_Declaration =>
                     Print_Name_Visibility_Declaration (List_Node);

231
232
233
                  when K_Annex_Library =>
                     Print_Annex_Library (List_Node);

234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
                  when others =>
                     raise Program_Error;
               end case;
            end if;

            Write_Eol;
            List_Node := Next_Node (List_Node);
         end loop;

         if not Is_Empty (Ocarina.ME_AADL.AADL_Tree.Nodes.Properties (Node))
           and then AADL_Version = AADL_V1
         then
            declare
               Number_Of_Properties : Integer := 0;
            begin
249
250
251
               List_Node :=
                 First_Node
                   (Ocarina.ME_AADL.AADL_Tree.Nodes.Properties (Node));
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268

               while Present (List_Node) loop
                  if not Is_Private (List_Node)
                    and then Is_Printable (List_Node, Criterion)
                  then
                     Number_Of_Properties := Number_Of_Properties + 1;
                  end if;

                  List_Node := Next_Node (List_Node);
               end loop;

               if Number_Of_Properties > 0 then
                  Print_Token (T_Properties);
                  Write_Eol;
               end if;
            end;

269
270
            List_Node :=
              First_Node (Ocarina.ME_AADL.AADL_Tree.Nodes.Properties (Node));
271
272
273
274
275
276
277
278
279
280
281
282
283

            while Present (List_Node) loop
               if not Is_Private (List_Node)
                 and then Is_Printable (List_Node, Criterion)
               then
                  Print_Property_Association (List_Node);
               end if;

               List_Node := Next_Node (List_Node);
            end loop;
         end if;
      end if;

284
285
286
287
      --  Annex subclauses

      if not Is_Empty (Ocarina.ME_AADL.AADL_Tree.Nodes.Annexes (Node)) then
         Increment_Indentation;
288
289
         List_Node :=
           First_Node (Ocarina.ME_AADL.AADL_Tree.Nodes.Annexes (Node));
290
291
292
293
294
295
296
297
298
299

         while Present (List_Node) loop
            Print_Annex_Subclause (List_Node);
            List_Node := Next_Node (List_Node);
         end loop;

         Decrement_Indentation;
         Write_Eol;
      end if;

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
      --  private part

      if Has_Private then
         Print_Token (T_Private);
         Write_Eol;

         List_Node := First_Node (Declarations (Node));

         while Present (List_Node) loop
            if Is_Private (List_Node)
              and then Is_Printable (List_Node, Criterion)
            then
               case Kind (List_Node) is
                  when K_Component_Type =>
                     Print_Component_Type (List_Node);

                  when K_Component_Implementation =>
                     Print_Component_Implementation (List_Node);

                  when K_Feature_Group_Type =>
                     Print_Feature_Group_Type (List_Node);

                  when K_Name_Visibility_Declaration =>
                     Print_Name_Visibility_Declaration (List_Node);
                  when others =>
                     raise Program_Error;
               end case;

               Write_Eol;
            end if;

            List_Node := Next_Node (List_Node);
         end loop;

         if not Is_Empty (Ocarina.ME_AADL.AADL_Tree.Nodes.Properties (Node))
           and then AADL_Version = AADL_V1
         then
            declare
               Number_Of_Properties : Integer := 0;
            begin
340
341
342
               List_Node :=
                 First_Node
                   (Ocarina.ME_AADL.AADL_Tree.Nodes.Properties (Node));
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359

               while Present (List_Node) loop
                  if Is_Private (List_Node)
                    and then Is_Printable (List_Node, Criterion)
                  then
                     Number_Of_Properties := Number_Of_Properties + 1;
                  end if;

                  List_Node := Next_Node (List_Node);
               end loop;

               if Number_Of_Properties > 0 then
                  Print_Token (T_Properties);
                  Write_Eol;
               end if;
            end;

360
361
            List_Node :=
              First_Node (Ocarina.ME_AADL.AADL_Tree.Nodes.Properties (Node));
362
363
364
365
366
367
368
369
370
371
372
373
374
375

            while Present (List_Node) loop
               if Is_Private (List_Node)
                 and then Is_Printable (List_Node, Criterion)
               then
                  Print_Property_Association (List_Node);
               end if;

               List_Node := Next_Node (List_Node);
            end loop;
         end if;
      end if;

      if AADL_Version = AADL_V2 then
376
377
378
379
380
         if not Is_Empty
             (Ocarina.ME_AADL.AADL_Tree.Nodes.Properties (Node))
         then
            List_Node :=
              First_Node (Ocarina.ME_AADL.AADL_Tree.Nodes.Properties (Node));
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404

            while Present (List_Node) loop
               if Is_Printable (List_Node, Criterion) then
                  Print_Property_Association (List_Node);
               end if;

               List_Node := Next_Node (List_Node);
            end loop;
         end if;
      end if;

      Print_Token (T_End);
      Write_Space;
      Print_Identifier (Pack_Identifier);
      Print_Token (T_Semicolon);
      Write_Eol;
      Decrement_Indentation;
   end Print_Constrained_Package;

   -------------------
   -- Print_Package --
   -------------------

   procedure Print_Package (Node : Node_Id) is
405
406
      procedure Internal_Print_Package is new Print_Constrained_Package
        (Always_Printable);
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
   begin
      Internal_Print_Package (Node, No_Node);
   end Print_Package;

   ------------------------------------------
   -- Print_Constrained_AADL_Specification --
   ------------------------------------------

   procedure Print_Constrained_AADL_Specification
     (Node      : Node_Id;
      Criterion : Node_Id)
   is
      pragma Assert (Kind (Node) = K_AADL_Specification);

      --  Some internal procedures

423
424
      procedure Internal_Print_Package is new Print_Constrained_Package
        (Is_Printable);
yoogx's avatar
yoogx committed
425

426
427
428
      procedure Internal_Print_Property_Set is
         new Print_Constrained_Property_Set
        (Is_Printable);
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

      List_Node : Node_Id;
   begin
      if not Is_Empty (Declarations (Node)) then
         List_Node := First_Node (Declarations (Node));

         while Present (List_Node) loop
            case Kind (List_Node) is
               when K_Component_Type =>
                  if Is_Printable (List_Node, Criterion) then
                     Print_Component_Type (List_Node);
                  end if;

               when K_Component_Implementation =>
                  if Is_Printable (List_Node, Criterion) then
                     Print_Component_Implementation (List_Node);
                  end if;

               when K_Feature_Group_Type =>
                  if Is_Printable (List_Node, Criterion) then
                     Print_Feature_Group_Type (List_Node);
                  end if;

               when K_Package_Specification =>
                  Internal_Print_Package (List_Node, Criterion);

               when K_Property_Set =>
                  Internal_Print_Property_Set (List_Node, Criterion);

               when others =>
                  raise Program_Error;
            end case;

            Write_Eol;
            List_Node := Next_Node (List_Node);
         end loop;
      end if;
   end Print_Constrained_AADL_Specification;

   ------------------------------
   -- Print_AADL_Specification --
   ------------------------------

   procedure Print_AADL_Specification (Node : Node_Id) is
473
474
475
      procedure Internal_Print_AADL_Specification is
         new Print_Constrained_AADL_Specification
        (Always_Printable);
yoogx's avatar
yoogx committed
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
   begin
      Internal_Print_AADL_Specification (Node, No_Node);
   end Print_AADL_Specification;

   ---------------------------------------
   -- Print_Name_Visibility_Declaration --
   ---------------------------------------

   procedure Print_Name_Visibility_Declaration (Node : Node_Id) is
      List_Node : Node_Id;

   begin
      List_Node := First_Node (List_Items (Node));

      while Present (List_Node) loop
         Write_Indentation;
         case Kind (List_Node) is
            when K_Import_Declaration =>
               Print_Import_Declaration (List_Node);

            when K_Alias_Declaration =>
               Print_Alias_Declaration (List_Node);
            when others =>
               raise Program_Error;
         end case;

         Write_Eol;
         List_Node := Next_Node (List_Node);
      end loop;
   end Print_Name_Visibility_Declaration;

   ------------------------------
   -- Print_Import_Declaration --
   ------------------------------

   procedure Print_Import_Declaration (Node : Node_Id) is
      List_Node : Node_Id;
      Name_Node : Node_Id;

   begin
      List_Node := First_Node (List_Items (Node));

      Print_Token (T_With);
      Write_Space;

      while Present (List_Node) loop
         if List_Node /= First_Node (List_Items (Node)) then
            Print_Token (T_Comma);
            Write_Space;
         end if;

         case Kind (List_Node) is
            when K_Identifier =>
               Print_Identifier (List_Node);

            when K_Package_Name =>
533
534
535
               Name_Node :=
                 First_Node
                   (Ocarina.ME_AADL.AADL_Tree.Nodes.Identifiers (List_Node));
536
               while Present (Name_Node) loop
537
538
539
                  if Name_Node /=
                    First_Node
                      (Ocarina.ME_AADL.AADL_Tree.Nodes.Identifiers (List_Node))
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
                  then
                     Print_Token (T_Colon_Colon);
                  end if;

                  Print_Identifier (Name_Node);
                  Name_Node := Next_Node (Name_Node);
               end loop;

            when others =>
               raise Program_Error;
         end case;

         List_Node := Next_Node (List_Node);
      end loop;

      Print_Token (T_Semicolon);
   end Print_Import_Declaration;

   -----------------------------
   -- Print_Alias_Declaration --
   -----------------------------

   procedure Print_Alias_Declaration (Node : Node_Id) is
      List_Node  : Node_Id;
      Entity_Cat : Ocarina.ME_AADL.Entity_Category;
      Is_All     : Boolean := False;

   begin
568
569
570
      Entity_Cat :=
        Ocarina.ME_AADL.Entity_Category'Val
          (Ocarina.ME_AADL.AADL_Tree.Nodes.Entity_Category (Node));
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585

      Is_All := Ocarina.ME_AADL.AADL_Tree.Nodes.Is_All (Node);

      case Entity_Cat is
         when EC_Package =>
            if Is_All then
               Print_Token (T_Renames);
            else
               Print_Identifier (Identifier (Node));
               Write_Space;
               Print_Tokens ((T_Renames, T_Package));
            end if;

            Write_Space;

586
587
588
589
            List_Node :=
              First_Node
                (Ocarina.ME_AADL.AADL_Tree.Nodes.Identifiers
                   (Package_Name (Node)));
590
            while Present (List_Node) loop
591
592
593
594
               if List_Node /=
                 First_Node
                   (Ocarina.ME_AADL.AADL_Tree.Nodes.Identifiers
                      (Package_Name (Node)))
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
               then
                  Print_Token (T_Colon_Colon);
               end if;

               Print_Identifier (List_Node);

               List_Node := Next_Node (List_Node);
            end loop;

            if Is_All then
               Print_Token (T_Colon_Colon);
               Print_Token (T_All);
            end if;

         when EC_Component =>
            if Identifier (Node) /= No_Node then
               Print_Identifier (Identifier (Node));
               Write_Space;
            end if;

            Print_Token (T_Renames);
            Write_Space;
            Print_Component_Category (Category (Node));
            Write_Space;
            Print_Entity_Reference (Reference (Node));

         when EC_Feature_Group_Type =>
            if Identifier (Node) /= No_Node then
               Print_Identifier (Identifier (Node));
               Write_Space;
            end if;

            Print_Tokens ((T_Renames, T_Feature, T_Group));
            Write_Space;
            Print_Entity_Reference (Reference (Node));

         when others =>
            raise Program_Error;
      end case;

      Print_Token (T_Semicolon);

   end Print_Alias_Declaration;

end Ocarina.BE_AADL.Namespaces;