ocarina-backends-po_hi_ada-types.adb 58 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 . P O _ H I _ A D A . T Y P E S      --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--    Copyright (C) 2006-2009 Telecom ParisTech, 2010-2016 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.Namet;
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

with Ocarina.ME_AADL;
with Ocarina.ME_AADL.AADL_Tree.Nodes;
with Ocarina.ME_AADL.AADL_Instances.Nodes;
with Ocarina.ME_AADL.AADL_Instances.Nutils;
with Ocarina.ME_AADL.AADL_Instances.Entities;

with Ocarina.Backends.Utils;
with Ocarina.Backends.Properties;
with Ocarina.Backends.Messages;
with Ocarina.Backends.Ada_Tree.Nutils;
with Ocarina.Backends.Ada_Tree.Nodes;
with Ocarina.Backends.Ada_Values;
with Ocarina.Backends.PO_HI_Ada.Mapping;
with Ocarina.Backends.PO_HI_Ada.Runtime;

package body Ocarina.Backends.PO_HI_Ada.Types is

51
   use Ocarina.Namet;
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
   use Ocarina.ME_AADL;
   use Ocarina.ME_AADL.AADL_Instances.Nodes;
   use Ocarina.ME_AADL.AADL_Instances.Entities;
   use Ocarina.Backends.Utils;
   use Ocarina.Backends.Properties;
   use Ocarina.Backends.Messages;
   use Ocarina.Backends.Ada_Tree.Nutils;
   use Ocarina.Backends.Ada_Values;
   use Ocarina.Backends.PO_HI_Ada.Mapping;
   use Ocarina.Backends.PO_HI_Ada.Runtime;

   package ATN renames Ocarina.ME_AADL.AADL_Tree.Nodes;
   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;

   function Length_Spec (E : Node_Id) return Node_Id;
   --  Length of an array type to be exported to C code

   -----------------
   -- Length_Spec --
   -----------------

   function Length_Spec (E : Node_Id) return Node_Id is
      N : Node_Id;
   begin
      pragma Assert (Get_Data_Representation (E) = Data_Array);

80 81 82 83 84 85 86 87 88
      N :=
        Make_Subprogram_Specification
          (Defining_Identifier => Make_Defining_Identifier (SN (S_Length)),
           Parameter_Profile   =>
             Make_List_Id
               (Make_Parameter_Specification
                  (Defining_Identifier => Make_Defining_Identifier (PN (P_A)),
                   Subtype_Mark        => Map_Ada_Defining_Identifier (E))),
           Return_Type => RE (RE_Integer));
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

      return N;
   end Length_Spec;

   ------------------
   -- 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_Subprogram_Instance (E : Node_Id);
      procedure Visit_Data_Instance (E : Node_Id);

      function Feature_Spg_Spec (E : Node_Id) return Node_Id;
      --  Builds a spec for a protected object procedure from an AADL
      --  subprogram spec E.

      function Pragma_Export_Length (E : Node_Id) return Node_Id;
      --  Length of an array type to be exported to C code

      ----------------------
      -- Feature_Spg_Spec --
      ----------------------

      function Feature_Spg_Spec (E : Node_Id) return Node_Id is
         Profile : constant List_Id := New_List (ADN.K_Parameter_Profile);
         N       : Node_Id;
         Mode    : Mode_Id;
         P       : Node_Id;
         Spg     : Node_Id;
      begin
125 126 127
         pragma Assert
           (Kind (E) = K_Subprogram_Spec_Instance
            or else Kind (E) = K_Subcomponent_Access_Instance);
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

         Spg := Corresponding_Instance (E);

         pragma Assert (AAU.Is_Subprogram (Spg));

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

            while Present (P) loop
               if Kind (P) = K_Parameter_Instance then

                  --  Create a parameter specification

                  if Is_In (P) and then Is_Out (P) then
                     Mode := Mode_Inout;
                  elsif Is_Out (P) then
                     Mode := Mode_Out;
                  else
                     Mode := Mode_In;
                  end if;

                  if No (Backend_Node (Identifier (E))) then
                     Visit_Component_Instance (Corresponding_Instance (P));
                  end if;

153 154 155 156 157 158 159
                  N :=
                    Make_Parameter_Specification
                      (Defining_Identifier => Map_Ada_Defining_Identifier (P),
                       Subtype_Mark        =>
                         Map_Ada_Data_Type_Designator
                           (Corresponding_Instance (P)),
                       Parameter_Mode => Mode);
160 161 162 163 164 165 166
                  Append_Node_To_List (N, Profile);
               end if;

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

167 168 169 170
         N :=
           Make_Subprogram_Specification
             (Defining_Identifier => Map_Ada_Defining_Identifier (E),
              Parameter_Profile   => Profile);
171 172 173 174 175 176 177 178 179 180 181 182 183

         return N;
      end Feature_Spg_Spec;

      --------------------------
      -- Pragma_Export_Length --
      --------------------------

      function Pragma_Export_Length (E : Node_Id) return Node_Id is
         N : Node_Id;
      begin
         pragma Assert (Get_Data_Representation (E) = Data_Array);

184 185 186 187 188 189 190 191
         N :=
           Make_Pragma_Statement
             (Pragma_Export,
              Make_List_Id
                (Make_Defining_Identifier (PN (P_C)),
                 Make_Defining_Identifier (SN (S_Length)),
                 Make_Literal
                   (New_String_Value (Map_Exported_Length_Symbol (E)))));
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

         return N;
      end Pragma_Export_Length;

      -----------
      -- 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
228 229
         Category : constant Component_Category :=
           Get_Category_Of_Component (E);
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
      begin
         case Category 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
257 258 259 260 261 262 263 264 265
         Data_Representation   : Supported_Data_Representation;
         Language_Type         : Supported_Source_Language;
         N                     : Node_Id;
         S                     : Node_Id;
         Name                  : Name_Id;
         Actual_Data_Size      : Unsigned_Long_Long;
         Data_Size             : Size_Type;
         Number_Representation : constant Supported_Number_Representation :=
           Get_Number_Representation (E);
266
         Is_Signed : constant Boolean := Number_Representation = Signed;
267 268 269 270
      begin
         --  Do not generate Ada type more than once

         if No (Get_Handling (E, By_Name, H_Ada_Type_Spec)) then
271 272 273 274 275

            --  Add a fake handling for now, to avoid infinite recursion

            Set_Handling (E, By_Name, H_Ada_Type_Spec, No_Node + 1);

276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
            Language_Type := Get_Source_Language (E);

            if Language_Type = Language_ASN1 then
               --  If the type is defined through an ASN.1
               --  specification, then we assume the type is generated
               --  in the ASN1_Types package. We simply bind this type
               --  to the specification.

               Add_With_Package
                 (E            => RU (RU_ASN1_Types),
                  Used         => True,
                  Warnings_Off => True,
                  Elaborated   => True);

               Name := Get_Type_Source_Name (E);
               if Name = No_Name then
                  Display_Located_Error
                    (Loc (E),
                     "ASN1 types require use of the Type_Source_Name property",
                     Fatal => True);
               end if;

298 299 300 301
               N :=
                 Make_Designator
                   (Name,
                    Fully_Qualified_Name (RU (RU_ASN1_Types)));
302 303 304 305 306 307 308 309 310 311 312

            elsif Language_Type = Language_Ada_95 then
               --  If the type is defined through as an Ada type, then
               --  we simply drag a dependency onto the Ada package
               --  that hosts this type.

               Name := Get_Type_Source_Name (E);

               if Name = No_Name then
                  Display_Located_Error
                    (Loc (E),
313 314
                     "Ada opaque types require the definition of the " &
                     "'Type_Source_Name' property",
315 316 317 318 319 320 321 322
                     Fatal => True);
               end if;

               declare
                  U : constant Name_Id := Unit_Name (Name);
                  L : constant Name_Id := Local_Name (Name);
                  P : Node_Id;
               begin
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
                  if U /= No_Name then
                     --  The user provided a fully qualified name that
                     --  is not prefixed by Standard, add this fully
                     --  qualified name in the package

                     P := Make_Designator (U);
                     ADN.Set_Corresponding_Node
                       (ADN.Defining_Identifier (P),
                        New_Node (ADN.K_Package_Specification));
                     Add_With_Package (P);

                     N := Make_Designator (L);
                     Set_Homogeneous_Parent_Unit_Name (N, P);
                  else
                     --  Otherwise, simply refer to Standard package
338

339 340 341
                     N := Make_Designator (L);
                     Set_Homogeneous_Parent_Unit_Name (N, RU (RU_Standard));
                  end if;
342

343 344 345 346 347
                  N :=
                    Make_Full_Type_Declaration
                      (Defining_Identifier => Map_Ada_Defining_Identifier (E),
                       Type_Definition     =>
                         Make_Derived_Type_Definition (N, Is_Subtype => True),
348
                       Is_Subtype => True);
349 350 351 352 353 354 355
               end;
            else
               --  Otherwise, we extract from the Data_Model specific
               --  properties the exact nature of the type and
               --  generate its definition.

               Data_Representation := Get_Data_Representation (E);
356 357
               Data_Size           := Get_Data_Size (E);
               Actual_Data_Size    := To_Bytes (Data_Size);
358 359 360 361 362

               case Data_Representation is
                  when Data_Array =>
                     declare
                        Dimension : constant ULL_Array := Get_Dimension (E);
363
                        RC : constant List_Id   := New_List (ADN.K_List_Id);
364
                     begin
365 366
                        Visit
                          (ATN.Entity (ATN.First_Node (Get_Base_Type (E))));
367 368

                        for Index in Dimension'Range loop
369 370 371 372 373 374 375 376 377
                           N :=
                             Make_Range_Constraint
                               (Make_Literal (New_Integer_Value (1, 1, 10)),
                                Make_Literal
                                  (New_Integer_Value
                                     (Dimension (Index),
                                      1,
                                      10)),
                                RE (RE_Positive));
378 379 380
                           Append_Node_To_List (N, RC);
                        end loop;

381 382 383 384 385 386 387 388 389 390 391 392
                        N :=
                          Make_Full_Type_Declaration
                            (Defining_Identifier =>
                               Map_Ada_Defining_Identifier (E),
                             Type_Definition =>
                               Make_Array_Type_Definition
                                 (Range_Constraints    => RC,
                                  Component_Definition =>
                                    Map_Ada_Data_Type_Designator
                                      (ATN.Entity
                                         (ATN.First_Node
                                            (Get_Base_Type (E))))));
393 394 395
                     end;

                  when Data_Boolean =>
396 397 398 399 400 401
                     N :=
                       Make_Full_Type_Declaration
                         (Defining_Identifier =>
                            Map_Ada_Defining_Identifier (E),
                          Type_Definition =>
                            Make_Derived_Type_Definition (RE (RE_Boolean)));
402 403

                  when Data_Character =>
404 405 406 407 408 409
                     N :=
                       Make_Full_Type_Declaration
                         (Defining_Identifier =>
                            Map_Ada_Defining_Identifier (E),
                          Type_Definition =>
                            Make_Derived_Type_Definition (RE (RE_Character)));
410 411

                  when Data_Wide_Character =>
412 413 414 415 416 417 418
                     N :=
                       Make_Full_Type_Declaration
                         (Defining_Identifier =>
                            Map_Ada_Defining_Identifier (E),
                          Type_Definition =>
                            Make_Derived_Type_Definition
                              (RE (RE_Wide_Character)));
419 420 421

                  when Data_Enum =>
                     declare
422 423
                        Enumerators : constant Name_Array :=
                          Get_Enumerators (E);
424 425 426 427 428 429 430 431
                        Enumeration_List : constant List_Id :=
                          New_List (ADN.K_Enumeration_Literals);
                     begin
                        for J in Enumerators'Range loop
                           N := Make_Defining_Identifier (Enumerators (J));
                           Append_Node_To_List (N, Enumeration_List);
                        end loop;

432 433 434 435 436 437 438
                        N :=
                          Make_Full_Type_Declaration
                            (Defining_Identifier =>
                               Map_Ada_Defining_Identifier (E),
                             Type_Definition =>
                               Make_Enumeration_Type_Definition
                                 (Enumeration_List));
439 440 441
                     end;

                  when Data_Float =>
442 443 444 445 446 447
                     N :=
                       Make_Full_Type_Declaration
                         (Defining_Identifier =>
                            Map_Ada_Defining_Identifier (E),
                          Type_Definition =>
                            Make_Derived_Type_Definition (RE (RE_Long_Float)));
448 449 450

                  when Data_Fixed =>
                     declare
451 452 453 454
                        Data_Digits : constant Unsigned_Long_Long :=
                          Get_Data_Digits (E);
                        Data_Scale : constant Unsigned_Long_Long :=
                          Get_Data_Scale (E);
455 456
                     begin
                        if Data_Digits /= 0 and then Data_Scale /= 0 then
457 458 459 460 461 462 463 464
                           N :=
                             Make_Full_Type_Declaration
                               (Defining_Identifier =>
                                  Map_Ada_Defining_Identifier (E),
                                Type_Definition =>
                                  Make_Decimal_Type_Definition
                                    (Data_Digits,
                                     Data_Scale));
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487

                        else
                           if Data_Digits = 0 then
                              Display_Located_Error
                                (Loc (E),
                                 "Missing 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_Integer =>
                     if Data_Size.S = 0 then
                        --  If no size info is given, we default to a
                        --  standard integer

488 489 490 491 492 493
                        N :=
                          Make_Full_Type_Declaration
                            (Defining_Identifier =>
                               Map_Ada_Defining_Identifier (E),
                             Type_Definition =>
                               Make_Derived_Type_Definition (RE (RE_Integer)));
494 495

                     elsif Actual_Data_Size = 1 and then Is_Signed then
496 497 498 499 500 501 502
                        N :=
                          Make_Full_Type_Declaration
                            (Defining_Identifier =>
                               Map_Ada_Defining_Identifier (E),
                             Type_Definition =>
                               Make_Derived_Type_Definition
                                 (RE (RE_Integer_8)));
503 504

                     elsif Actual_Data_Size = 1 and then not Is_Signed then
505 506 507 508 509 510 511
                        N :=
                          Make_Full_Type_Declaration
                            (Defining_Identifier =>
                               Map_Ada_Defining_Identifier (E),
                             Type_Definition =>
                               Make_Derived_Type_Definition
                                 (RE (RE_Unsigned_8)));
512 513

                     elsif Actual_Data_Size = 2 and then Is_Signed then
514 515 516 517 518 519 520
                        N :=
                          Make_Full_Type_Declaration
                            (Defining_Identifier =>
                               Map_Ada_Defining_Identifier (E),
                             Type_Definition =>
                               Make_Derived_Type_Definition
                                 (RE (RE_Integer_16)));
521 522

                     elsif Actual_Data_Size = 2 and then not Is_Signed then
523 524 525 526 527 528 529
                        N :=
                          Make_Full_Type_Declaration
                            (Defining_Identifier =>
                               Map_Ada_Defining_Identifier (E),
                             Type_Definition =>
                               Make_Derived_Type_Definition
                                 (RE (RE_Unsigned_16)));
530 531

                     elsif Actual_Data_Size = 4 and then Is_Signed then
532 533 534 535 536 537 538
                        N :=
                          Make_Full_Type_Declaration
                            (Defining_Identifier =>
                               Map_Ada_Defining_Identifier (E),
                             Type_Definition =>
                               Make_Derived_Type_Definition
                                 (RE (RE_Integer_32)));
539 540

                     elsif Actual_Data_Size = 4 and then not Is_Signed then
541 542 543 544 545 546 547
                        N :=
                          Make_Full_Type_Declaration
                            (Defining_Identifier =>
                               Map_Ada_Defining_Identifier (E),
                             Type_Definition =>
                               Make_Derived_Type_Definition
                                 (RE (RE_Unsigned_32)));
548 549

                     elsif Actual_Data_Size = 8 and then Is_Signed then
550 551 552 553 554 555 556
                        N :=
                          Make_Full_Type_Declaration
                            (Defining_Identifier =>
                               Map_Ada_Defining_Identifier (E),
                             Type_Definition =>
                               Make_Derived_Type_Definition
                                 (RE (RE_Integer_64)));
557 558

                     elsif Actual_Data_Size = 8 and then not Is_Signed then
559 560 561 562 563 564 565
                        N :=
                          Make_Full_Type_Declaration
                            (Defining_Identifier =>
                               Map_Ada_Defining_Identifier (E),
                             Type_Definition =>
                               Make_Derived_Type_Definition
                                 (RE (RE_Unsigned_64)));
566 567 568

                     else
                        Display_Located_Error
569 570 571
                          (Loc (E),
                           "Unsupported data size" & Actual_Data_Size'Img,
                           Fatal => True);
572 573 574 575 576 577
                     end if;

                  when Data_String =>
                     declare
                        Dimension : constant ULL_Array := Get_Dimension (E);
                     begin
578 579 580 581 582 583 584 585 586 587 588 589 590 591
                        N :=
                          Make_Package_Instantiation
                            (Defining_Identifier =>
                               Map_Ada_Package_Identifier (E),
                             Generic_Package =>
                               RU
                               (RU_Ada_Strings_Bounded_Generic_Bounded_Length),
                             Parameter_List =>
                               Make_List_Id
                                 (Make_Literal
                                    (New_Integer_Value
                                       (Dimension (Dimension'First),
                                        1,
                                        10))));
592
                        Append_Node_To_List
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
                          (N,
                           ADN.Visible_Part (Current_Package));

                        N :=
                          Make_Full_Type_Declaration
                            (Defining_Identifier =>
                               Map_Ada_Defining_Identifier (E),
                             Is_Subtype      => True,
                             Type_Definition =>
                               Make_Derived_Type_Definition
                                 (Make_Selected_Component
                                    (Map_Ada_Package_Identifier (E),
                                     Make_Defining_Identifier
                                       (TN (T_Bounded_String))),
                                  Is_Subtype => True));
608 609 610 611 612
                     end;

                  when Data_Wide_String =>
                     declare
                        Dimension : constant ULL_Array := Get_Dimension (E);
613
                        RU_Wi_Str : constant RU_Id     :=
614 615
                          RU_Ada_Strings_Wide_Bounded_Generic_Bounded_Length;
                     begin
616 617 618 619 620 621 622 623 624 625 626 627
                        N :=
                          Make_Package_Instantiation
                            (Defining_Identifier =>
                               Map_Ada_Package_Identifier (E),
                             Generic_Package => RU (RU_Wi_Str),
                             Parameter_List  =>
                               Make_List_Id
                                 (Make_Literal
                                    (New_Integer_Value
                                       (Dimension (Dimension'First),
                                        1,
                                        10))));
628
                        Append_Node_To_List
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
                          (N,
                           ADN.Visible_Part (Current_Package));

                        N :=
                          Make_Full_Type_Declaration
                            (Defining_Identifier =>
                               Map_Ada_Defining_Identifier (E),
                             Is_Subtype      => True,
                             Type_Definition =>
                               Make_Derived_Type_Definition
                                 (Make_Selected_Component
                                    (Map_Ada_Package_Identifier (E),
                                     Make_Defining_Identifier
                                       (TN (T_Bounded_Wide_String))),
                                  Is_Subtype => True));
644 645 646 647
                     end;

                  when Data_Struct | Data_With_Accessors =>
                     declare
648 649 650 651 652 653 654
                        Components : constant List_Id :=
                          New_List (ADN.K_Component_List);
                        C         : Node_Id := First_Node (Subcomponents (E));
                        Visible_P : List_Id;
                        Private_P : List_Id;
                        I         : Unsigned_Long_Long;
                        O         : Node_Id;
655 656 657 658 659 660 661 662 663 664 665
                     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

666
                           if AAU.Is_Data (Corresponding_Instance (C)) then
667 668 669 670 671 672 673
                              N :=
                                Make_Component_Declaration
                                  (Defining_Identifier =>
                                     Map_Ada_Defining_Identifier (C),
                                   Subtype_Indication =>
                                     Map_Ada_Data_Type_Designator
                                       (Corresponding_Instance (C)));
674 675
                              Append_Node_To_List (N, Components);
                           end if;
676 677 678 679 680 681 682

                           C := Next_Node (C);
                        end loop;

                        if Data_Representation = Data_Struct then
                           --  Record type

683 684 685 686 687 688 689
                           N :=
                             Make_Full_Type_Declaration
                               (Defining_Identifier =>
                                  Map_Ada_Defining_Identifier (E),
                                Type_Definition =>
                                  Make_Record_Type_Definition
                                    (Make_Record_Definition (Components)));
690 691 692 693 694 695 696 697 698 699 700 701
                        else
                           --  Protected type

                           declare
                              CCP : Supported_Concurrency_Control_Protocol;
                           begin
                              --  Per the Ravenscar profile, all
                              --  protected objects are supposed to be
                              --  PCP, ensure this is true also for
                              --  the AADL model.

                              CCP := Get_Concurrency_Protocol (E);
702
                              if CCP /= Priority_Ceiling then
703 704
                                 Display_Located_Error
                                   (Loc (E),
705 706 707
                                    "Incompatible concurrency protocol, " &
                                    "PolyORB-HI/Ada requires " &
                                    "Priority_Ceiling",
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728
                                    True);
                              end if;
                           end;

                           Visible_P := New_List (ADN.K_Declaration_List);
                           Private_P := Components;

                           S := First_Node (Features (E));

                           while Present (S) loop
                              --  We are sure that S is of kind
                              --  K_Subprogram_Spec_Instance. Otherwise,
                              --  an error whould be raised when trying
                              --  to find the data type.

                              --  Build a subprogram spec and append it
                              --  to the visible part of the protected
                              --  type.

                              N := Feature_Spg_Spec (S);
                              Bind_AADL_To_Feature_Subprogram
729 730
                                (Identifier (S),
                                 N);
731 732 733 734 735 736 737
                              Append_Node_To_List (N, Visible_P);

                              S := Next_Node (S);
                           end loop;

                           --  Build the private type spec

738 739 740 741 742 743 744
                           N :=
                             Make_Protected_Object_Spec
                               (Defining_Identifier =>
                                  Map_Ada_Defining_Identifier (E),
                                Visible_Part => Visible_P,
                                Private_Part => Private_P,
                                Is_Type      => True);
745 746 747 748 749 750 751 752

                           I := Get_Priority_Celing_Of_Data_Access (E);

                           if I /= 0 then
                              --  The data component defines a priority,
                              --  use it for the ceiling priority of the
                              --  protected object.

753 754 755 756
                              O :=
                                Make_Pragma_Statement
                                  (Pragma_Priority,
                                   Make_List_Id (Map_Ada_Priority (I)));
757 758 759 760 761 762 763 764 765
                              Append_Node_To_List (O, ADN.Private_Part (N));

                           else
                              --  The data component defines no priority,
                              --  use System.Priority'Last for the
                              --  ceiling priority of the protected
                              --  object.

                              Display_Located_Error
766 767 768 769 770 771 772 773 774 775 776 777 778
                                (Loc (E),
                                 "No  priority defined, will use" &
                                 " default value: System.Priority'Last",
                                 False,
                                 True);

                              O :=
                                Make_Pragma_Statement
                                  (Pragma_Priority,
                                   Make_List_Id
                                     (Make_Attribute_Designator
                                        (RE (RE_Priority),
                                         A_Last)));
779 780 781 782 783 784 785
                              Append_Node_To_List (O, ADN.Private_Part (N));
                           end if;
                        end if;
                     end;

                  when Data_Union =>
                     Display_Located_Error
786 787 788 789 790
                       (Loc (E),
                        "unsupported data type (" &
                        Supported_Data_Representation'Image
                          (Data_Representation) &
                        ")",
791 792 793 794
                        Fatal => True);

                  when Data_None =>
                     Display_Located_Error
795 796
                       (Loc (E),
                        "unspecified data representation",
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
                        Fatal => True);
               end case;
            end if;

            --  Mark the data type as being handled and append it to
            --  the handled list.

            Set_Handling (E, By_Name, H_Ada_Type_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.

            if Data_Representation = 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

            if Language_Type /= Language_ASN1 then
               Append_Node_To_List (N, ADN.Visible_Part (Current_Package));
            end if;

            --  If the user specified a data size in the AADL model,
            --  generate a corresponding Ada clause.

            if Get_Data_Size (E) /= Null_Size then
833 834 835 836 837 838 839 840 841
               N :=
                 Make_Attribute_Definition_Clause
                   (Map_Ada_Defining_Identifier (E),
                    A_Size,
                    Make_Literal
                      (New_Integer_Value
                         (To_Bits (Get_Data_Size (E)),
                          1,
                          10)));
842 843 844 845 846 847 848 849 850 851 852 853 854 855 856
               Append_Node_To_List (N, ADN.Visible_Part (Current_Package));
            end if;

            if Get_Data_Representation (E) /= Data_With_Accessors then
               declare
                  Data_Size : Unsigned_Long_Long;
               begin
                  if Get_Data_Size (E) /= Null_Size then
                     Data_Size := To_Bits (Get_Data_Size (E));
                  else
                     Data_Size := Estimate_Data_Size (E);
                  end if;

                  --  A documentary comment for the data size

857 858 859 860 861 862 863
                  N :=
                    Message_Comment
                      (Get_Name_String
                         (To_Ada_Name (AIN.Name (Identifier (E)))) &
                       "'Object_Size ~=" &
                       Unsigned_Long_Long'Image (Data_Size) &
                       " bits");
864 865 866 867
                  Append_Node_To_List (N, ADN.Visible_Part (Current_Package));
               end;
            end if;

868 869 870 871 872 873
            if Get_Data_Representation (E) = Data_Struct then
               N :=
                 Make_Attribute_Definition_Clause
                   (Map_Ada_Defining_Identifier (E),
                    Attribute_Designator => A_Alignment,
                    Expression => Make_Literal (New_Integer_Value (8, 1, 10)));
874 875 876
               Append_Node_To_List (N, ADN.Visible_Part (Current_Package));
            end if;

877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898
            --  Array types have also a subprogram 'Length' which is
            --  generated for use in other languages in which arrays
            --  are not aware of their lengths (such as C).

            if Data_Representation = Data_Array then
               N := Length_Spec (E);
               Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

               --  Add a pragma Export for 'Length' in order for it to
               --  be seen by C code.

               N := Pragma_Export_Length (E);
               Append_Node_To_List (N, ADN.Visible_Part (Current_Package));
            end if;
         end if;

         --  Bind the type to its mapping

         Bind_AADL_To_Type_Definition
           (Identifier (E),
            Get_Handling (E, By_Name, H_Ada_Type_Spec));

899 900 901 902 903
         --  Declare the "default value" of a type.

         --  Note: If a default value can be computed, then this value
         --  is declared as a 'constant' so that the user cannot
         --  modify it.
904 905

         if No (Get_Handling (E, By_Name, H_Ada_Type_Default_Value)) then
906
               Data_Representation := Get_Data_Representation (E);
907

908 909
               --  We generate default values for all types except
               --  protected types.
910

911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930
               if Data_Representation /= Data_With_Accessors then
                  declare
                     Default_Value : constant Node_Id :=
                       Get_Ada_Default_Value (E);
                  begin
                     N :=
                       Make_Object_Declaration
                       (Defining_Identifier =>
                          Map_Ada_Default_Value_Identifier (E),
                        Constant_Present  => Present (Default_Value),
                        Object_Definition => Map_Ada_Defining_Identifier (E),
                        Expression        => Default_Value);

                     Set_Handling (E, By_Name, H_Ada_Type_Default_Value, N);
                     Append_Node_To_List
                       (N, ADN.Visible_Part (Current_Package));
                  end;
               else
                  N := No_Node;
               end if;
931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947
         end if;

         --  Bind the type to its default value if a default value has
         --  been generated.

         if Present (N) then
            Bind_AADL_To_Default_Value
              (Identifier (E),
               Get_Handling (E, By_Name, H_Ada_Type_Default_Value));
         end if;
      end Visit_Data_Instance;

      ----------------------------
      -- Visit_Process_Instance --
      ----------------------------

      procedure Visit_Process_Instance (E : Node_Id) is
948 949 950
         U : constant Node_Id :=
           ADN.Distributed_Application_Unit
             (ADN.Deployment_Node (Backend_Node (Identifier (E))));
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
         P : constant Node_Id := ADN.Entity (U);
         S : Node_Id;
      begin
         Push_Entity (P);
         Push_Entity (U);
         Set_Types_Spec;

         --  Start recording the handling since they have to be reset
         --  for each node.

         Start_Recording_Handlings;

         --  Visit all the subcomponents of the process

         if not AAU.Is_Empty (Subcomponents (E)) then
            S := First_Node (Subcomponents (E));
            while Present (S) loop
               --  Visit the component instance corresponding to the
               --  subcomponent S.

               Visit (Corresponding_Instance (S));
               S := Next_Node (S);
            end loop;
         end if;

         --  Unmark all the marked types

         Reset_Handlings;

         Pop_Entity; -- U
         Pop_Entity; -- P
      end Visit_Process_Instance;

      -------------------------------
      -- Visit_Subprogram_Instance --
      -------------------------------

      procedure Visit_Subprogram_Instance (E : Node_Id) is
         Call_Seq : Node_Id;
         Spg_Call : Node_Id;
         F        : 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;

         --  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 (Ada_Root);

         --  Visit all the subcomponents of the system

         if not AAU.Is_Empty (Subcomponents (E)) then
            S := First_Node (Subcomponents (E));
            while Present (S) loop
               --  Visit the component instance corresponding to the
               --  subcomponent S.

               Visit (Corresponding_Instance (S));
               S := Next_Node (S);
            end loop;
         end if;

         Pop_Entity; --  Ada_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
         --  Declare all necessary data types. We cannot rely only on
         --  subprogram calls to generate necessary data type becaus
         --  threads may not contain subprogram calls.

         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 AIN.Is_Data (F) then
                  Visit (Corresponding_Instance (F));
               end if;

               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;

   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_Subprogram_Instance (E : Node_Id);
      procedure Visit_Data_Instance (E : Node_Id);

1121
      function Feature_Spg_Body (E : Node_Id; Data : Node_Id) return Node_Id;
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131
      --  Builds a body for a protected object procedure from an AADL
      --  subprogram spec E.

      function Length_Body (E : Node_Id) return Node_Id;
      --  Body of the 'Length' function associated to array type E

      ----------------------
      -- Feature_Spg_Body --
      ----------------------

1132
      function Feature_Spg_Body (E : Node_Id; Data : Node_Id) return Node_Id is
1133 1134 1135 1136 1137 1138 1139 1140
         N            : Node_Id;
         Call_Profile : constant List_Id := New_List (ADN.K_Parameter_Profile);
         Param        : Node_Id;
         C_Access     : Node_Id;
         D            : Node_Id;
         Statements   : constant List_Id := New_List (ADN.K_Statement_List);
         Spg          : Node_Id;
      begin
1141 1142 1143
         pragma Assert
           (Kind (E) = K_Subprogram_Spec_Instance
            or else Kind (E) = K_Subcomponent_Access_Instance);
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

         Spg := Corresponding_Instance (E);

         pragma Assert (AAU.Is_Subprogram (Spg));

         --  The body of a subprogram contained in a protected type
         --  contains simply a call to the user implementation of the
         --  corresponding AADL subprogram.

         --  Since the subprogram has Data Access to its containing
         --  data component. It gives all the protected fields of the
         --  protected type as IN, OUT or IN OUT (depending on the
         --  data access property) parameters to the subprogram
         --  implementation call. Therefore the parameters for the
         --  subprogram implementation call are:

         --  1 - The list of the AADL subprogram parameters:

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

            while Present (Param) loop
               if Kind (Param) = K_Parameter_Instance then
                  --  Create a parameter association

1169 1170 1171 1172 1173
                  N :=
                    Make_Parameter_Association
                      (Selector_Name    => Map_Ada_Defining_Identifier (Param),
                       Actual_Parameter =>
                         Map_Ada_Defining_Identifier (Param));
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188
                  Append_Node_To_List (N, Call_Profile);
               end if;

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

         --  2 - The list of all record fields given

         --  FIXME: Respect the mapping rules by setting the correct
         --  parameter orientation. For now all parameter are
         --  considered IN OUT. Provide all necessary routines
         --  (passing through intermediate variables, to prevent the
         --  user from cheating).

1189 1190 1191
         if not AAU.Is_Empty (Features (Spg))
           and then not Is_Priority_Shifter (Data)
         then
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204

            C_Access := First_Node (Features (Spg));

            while Present (C_Access) loop
               if Kind (C_Access) = K_Subcomponent_Access_Instance then
                  D := Corresponding_Instance (C_Access);

                  if not AAU.Is_Empty (Subcomponents (D)) then
                     Param := First_Node (Subcomponents (D));

                     while Present (Param) loop
                        --  Create a parameter association

1205
                        if AAU.Is_Data (Corresponding_Instance (Param)) then
1206 1207 1208 1209 1210 1211 1212 1213
                           N :=
                             Make_Parameter_Association
                               (Selector_Name =>
                                  Map_Ada_Protected_Aggregate_Identifier
                                    (C_Access,
                                     Param),
                                Actual_Parameter =>
                                  Map_Ada_Defining_Identifier (Param));
1214

1215 1216
                           Append_Node_To_List (N, Call_Profile);
                        end if;
1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228

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

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

         --  Call the implementation subprogram with the built profile

1229 1230 1231 1232 1233 1234
         N :=
           Make_Subprogram_Call
             (Extract_Designator
                (ADN.Subprogram_Node
                   (Backend_Node (Identifier (Corresponding_Instance (E))))),
              Call_Profile);
1235 1236 1237 1238
         Append_Node_To_List (N, Statements);

         --  Build the subprogram implementation

1239 1240 1241 1242 1243
         N :=
           Make_Subprogram_Implementation
             (ADN.Feature_Subprogram_Node (Backend_Node (Identifier (E))),
              No_List,
              Statements);
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254

         return N;
      end Feature_Spg_Body;

      -----------------
      -- Length_Body --
      -----------------

      function Length_Body (E : Node_Id) return Node_Id is
         N : Node_Id;
      begin
1255 1256 1257 1258 1259 1260 1261 1262 1263
         N :=
           Make_Subprogram_Implementation
             (Length_Spec (E),
              No_List,
              Make_List_Id
                (Make_Return_Statement
                   (Make_Attribute_Designator
                      (Make_Defining_Identifier (PN (P_A)),
                       A_Length))));
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

         return N;
      end Length_Body;

      -----------
      -- 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
1300 1301
         Category : constant Component_Category :=
           Get_Category_Of_Component (E);
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
      begin
         case Category 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
         Data_Representation : Supported_Data_Representation;
         N                   : Node_Id;
      begin
         --  Do not generate Ada type more than once

         if No (Get_Handling (E, By_Name, H_Ada_Type_Body)) then
1335 1336 1337 1338

            --  Add a fake handling for now, to avoid infinite recursion
            Set_Handling (E, By_Name, H_Ada_Type_Body, No_Node + 1);

1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354
            Data_Representation := Get_Data_Representation (E);

            case Data_Representation is
               when Data_Array =>
                  N := Length_Body (E);

                  --  Append the type declaration to the package body

                  Append_Node_To_List (N, ADN.Statements (Current_Package));

                  --  Mark the data type as being handled

                  Set_Handling (E, By_Name, H_Ada_Type_Body, N);

               when Data_With_Accessors =>
                  declare
1355 1356 1357 1358
                     Statements : constant List_Id :=
                       New_List (ADN.K_Statement_List);
                     C : Node_Id := First_Node (Subcomponents (E));
                     S : Node_Id;
1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382
                  begin
                     --  Visit the subcomponents

                     while Present (C) loop
                        Visit (Corresponding_Instance (C));
                        C := Next_Node (C);
                     end loop;

                     --  Protected type

                     S := First_Node (Features (E));

                     while Present (S) loop
                        --  Build a subprogram spec and append it to
                        --  the visible part of the protected type.

                        N := Feature_Spg_Body (S, E);
                        Append_Node_To_List (N, Statements);

                        S := Next_Node (S);
                     end loop;

                     --  Build the private type body

1383 1384 1385 1386 1387
                     N :=
                       Make_Protected_Object_Body
                         (Defining_Identifier =>
                            Map_Ada_Defining_Identifier (E),
                          Statements => Statements);
1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420

                     --  Append the type declaration to the package body

                     Append_Node_To_List (N, ADN.Statements (Current_Package));

                     --  Mark the data type as being handled

                     Set_Handling (E, By_Name, H_Ada_Type_Body, N);
                  end;

               when Data_Struct =>
                  declare
                     C : Node_Id := First_Node (Subcomponents (E));
                  begin
                     --  Visit the subcomponents

                     while Present (C) loop
                        Visit (Corresponding_Instance (C));
                        C := Next_Node (C);
                     end loop;
                  end;

               when others =>
                  null;
            end case;
         end if;
      end Visit_Data_Instance;

      ----------------------------
      -- Visit_Process_Instance --
      ----------------------------

      procedure Visit_Process_Instance (E : Node_Id) is
1421 1422 1423
         U : constant Node_Id :=
           ADN.Distributed_Application_Unit
             (ADN.Deployment_Node (Backend_Node (Identifier (E))));
1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578
         P : constant Node_Id := ADN.Entity (U);
         S : Node_Id;
      begin
         Push_Entity (P);
         Push_Entity (U);
         Set_Types_Body;

         --  Start recording the handling since they have to be reset
         --  for each node.

         Start_Recording_Handlings;

         --  Visit all the subcomponents of the process

         if not AAU.Is_Empty (Subcomponents (E)) then
            S := First_Node (Subcomponents (E));
            while Present (S) loop
               --  Visit the component instance corresponding to the
               --  subcomponent S.

               Visit (Corresponding_Instance (S));
               S := Next_Node (S);
            end loop;
         end if;

         --  Unmark all the marked types

         Reset_Handlings;

         Pop_Entity; -- U
         Pop_Entity; -- P
      end Visit_Process_Instance;

      -------------------------------
      -- Visit_Subprogram_Instance --
      -------------------------------

      procedure Visit_Subprogram_Instance (E : Node_Id) is
         Call_Seq : Node_Id;
         Spg_Call : Node_Id;
         F        : 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;

         --  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 (Ada_Root);

         --  Visit all the subcomponents of the system

         if not AAU.Is_Empty (Subcomponents (E)) then
            S := First_Node (Subcomponents (E));
            while Present (S) loop
               --  Visit the component instance corresponding to the
               --  subcomponent S.

               Visit (Corresponding_Instance (S));
               S := Next_Node (S);
            end loop;
         end if;

         Pop_Entity; --  Ada_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
         --  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 and then AIN.Is_Data (F) then
                  Visit (Corresponding_Instance (F));
               end if;

               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;

   end Package_Body;

end Ocarina.Backends.PO_HI_Ada.Types;