ocarina-backends-utils.adb 122 KB
Newer Older
1
2
3
4
5
6
7
8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--               O C A R I N A . B A C K E N D S . U T I L S                --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--    Copyright (C) 2005-2009 Telecom ParisTech, 2010-2014 ESA & ISAE.      --
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
--                                                                          --
-- 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.                                       --
--                                                                          --
jhugues's avatar
jhugues committed
29
30
--                 Ocarina is maintained by the TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
31
32
33
34
--                                                                          --
------------------------------------------------------------------------------

with GNAT.OS_Lib;
35
with Ada.Directories;
36
37
with GNAT.Table;

38
with Ocarina.Namet;
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
with Locations;

with Ocarina.ME_AADL;
with Ocarina.ME_AADL.AADL_Tree.Nodes;
with Ocarina.ME_AADL.AADL_Tree.Nutils;
with Ocarina.ME_AADL.AADL_Tree.Entities.Properties;
with Ocarina.ME_AADL.AADL_Instances.Nodes;
with Ocarina.ME_AADL.AADL_Instances.Nutils;
with Ocarina.ME_AADL.AADL_Instances.Entities;
with Ocarina.Backends.Messages;
with Ocarina.Backends.Ada_Tree.Nodes;
with Ocarina.Backends.Ada_Tree.Nutils;
with Ocarina.Backends.Ada_Values;

package body Ocarina.Backends.Utils is

   package ATN renames Ocarina.ME_AADL.AADL_Tree.Nodes;
   package ATU renames Ocarina.ME_AADL.AADL_Tree.Nutils;
   package AIN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
   package AAU renames Ocarina.ME_AADL.AADL_Instances.Nutils;
   package ADN renames Ocarina.Backends.Ada_Tree.Nodes;
   package ADU renames Ocarina.Backends.Ada_Tree.Nutils;
   package ADV renames Ocarina.Backends.Ada_Values;

   use GNAT.OS_Lib;
64
65
   use Ada.Directories;

66
   use Ocarina.Namet;
67
68
69
70
71
72
73
74
75
76
   use Locations;
   use Ocarina.ME_AADL;
   use Ocarina.ME_AADL.AADL_Instances.Nodes;
   use Ocarina.ME_AADL.AADL_Instances.Nutils;
   use Ocarina.ME_AADL.AADL_Instances.Entities;
   use Ocarina.Backends.Messages;
   use Ocarina.Backends.Ada_Tree.Nutils;

   --  The entered directories stack

77
   package Directories_Stack is new GNAT.Table (Name_Id, Int, 1, 5, 10);
78
79
80
81

   function Get_Handling_Internal_Name
     (E          : Node_Id;
      Comparison : Comparison_Kind;
82
      Handling   : Handling_Kind) return Name_Id;
83
84
85
86
87
88
89
90
91
92
93
94
95
96
   --  Code factorisation between Set_Handling and Get_Handling. This
   --  function computes an internal name used to store the handling
   --  information.

   function Map_Ada_Subprogram_Status_Name (S : Node_Id) return Name_Id;
   --  Maps an name for the record type corresponding to a hybrid
   --  subprogram.

   function Map_Ada_Call_Seq_Access_Name (S : Node_Id) return Name_Id;
   --  Maps an name for the subprogram access type corresponding to a
   --  hybrid subprogram.

   function Map_Ada_Call_Seq_Subprogram_Name
     (Spg : Node_Id;
97
      Seq : Node_Id) return Name_Id;
98
99
100
101
102
103
104
105
106
107
108
109
110
111
   --  Maps an name for the subprogram corresponding to a hybrid
   --  subprogram call sequence.

   type Repository_Entry is record
      E          : Node_Id;
      Comparison : Comparison_Kind;
      Handling   : Handling_Kind;
      A          : Node_Id;
   end record;
   --  One entry of the internal handling repository

   Recording_Requested : Boolean := False;

   package Handling_Repository is new GNAT.Table
112
113
114
115
116
     (Repository_Entry,
      Int,
      1,
      5,
      10);
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
   --  The internal handling repository

   procedure May_Be_Append_Handling_Entry
     (E          : Node_Id;
      Comparison : Comparison_Kind;
      Handling   : Handling_Kind;
      A          : Node_Id);
   --  Add a new entry corresponding to the given parameters to the
   --  internal handling repository. The addition is only done in case
   --  the user requested explicitely the recording of handling

   function Bind_Transport_API_Internal_Name (P : Node_Id) return Name_Id;
   --  For code factorization purpose

   ----------------------
   -- Create_Directory --
   ----------------------

   procedure Create_Directory (Dir_Full_Name : Name_Id) is
      Dir_Full_String : constant String := Get_Name_String (Dir_Full_Name);
   begin
      if Is_Regular_File (Dir_Full_String)
        or else Is_Symbolic_Link (Dir_Full_String)
      then
         Display_Error
142
143
144
           ("Cannot create " &
            Dir_Full_String &
            " because there is a file with the same name",
145
146
147
148
149
            Fatal => True);
         return;
      end if;

      if Is_Directory (Dir_Full_String) then
150
151
         if Dir_Full_String /= "." then
            Display_Error
152
              (Dir_Full_String & " already exists",
153
154
155
               Fatal   => False,
               Warning => True);
         end if;
156
157
158
159
160
         return;
      end if;

      --  The directory name does not clash with anything, create it

161
      Create_Directory (Dir_Full_String);
162
163
164
165
166
167
168
169
170
   end Create_Directory;

   ---------------------
   -- Enter_Directory --
   ---------------------

   procedure Enter_Directory (Dirname : Name_Id) is
      use Directories_Stack;

171
172
      Current_Dir : constant Name_Id := Get_String_Name (Current_Directory);

173
174
   begin
      Increment_Last;
175
      Table (Last) := Current_Dir;
176
      Display_Debug_Message ("Left    : " & Get_Name_String (Current_Dir));
177
      Set_Directory (Get_Name_String (Dirname));
178
179
180
181
182
183
184
185
186
187
      Display_Debug_Message ("Entered : " & Get_Name_String (Dirname));
   end Enter_Directory;

   ---------------------
   -- Leave_Directory --
   ---------------------

   procedure Leave_Directory is
      use Directories_Stack;

188
189
      Last_Directory : constant Name_Id := Table (Last);

190
191
   begin
      Decrement_Last;
192
193
      Display_Debug_Message ("Left    : " & Current_Directory);
      Set_Directory (Get_Name_String (Last_Directory));
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
      Display_Debug_Message ("Entered : " & Get_Name_String (Last_Directory));
   end Leave_Directory;

   -----------------------------
   -- Add_Directory_Separator --
   -----------------------------

   function Add_Directory_Separator (Path : Name_Id) return Name_Id is
   begin
      Get_Name_String (Path);
      if Name_Buffer (Name_Len) /= Directory_Separator then
         Add_Char_To_Name_Buffer (Directory_Separator);
      end if;
      return Name_Find;
   end Add_Directory_Separator;

   --------------------------------
   -- Remove_Directory_Separator --
   --------------------------------

   function Remove_Directory_Separator (Path : Name_Id) return Name_Id is
   begin
      Get_Name_String (Path);

      if Name_Buffer (Name_Len) = Directory_Separator then
         Name_Len := Name_Len - 1;
      end if;
      return Name_Find;
   end Remove_Directory_Separator;

   ----------------------------------
   -- May_Be_Append_Handling_Entry --
   ----------------------------------

   procedure May_Be_Append_Handling_Entry
     (E          : Node_Id;
      Comparison : Comparison_Kind;
      Handling   : Handling_Kind;
      A          : Node_Id)
   is
      package HR renames Handling_Repository;
      The_Entry : constant Repository_Entry :=
236
237
        Repository_Entry'
          (E => E, Comparison => Comparison, Handling => Handling, A => A);
238
239
240
241
242
243
244
245
246
247
248
249
250
251
   begin
      if Recording_Requested then
         HR.Increment_Last;
         HR.Table (HR.Last) := The_Entry;
      end if;
   end May_Be_Append_Handling_Entry;

   -------------------------------
   -- Start_Recording_Handlings --
   -------------------------------

   procedure Start_Recording_Handlings is
   begin
      if Recording_Requested then
252
253
         raise Program_Error
           with "Consecutive calls to Start_Recording_Handlings are forbidden";
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
      else
         Recording_Requested := True;
      end if;
   end Start_Recording_Handlings;

   ------------------------------
   -- Stop_Recording_Handlings --
   ------------------------------

   procedure Stop_Recording_Handlings is
   begin
      Recording_Requested := False;
   end Stop_Recording_Handlings;

   ---------------------
   -- Reset_Handlings --
   ---------------------

   procedure Reset_Handlings is
      package HR renames Handling_Repository;

      Index     : Int := HR.First;
      The_Entry : Repository_Entry;
   begin
      --  Disable the user handling request. It is important to do
      --  this at the beginning to avoid adding new entries when
      --  resetting.

      Recording_Requested := False;

      while Index <= HR.Last loop
         The_Entry := HR.Table (Index);

         --  Reset the handling information

         Set_Handling
           (The_Entry.E,
            The_Entry.Comparison,
            The_Entry.Handling,
            No_Node);

         Index := Index + 1;
      end loop;

      --  Deallocate and reinitialize the repository

      HR.Free;
      HR.Init;
   end Reset_Handlings;

   --------------------
   -- Normalize_Name --
   --------------------

308
309
310
311
   function Normalize_Name
     (Name      : Name_Id;
      Ada_Style : Boolean := False) return Name_Id
   is
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
      Normalized_Name : Name_Id;
   begin
      --  FIXME: The algorithm does not ensure a bijection between
      --  the input and the output. It should be improved.

      if Name = No_Name then
         Normalized_Name := Name;
      else
         declare
            Initial_Name : constant String := Get_Name_String (Name);
         begin
            Name_Len := 0;

            for Index in Initial_Name'First .. Initial_Name'Last loop
               if Initial_Name (Index) = '.' then
                  Add_Char_To_Name_Buffer ('_');
                  if Ada_Style then
                     Add_Char_To_Name_Buffer ('_');
                  end if;
               elsif Initial_Name (Index) = '-' then
                  Add_Char_To_Name_Buffer ('_');
                  if Ada_Style then
                     Add_Char_To_Name_Buffer ('_');
                  end if;
yoogx's avatar
yoogx committed
336
337
338
339
340
341
               elsif Initial_Name (Index) = ':' then
                  Add_Char_To_Name_Buffer ('_');
                  if Ada_Style then
                     Add_Char_To_Name_Buffer ('_');
                  end if;

342
343
344
345
346
347
348
349
350
351
352
353
               else
                  Add_Char_To_Name_Buffer (Initial_Name (Index));
               end if;
            end loop;

            Normalized_Name := Name_Find;
         end;
      end if;

      return Normalized_Name;
   end Normalize_Name;

354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
   -----------------------------------
   -- Fully_Qualified_Instance_Name --
   -----------------------------------

   function Fully_Qualified_Instance_Name (E : Node_Id) return Name_Id is
      Current_Node : Node_Id := Parent_Subcomponent (E);
      Current_Name : Name_Id;

   begin
      Set_Str_To_Name_Buffer ("");
      Get_Name_String (Normalize_Name (Name (Identifier (Current_Node))));
      Current_Name := Name_Find;
      Current_Node := Parent_Component (Current_Node);

      while Present (Current_Node) loop
         exit when No (Parent_Subcomponent (Current_Node));

371
372
373
374
375
376
377
         Get_Name_String
           (Normalize_Name
              (Name (Identifier (Parent_Subcomponent (Current_Node)))));
         Set_Str_To_Name_Buffer
           (Get_Name_String (Name_Find) &
            "_" &
            Get_Name_String (Current_Name));
378
379
380
381
382
383
384
385
         Current_Name := Name_Find;

         Current_Node := Parent_Component (Parent_Subcomponent (Current_Node));
      end loop;

      return Current_Name;
   end Fully_Qualified_Instance_Name;

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
   ------------------
   -- Is_Namespace --
   ------------------

   function Is_Namespace (N : Node_Id) return Boolean is
   begin
      return Kind (N) = K_Namespace_Instance;
   end Is_Namespace;

   ----------------
   -- Is_Delayed --
   ----------------

   function Is_Delayed (E : Node_Id) return Boolean is
      C : Node_Id;
      S : Node_Id;
   begin
      pragma Assert
        (Kind (E) = K_Port_Spec_Instance and then not Is_Event (E));

      if not AAU.Is_Empty (Sources (E)) then
         C := Extra_Item (First_Node (Sources (E)));

         case AADL_Version is
            when AADL_V1 =>
411
412
               if ATN.Category (Corresponding_Declaration (C)) =
                 Connection_Type'Pos (CT_Data_Delayed)
413
414
415
416
417
418
419
               then
                  return True;
               else
                  --  Recurse through the connection path

                  S := Item (First_Node (Sources (E)));

420
421
422
                  return S /= E
                    and then Kind (S) = K_Port_Spec_Instance
                    and then Is_Delayed (S);
423
424
425
426
427
428
429
430
431
432
               end if;

            when AADL_V2 =>
               if Get_Port_Timing (E) = Port_Timing_Delayed then
                  return True;
               else
                  --  Recurse through the connection path

                  S := Item (First_Node (Sources (E)));

433
434
435
                  return S /= E
                    and then Kind (S) = K_Port_Spec_Instance
                    and then Is_Delayed (S);
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
               end if;
         end case;
      end if;

      return False;
   end Is_Delayed;

   -----------------------
   -- Has_In_Parameters --
   -----------------------

   function Has_In_Parameters (E : Node_Id) return Boolean is
      F : Node_Id;
   begin
      if not AAU.Is_Empty (Features (E)) then
         F := First_Node (Features (E));

         while Present (F) loop
            if Kind (F) = K_Parameter_Instance and then Is_In (F) then
               return True;
            end if;

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

      return False;
   end Has_In_Parameters;

   ------------------------
   -- Has_Out_Parameters --
   ------------------------

   function Has_Out_Parameters (E : Node_Id) return Boolean is
      F : Node_Id;
   begin
      if not AAU.Is_Empty (Features (E)) then
         F := First_Node (Features (E));

         while Present (F) loop
            if Kind (F) = K_Parameter_Instance and then Is_Out (F) then
               return True;
            end if;

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

      return False;
   end Has_Out_Parameters;

   ------------------
   -- Has_In_Ports --
   ------------------

   function Has_In_Ports (E : Node_Id) return Boolean is
      F : Node_Id;
   begin
      if not AAU.Is_Empty (Features (E)) then
         F := First_Node (Features (E));

         while Present (F) loop
            if Kind (F) = K_Port_Spec_Instance and then Is_In (F) then
               return True;
            end if;

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

      return False;
   end Has_In_Ports;

   ------------------------
   -- Has_In_Event_Ports --
   ------------------------

   function Has_In_Event_Ports (E : Node_Id) return Boolean is
      F : Node_Id;
   begin
      if not AAU.Is_Empty (Features (E)) then
         F := First_Node (Features (E));

         while Present (F) loop
520
521
522
            if Kind (F) = K_Port_Spec_Instance
              and then Is_In (F)
              and then Is_Event (F)
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
            then
               return True;
            end if;

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

      return False;
   end Has_In_Event_Ports;

   -------------------
   -- Has_Out_Ports --
   -------------------

   function Has_Out_Ports (E : Node_Id) return Boolean is
      F : Node_Id;
   begin
      if not AAU.Is_Empty (Features (E)) then
         F := First_Node (Features (E));

         while Present (F) loop
            if Kind (F) = K_Port_Spec_Instance and then Is_Out (F) then
               return True;
            end if;

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

      return False;
   end Has_Out_Ports;

   -------------------------
   -- Has_Out_Event_Ports --
   -------------------------

   function Has_Out_Event_Ports (E : Node_Id) return Boolean is
      F : Node_Id;
   begin
      if not AAU.Is_Empty (Features (E)) then
         F := First_Node (Features (E));

         while Present (F) loop
567
568
569
            if Kind (F) = K_Port_Spec_Instance
              and then Is_Out (F)
              and then Is_Event (F)
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
            then
               return True;
            end if;

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

      return False;
   end Has_Out_Event_Ports;

   ---------------
   -- Has_Ports --
   ---------------

   function Has_Ports (E : Node_Id) return Boolean is
      F : Node_Id;
   begin
      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
               return True;
            end if;

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

      return False;
   end Has_Ports;

603
604
605
606
607
608
609
610
611
612
613
   ----------------------
   -- Has_Output_Ports --
   ----------------------

   function Has_Output_Ports (E : Node_Id) return Boolean is
      F : Node_Id;
   begin
      if not AAU.Is_Empty (Features (E)) then
         F := First_Node (Features (E));

         while Present (F) loop
614
            if Kind (F) = K_Port_Spec_Instance and then Is_Out (F) then
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
               return True;
            end if;

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

      return False;
   end Has_Output_Ports;

   ---------------------
   -- Has_Input_Ports --
   ---------------------

   function Has_Input_Ports (E : Node_Id) return Boolean is
      F : Node_Id;
   begin
      if not AAU.Is_Empty (Features (E)) then
         F := First_Node (Features (E));

         while Present (F) loop
636
            if Kind (F) = K_Port_Spec_Instance and then Is_In (F) then
637
638
639
640
641
642
643
644
645
646
               return True;
            end if;

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

      return False;
   end Has_Input_Ports;

647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
   ---------------
   -- Has_Modes --
   ---------------

   function Has_Modes (E : Node_Id) return Boolean is
   begin
      pragma Assert (Kind (E) = K_Component_Instance);

      return not AAU.Is_Empty (Modes (E));
   end Has_Modes;

   ----------------------
   -- Get_Source_Ports --
   ----------------------

   function Get_Source_Ports (P : Node_Id) return List_Id is
      function Rec_Get_Source_Ports
        (P : Node_Id;
665
         B : Node_Id := No_Node) return List_Id;
666
667
668
669
670
671
672
673
      --  Recursive internal routine

      --------------------------
      -- Rec_Get_Source_Ports --
      --------------------------

      function Rec_Get_Source_Ports
        (P : Node_Id;
674
         B : Node_Id := No_Node) return List_Id
675
676
677
678
679
680
681
      is
         Result : constant List_Id := New_List (K_List_Id, No_Location);
         C      : Node_Id;
         S      : Node_Id;
         Bus    : Node_Id;
      begin
         if AAU.Is_Empty (Sources (P)) then
682
            AAU.Append_Node_To_List (Make_Node_Container (P, B), Result);
683
684
685
686
687
688
689
690
691
692
693
694
         end if;

         S := First_Node (Sources (P));

         while Present (S) loop
            if Kind (Item (S)) = K_Port_Spec_Instance
              and then Parent_Component (Item (S)) /= No_Node
              and then Is_Thread (Parent_Component (Item (S)))
            then
               --  We reached our end point, append it to the result list

               AAU.Append_Node_To_List
695
696
                 (Make_Node_Container (Item (S), B),
                  Result);
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
            elsif Kind (Item (S)) = K_Port_Spec_Instance
              and then Parent_Component (Item (S)) /= No_Node
              and then (Is_Process_Or_Device (Parent_Component (Item (S))))
            then

               if Is_In (Item (S)) then
                  --  See whether the connection to the process is
                  --  bound to a bus.

                  C := Extra_Item (S);

                  if No (C) then
                     --  There has been definitly a bug while
                     --  expanding connections.

                     raise Program_Error with "Wrong expansion of connections";
                  end if;

                  --  Get the bus of the connection

                  Bus := Get_Bound_Bus (C, False);
               else
                  Bus := No_Node;
               end if;

               if Present (B) and then Present (Bus) and then B /= Bus then
                  Display_Located_Error
                    (Loc (C),
725
726
                     "This connection is involved in a data flow" &
                     " mapped to several different buses",
727
728
729
730
731
732
                     Fatal => True);
               end if;

               --  Fetch recursively all the sources of S

               AAU.Append_Node_To_List
733
734
                 (First_Node (Rec_Get_Source_Ports (Item (S), Bus)),
                  Result);
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
            else
               Display_Located_Error
                 (Loc (P),
                  "This port has a source of a non supported kind",
                  Fatal => True);
            end if;

            S := Next_Node (S);
         end loop;

         return Result;
      end Rec_Get_Source_Ports;

   begin
      if AAU.Is_Empty (Sources (P)) then
         return No_List;
      else
         return Rec_Get_Source_Ports (P, No_Node);
      end if;
   end Get_Source_Ports;

   ---------------------------
   -- Get_Destination_Ports --
   ---------------------------

760
   function Get_Destination_Ports
761
762
763
     (P             : Node_Id;
      Custom_Parent : Node_Id := No_Node) return List_Id
   is
764
765

      function Rec_Get_Destination_Ports
766
767
768
        (P             : Node_Id;
         B             : Node_Id := No_Node;
         Custom_Parent : Node_Id := No_Node) return List_Id;
769
770
771
772
773
774
775
      --  Recursive internal routine

      -------------------------------
      -- Rec_Get_Destination_Ports --
      -------------------------------

      function Rec_Get_Destination_Ports
776
777
778
        (P             : Node_Id;
         B             : Node_Id := No_Node;
         Custom_Parent : Node_Id := No_Node) return List_Id
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
      is
         Result : constant List_Id := New_List (K_List_Id, No_Location);
         C      : Node_Id;
         D      : Node_Id;
         Bus    : Node_Id;
      begin
         D := First_Node (Destinations (P));

         while Present (D) loop
            if Kind (Item (D)) = K_Port_Spec_Instance
              and then Parent_Component (Item (D)) /= No_Node
              and then Is_Thread (Parent_Component (Item (D)))
            then
               --  We reached our end point, append it to the result list

               AAU.Append_Node_To_List
795
796
                 (Make_Node_Container (Item (D), B),
                  Result);
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

            elsif Kind (Item (D)) = K_Port_Spec_Instance
              and then Parent_Component (Item (D)) /= No_Node
              and then Is_Process (Parent_Component (Item (D)))
            then
               if Is_In (Item (D)) then
                  --  See whether the connection to the process is
                  --  bound to a bus.

                  C := Extra_Item (D);

                  if No (C) then
                     --  There has been definitly a bug while
                     --  expanding connections.

                     raise Program_Error with "Wrong expansion of connections";
                  end if;

                  --  Get the bus of the connection

                  Bus := Get_Bound_Bus (C, False);
               else
                  Bus := No_Node;
               end if;

               if Present (B) and then Present (Bus) and then B /= Bus then
                  Display_Located_Error
                    (Loc (C),
825
826
                     "This connection is involved in a data flow" &
                     " mapped to several different buses",
827
828
829
830
831
832
                     Fatal => True);
               end if;

               --  Fetch recursively all the destinations of D

               AAU.Append_Node_To_List
833
834
                 (First_Node (Rec_Get_Destination_Ports (Item (D), Bus)),
                  Result);
835
836
837
838
839
840
841
842

            elsif Kind (Item (D)) = K_Port_Spec_Instance
              and then Parent_Component (Item (D)) /= No_Node
              and then Is_Device (Parent_Component (Item (D)))
            then
               --  We reached our end point, append it to the result list

               AAU.Append_Node_To_List
843
844
845
846
847
848
                 (Make_Node_Container (Item (D), B),
                  Result);
            elsif Custom_Parent /= No_Node
              and then Is_Device (Custom_Parent)
              and then Get_Port_By_Name (P, Custom_Parent) /= No_Node
            then
849

850
851
               AAU.Append_Node_To_List
                 (First_Node
852
853
854
855
                    (Rec_Get_Destination_Ports
                       (Get_Port_By_Name (P, Custom_Parent),
                        B,
                        No_Node)),
856
                  Result);
857
858
859
860
861
862
863
864
865
866
867
868
869
            else
               Display_Located_Error
                 (Loc (P),
                  "This port has a destination of a non supported kind",
                  Fatal => True);
            end if;

            D := Next_Node (D);
         end loop;

         return Result;
      end Rec_Get_Destination_Ports;
   begin
870
      return Rec_Get_Destination_Ports (P, No_Node, Custom_Parent);
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
   end Get_Destination_Ports;

   ----------------------
   -- Get_Actual_Owner --
   ----------------------

   function Get_Actual_Owner (Spg_Call : Node_Id) return Node_Id is
      Spg            : constant Node_Id := Corresponding_Instance (Spg_Call);
      Data_Component : Node_Id;
      F              : Node_Id;
   begin
      --  If the subprogram call is not a method return No_Node

      if AAU.Is_Empty (Path (Spg_Call)) then
         return No_Node;
      end if;

      Data_Component := Item (First_Node (Path (Spg_Call)));

      --  Traverse all the required access of the subprogram instance
      --  and find the one corresponding to the owner data component.

      if not AAU.Is_Empty (Features (Spg)) then
         F := First_Node (Features (Spg));

         while Present (F) loop
            if Kind (F) = K_Subcomponent_Access_Instance then
               --  FIXME: We stop at the first met feature that
               --  corresponds to our criteria.

               --  The corresponding declaration of Data_Component is
               --  always a component type and not a component
               --  implementation. However the type of the feature F
               --  may be a component type as well as a component
               --  implementation. We test both cases.

               declare
                  Dcl_Data_Component : constant Node_Id :=
                    Corresponding_Declaration (Data_Component);
910
                  Dcl_F : constant Node_Id :=
911
912
913
914
915
                    Corresponding_Declaration (Corresponding_Instance (F));

                  use Ocarina.ME_AADL.AADL_Tree.Nodes;
               begin
                  exit when
916
917
                    (ATN.Kind (Dcl_F) = K_Component_Type
                     and then Dcl_F = Dcl_Data_Component)
918
                    or else
919
920
921
922
923
                    (ATN.Kind (Dcl_F) = K_Component_Implementation
                     and then
                       ATN.Corresponding_Entity
                         (ATN.Component_Type_Identifier (Dcl_F)) =
                       Dcl_Data_Component);
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
               end;
            end if;

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

      --  If no feature matched, raise an error

      if AAU.Is_Empty (Features (Spg)) or else No (F) then
         Display_Located_Error
           (Loc (Spg),
            "Feature subprogram has not access to its owner component",
            Fatal => True);
      end if;

      return Get_Subcomponent_Access_Source (F);
   end Get_Actual_Owner;

   ---------------------------
   -- Get_Container_Process --
   ---------------------------

   function Get_Container_Process (E : Node_Id) return Node_Id is
      pragma Assert (Present (E));
949
   begin
950
951
952
953
954
955
956
957
      case Kind (E) is
         when K_Call_Instance =>
            return Get_Container_Process (Parent_Sequence (E));

         when K_Call_Sequence_Instance | K_Subcomponent_Instance =>
            return Get_Container_Process (Parent_Component (E));

         when others =>
958
959
            if Is_Thread (E)
              or else Is_Subprogram (E)
960
961
              or else AAU.Is_Data (E)
            then
962
               return Get_Container_Process (Parent_Subcomponent (E));
963

964
965
            elsif Is_Process (E) or else Is_Device (E) then
               return Parent_Subcomponent (E);
966

967
968
969
970
971
972
973
974
            elsif Is_Abstract (E) then
               --  It is allowed for a thread to be part of an
               --  abstract component (e.g. a device driver). In this
               --  case, we cannot retrieve the corresponding process
               --  instance.

               return No_Node;

975
            else
976
977
978
979
980
981
               raise Program_Error
                 with "Wrong node kind in " &
                 "Get_Container_Process: " &
                 Kind (E)'Img &
                 " " &
                 Get_Category_Of_Component (E)'Img;
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000

            end if;
      end case;
   end Get_Container_Process;

   --------------------------
   -- Get_Container_Thread --
   --------------------------

   function Get_Container_Thread (E : Node_Id) return Node_Id is
   begin
      case Kind (E) is
         when K_Call_Instance =>
            return Get_Container_Thread (Parent_Sequence (E));

         when K_Call_Sequence_Instance =>
            return Parent_Component (E);

         when others =>
For faster browsing, not all history is shown. View entire blame