home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gnat-2.06-src.tgz / tar.out / fsf / gnat / ada / sem_dist.adb < prev    next >
Text File  |  1996-09-28  |  117KB  |  3,530 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT COMPILER COMPONENTS                         --
  4. --                                                                          --
  5. --                             S E M _ D I S T                              --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.80 $                             --
  10. --                                                                          --
  11. --        Copyright (c) 1992,1993,1994,1995 NYU, All Rights Reserved        --
  12. --                                                                          --
  13. -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  14. -- terms of the  GNU General Public License as published  by the Free Soft- --
  15. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  16. -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  17. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  18. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  19. -- for  more details.  You should have  received  a copy of the GNU General --
  20. -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
  21. -- to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. --
  22. --                                                                          --
  23. ------------------------------------------------------------------------------
  24.  
  25. with Atree;    use Atree;
  26. with Einfo;    use Einfo;
  27. with Errout;   use Errout;
  28. with Elists;   use Elists;
  29. with Exp_Dist; use Exp_Dist;
  30. with Lib;      use Lib;
  31. with Nlists;   use Nlists;
  32. with Nmake;    use Nmake;
  33. with Namet;    use Namet;
  34. with Osint;    use Osint;
  35. with Opt;      use Opt;
  36. with Sem;      use Sem;
  37. with Sem_Ch7;  use Sem_Ch7;
  38. with Sem_Prag; use Sem_Prag;
  39. with Sem_Util; use Sem_Util;
  40. with Sinfo;    use Sinfo;
  41. with Snames;   use Snames;
  42. with Sprint;   use Sprint;
  43. with Stand;    use Stand;
  44. with Tbuild;   use Tbuild;
  45. with Uintp;    use Uintp;
  46.  
  47. package body Sem_Dist is
  48.  
  49.    -----------------------
  50.    -- Local Subprograms --
  51.    -----------------------
  52.  
  53.    procedure Check_Categorization_Dependencies
  54.      (Unit_Entity     : Entity_Id;
  55.       Depended_Entity : Entity_Id;
  56.       Info_Node       : Node_Id);
  57.    --  This procedure checks that the categorization of a lib unit and that
  58.    --  of the depended unit satisfy dependency restrictions.
  59.    --  What is the info-Node param, need more documentation ???
  60.  
  61.    procedure Check_Non_Static_Default_Expr (L : List_Id);
  62.    --  Iterate through the component list of a record definition, check
  63.    --  that no component is declared with a non-static default value.
  64.  
  65.    function Get_Name_Id (Name : String) return Name_Id;
  66.    --  Given a string, return the Name_Id that represent the string
  67.  
  68.    function Has_Pragma_All_Calls_Remote (L : List_Id) return Boolean;
  69.    --  Return true if L contains a pragma All_Calls_Remote node.
  70.  
  71.    function Static_Discriminant_Expr (L : List_Id) return Boolean;
  72.    --  Iterate through the list of discriminants to check if any of them
  73.    --  contains non-static default expression, which is a violation in
  74.    --  a preelaborated library unit.
  75.  
  76.    ------------------------
  77.    --  Append_System_RPC --
  78.    ------------------------
  79.  
  80.    procedure Append_System_RPC (N : Node_Id) is
  81.       Decls  : constant List_Id    := Visible_Declarations (Specification
  82.                                         (Unit (N)));
  83.       S      : constant Source_Ptr := Sloc (N);
  84.       Items  : List_Id := Context_Items (N);
  85.       F      : List_Id := Following_Pragmas (N);
  86.       Decl   : Node_Id;
  87.       Item   : Node_Id;
  88.  
  89.       procedure Appends (N : in out Node_Id);
  90.       --  Given N, first node in a list (visible declarations or following
  91.       --  pragmas) append to the list context items "with System.Rpc" if
  92.       --  unit is either RCI or remote types.
  93.  
  94.       procedure Appends (N : in out Node_Id) is
  95.       begin
  96.          while Present (N) and then Nkind (N) = N_Pragma loop
  97.  
  98.             if Chars (N) = Name_Remote_Call_Interface
  99.               or else Chars (N) = Name_Remote_Types
  100.             then
  101.                Item := Make_With_Clause (S,
  102.                  Make_Selected_Component (S,
  103.                    Prefix        => Make_Identifier (S, Name_System),
  104.                    Selector_Name => Make_Identifier (S, Name_Rpc)));
  105.  
  106.                if Present (Items) then
  107.                   Append (Item, Items);
  108.                else
  109.                   Items := New_List;
  110.                   Append (Item, Items);
  111.                end if;
  112.             end if;
  113.  
  114.             N := Next (N);
  115.          end loop;
  116.       end Appends;
  117.  
  118.    --  Start processing of Append_System_Rpc
  119.  
  120.    begin
  121.       if not Present (Decls) then
  122.          return;
  123.       end if;
  124.  
  125.       Decl := First (Decls);
  126.       Appends (Decl);
  127.  
  128.       if not Present (F) then
  129.          return;
  130.       end if;
  131.  
  132.       Decl := First (F);
  133.       Appends (Decl);
  134.    end Append_System_RPC;
  135.  
  136.    --------------------------
  137.    -- Append_System_RPC_PI --
  138.    --------------------------
  139.  
  140.    procedure Append_System_RPC_PI (N : Node_Id; L : Node_Id) is
  141.       Loc : constant Source_Ptr := Sloc (N);
  142.  
  143.       procedure Appends (Items : List_Id);
  144.       --  Given Items, a list of visible declarations or following pragmas
  145.       --  of L, append System.Rpc.Partition_Interface to the context items
  146.       --  of N if any of there is Remote_Call_Interface or Remote_Types
  147.       --  pragma in the list.
  148.  
  149.       procedure Appends (Items : List_Id) is
  150.          Nd : Node_Id;
  151.  
  152.       begin
  153.          if Present (Items) then
  154.             Nd := First (Items);
  155.             while Present (Nd) loop
  156.  
  157.                --  Search ends when non-pragma is met since they appear first
  158.  
  159.                exit when Nkind (Nd) /= N_Pragma;
  160.  
  161.                if Chars (Nd) = Name_Remote_Call_Interface
  162.                  or else Chars (Nd) = Name_Remote_Types
  163.                then
  164.                   Append_To (Context_Items (N),
  165.                     Make_With_Clause (Loc,
  166.                       Make_Selected_Component (Loc,
  167.                         Prefix        =>
  168.                           Make_Selected_Component (Loc,
  169.                             Prefix        =>
  170.                               Make_Identifier (Loc, Name_System),
  171.                             Selector_Name =>
  172.                               Make_Identifier (Loc, Name_Rpc)),
  173.  
  174.                         Selector_Name =>
  175.                           Make_Identifier (Loc, Name_Partition_Interface))));
  176.                end if;
  177.  
  178.                Nd := Next (Nd);
  179.             end loop;
  180.          end if;
  181.       end Appends;
  182.  
  183.    --  Start processing of Append_System_Rpc_PI
  184.  
  185.    begin
  186.       if Nkind (Unit (L)) = N_Package_Declaration then
  187.          Appends (Visible_Declarations (Specification (Unit (L))));
  188.          Appends (Following_Pragmas (L));
  189.       end if;
  190.    end Append_System_RPC_PI;
  191.  
  192.    ---------------------------------------
  193.    -- Check_Categorization_Dependencies --
  194.    ---------------------------------------
  195.  
  196.    procedure Check_Categorization_Dependencies
  197.      (Unit_Entity     : Entity_Id;
  198.       Depended_Entity : Entity_Id;
  199.       Info_Node       : Node_Id)
  200.    is
  201.       N                  : Node_Id := Info_Node;
  202.       Depended_Unit_Node : Node_Id;
  203.  
  204.    begin
  205.       if Nkind (Info_Node) = N_With_Clause then
  206.  
  207.          --  Compilation unit node of withed unit.
  208.  
  209.          Depended_Unit_Node := Library_Unit (Info_Node);
  210.  
  211.       else
  212.          --  Parent spec compilation unit node.
  213.  
  214.          Depended_Unit_Node := Info_Node;
  215.       end if;
  216.  
  217.       if Is_Preelaborated (Unit_Entity)
  218.         and then not Is_Preelaborated (Depended_Entity)
  219.         and then not Is_Remote_Call_Interface (Depended_Entity)
  220.         and then not Is_Remote_Types (Depended_Entity)
  221.         and then not Is_Shared_Passive (Depended_Entity)
  222.         and then not Is_Pure (Depended_Entity)
  223.       then
  224.          Error_Msg_N ("preelaborated unit dependency violation", N);
  225.  
  226.       elsif Is_Pure (Unit_Entity)
  227.         and then not Is_Pure (Depended_Entity)
  228.       then
  229.          Error_Msg_N ("pure unit dependency violation", N);
  230.  
  231.       elsif Is_Shared_Passive (Unit_Entity)
  232.         and then (not Is_Shared_Passive (Depended_Entity)
  233.                    and not Is_Pure (Depended_Entity))
  234.       then
  235.          Error_Msg_N ("shared passive unit dependency violation", N);
  236.  
  237.       elsif Is_Remote_Types (Unit_Entity)
  238.         and then not Is_Remote_Types (Depended_Entity)
  239.         and then not Is_Shared_Passive (Depended_Entity)
  240.         and then not Is_Pure (Depended_Entity)
  241.       then
  242.  
  243.          --  System.Rpc is withed in processing remote access to subprogram
  244.          --  type by RCI and remote types units to generate fat pointer type.
  245.          --  Since System.Rpc is not categorized (not an error, by the way),
  246.          --  there will be a dependency violation if we don't skip checking
  247.          --  at this point.
  248.  
  249.          if Chars (Depended_Entity) = Name_Rpc
  250.            and then Present (Scope (Depended_Entity))
  251.            and then Chars (Scope (Depended_Entity)) = Name_System
  252.          then
  253.             return;
  254.          end if;
  255.  
  256.          Error_Msg_N ("remote_types unit dependency violation", N);
  257.  
  258.       elsif Is_Remote_Call_Interface (Unit_Entity)
  259.         and then not Is_Remote_Call_Interface (Depended_Entity)
  260.         and then not Is_Remote_Types (Depended_Entity)
  261.         and then not Is_Shared_Passive (Depended_Entity)
  262.         and then not Is_Pure (Depended_Entity)
  263.       then
  264.          --  System.Rpc is withed in processing remote access to subprogram
  265.          --  type by RCI and remote types units to generate fat pointer type.
  266.          --  Since System.Rpc is not categorized (not an error, by the way),
  267.          --  there will be a dependency violation if we don't skip checking
  268.          --  at this point.
  269.  
  270.          if Chars (Depended_Entity) = Name_Rpc
  271.            and then Present (Scope (Depended_Entity))
  272.            and then Chars (Scope (Depended_Entity)) = Name_System
  273.          then
  274.             return;
  275.          end if;
  276.  
  277.          Error_Msg_N ("remote call interface unit dependency violation", N);
  278.       end if;
  279.  
  280.    end Check_Categorization_Dependencies;
  281.  
  282.    -----------------------------------
  283.    -- Check_Non_Static_Default_Expr --
  284.    -----------------------------------
  285.  
  286.    procedure Check_Non_Static_Default_Expr (L : List_Id) is
  287.       Component_Decl : Node_Id;
  288.  
  289.    begin
  290.       --  Check against that component declarations does not involve
  291.       --  ******* above line is incomprehensible ??? ********
  292.  
  293.       --  a. a non-static default expression, where the object is
  294.       --     declared to be default initialized.
  295.  
  296.       --  b. a dynamic Itype (discriminants and constraints)
  297.  
  298.       Component_Decl := First (L);
  299.       while Present (Component_Decl)
  300.         and then Nkind (Component_Decl) = N_Component_Declaration
  301.       loop
  302.          if Present (Expression (Component_Decl))
  303.            and then not Is_Static_Expression (Expression (Component_Decl))
  304.          then
  305.             Error_Msg_N
  306.               ("non-static expression in declaration in preelaborated unit",
  307.                Component_Decl);
  308.  
  309.          elsif Has_Dynamic_Itype (Component_Decl) then
  310.             Error_Msg_N
  311.               ("dynamic type discriminant, constraint in preelaborated unit",
  312.                Component_Decl);
  313.          end if;
  314.  
  315.          Component_Decl := Next (Component_Decl);
  316.       end loop;
  317.    end Check_Non_Static_Default_Expr;
  318.  
  319.    --------------------------------------
  320.    -- CW_Remote_Extension_Add_Receiver --
  321.    --------------------------------------
  322.  
  323.    procedure CW_Remote_Extension_Add_Receiver (N : Node_Id) is
  324.       PN : constant Node_Id := Parent (N);
  325.       LU : Node_Id;
  326.       PD : Node_Id;
  327.       SP : Node_Id;
  328.       BL : List_Id;
  329.       LN : Node_Id;
  330.  
  331.       procedure Add_Receiver (L : List_Id);
  332.       --  In case there is a classwide type remote extension (check spec
  333.       --  for definition) on the list, append a receiver for such type
  334.       --  (extension)
  335.  
  336.       procedure Add_Receiver (L : List_Id) is
  337.          Decl : Node_Id;
  338.  
  339.       begin
  340.          if not Present (L) then
  341.             return;
  342.          end if;
  343.  
  344.          Decl := First (L);
  345.  
  346.          while Present (Decl) loop
  347.  
  348.             if Is_Class_Wide_Type_Remote_Extension (Decl) then
  349.  
  350.                if not Is_Remote_Call_Interface (Defining_Identifier
  351.                  (Decl))
  352.                then
  353.  
  354.                   --  Add to BL (package body declaration list) the
  355.                   --  receiver subprogram for the type (extension)
  356.  
  357.                   null; --  ??? To be updated soon
  358.                end if;
  359.  
  360.             end if;
  361.  
  362.             Decl := Next (Decl);
  363.          end loop;
  364.       end Add_Receiver;
  365.  
  366.    --  Start of processing CW_Remote_Extension_Add_Receiver
  367.  
  368.    begin
  369.       if Nkind (PN) /= N_Compilation_Unit then
  370.          return;
  371.       end if;
  372.  
  373.       LU := Library_Unit (PN);
  374.  
  375.       if not Present (LU) then
  376.          return;
  377.       end if;
  378.  
  379.       PD := Unit (LU);
  380.  
  381.       if Nkind (PD) /= N_Package_Declaration then
  382.          return;
  383.       end if;
  384.  
  385.       SP := Specification (PD);
  386.       BL := Declarations (N);
  387.  
  388.       LN := Last (BL);
  389.       Add_Receiver (Visible_Declarations (SP));
  390.       Add_Receiver (Private_Declarations (SP));
  391.       Add_Receiver (BL);
  392.  
  393.    end CW_Remote_Extension_Add_Receiver;
  394.  
  395.    -------------------------------
  396.    -- Enclosing_Lib_Unit_Entity --
  397.    -------------------------------
  398.  
  399.    function Enclosing_Lib_Unit_Entity return Entity_Id is
  400.       Unit_Entity : Entity_Id := Current_Scope;
  401.  
  402.    begin
  403.       --  Look for enclosing library unit entity by following scope links.
  404.       --  Equivalent to, but faster than indexing through the scope stack.
  405.  
  406.       while (Present (Scope (Unit_Entity))
  407.         and then Scope (Unit_Entity) /= Standard_Standard)
  408.         and not Is_Child_Unit (Unit_Entity)
  409.       loop
  410.          Unit_Entity := Scope (Unit_Entity);
  411.       end loop;
  412.  
  413.       return Unit_Entity;
  414.    end Enclosing_Lib_Unit_Entity;
  415.  
  416.    -----------------------------
  417.    -- Enclosing_Lib_Unit_Node --
  418.    -----------------------------
  419.  
  420.    function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
  421.       Current_Node : Node_Id := N;
  422.  
  423.    begin
  424.       while Present (Current_Node)
  425.         and then Nkind (Current_Node) /= N_Compilation_Unit
  426.       loop
  427.          Current_Node := Parent (Current_Node);
  428.       end loop;
  429.  
  430.       if Nkind (Current_Node) /= N_Compilation_Unit then
  431.          return Empty;
  432.       end if;
  433.  
  434.       return Current_Node;
  435.    end Enclosing_Lib_Unit_Node;
  436.  
  437.    --------------------------
  438.    -- Generate_Stubs_Files --
  439.    --------------------------
  440.  
  441.    procedure Generate_Stubs_Files (N : Node_Id) is
  442.       Unit_Node : Node_Id := Unit (N);
  443.       Copy      : Node_Id;
  444.       CB        : Node_Id := Empty;
  445.       SS        : Node_Id := Empty;
  446.       SB        : Node_Id := Empty;
  447.  
  448.       procedure Output_Stubs_File (Stubs_Node : Node_Id);
  449.       --  Create the source file for a stubs node
  450.  
  451.       procedure Output_Stubs_File (Stubs_Node : Node_Id) is
  452.       begin
  453.          Stub_Output_Start;
  454.          Sprint_Node_Pure_Ada (Stubs_Node);
  455.          Stub_Output_Stop;
  456.       end Output_Stubs_File;
  457.  
  458.    --  Start of processing for Generate_Stubs_Files
  459.  
  460.    begin
  461.       if Stub_Mode = Generate_Caller_Stub_Body then
  462.          if Nkind (Unit_Node) = N_Package_Declaration then
  463.             Init_Names;
  464.             Output_Stubs_File (Build_Calling_Stubs_Bodies_Cunit (N));
  465.  
  466.          else
  467.             Error_Msg_N ("Specification file expected from command line",
  468.               Unit_Node);
  469.          end if;
  470.  
  471.       elsif Stub_Mode = Generate_Receiver_Stub_Body then
  472.          Init_Names;
  473.          Output_Stubs_File (Build_Receiving_Stubs_Bodies_Cunit (N));
  474.  
  475.       end if;
  476.  
  477.    end Generate_Stubs_Files;
  478.  
  479.    -----------------
  480.    -- Get_Name_Id --
  481.    -----------------
  482.  
  483.    function Get_Name_Id (Name : String) return Name_Id is
  484.    begin
  485.       Name_Len := Name'Length;
  486.       Name_Buffer (1 ..  Name_Len) := Name;
  487.       return Name_Find;
  488.    end Get_Name_Id;
  489.  
  490.    ---------------------------------
  491.    -- Has_Pragma_All_Calls_Remote --
  492.    ---------------------------------
  493.  
  494.    function Has_Pragma_All_Calls_Remote (L : List_Id) return Boolean is
  495.       Decl : Node_Id;
  496.  
  497.    begin
  498.       if Present (L) then
  499.          Decl := First (L);
  500.          while Present (Decl)
  501.            and then (Nkind (Decl) /= N_Pragma
  502.                       or else Chars (Decl) /= Name_All_Calls_Remote)
  503.          loop
  504.             Decl := Next (Decl);
  505.          end loop;
  506.  
  507.          if Present (Decl) then
  508.             return True;
  509.          end if;
  510.       end if;
  511.  
  512.       return False;
  513.    end Has_Pragma_All_Calls_Remote;
  514.  
  515.    -------------------------------
  516.    -- Inside_Preelaborated_Unit --
  517.    -------------------------------
  518.  
  519.    function Inside_Preelaborated_Unit return Boolean is
  520.       Unit_Entity : constant Entity_Id := Current_Scope;
  521.  
  522.    begin
  523.       --  Body of RCI unit is unconstrained.
  524.       --  Body of RCI subprogram is not tested here.
  525.       --  Above comments are not clear to me ??? (RBKD)
  526.  
  527.       return Is_Preelaborated (Unit_Entity)
  528.         or else Is_Pure (Unit_Entity)
  529.         or else Is_Shared_Passive (Unit_Entity)
  530.         or else Is_Remote_Types (Unit_Entity)
  531.         or else (Is_Remote_Call_Interface (Unit_Entity)
  532.                   and then Nkind (Unit (Cunit (Current_Sem_Unit)))
  533.                     /= N_Package_Body);
  534.  
  535.    end Inside_Preelaborated_Unit;
  536.  
  537.    ----------------------
  538.    -- Inside_Pure_Unit --
  539.    ----------------------
  540.  
  541.    function Inside_Pure_Unit return Boolean is
  542.    begin
  543.       return Is_Pure (Current_Scope);
  544.    end Inside_Pure_Unit;
  545.  
  546.    ---------------------------------------
  547.    -- Inside_Remote_Call_Interface_Unit --
  548.    ---------------------------------------
  549.  
  550.    function Inside_Remote_Call_Interface_Unit return Boolean is
  551.       Unit_Entity : constant Entity_Id := Current_Scope;
  552.  
  553.    begin
  554.       --  Body of RCI unit is unconstrained.
  555.       --  Body of RCI subprogram is not tested here since there is no
  556.       --  such thing as an RCI subprogram library unit.
  557.       --  Above comments are unclear to me (RBKD) ???
  558.  
  559.       return Is_Remote_Call_Interface (Unit_Entity)
  560.         and then Nkind (Unit (Cunit (Current_Sem_Unit))) /= N_Package_Body;
  561.    end Inside_Remote_Call_Interface_Unit;
  562.  
  563.    -----------------------------
  564.    -- Inside_Remote_Types_Unit --
  565.    -----------------------------
  566.  
  567.    function Inside_Remote_Types_Unit return Boolean is
  568.       Unit_Entity : constant Entity_Id := Current_Scope;
  569.  
  570.    begin
  571.       --  Body of Remote Types unit is unconstrained (RM E.2(9))
  572.  
  573.       return Is_Remote_Types (Unit_Entity)
  574.         and then Nkind (Unit (Cunit (Current_Sem_Unit))) /= N_Package_Body;
  575.    end Inside_Remote_Types_Unit;
  576.  
  577.    --------------------------------
  578.    -- Inside_Shared_Passive_Unit --
  579.    --------------------------------
  580.  
  581.    function Inside_Shared_Passive_Unit return Boolean is
  582.       Unit_Entity : constant Entity_Id := Current_Scope;
  583.  
  584.    begin
  585.       return Is_Shared_Passive (Unit_Entity);
  586.    end Inside_Shared_Passive_Unit;
  587.  
  588.    -------------------------------------------
  589.    -- Inside_Subprogram_Task_Protected_Unit --
  590.    -------------------------------------------
  591.  
  592.    function Inside_Subprogram_Task_Protected_Unit return Boolean is
  593.       E : Entity_Id;
  594.       K : Entity_Kind;
  595.  
  596.    begin
  597.       --  The following is to verify that a declaration is inside
  598.       --  subprogram, generic subprogram, task unit, protected unit.
  599.       --  Used to validate if a lib. unit is Pure. RM 10.2.1(16).
  600.  
  601.       --  Use scope chain to check successively outer scopes
  602.  
  603.       E := Current_Scope;
  604.       loop
  605.          K := Ekind (E);
  606.  
  607.          if        K = E_Procedure
  608.            or else K = E_Function
  609.            or else K = E_Generic_Procedure
  610.            or else K = E_Generic_Function
  611.            or else K = E_Task_Type
  612.            or else K = E_Task_Subtype
  613.            or else K = E_Protected_Type
  614.            or else K = E_Protected_Subtype
  615.          then
  616.             return True;
  617.  
  618.          elsif E = Standard_Standard then
  619.             return False;
  620.          end if;
  621.  
  622.          E := Scope (E);
  623.       end loop;
  624.  
  625.    end Inside_Subprogram_Task_Protected_Unit;
  626.  
  627.    ----------------------------
  628.    -- Inside_Subprogram_Unit --
  629.    ----------------------------
  630.  
  631.    function Inside_Subprogram_Unit return Boolean is
  632.       E : Entity_Id;
  633.       K : Entity_Kind;
  634.  
  635.    begin
  636.       --  Use scope chain to check successively outer scopes
  637.  
  638.       E := Current_Scope;
  639.       loop
  640.          K := Ekind (E);
  641.  
  642.          if        K = E_Procedure
  643.            or else K = E_Function
  644.            or else K = E_Generic_Procedure
  645.            or else K = E_Generic_Function
  646.          then
  647.             return True;
  648.  
  649.          elsif E = Standard_Standard then
  650.             return False;
  651.          end if;
  652.  
  653.          E := Scope (E);
  654.       end loop;
  655.  
  656.    end Inside_Subprogram_Unit;
  657.  
  658.    -----------------------------------------
  659.    -- Is_Class_Wide_Type_Remote_Extension --
  660.    -----------------------------------------
  661.  
  662.    function Is_Class_Wide_Type_Remote_Extension
  663.      (N    : Node_Id)
  664.       return Boolean
  665.    is
  666.       Derived  : Entity_Id;
  667.       Root_Ty  : Entity_Id;
  668.       Contexts : List_Id;
  669.       Item     : Node_Id;
  670.       Item_Ety : Entity_Id;
  671.       RACW     : Entity_Id;
  672.       DD       : Node_Id;
  673.  
  674.       function Compare_Root_W_RACW (E : Entity_Id) return Boolean;
  675.       --  Return True if the list containing input entity E has a
  676.       --  remote access to classwide type and whose designated type is
  677.       --  the root abstract type of the Derived type
  678.  
  679.       function Compare_Root_W_RACW (E : Entity_Id) return Boolean is
  680.          Remote_Access : Entity_Id := E;
  681.  
  682.       begin
  683.          while Present (Remote_Access) loop
  684.             if Is_Remote_Access_To_Class_Wide_Type (Remote_Access) then
  685.                DD := Directly_Designated_Type (Remote_Access);
  686.  
  687.                --  Test if the designated type of this Remote-Access-To-
  688.                --  Classwide-type is the Root abstract type of the
  689.                --  derived type.
  690.  
  691.                if Etype (DD) = Root_Ty then
  692.                   return True;
  693.                end if;
  694.             end if;
  695.  
  696.             Remote_Access := Next_Entity (Remote_Access);
  697.          end loop;
  698.  
  699.          return False;
  700.       end Compare_Root_W_RACW;
  701.  
  702.    begin
  703.       if Nkind (N) /= N_Full_Type_Declaration then
  704.          return False;
  705.       end if;
  706.       if Nkind (Type_Definition (N)) /= N_Derived_Type_Definition then
  707.          return False;
  708.       end if;
  709.  
  710.       Derived := Defining_Identifier (N);
  711.  
  712.       if not Is_Limited_Record (Derived) then
  713.          return False;
  714.       end if;
  715.  
  716.       if not Is_Tagged_Type (Derived) then
  717.          return False;
  718.       end if;
  719.  
  720.       Root_Ty := Etype (Derived);
  721.       Contexts := Context_Items (Cunit (Current_Sem_Unit));
  722.  
  723.       if not Present (Contexts) then
  724.          return False;
  725.       end if;
  726.  
  727.       Item := First (Contexts);
  728.  
  729.       while Present (Item) loop
  730.  
  731.          if Nkind (Item) = N_With_Clause then
  732.             Item_Ety := Entity (Name (Item));
  733.  
  734.             if Is_Remote_Call_Interface (Item_Ety) then
  735.                RACW := First_Entity (Item_Ety);
  736.  
  737.                if Compare_Root_W_RACW (RACW) then
  738.                   return True;
  739.                end if;
  740.             end if;
  741.          end if;
  742.  
  743.          Item := Next (Item);
  744.       end loop;
  745.  
  746.       --  For compiler generated classwide extensions "object_stub" in
  747.       --  an RCI unit (spec and body)
  748.  
  749.       if Is_Remote_Call_Interface (Derived) then
  750.          RACW := First_Entity (Scope (Derived));
  751.  
  752.          if Compare_Root_W_RACW (RACW) then
  753.             return True;
  754.          end if;
  755.       end if;
  756.  
  757.       return False;
  758.    end Is_Class_Wide_Type_Remote_Extension;
  759.  
  760.    -----------------------------------------
  761.    -- Is_Remote_Access_To_Class_Wide_Type --
  762.    -----------------------------------------
  763.  
  764.    function Is_Remote_Access_To_Class_Wide_Type
  765.      (E    : Entity_Id)
  766.       return Boolean
  767.    is
  768.       DD : Node_Id;
  769.       ED : Node_Id;
  770.       EE : Entity_Id;
  771.  
  772.    begin
  773.       --  This type entity would have been set Is_Remote_Call_Interface
  774.       --  during the type declaration in case it is inside an RCI unit.
  775.       --  This type entity would have been set Is_Remote_Types during
  776.       --  the type declaration in case it is inside a Remote_Types unit.
  777.  
  778.       if not Is_Remote_Call_Interface (E)
  779.         and then not Is_Remote_Types (E)
  780.       then
  781.          return False;
  782.       end if;
  783.  
  784.       if Ekind (E) = E_General_Access_Type then
  785.          DD := Directly_Designated_Type (E);
  786.          ED := Parent (Etype (DD));
  787.  
  788.          if Nkind (ED) = N_Private_Type_Declaration
  789.            and then Limited_Present (ED)
  790.            and then Ekind (DD) = E_Class_Wide_Type
  791.          then
  792.             return True;
  793.          end if;
  794.       end if;
  795.  
  796.       return False;
  797.    end Is_Remote_Access_To_Class_Wide_Type;
  798.  
  799.    -----------------------------------------
  800.    -- Is_Remote_Access_To_Subprogram_Type --
  801.    -----------------------------------------
  802.  
  803.    function Is_Remote_Access_To_Subprogram_Type
  804.      (E    : Entity_Id)
  805.       return Boolean
  806.    is
  807.       EE : Entity_Id;
  808.       SE : Entity_Id;
  809.       DD : Entity_Id;
  810.  
  811.    begin
  812.       --  This type entity would have been set Is_Remote_Call_Interface
  813.       --  during the type declaration in case it is inside an RCI unit.
  814.       --  This type entity would have been set Is_Remote_Types during
  815.       --  the type declaration in case it is inside a Remote_Types unit.
  816.  
  817.       if not Is_Remote_Call_Interface (E)
  818.         and then not Is_Remote_Types (E)
  819.       then
  820.          return False;
  821.       end if;
  822.  
  823.       if Ekind (E) = E_Access_Subprogram_Type then
  824.          return True;
  825.       end if;
  826.  
  827.       return False;
  828.    end Is_Remote_Access_To_Subprogram_Type;
  829.  
  830.    ----------------------------------
  831.    -- Process_Remote_AST_Attribute --
  832.    ----------------------------------
  833.  
  834.    procedure Process_Remote_AST_Attribute (N : Node_Id; UN : Node_Id) is
  835.       PE  : constant Entity_Id   := Entity (Prefix (N));
  836.       S   : constant Source_Ptr  := Sloc (N);
  837.       NN  : Node_Id;
  838.       N1  : Node_Id;
  839.       Ex  : List_Id := New_List;
  840.       Nd  : Node_Id;
  841.       Nd1 : Node_Id;
  842.       Nd2 : Node_Id;
  843.       SS  : Node_Id;
  844.       NM  : Name_Id;
  845.       E1  : Entity_Id;
  846.       E2  : Entity_Id;
  847.       CL  : List_Id;
  848.       CT  : Node_Id;
  849.  
  850.       function Compare_Params (L1 : List_Id; L2 : List_Id) return Boolean;
  851.       --  Given L1, L2 two lists of parameters, return True if they match
  852.       --  every parameter.
  853.  
  854.       function Compare_Params (L1 : List_Id; L2 : List_Id) return Boolean is
  855.          N1 : Node_Id;
  856.          N2 : Node_Id;
  857.          E1 : Entity_Id;
  858.          E2 : Entity_Id;
  859.  
  860.       begin
  861.          if not Present (L1)
  862.            and then not Present (L2)
  863.          then
  864.             return True;
  865.          end if;
  866.  
  867.          if not Present (L1)
  868.            or else not Present (L2)
  869.          then
  870.             return False;
  871.          end if;
  872.  
  873.          N1 := First (L1);
  874.          N2 := First (L2);
  875.  
  876.          while Present (N1) and then Present (N2) loop
  877.             E1 := Etype (Defining_Identifier (N1));
  878.             E2 := Etype (Defining_Identifier (N2));
  879.  
  880.             if E1 /= E2 then
  881.                return False;
  882.             end if;
  883.  
  884.             N1 := Next (N1);
  885.             N2 := Next (N2);
  886.          end loop;
  887.  
  888.          return True;
  889.       end Compare_Params;
  890.  
  891.       function Get_Entity (S : Node_Id; L : List_Id) return Entity_Id;
  892.       --  Search through L, the list of declarations to find a remote
  893.       --  access to subprogram type declaration whose signature matches
  894.       --  that of S, the procedure/function specification node of a remote
  895.       --  subprogram.
  896.       --  Return Empty if there is no match, return the entity of fat pointer
  897.       --  type if there is a match.
  898.  
  899.       function Get_Entity (S : Node_Id; L : List_Id) return Entity_Id is
  900.          EK : constant Entity_Kind := Ekind (PE);
  901.          N  : Node_Id;
  902.          N1 : Node_Id;
  903.          N2 : Node_Id;
  904.          L1 : List_Id;
  905.          L2 : List_Id;
  906.  
  907.       begin
  908.          if not Present (L) then
  909.             return Empty;
  910.          end if;
  911.  
  912.          --  Search backwards
  913.  
  914.          N := Last (L);
  915.  
  916.          while Present (N) loop
  917.             if Nkind (N) = N_Full_Type_Declaration then
  918.                N1 := Type_Definition (N);
  919.  
  920.                if  Nkind (N1) = N_Access_Procedure_Definition
  921.                  and then EK = E_Procedure
  922.                then
  923.                   L1 := Parameter_Specifications (S);
  924.                   L2 := Parameter_Specifications (N1);
  925.  
  926.                   if Compare_Params (L1, L2) then
  927.  
  928.                      --  Return the defining identifier of the following
  929.                      --  fat pointer type declaration
  930.  
  931.                      return Defining_Identifier (Next (N));
  932.                   end if;
  933.  
  934.                elsif  Nkind (N1) = N_Access_Function_Definition
  935.                  and then EK = E_Function
  936.                  and then Entity (Subtype_Mark (N1)) = Entity (Subtype_Mark
  937.                    (S))
  938.                then
  939.                   L1 := Parameter_Specifications (S);
  940.                   L2 := Parameter_Specifications (N1);
  941.  
  942.                   if Compare_Params (L1, L2) then
  943.  
  944.                      --  Return the defining identifier of the following
  945.                      --  fat pointer type declaration
  946.  
  947.                      return Defining_Identifier (Next (N));
  948.                   end if;
  949.                end if;
  950.             end if;
  951.  
  952.             N := Prev (N);
  953.          end loop;
  954.  
  955.          return Empty;
  956.       end Get_Entity;
  957.  
  958.    --  Start processing of Process_Remote_AST_Attribute
  959.  
  960.    begin
  961.       --  Process only if this is a remote subprogram access attribute
  962.  
  963.       if not Is_Remote_Call_Interface (PE)
  964.         and then not Is_Remote_Types (PE)
  965.       then
  966.          return;
  967.       end if;
  968.  
  969.       --  In case prefix is remote subprogram then we intend to transform
  970.       --  remore_subprogram_name'access   into
  971.       --  (package_name.remote_access_to_subprogram_typeR'access,
  972.       --   remote_subprogram_name'access,
  973.       --   system.rpc.partition_interface.get_local_partition_id
  974.       --   True/False)
  975.  
  976.       --  Return if it is rewritten by this procedure already
  977.  
  978.       if Nkind (Parent (N)) = N_Component_Association
  979.         or Nkind (Parent (N)) = N_Aggregate
  980.       then
  981.          return;
  982.       end if;
  983.  
  984.       --  In order to construct the aggregate (it's first component),
  985.       --  we need to find the remote access to subprogram type declaration
  986.       --  that matches the signature of (this attribute reference) prefix
  987.       --  remote_subprogram_name.
  988.       --  Search through specification of this unit first.
  989.  
  990.       SS  := Parent (PE);
  991.       Nd  := Enclosing_Lib_Unit_Node (N);
  992.       E1  := Enclosing_Lib_Unit_Entity;
  993.       CL  := Context_Items (Nd);
  994.       Nd1 := Unit (Nd);
  995.  
  996.       if Nkind (Nd1) = N_Package_Declaration
  997.         and then (Is_Remote_Call_Interface (E1)
  998.                   or else Is_Remote_Types (E1))
  999.       then
  1000.          E2 := Get_Entity (SS, Visible_Declarations (Specification (Nd1)));
  1001.          if Present (E2) then
  1002.             N1 := Make_Attribute_Reference (S,
  1003.               Prefix =>
  1004.                 Make_Selected_Component (S,
  1005.                   Prefix        => Make_Identifier (S, Chars (E1)),
  1006.                   Selector_Name => Make_Identifier (S,
  1007.                     New_External_Name (Chars (E2), 'R', 0, ' '))),
  1008.               Attribute_Name => Name_Access);
  1009.             goto Found;
  1010.          end if;
  1011.       end if;
  1012.  
  1013.       --  Then search (body) of this unit
  1014.  
  1015.       if Nkind (Nd1) = N_Package_Body then
  1016.          E2  := Corresponding_Spec (Nd1);
  1017.  
  1018.          if Is_Remote_Call_Interface (E2)
  1019.            or else Is_Remote_Types (E2)
  1020.          then
  1021.             Nd2 := Parent (E2);
  1022.             E2 := Get_Entity (SS, Visible_Declarations (Nd2));
  1023.  
  1024.             if Present (E2) then
  1025.                N1 := Make_Attribute_Reference (S,
  1026.                  Prefix =>
  1027.                    Make_Selected_Component (S,
  1028.                      Prefix        => Make_Identifier (S, Chars (E1)),
  1029.                      Selector_Name => Make_Identifier (S,
  1030.                        New_External_Name (Chars (E2), 'R', 0, ' '))),
  1031.                  Attribute_Name => Name_Access);
  1032.                goto Found;
  1033.             end if;
  1034.          end if;
  1035.       end if;
  1036.  
  1037.       --  Then search the withed unit (specification)
  1038.  
  1039.       CT := First (CL);
  1040.       while Present (CT) loop
  1041.          if Nkind (CT) = N_With_Clause
  1042.            and then Nkind (Unit (Library_Unit (CT))) = N_Package_Declaration
  1043.          then
  1044.             E2 := Entity (Name (CT));
  1045.             E1 := E2;
  1046.  
  1047.             if Is_Remote_Call_Interface (E2)
  1048.               or else Is_Remote_Types (E2)
  1049.             then
  1050.                Nd2 := Parent (E2);
  1051.                E2 := Get_Entity (SS, Visible_Declarations (Nd2));
  1052.  
  1053.                if Present (E2) then
  1054.                   N1 := Make_Attribute_Reference (S,
  1055.                     Prefix =>
  1056.                       Make_Selected_Component (S,
  1057.                         Prefix        => Make_Identifier (S, Chars (E1)),
  1058.                         Selector_Name => Make_Identifier (S,
  1059.                           New_External_Name (Chars (E2), 'R', 0, ' '))),
  1060.                     Attribute_Name => Name_Access);
  1061.                   goto Found;
  1062.                end if;
  1063.             end if;
  1064.          end if;
  1065.  
  1066.          CT := Next (CT);
  1067.       end loop;
  1068.  
  1069.       --  Now since we did not find such remote access to subprogram type
  1070.       --  we should not do the transformation.
  1071.  
  1072.       return;
  1073.  
  1074.       <<Found>>
  1075.          null;
  1076.  
  1077.       --  Now construct the third component of this aggregate
  1078.       --   system.rpc.partition_interface.get_local_partition_id
  1079.  
  1080.       E1 := Make_Selected_Component (S,
  1081.               Prefix => Make_Selected_Component (S,
  1082.                 Prefix => Make_Selected_Component (S,
  1083.                   Prefix        => Make_Identifier (S, Name_System),
  1084.                   Selector_Name => Make_Identifier (S, Name_Rpc)),
  1085.                 Selector_Name => Make_Identifier (S,
  1086.                   Name_Partition_Interface)),
  1087.               Selector_Name => Make_Identifier (S,
  1088.                 Name_Get_Local_Partition_ID));
  1089.  
  1090.       --  Now construct the fourth component of this aggregate
  1091.       --   True/False
  1092.       --  which represent if the subprogram is asynchronous.
  1093.       --  Do a search in the package that the remote subprogram is declared
  1094.       --  to check if there is a pragma asynchronous associated with it.
  1095.  
  1096.       Nd := Next (Parent (SS));
  1097.       while Present (Nd) loop
  1098.          if Nkind (Nd) = N_Pragma
  1099.            and then Chars (Nd) = Name_Asynchronous
  1100.          then
  1101.             Nd1 := Expression (First (Pragma_Argument_Associations (Nd)));
  1102.  
  1103.             if Chars (Nd1) = Chars (PE) then
  1104.                Nd2 := Make_Identifier (S, Chars (Standard_True));
  1105.                goto  Found_Pragma;
  1106.             end if;
  1107.          end if;
  1108.  
  1109.          Nd := Next (Nd);
  1110.       end loop;
  1111.  
  1112.       Nd2 := Make_Identifier (S, Chars (Standard_False));
  1113.  
  1114.       <<Found_Pragma>>
  1115.          null;
  1116.  
  1117.       --  Now build the aggregate and rewrite the attribute reference to
  1118.       --  the aggregate
  1119.  
  1120.       Append (N1, Ex);
  1121.       Append (UN, Ex);
  1122.       Append (E1, Ex);
  1123.       Append (Nd2, Ex);
  1124.  
  1125.       NN := Make_Aggregate (S, Ex);
  1126.       Analyze (NN);
  1127.       Rewrite_Substitute_Tree (N, NN);
  1128.    end Process_Remote_AST_Attribute;
  1129.  
  1130.    ------------------------------------
  1131.    -- Process_Remote_AST_Declaration --
  1132.    ------------------------------------
  1133.  
  1134.    procedure Process_Remote_AST_Declaration (N : Node_Id) is
  1135.       Decls        : constant List_Id    := List_Containing (N);
  1136.       Defining_Id  : constant Node_Id    := Defining_Identifier (N);
  1137.       Old_Name     : constant Name_Id    := Chars (Defining_Id);
  1138.       New_Name     : constant Name_Id    := New_External_Name
  1139.                                              (Old_Name, 'A', 0, ' ');
  1140.       Sub_Name     : constant Name_Id    := New_External_Name
  1141.                                              (Old_Name, 'D', 0, ' ');
  1142.       Loc          : constant Source_Ptr := Sloc (N);
  1143.       Record_Ty    : Node_Id;
  1144.       NN           : Node_Id;
  1145.       N1           : Node_Id;
  1146.       PL           : List_Id;
  1147.       SM           : Node_Id;
  1148.       PS           : Node_Id;
  1149.       SD           : Node_Id;
  1150.       Nd           : Node_Id;
  1151.       Nd1          : Node_Id;
  1152.       DL           : List_Id;
  1153.       DL2          : List_Id;
  1154.       SL           : List_Id;
  1155.       Ori_Arg_List : List_Id;
  1156.       Arg_List     : List_Id;
  1157.       Param_Type   : Node_Id;
  1158.       Arg          : Node_Id;
  1159.       Param        : Node_Id;
  1160.       SP           : Node_Id;
  1161.       Name1        : Name_Id;
  1162.       Name2        : Name_Id;
  1163.       Name3        : Name_Id;
  1164.       Name4        : Name_Id;
  1165.       Name5        : Name_Id;
  1166.       Name6        : Name_Id;
  1167.       Name7        : Name_Id;
  1168.       Name8        : Name_Id;
  1169.       Name9        : Name_Id;
  1170.       Name10       : Name_Id;
  1171.       L1           : List_Id := New_List;
  1172.       L2           : List_Id := New_List;
  1173.       L3           : List_Id := New_List;
  1174.       AST_RVR      : Node_Id;
  1175.       Then_Stmts   : List_Id := New_List;
  1176.       Else_Stmts   : List_Id := New_List;
  1177.       Left_Opnd    : Node_Id;
  1178.       Right_Opnd   : Node_Id;
  1179.       Reraise_Nm   : Name_Id;
  1180.  
  1181.    begin
  1182.       --  We transform a declaration of remote access to subprogram type:
  1183.  
  1184.       --    type oldname is access to procedure (arg : arg_type);
  1185.  
  1186.       --  into a similar declaration with new type name:
  1187.  
  1188.       --    type newname is access to procedure (arg : arg_type);
  1189.  
  1190.       --  and a record type declaration with the name of the original type
  1191.  
  1192.       --  type oldname is
  1193.       --     record
  1194.       --        ast_receiver : system.rpc.rpc_receiver;
  1195.       --        pointer      : newname;
  1196.       --        pid          : system.rpc.partition_id;
  1197.       --        Asynchronous : boolean;
  1198.       --     end record;
  1199.  
  1200.       Set_Chars (Defining_Id, New_Name);
  1201.  
  1202.       Record_Ty := Make_Full_Type_Declaration (Loc,
  1203.         Defining_Identifier => Make_Defining_Identifier (Loc, Old_Name),
  1204.         Type_Definition     => Make_Record_Definition (Loc,
  1205.           Component_List    => Make_Component_List (Loc,
  1206.             Component_Items => New_List (
  1207.               Make_Component_Declaration (Loc,
  1208.                 Defining_Identifier =>
  1209.                   Make_Defining_Identifier (Loc, Name_Ast_Receiver),
  1210.                 Subtype_Indication  =>
  1211.                   Make_Selected_Component (Loc,
  1212.                     Prefix        =>
  1213.                       Make_Selected_Component (Loc,
  1214.                         Prefix        =>
  1215.                           Make_Identifier (Loc, Name_System),
  1216.                         Selector_Name =>
  1217.                           Make_Identifier (Loc, Name_Rpc)),
  1218.                     Selector_Name =>
  1219.                       Make_Identifier (Loc, Name_Rpc_Receiver))),
  1220.  
  1221.               Make_Component_Declaration (Loc,
  1222.                 Defining_Identifier =>
  1223.                   Make_Defining_Identifier (Loc, Name_Pointer),
  1224.                 Subtype_Indication  =>
  1225.                   Make_Identifier (Loc, New_Name)),
  1226.  
  1227.               Make_Component_Declaration (Loc,
  1228.                 Defining_Identifier =>
  1229.                   Make_Defining_Identifier (Loc, Name_Pid),
  1230.                 Subtype_Indication  =>
  1231.                   Make_Selected_Component (Loc,
  1232.                     Prefix        =>
  1233.                       Make_Selected_Component (Loc,
  1234.                         Prefix        =>
  1235.                           Make_Identifier (Loc, Name_System),
  1236.                         Selector_Name =>
  1237.                           Make_Identifier (Loc, Name_Rpc)),
  1238.                     Selector_Name =>
  1239.                       Make_Identifier (Loc, Name_Partition_ID))),
  1240.  
  1241.               Make_Component_Declaration (Loc,
  1242.                 Defining_Identifier =>
  1243.                   Make_Defining_Identifier (Loc, Name_Asynchronous),
  1244.                 Subtype_Indication  =>
  1245.                   Make_Identifier (Loc, Chars (Standard_Boolean)))))));
  1246.  
  1247.  
  1248.       Insert_After (N, Record_Ty);
  1249.  
  1250.       --  Now add declaration of the subprogram that would handle dereference.
  1251.       --  The signature has an extra parameter to pass in the fat pointer.
  1252.       --  For example,
  1253.  
  1254.       --    procedure oldnameD (pointer : oldname; arg : arg_type);
  1255.  
  1256.       --  would be the new added declaration in our example.
  1257.       --  Such declaration is one per remote access to subprogram type.
  1258.  
  1259.       NN := Copy_Separate_Tree (N);
  1260.       N1 := Copy_Separate_Tree (N);
  1261.       PL := Parameter_Specifications (Type_Definition (NN));
  1262.       Ori_Arg_List := Parameter_Specifications (Type_Definition (N1));
  1263.       Arg_List     := PL;
  1264.  
  1265.       PS := Make_Parameter_Specification (Loc,
  1266.         Defining_Identifier => Make_Defining_Identifier (Loc, Name_Pointer),
  1267.         Parameter_Type      => Make_Identifier (Loc, Old_Name));
  1268.  
  1269.       Prepend (PS, PL);
  1270.  
  1271.       if Nkind (Type_Definition (N)) = N_Access_Function_Definition then
  1272.          SM := Copy_Separate_Tree (Subtype_Mark (Type_Definition (N)));
  1273.  
  1274.          SD := Make_Subprogram_Declaration (Loc,
  1275.            Make_Function_Specification (Loc,
  1276.              Defining_Unit_Name       =>
  1277.                Make_Defining_Identifier (Loc, Sub_Name),
  1278.              Parameter_Specifications => PL,
  1279.              Subtype_Mark             => SM));
  1280.  
  1281.       elsif Nkind (Type_Definition (N)) = N_Access_Procedure_Definition then
  1282.          SD := Make_Subprogram_Declaration (Loc,
  1283.            Make_Procedure_Specification (Loc,
  1284.              Defining_Unit_Name       =>
  1285.                Make_Defining_Identifier (Loc, Sub_Name),
  1286.              Parameter_Specifications => PL));
  1287.       end if;
  1288.  
  1289.       Insert_After (Record_Ty, SD);
  1290.  
  1291.       --  Now add declaration of the subprogram that would handle receiving
  1292.       --  for remote call. The declaration is:
  1293.  
  1294.       --  procedure remote_access_to_subprogram_typeR
  1295.       --    (params : access system.rpc.params_stream_type;
  1296.       --     result : access system.rpc.params_stream_type);
  1297.  
  1298.       --  This receiver is one per remote access to subprogram type type
  1299.  
  1300.       --    params : access system.rpc.params_stream_type;
  1301.  
  1302.       PL := New_List;
  1303.       PS := Make_Parameter_Specification (Loc,
  1304.         Defining_Identifier => Make_Defining_Identifier (Loc, Name_Params),
  1305.         Parameter_Type      =>
  1306.           Make_Access_Definition (Loc,
  1307.             Subtype_Mark =>
  1308.               Make_Selected_Component (Loc,
  1309.                 Prefix        =>
  1310.                   Make_Selected_Component (Loc,
  1311.                     Prefix        =>
  1312.                       Make_Identifier (Loc, Name_System),
  1313.                     Selector_Name =>
  1314.                       Make_Identifier (Loc, Name_Rpc)),
  1315.                 Selector_Name =>
  1316.                   Make_Identifier (Loc, Name_Params_Stream_Type))));
  1317.  
  1318.       Append (PS, PL);
  1319.  
  1320.       --  result : access system.rpc.params_stream_type
  1321.  
  1322.       PS := Make_Parameter_Specification (Loc,
  1323.         Defining_Identifier => Make_Defining_Identifier (Loc, Name_Result),
  1324.         Parameter_Type      =>
  1325.           Make_Access_Definition (Loc,
  1326.             Subtype_Mark =>
  1327.               Make_Selected_Component (Loc,
  1328.                 Prefix        =>
  1329.                   Make_Selected_Component (Loc,
  1330.                     Prefix        =>
  1331.                       Make_Identifier (Loc, Name_System),
  1332.                     Selector_Name =>
  1333.                       Make_Identifier (Loc, Name_Rpc)),
  1334.                 Selector_Name =>
  1335.                   Make_Identifier (Loc, Name_Params_Stream_Type))));
  1336.  
  1337.       Append (PS, PL);
  1338.  
  1339.       AST_RVR := Make_Subprogram_Declaration (Loc,
  1340.         Specification =>
  1341.           Make_Procedure_Specification (Loc,
  1342.             Defining_Unit_Name =>
  1343.               Make_Defining_Identifier (Loc,
  1344.                 New_External_Name (Old_Name, 'R', 0, ' ')),
  1345.             Parameter_Specifications => PL));
  1346.  
  1347.       Insert_After (SD, AST_RVR);
  1348.  
  1349.       --  Return if the RCI or Remote Types unit specification is not
  1350.       --  currently compiled with its body but is rather compiled with
  1351.       --  other withing unit.
  1352.  
  1353.       Nd := Parent (N);
  1354.       if Nkind (Nd) /= N_Package_Specification then
  1355.          return;
  1356.       end if;
  1357.  
  1358.       Name1 := Chars (Defining_Unit_Name (Nd));
  1359.       Nd    := Unit (Cunit (Main_Unit));
  1360.  
  1361.       if Nkind (Nd) /= N_Package_Body then
  1362.          return;
  1363.       end if;
  1364.  
  1365.       Name2 := Chars (Defining_Unit_Name (Nd));
  1366.  
  1367.       if Name1 /= Name2 then
  1368.          return;
  1369.       end if;
  1370.  
  1371.       --  Now add the subprogram body that handles the dereference of values
  1372.       --  of such remote access to subprogram type to the RCI, Remote Types
  1373.       --  package body.
  1374.  
  1375.       --  Differentiate function body and procedure body.
  1376.  
  1377.       DL := Declarations (Nd);
  1378.  
  1379.       Nd    := Copy_Separate_Tree (SD);
  1380.       SP    := Specification (Nd);
  1381.       SL    := New_List;
  1382.       DL2   := New_List;
  1383.       Name3 := New_External_Name ('R', 0);
  1384.       Name4 := New_External_Name ('S', 1);
  1385.       Name5 := New_External_Name ('S', 2);
  1386.       Name6 := New_External_Name ('E', 3);
  1387.  
  1388.       if Nkind (Type_Definition (N)) = N_Access_Function_Definition then
  1389.          SM := Copy_Separate_Tree (Subtype_Mark (Type_Definition (N)));
  1390.  
  1391.          --  R0 : return_type;
  1392.  
  1393.          Nd := Make_Object_Declaration (Loc,
  1394.            Defining_Identifier => Make_Defining_Identifier (Loc, Name3),
  1395.            Object_definition   => SM);
  1396.  
  1397.          Append (Nd, DL2);
  1398.  
  1399.          Nd := Make_Return_Statement (Loc,
  1400.            Expression => Make_Identifier (Loc, Name3));
  1401.  
  1402.          Append (Nd, SL);
  1403.       end if;
  1404.  
  1405.       --  S1 : system.rpc.params_stream_type (0);
  1406.  
  1407.       Append (Make_Integer_Literal (Loc, Uint_0), L1);
  1408.  
  1409.       Nd := Make_Object_Declaration (Loc,
  1410.         Defining_Identifier => Make_Defining_Identifier (Loc, Name4),
  1411.         Object_definition   =>
  1412.           Make_Subtype_Indication (Loc,
  1413.             Subtype_Mark => Make_Selected_Component (Loc,
  1414.               Prefix => Make_Selected_Component (Loc,
  1415.                 Prefix => Make_Identifier (Loc, Name_System),
  1416.                 Selector_Name => Make_Identifier (Loc, Name_Rpc)),
  1417.               Selector_Name => Make_Identifier (Loc, Name_Params_Stream_Type)),
  1418.             Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
  1419.               Constraints => L1)));
  1420.  
  1421.       Set_Aliased_Present (Nd, True);
  1422.       Append (Nd, DL2);
  1423.  
  1424.       --  S2 : system.rpc.params_stream_type (0);
  1425.  
  1426.       L1 := New_List;
  1427.       Append (Make_Integer_Literal (Loc, Uint_0), L1);
  1428.  
  1429.       Nd := Make_Object_Declaration (Loc,
  1430.         Defining_Identifier => Make_Defining_Identifier (Loc, Name5),
  1431.         Object_definition   =>
  1432.           Make_Subtype_Indication (Loc,
  1433.             Subtype_Mark => Make_Selected_Component (Loc,
  1434.               Prefix => Make_Selected_Component (Loc,
  1435.                 Prefix => Make_Identifier (Loc, Name_System),
  1436.                 Selector_Name => Make_Identifier (Loc, Name_Rpc)),
  1437.               Selector_Name => Make_Identifier (Loc, Name_Params_Stream_Type)),
  1438.             Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
  1439.               Constraints => L1)));
  1440.  
  1441.       Set_Aliased_Present (Nd, True);
  1442.       Append (Nd, DL2);
  1443.  
  1444.       --  E3 : ada.exceptions.exception_occurrence;
  1445.  
  1446.       Nd := Make_Object_Declaration (Loc,
  1447.         Defining_Identifier => Make_Defining_Identifier (Loc, Name6),
  1448.         Object_definition   =>
  1449.           Make_Selected_Component (Loc,
  1450.             Prefix => Make_Selected_Component (Loc,
  1451.               Prefix => Make_Identifier (Loc, Name_Ada),
  1452.               Selector_Name => Make_Identifier (Loc, Name_Exceptions)),
  1453.             Selector_Name =>
  1454.               Make_Identifier (Loc, Name_Exception_Occurrence)));
  1455.  
  1456.       Append (Nd, DL2);
  1457.  
  1458.       --   system.rpc.rpc_receiver'write (s1'access, pointer.ast_receiver);
  1459.  
  1460.       L1 := New_List;
  1461.       Nd := Make_Attribute_Reference (Loc,
  1462.         Prefix => Make_Identifier (Loc, Name4),
  1463.         Attribute_Name => Name_Access);
  1464.  
  1465.       Append (Nd, L1);
  1466.  
  1467.       Nd := Make_Selected_Component (Loc,
  1468.         Prefix => Make_Identifier (Loc, Name_Pointer),
  1469.         Selector_Name => Make_Identifier (Loc, Name_Ast_Receiver));
  1470.  
  1471.       Append (Nd, L1);
  1472.  
  1473.       Nd1 := Make_Procedure_Call_Statement (Loc,
  1474.         Name => Make_Attribute_Reference (Loc,
  1475.           Prefix => Make_Selected_Component (Loc,
  1476.             Prefix => Make_Selected_Component (Loc,
  1477.               Prefix => Make_Identifier (Loc, Name_System),
  1478.               Selector_Name => Make_Identifier (Loc, Name_Rpc)),
  1479.             Selector_Name => Make_Identifier (Loc, Name_Rpc_Receiver)),
  1480.           Attribute_Name => Name_Write,
  1481.           Expressions => L1));
  1482.  
  1483.       Prepend (Nd1, SL);
  1484.  
  1485.       --   newname'write (s1'access, pointer.pointer);
  1486.  
  1487.       L1 := New_List;
  1488.       Nd := Make_Attribute_Reference (Loc,
  1489.         Prefix => Make_Identifier (Loc, Name4),
  1490.         Attribute_Name => Name_Access);
  1491.  
  1492.       Append (Nd, L1);
  1493.  
  1494.       Nd := Make_Selected_Component (Loc,
  1495.         Prefix => Make_Identifier (Loc, Name_Pointer),
  1496.         Selector_Name => Make_Identifier (Loc, Name_Pointer));
  1497.  
  1498.       Append (Nd, L1);
  1499.  
  1500.       Nd := Make_Procedure_Call_Statement (Loc,
  1501.         Name => Make_Attribute_Reference (Loc,
  1502.           Prefix => Make_Identifier (Loc, New_Name),
  1503.           Attribute_Name => Name_Write,
  1504.           Expressions => L1));
  1505.  
  1506.       Insert_After (Nd1, Nd);
  1507.       Nd1 := Nd;
  1508.  
  1509.       --  Now, for each parameter in the original remote subprogram parameter
  1510.       --  list do a write to the parameter stream.
  1511.  
  1512.       Param := First (Ori_Arg_List);
  1513.       while Present (Param) loop
  1514.          Param_Type := Copy_Separate_Tree (Parameter_Type (Param));
  1515.          Arg        := Copy_Separate_Tree (Defining_Identifier (Param));
  1516.  
  1517.          --   param_type'write (s1'access, arg);
  1518.  
  1519.          L1 := New_List;
  1520.          Nd := Make_Attribute_Reference (Loc,
  1521.            Prefix => Make_Identifier (Loc, Name4),
  1522.            Attribute_Name => Name_Access);
  1523.  
  1524.          Append (Nd, L1);
  1525.  
  1526.          Append (Arg, L1);
  1527.  
  1528.          Nd := Make_Procedure_Call_Statement (Loc,
  1529.            Name => Make_Attribute_Reference (Loc,
  1530.              Prefix => Param_Type,
  1531.              Attribute_Name => Name_Write,
  1532.              Expressions => L1));
  1533.  
  1534.          Insert_After (Nd1, Nd);
  1535.          Nd1 := Nd;
  1536.  
  1537.          Param := Next (Param);
  1538.       end loop;
  1539.  
  1540.       --   Depending on whether the fat pointer component asynchronous
  1541.       --   is True or False, we do a
  1542.       --   system.rpc.do_apc or system.rpc.do_rpc
  1543.       --
  1544.       --   if pointer.asynchronous then
  1545.       --      system.rpc.do_apc (pointer.pid, s1'access);
  1546.       --      return;
  1547.       --   else
  1548.       --      system.rpc.do_rpc (pointer.pid, s1'access, s2'access);
  1549.       --   end if;
  1550.  
  1551.       --      system.rpc.do_apc (pointer.pid, s1'access);
  1552.  
  1553.       L1 := New_List;
  1554.       Nd := Make_Selected_Component (Loc,
  1555.         Prefix => Make_Identifier (Loc, Name_Pointer),
  1556.         Selector_Name => Make_Identifier (Loc, Name_Pid));
  1557.  
  1558.       Append (Nd, L1);
  1559.  
  1560.       Nd := Make_Attribute_Reference (Loc,
  1561.         Prefix => Make_Identifier (Loc, Name4),
  1562.         Attribute_Name => Name_Access);
  1563.  
  1564.       Append (Nd, L1);
  1565.  
  1566.       Nd := Make_Procedure_Call_Statement (Loc,
  1567.         Name => Make_Selected_Component (Loc,
  1568.           Prefix => Make_Selected_Component (Loc,
  1569.             Prefix => Make_Identifier (Loc, Name_System),
  1570.             Selector_Name => Make_Identifier (Loc, Name_Rpc)),
  1571.           Selector_Name => Make_Identifier (Loc, Name_Do_Apc)),
  1572.         Parameter_Associations => L1);
  1573.  
  1574.       Append (Nd, Then_Stmts);
  1575.  
  1576.       --  return;
  1577.  
  1578.       Nd := Make_Return_Statement (Loc);
  1579.  
  1580.       Append (Nd, Then_Stmts);
  1581.  
  1582.       --      system.rpc.do_rpc (pointer.pid, s1'access, s2'access);
  1583.  
  1584.       L1 := New_List;
  1585.       Nd := Make_Selected_Component (Loc,
  1586.         Prefix => Make_Identifier (Loc, Name_Pointer),
  1587.         Selector_Name => Make_Identifier (Loc, Name_Pid));
  1588.  
  1589.       Append (Nd, L1);
  1590.  
  1591.       Nd := Make_Attribute_Reference (Loc,
  1592.         Prefix => Make_Identifier (Loc, Name4),
  1593.         Attribute_Name => Name_Access);
  1594.  
  1595.       Append (Nd, L1);
  1596.  
  1597.       Nd := Make_Attribute_Reference (Loc,
  1598.         Prefix => Make_Identifier (Loc, Name5),
  1599.         Attribute_Name => Name_Access);
  1600.  
  1601.       Append (Nd, L1);
  1602.  
  1603.       Nd := Make_Procedure_Call_Statement (Loc,
  1604.         Name => Make_Selected_Component (Loc,
  1605.           Prefix => Make_Selected_Component (Loc,
  1606.             Prefix => Make_Identifier (Loc, Name_System),
  1607.             Selector_Name => Make_Identifier (Loc, Name_Rpc)),
  1608.           Selector_Name => Make_Identifier (Loc, Name_Do_Rpc)),
  1609.         Parameter_Associations => L1);
  1610.  
  1611.       Append (Nd, Else_Stmts);
  1612.  
  1613.       --  If ...  then  ..  else ..
  1614.  
  1615.       Nd := Make_If_Statement (Loc,
  1616.         Condition => Make_Selected_Component (Loc,
  1617.           Prefix        => Make_Identifier (Loc, Name_Pointer),
  1618.           Selector_Name => Make_Identifier (Loc, Name_Asynchronous)),
  1619.         Then_Statements => Then_Stmts,
  1620.         Else_Statements => Else_Stmts);
  1621.  
  1622.       Insert_After (Nd1, Nd);
  1623.       Nd1 := Nd;
  1624.  
  1625.       --  Now, for each out parameter in the original remote subprogram
  1626.       --  parameter list do a read from the result stream to arg.
  1627.  
  1628.       Param := First (Ori_Arg_List);
  1629.       while Present (Param) loop
  1630.  
  1631.          if Out_Present (Param) then
  1632.  
  1633.             Param_Type := Copy_Separate_Tree (Parameter_Type (Param));
  1634.             Arg        := Copy_Separate_Tree (Defining_Identifier (Param));
  1635.  
  1636.             --   param_type'read (s2'access, arg);
  1637.  
  1638.             L1 := New_List;
  1639.             Nd := Make_Attribute_Reference (Loc,
  1640.               Prefix => Make_Identifier (Loc, Name5),
  1641.               Attribute_Name => Name_Access);
  1642.  
  1643.             Append (Nd, L1);
  1644.  
  1645.             Append (Arg, L1);
  1646.  
  1647.             Nd := Make_Procedure_Call_Statement (Loc,
  1648.               Name => Make_Attribute_Reference (Loc,
  1649.                 Prefix => Param_Type,
  1650.                 Attribute_Name => Name_Read,
  1651.                 Expressions => L1));
  1652.  
  1653.             Insert_After (Nd1, Nd);
  1654.             Nd1 := Nd;
  1655.          end if;
  1656.  
  1657.          Param := Next (Param);
  1658.       end loop;
  1659.  
  1660.       --  Now, in case of function, for the return type in original remote
  1661.       --  subprogram specification do a read from the result stream to arg.
  1662.  
  1663.       if Nkind (Type_Definition (N)) = N_Access_Function_Definition then
  1664.          SM := Copy_Separate_Tree (Subtype_Mark (Type_Definition (N)));
  1665.  
  1666.          --   return_type'read (s2'access, r0);
  1667.  
  1668.          L1 := New_List;
  1669.          Nd := Make_Attribute_Reference (Loc,
  1670.            Prefix => Make_Identifier (Loc, Name5),
  1671.            Attribute_Name => Name_Access);
  1672.  
  1673.          Append (Nd, L1);
  1674.  
  1675.          Nd := Make_Identifier (Loc, Name3);
  1676.  
  1677.          Append (Nd, L1);
  1678.  
  1679.          Nd := Make_Procedure_Call_Statement (Loc,
  1680.            Name => Make_Attribute_Reference (Loc,
  1681.              Prefix => SM,
  1682.              Attribute_Name => Name_Read,
  1683.              Expressions => L1));
  1684.  
  1685.          Insert_After (Nd1, Nd);
  1686.          Nd1 := Nd;
  1687.       end if;
  1688.  
  1689.       --   ada.exceptions.exception_occurrence'read (s2'access, e3);
  1690.  
  1691.       L1 := New_List;
  1692.       Nd := Make_Attribute_Reference (Loc,
  1693.         Prefix => Make_Identifier (Loc, Name5),
  1694.         Attribute_Name => Name_Access);
  1695.  
  1696.       Append (Nd, L1);
  1697.  
  1698.       Nd := Make_Identifier (Loc, Name6);
  1699.  
  1700.       Append (Nd, L1);
  1701.  
  1702.       Nd := Make_Procedure_Call_Statement (Loc,
  1703.         Name => Make_Attribute_Reference (Loc,
  1704.           Prefix => Make_Selected_Component (Loc,
  1705.             Prefix => Make_Selected_Component (Loc,
  1706.               Prefix => Make_Identifier (Loc, Name_Ada),
  1707.               Selector_Name => Make_Identifier (Loc, Name_Exceptions)),
  1708.             Selector_Name => Make_Identifier (Loc, Name_Exception_Occurrence)),
  1709.           Attribute_Name => Name_Read,
  1710.           Expressions => L1));
  1711.  
  1712.       Insert_After (Nd1, Nd);
  1713.       Nd1 := Nd;
  1714.  
  1715.       --  if ada.exceptions.exception_identity (e3) /=
  1716.       --    ada.exceptions.null_id
  1717.       --  then
  1718.       --     ada.exceptions.reraise_occurrence (e3);
  1719.       --  end if;
  1720.  
  1721.       --     ada.exceptions.reraise_occurrence (e3);
  1722.  
  1723.       L1 := New_List;
  1724.       Nd := Make_Identifier (Loc, Name6);
  1725.  
  1726.       Append (Nd, L1);
  1727.  
  1728.       Reraise_Nm := Get_Name_Id ("reraise_occurrence");
  1729.  
  1730.       Nd := Make_Procedure_Call_Statement (Loc,
  1731.         Name => Make_Selected_Component (Loc,
  1732.           Prefix => Make_Selected_Component (Loc,
  1733.             Prefix => Make_Identifier (Loc, Name_Ada),
  1734.             Selector_Name => Make_Identifier (Loc, Name_Exceptions)),
  1735.           Selector_Name => Make_Identifier (Loc, Reraise_Nm)),
  1736.         Parameter_Associations => L1);
  1737.  
  1738.       Then_Stmts := New_List;
  1739.       Append (Nd, Then_Stmts);
  1740.  
  1741.       --  Condition left operand
  1742.       --  ada.exceptions.exception_identity (e3)
  1743.  
  1744.       L1 := New_List;
  1745.       Nd := Make_Identifier (Loc, Name6);
  1746.  
  1747.       Append (Nd, L1);
  1748.  
  1749.       Left_Opnd  := Make_Indexed_Component (Loc,
  1750.         Prefix            => Make_Selected_Component (Loc,
  1751.           Prefix          => Make_Selected_Component (Loc,
  1752.             Prefix        => Make_Identifier (Loc, Name_Ada),
  1753.             Selector_Name => Make_Identifier (Loc, Name_Exceptions)),
  1754.           Selector_Name   => Make_Identifier (Loc, Name_Exception_Identity)),
  1755.         Expressions       => L1);
  1756.  
  1757.       --  Condition right operand
  1758.       --  ada.exceptions.null_id
  1759.  
  1760.       Right_Opnd := Make_Selected_Component (Loc,
  1761.         Prefix          => Make_Selected_Component (Loc,
  1762.           Prefix        => Make_Identifier (Loc, Name_Ada),
  1763.           Selector_Name => Make_Identifier (Loc, Name_Exceptions)),
  1764.         Selector_Name   => Make_Identifier (Loc, Name_Null_Id));
  1765.  
  1766.       Nd := Make_If_Statement (Loc,
  1767.         Condition => Make_Op_Ne (Loc,
  1768.           Left_Opnd  => Left_Opnd,
  1769.           Right_Opnd => Right_Opnd),
  1770.         Then_Statements => Then_Stmts);
  1771.  
  1772.       Insert_After (Nd1, Nd);
  1773.       Nd1 := Nd;
  1774.  
  1775.       Nd := Make_Subprogram_Body (Loc,
  1776.         Specification => SP,
  1777.         Declarations  => DL2,
  1778.         Handled_Statement_Sequence =>
  1779.           Make_Handled_Sequence_Of_Statements (Loc,
  1780.             Statements => SL));
  1781.  
  1782.       Prepend (Nd, DL);
  1783.  
  1784.       --  Now add body of the subprogram that would handle receiving
  1785.       --  for remote call:
  1786.  
  1787.       --    procedure remote_access_to_subprogram_typeR
  1788.       --      (params : access system.rpc.params_stream_type;
  1789.       --       result : access system.rpc.params_stream_type) is ...
  1790.  
  1791.       Nd  := Copy_Separate_Tree (AST_RVR);
  1792.       SP  := Specification (Nd);
  1793.       SL  := New_List;
  1794.       DL2 := New_List;
  1795.  
  1796.       Name7 := New_External_Name ('P', 1);
  1797.       Name8 := New_External_Name ('E', 2);
  1798.  
  1799.       --  Some local declarations.
  1800.       --   P1 : newname;
  1801.  
  1802.       Nd := Make_Object_Declaration (Loc,
  1803.         Defining_Identifier => Make_Defining_Identifier (Loc, Name7),
  1804.         Object_definition   => Make_Identifier (Loc, New_Name));
  1805.  
  1806.       Append (Nd, DL2);
  1807.  
  1808.       --  In case this remote subprogram is a function, declare a local
  1809.       --  variable to contain the return value.
  1810.  
  1811.       if Nkind (Type_Definition (N)) = N_Access_Function_Definition then
  1812.          SM := Copy_Separate_Tree (Subtype_Mark (Type_Definition (N)));
  1813.  
  1814.          --  R0 : return_type;
  1815.  
  1816.          Nd := Make_Object_Declaration (Loc,
  1817.            Defining_Identifier => Make_Defining_Identifier (Loc, Name3),
  1818.            Object_definition   => SM);
  1819.  
  1820.          Append (Nd, DL2);
  1821.       end if;
  1822.  
  1823.       --  Now, for each parameter in the original remote subprogram parameter
  1824.       --  list declare a variable (with name param_nameN) for it.
  1825.  
  1826.       Param := First (Ori_Arg_List);
  1827.       while Present (Param) loop
  1828.          Arg := Defining_Identifier (Param);
  1829.          Set_Chars (Arg, New_External_Name (Chars (Arg), 'N', 0, ' '));
  1830.  
  1831.          Param_Type := Copy_Separate_Tree (Parameter_Type (Param));
  1832.          Arg        := Copy_Separate_Tree (Defining_Identifier (Param));
  1833.  
  1834.          --   param_nameN : param_type;
  1835.  
  1836.          Nd := Make_Object_Declaration (Loc,
  1837.            Defining_Identifier => Arg,
  1838.            Object_definition   => Param_Type);
  1839.  
  1840.          Append (Nd, DL2);
  1841.  
  1842.          Param := Next (Param);
  1843.       end loop;
  1844.  
  1845.       --   Read from stream the pointer to remote subprogram.
  1846.       --   newname'read (params, p1);
  1847.  
  1848.       L1 := New_List;
  1849.       Nd :=  Make_Identifier (Loc, Name_Params);
  1850.  
  1851.       Append (Nd, L1);
  1852.  
  1853.       Nd := Make_Identifier (Loc, Name7);
  1854.  
  1855.       Append (Nd, L1);
  1856.  
  1857.       Nd := Make_Procedure_Call_Statement (Loc,
  1858.         Name => Make_Attribute_Reference (Loc,
  1859.           Prefix => Make_Identifier (Loc, New_Name),
  1860.           Attribute_Name => Name_Read,
  1861.           Expressions => L1));
  1862.  
  1863.       Append (Nd, SL);
  1864.  
  1865.       --  Now initialize these (corresponding argument) variables with their
  1866.       --  values from (reading) stream.
  1867.  
  1868.       Param := First (Ori_Arg_List);
  1869.       while Present (Param) loop
  1870.          Param_Type := Copy_Separate_Tree (Parameter_Type (Param));
  1871.          Arg        := Make_Identifier (Loc,
  1872.                          Chars (Defining_Identifier (Param)));
  1873.  
  1874.          --   param_type'read (params, arg);
  1875.  
  1876.          L1 := New_List;
  1877.          Nd :=  Make_Identifier (Loc, Name_Params);
  1878.  
  1879.          Append (Nd, L1);
  1880.  
  1881.          Append (Arg, L1);
  1882.  
  1883.          Nd := Make_Procedure_Call_Statement (Loc,
  1884.            Name => Make_Attribute_Reference (Loc,
  1885.              Prefix => Param_Type,
  1886.              Attribute_Name => Name_Read,
  1887.              Expressions => L1));
  1888.  
  1889.          Append (Nd, SL);
  1890.  
  1891.          Param := Next (Param);
  1892.       end loop;
  1893.  
  1894.       --  Now, make a call to the (remote) subprrogram with arguments read
  1895.       --  from stream.
  1896.       --  In case the original remote subprogram is a function then store
  1897.       --  returned value into variable R0.
  1898.  
  1899.       --  p1 (arg1, arg2 , ... );
  1900.       --   or
  1901.       --  R0 := p1 (arg1, arg2 , ... );
  1902.  
  1903.       --  Collecting the arguments
  1904.  
  1905.       L1 := New_List;
  1906.       Param := First (Ori_Arg_List);
  1907.       while Present (Param) loop
  1908.          Arg := Make_Identifier (Loc, Chars (Defining_Identifier (Param)));
  1909.          Append (Arg, L1);
  1910.  
  1911.          Param := Next (Param);
  1912.       end loop;
  1913.  
  1914.       if Nkind (Type_Definition (N)) = N_Access_Function_Definition then
  1915.  
  1916.          --  R0 := p1 (arg1, arg2 , ... );
  1917.  
  1918.          Nd := Make_Assignment_Statement (Loc,
  1919.            Name          => Make_Identifier (Loc, Name3),
  1920.            Expression   => Make_Indexed_Component (Loc,
  1921.              Prefix      => Make_Identifier (Loc, Name7),
  1922.              Expressions => L1));
  1923.  
  1924.          Append (Nd, SL);
  1925.       else
  1926.  
  1927.          --  p1 (arg1, arg2 , ... );
  1928.  
  1929.          Nd := Make_Procedure_Call_Statement (Loc,
  1930.            Name                   => Make_Identifier (Loc, Name7),
  1931.            Parameter_Associations => L1);
  1932.  
  1933.          Append (Nd, SL);
  1934.       end if;
  1935.  
  1936.       --  Now, for each out parameter in the original remote subprogram
  1937.       --  parameter list do a write to the result stream from arg.
  1938.  
  1939.       Param := First (Ori_Arg_List);
  1940.       while Present (Param) loop
  1941.  
  1942.          if Out_Present (Param) then
  1943.  
  1944.             Param_Type := Copy_Separate_Tree (Parameter_Type (Param));
  1945.             Arg        := Copy_Separate_Tree (Defining_Identifier (Param));
  1946.  
  1947.             --   param_type'write (result, arg);
  1948.  
  1949.             L1 := New_List;
  1950.             Nd := Make_Identifier (Loc, Name_Result);
  1951.  
  1952.             Append (Nd, L1);
  1953.  
  1954.             Append (Arg, L1);
  1955.  
  1956.             Nd := Make_Procedure_Call_Statement (Loc,
  1957.               Name => Make_Attribute_Reference (Loc,
  1958.                 Prefix => Param_Type,
  1959.                 Attribute_Name => Name_Write,
  1960.                 Expressions => L1));
  1961.  
  1962.             Append (Nd, SL);
  1963.          end if;
  1964.  
  1965.          Param := Next (Param);
  1966.       end loop;
  1967.  
  1968.       --  Now, in case of function, for the return type in original remote
  1969.       --  subprogram specification do a read from the result stream to arg.
  1970.  
  1971.       if Nkind (Type_Definition (N)) = N_Access_Function_Definition then
  1972.          SM := Copy_Separate_Tree (Subtype_Mark (Type_Definition (N)));
  1973.  
  1974.          --   return_type'write (result, r0);
  1975.  
  1976.          L1 := New_List;
  1977.          Nd := Make_Identifier (Loc, Name_Result);
  1978.  
  1979.          Append (Nd, L1);
  1980.  
  1981.          Nd := Make_Identifier (Loc, Name3);
  1982.  
  1983.          Append (Nd, L1);
  1984.  
  1985.          Nd := Make_Procedure_Call_Statement (Loc,
  1986.            Name => Make_Attribute_Reference (Loc,
  1987.              Prefix => SM,
  1988.              Attribute_Name => Name_Write,
  1989.              Expressions => L1));
  1990.  
  1991.          Append (Nd, SL);
  1992.       end if;
  1993.  
  1994.       --  Now construct the exception handler
  1995.       --   exception
  1996.       --      when E2 : others =>
  1997.       --         ada.exceptions.exception_occurrence'write (result,E2);
  1998.  
  1999.       L1 := New_List;
  2000.       Nd := Make_Others_Choice (Loc);
  2001.  
  2002.       Append (Nd, L1);
  2003.  
  2004.       --   ada.exceptions.exception_occurrence'write (result, e2);
  2005.  
  2006.       L3 := New_List;
  2007.       L2 := New_List;
  2008.       Nd := Make_Identifier (Loc, Name_Result);
  2009.  
  2010.       Append (Nd, L2);
  2011.  
  2012.       Nd := Make_Identifier (Loc, Name8);
  2013.  
  2014.       Append (Nd, L2);
  2015.  
  2016.       Nd := Make_Procedure_Call_Statement (Loc,
  2017.         Name => Make_Attribute_Reference (Loc,
  2018.           Prefix => Make_Selected_Component (Loc,
  2019.             Prefix => Make_Selected_Component (Loc,
  2020.               Prefix => Make_Identifier (Loc, Name_Ada),
  2021.               Selector_Name => Make_Identifier (Loc, Name_Exceptions)),
  2022.             Selector_Name => Make_Identifier (Loc, Name_Exception_Occurrence)),
  2023.           Attribute_Name => Name_Write,
  2024.           Expressions => L2));
  2025.  
  2026.       Append (Nd, L3);
  2027.  
  2028.       Nd := Make_Exception_Handler (Loc,
  2029.         Choice_Parameter => Make_Defining_Identifier (Loc, Name8),
  2030.         Exception_Choices => L1,
  2031.         Statements => L3);
  2032.  
  2033.       L2 := New_List;
  2034.       Append (Nd, L2);
  2035.  
  2036.       --  Now create the receiver subprogram body
  2037.       --  Append to package declarations
  2038.  
  2039.       Nd := Make_Subprogram_Body (Loc,
  2040.         Specification => SP,
  2041.         Declarations  => DL2,
  2042.         Handled_Statement_Sequence =>
  2043.           Make_Handled_Sequence_Of_Statements (Loc,
  2044.             Statements         => SL,
  2045.             Exception_Handlers => L2));
  2046.  
  2047.       Prepend (Nd, DL);
  2048.    end Process_Remote_AST_Declaration;
  2049.  
  2050.    -------------------------------------------
  2051.    -- Process_Remote_Access_Subprogram_Type --
  2052.    -------------------------------------------
  2053.  
  2054.    procedure Process_Remote_Access_Subprogram_Type (N : Node_Id) is
  2055.       Id : constant Entity_Id := Defining_Unit_Simple_Name (N);
  2056.       Vi : constant List_Id   := Visible_Declarations (N);
  2057.       Pr : constant List_Id   := Private_Declarations (N);
  2058.       Dn : Node_Id;
  2059.       Fl : List_Id := New_List;
  2060.       Pl : List_Id := New_List;
  2061.       Tl : List_Id := New_List;
  2062.       Sp : Node_Id;
  2063.       Ft : Node_Id;
  2064.       Pt : Node_Id;
  2065.       Df : Node_Id;
  2066.  
  2067.       procedure Build_Lists (L : List_Id);
  2068.       --  Given input list L, seperate declarations into three lists, one
  2069.       --  access type list, one function specification list and one
  2070.       --  procedure specification list
  2071.  
  2072.       procedure Build_Lists (L : List_Id) is
  2073.          Decl : Node_Id := First (L);
  2074.  
  2075.       begin
  2076.          while Present (Decl) loop
  2077.             if Nkind (Decl) = N_Subprogram_Declaration then
  2078.                Sp := Specification (Decl);
  2079.  
  2080.                if Nkind (Sp) = N_Procedure_Specification then
  2081.                   Append (Sp, Pl);
  2082.  
  2083.                elsif Nkind (Sp) = N_Function_Specification then
  2084.                   Append (Sp, Fl);
  2085.                end if;
  2086.  
  2087.             elsif Nkind (Decl) = N_Full_Type_Declaration then
  2088.                Df := Type_Definition (Decl);
  2089.  
  2090.                if Present (Df) then
  2091.                   if Nkind (Df) = N_Access_Procedure_Definition
  2092.                     or else Nkind (Df) = N_Access_Function_Definition
  2093.                   then
  2094.                      Append (Df, Tl);
  2095.                   end if;
  2096.                end if;
  2097.             end if;
  2098.  
  2099.             Decl := Next (Decl);
  2100.          end loop;
  2101.       end Build_Lists;
  2102.  
  2103.    --  Start processing of Process_Remote_Access_Subprogram_Type
  2104.  
  2105.    begin
  2106.       if Present (Vi) then
  2107.          Build_Lists (Vi);
  2108.       end if;
  2109.  
  2110.       if Present (Pr) then
  2111.          Build_Lists (Pr);
  2112.       end if;
  2113.  
  2114.       --  Return if no remote access to subprogram type declaration
  2115.  
  2116.       if not Present (Tl) then
  2117.          return;
  2118.       end if;
  2119.  
  2120.       return;
  2121.    end Process_Remote_Access_Subprogram_Type;
  2122.  
  2123.    ------------------------------
  2124.    -- Remote_AST_E_Dereference --
  2125.    ------------------------------
  2126.  
  2127.    function Remote_AST_E_Dereference
  2128.      (P    : Node_Id;
  2129.       UAN  : Node_Id)
  2130.       return Boolean
  2131.    is
  2132.       ET       : constant Entity_Id  := Etype (P);
  2133.       SCP      : constant Entity_Id  := Scope (ET);
  2134.       Loc      : constant Source_Ptr := Sloc (P);
  2135.       FAT      : Node_Id;
  2136.       Nd1      : Node_Id;
  2137.       Sub_Name : Name_Id;
  2138.  
  2139.    begin
  2140.       --  Rewrite the prefix node only if it is of an internal remote record
  2141.       --  (fat pointer) type whose first component is "Ast_Receiver".
  2142.  
  2143.       if Ekind (ET) /= E_Record_Type
  2144.         or else Comes_From_Source (ET)
  2145.         or else (not Is_Remote_Call_Interface (ET)
  2146.                   and then not Is_Remote_Types (ET))
  2147.         or else Chars (First_Entity (ET)) /= Name_Ast_Receiver
  2148.       then
  2149.          return False;
  2150.       end if;
  2151.  
  2152.       --  At this point, the original source program was:
  2153.  
  2154.       --    Name_of_Remote_Access_To_Subprogram_Type.all (arg1, arg2)
  2155.  
  2156.       --  This has been transformed by Process_Remote_AST_Declaration to
  2157.  
  2158.       --    Name_of_Remote_Fat_Pointer_Type.all (arg1, arg2)"
  2159.  
  2160.       --  since the fat pointer type has been substituted for the type
  2161.       --  name of the remove access to subprogram type. We now carry
  2162.       --  out a further transformation to get:
  2163.  
  2164.       --    Remote_Fat_Pointer_Type_NameD
  2165.       --      (Name_of_Remote_Fat_Pointer_Type, arg1, arg2)"
  2166.  
  2167.       --  which is a call to the subprogram that handles the dereference for
  2168.       --  this paticular fat pointer type. Notice the fat pointer value is
  2169.       --  passed in as an argumant. The result of this call will be a remote
  2170.       --  call to the remote subprogram.
  2171.  
  2172.       --  Copy the original unanalyzed prefix, prepend it to argument list
  2173.       --  of parent of parent of prefix, which is an N_Indexed_Component node.
  2174.  
  2175.       FAT := Copy_Separate_Tree (Prefix (UAN));
  2176.       Prepend (FAT, Expressions (Parent (Parent (P))));
  2177.  
  2178.       --  Change prefix name from XXX.Name to YYY.Fat_Pointer_TypeD and
  2179.  
  2180.       Sub_Name := New_External_Name (Chars (ET), 'D', 0, ' ');
  2181.       Nd1 :=
  2182.         Make_Selected_Component (Loc,
  2183.           Prefix        => Make_Identifier (Loc, Chars (SCP)),
  2184.           Selector_Name => Make_Identifier (Loc, Sub_Name));
  2185.  
  2186.       --  Analyze the rewritten prefix before return and then set the
  2187.       --  prefix of N_Indexed_Component to be name of the subprogram
  2188.       --  that handles dereference.
  2189.  
  2190.       Analyze (Nd1);
  2191.       Rewrite_Substitute_Tree (Parent (P), Nd1);
  2192.       return True;
  2193.    end Remote_AST_E_Dereference;
  2194.  
  2195.    ------------------------------
  2196.    -- Remote_AST_I_Dereference --
  2197.    ------------------------------
  2198.  
  2199.    function Remote_AST_I_Dereference
  2200.      (P    : Node_Id;
  2201.       UAN  : Node_Id)
  2202.       return Boolean
  2203.    is
  2204.       ET       : constant Entity_Id  := Etype (P);
  2205.       SCP      : constant Entity_Id  := Scope (ET);
  2206.       Loc      : constant Source_Ptr := Sloc (P);
  2207.       FAT      : Node_Id;
  2208.       Nd1      : Node_Id;
  2209.       Sub_Name : Name_Id;
  2210.  
  2211.    begin
  2212.       --  Rewrite the indexed component node only if prefix of original node
  2213.       --  is of an internal remote record (fat pointer) type whose first
  2214.       --  component is "Ast_Receiver".
  2215.  
  2216.       if Ekind (ET) /= E_Record_Type
  2217.         or else Comes_From_Source (ET)
  2218.         or else (not Is_Remote_Call_Interface (ET)
  2219.                   and then not Is_Remote_Types (ET))
  2220.         or else Chars (First_Entity (ET)) /= Name_Ast_Receiver
  2221.       then
  2222.          return False;
  2223.       end if;
  2224.  
  2225.       --  At this point, the original source program was:
  2226.  
  2227.       --    Name_of_Remote_Access_To_Subprogram_Type (arg1, arg2)
  2228.  
  2229.       --  This has been transformed by Process_Remote_AST_Declaration to
  2230.  
  2231.       --    Name_of_Remote_Fat_Pointer_Type (arg1, arg2)"
  2232.  
  2233.       --  since the fat pointer type has been substituted for the type
  2234.       --  name of the remove access to subprogram type. We now carry
  2235.       --  out a further transformation to get:
  2236.  
  2237.       --    Remote_Fat_Pointer_Type_NameD
  2238.       --      (Name_of_Remote_Fat_Pointer_Type, arg1, arg2)"
  2239.  
  2240.       --  which is a call to the subprogram that handles the dereference for
  2241.       --  this paticular fat pointer type. Notice the fat pointer value is
  2242.       --  passed in as an argumant. The result of this call will be a remote
  2243.       --  call to the remote subprogram.
  2244.  
  2245.       --  Copy the original unanalyzed prefix, prepend it to argument list
  2246.  
  2247.       FAT := Copy_Separate_Tree (Prefix (UAN));
  2248.       Prepend (FAT, Expressions (UAN));
  2249.  
  2250.       --  Change prefix name from XXX.Name to YYY.Fat_Pointer_TypeD
  2251.  
  2252.       Sub_Name := New_External_Name (Chars (ET), 'D', 0, ' ');
  2253.       Nd1 :=
  2254.         Make_Selected_Component (Loc,
  2255.           Prefix        => Make_Identifier (Loc, Chars (SCP)),
  2256.           Selector_Name => Make_Identifier (Loc, Sub_Name));
  2257.  
  2258.       Set_Prefix (UAN, Nd1);
  2259.  
  2260.       Analyze (UAN);
  2261.       Rewrite_Substitute_Tree (Parent (P), UAN);
  2262.  
  2263.       return True;
  2264.    end Remote_AST_I_Dereference;
  2265.  
  2266.    -----------------------------------------------
  2267.    -- Set_Categorization_From_Following_Pragmas --
  2268.    -----------------------------------------------
  2269.  
  2270.    procedure Set_Categorization_From_Following_Pragmas (N : Node_Id) is
  2271.       P : constant Node_Id := Parent (N);
  2272.  
  2273.    begin
  2274.       --  Deal with categorization pragmas in Following_Pragmas
  2275.       --  of Compilation_Unit. The purpose is to set flags.
  2276.  
  2277.       --  This code seems misplaced, it has nothing to do with distribution
  2278.       --  really, following pragmas must be handled more generally ???
  2279.  
  2280.       if Nkind (P) /= N_Compilation_Unit then
  2281.          return;
  2282.       end if;
  2283.  
  2284.       if Present (Following_Pragmas (P)) then
  2285.          declare
  2286.             Pragma_Node : Node_Id := First (Following_Pragmas (P));
  2287.  
  2288.          begin
  2289.             while Present (Pragma_Node) loop
  2290.  
  2291.                case Get_Pragma_Id (Chars (Pragma_Node)) is
  2292.                   when Pragma_All_Calls_Remote
  2293.                                            => Analyze (Pragma_Node);
  2294.                   when Pragma_Preelaborate => Analyze (Pragma_Node);
  2295.                   when Pragma_Pure         => Analyze (Pragma_Node);
  2296.                   when Pragma_Remote_Call_Interface
  2297.                                            => Analyze (Pragma_Node);
  2298.                   when Pragma_Remote_Types => Analyze (Pragma_Node);
  2299.                   when Pragma_Shared_Passive
  2300.                                            => Analyze (Pragma_Node);
  2301.                   when others              => null;
  2302.                end case;
  2303.  
  2304.                Pragma_Node := Next (Pragma_Node);
  2305.             end loop;
  2306.          end;
  2307.       end if;
  2308.    end Set_Categorization_From_Following_Pragmas;
  2309.  
  2310.    ---------------------------------
  2311.    -- Should_Declare_Partition_ID --
  2312.    ---------------------------------
  2313.  
  2314.    function Should_Declare_Partition_ID (L : List_Id) return Boolean is
  2315.       Nd : Node_Id := First (L);
  2316.       Ch : Name_Id;
  2317.       Na : Node_Id := Defining_Unit_Name (Parent (L));
  2318.  
  2319.    begin
  2320.       while Present (Nd) loop
  2321.          if Nkind (Nd) = N_Pragma then
  2322.             Ch := Chars (Nd);
  2323.  
  2324.             if Ch = Name_Preelaborate
  2325.               or else Ch = Name_Remote_Call_Interface
  2326.               or else Ch = Name_Shared_Passive
  2327.               or else Ch = Name_Remote_Types
  2328.             then
  2329.                return True;
  2330.  
  2331.             elsif Ch = Name_Pure then
  2332.                return False;
  2333.             end if;
  2334.          end if;
  2335.  
  2336.          Nd := Next (Nd);
  2337.       end loop;
  2338.  
  2339.       --  This is a non-categorizaed library unit
  2340.  
  2341.       if Nkind (Na) = N_Defining_Program_Unit_Name
  2342.         and then Nkind (Name (Na)) = N_Identifier
  2343.         and then Chars (Name (Na)) = Name_System
  2344.         and then Nkind (Defining_Identifier (Na)) = N_Defining_Identifier
  2345.         and then Chars (Defining_Identifier (Na)) = Name_Rpc
  2346.       then
  2347.          return True;
  2348.       end if;
  2349.  
  2350.       return False;
  2351.    end Should_Declare_Partition_ID;
  2352.  
  2353.    ------------------------------
  2354.    -- Static_Discriminant_Expr --
  2355.    ------------------------------
  2356.  
  2357.    function Static_Discriminant_Expr (L : List_Id) return Boolean is
  2358.       Discriminant_Spec : Node_Id;
  2359.  
  2360.    begin
  2361.       Discriminant_Spec := First (L);
  2362.       while Present (Discriminant_Spec) loop
  2363.          if Present (Expression (Discriminant_Spec))
  2364.            and then not Is_Static_Expression (Expression (Discriminant_Spec))
  2365.          then
  2366.             return False;
  2367.          end if;
  2368.  
  2369.          Discriminant_Spec := Next (Discriminant_Spec);
  2370.       end loop;
  2371.  
  2372.       return True;
  2373.    end Static_Discriminant_Expr;
  2374.  
  2375.    --------------------------------------
  2376.    -- Validate_Access_Type_Declaration --
  2377.    --------------------------------------
  2378.  
  2379.    procedure Validate_Access_Type_Declaration (T : Entity_Id; N : Node_Id) is
  2380.       Def : constant Node_Id := Type_Definition (N);
  2381.  
  2382.    begin
  2383.       case Nkind (Def) is
  2384.          when N_Access_To_Subprogram_Definition =>
  2385.  
  2386.             --  A pure library_item must not contain the declaration of a
  2387.             --  named access type, except within a subprogram, generic
  2388.             --  subprogram, task unit, or protected unit (RM 10.2.1(16)).
  2389.  
  2390.             if Comes_From_Source (T)
  2391.                and then Inside_Pure_Unit
  2392.                and then not Inside_Subprogram_Task_Protected_Unit
  2393.             then
  2394.                Error_Msg_N ("named access type not allowed in pure unit", T);
  2395.             end if;
  2396.  
  2397.             --  Set Is_Remote_Call_Interface flag on entity to allow easy
  2398.             --  checks later on for required validations of RCI units. This
  2399.             --  is only done for entities that are in the original source.
  2400.  
  2401.             if Comes_From_Source (T)
  2402.               and then Inside_Remote_Call_Interface_Unit
  2403.             then
  2404.                Set_Is_Remote_Call_Interface (T);
  2405.             end if;
  2406.  
  2407.             --  Set Is_Remote_Types flag on entity to allow easy
  2408.             --  checks later on for required validations of such units. This
  2409.             --  is only done for entities that are in the original source.
  2410.  
  2411.             if Comes_From_Source (T)
  2412.               and then Inside_Remote_Types_Unit
  2413.             then
  2414.                Set_Is_Remote_Types (T);
  2415.             end if;
  2416.  
  2417.          when N_Access_To_Object_Definition =>
  2418.  
  2419.             if Comes_From_Source (T)
  2420.               and then Inside_Pure_Unit
  2421.               and then not Inside_Subprogram_Task_Protected_Unit
  2422.             then
  2423.                Error_Msg_N
  2424.                  ("named access type not allowed in pure unit", T);
  2425.             end if;
  2426.  
  2427.             --  Check for RCI unit type declaration. It should not contain
  2428.             --  the declaration of an access-to-object type unless it is a
  2429.             --  general access type that designates a class-wide limited
  2430.             --  private type. There are also constraints about the primitive
  2431.             --  subprograms of the class-wide type.
  2432.  
  2433.             Validate_RCI_Access_Object_Type_Declaration (T);
  2434.  
  2435.             --  Check for shared passive unit type declaration. It should
  2436.             --  not contain the declaration of access to class wide type,
  2437.             --  access to task type and access to protected type with entry.
  2438.  
  2439.             Validate_SP_Access_Object_Type_Decl (T);
  2440.  
  2441.             --  Set Is_Remote_Types flag on entity to allow easy
  2442.             --  checks later on for required validations of such units. This
  2443.             --  is only done for entities that are in the original source.
  2444.  
  2445.             if Comes_From_Source (T)
  2446.               and then Inside_Remote_Types_Unit
  2447.             then
  2448.                Set_Is_Remote_Types (T);
  2449.             end if;
  2450.  
  2451.          when others => null;
  2452.  
  2453.       end case;
  2454.  
  2455.    end Validate_Access_Type_Declaration;
  2456.  
  2457.    ----------------------------------------
  2458.    -- Validate_Categorization_Dependency --
  2459.    ----------------------------------------
  2460.  
  2461.    procedure Validate_Categorization_Dependency
  2462.      (N : Node_Id;
  2463.       E : Entity_Id)
  2464.    is
  2465.       K : constant Node_Kind := Nkind (N);
  2466.       P : constant Node_Id   := Parent (N);
  2467.  
  2468.    begin
  2469.       --  Validate library unit only
  2470.  
  2471.       if Nkind (P) /= N_Compilation_Unit then
  2472.          return;
  2473.       end if;
  2474.  
  2475.       --  Body of RCI unit does not need validation.
  2476.  
  2477.       if Is_Remote_Call_Interface (E)
  2478.         and then (Nkind (N) = N_Package_Body
  2479.                    or else Nkind (N) = N_Subprogram_Body)
  2480.       then
  2481.          return;
  2482.       end if;
  2483.  
  2484.       --  Process with clauses
  2485.  
  2486.       declare
  2487.          Item             : Node_Id;
  2488.          Entity_Of_Withed : Entity_Id;
  2489.  
  2490.       begin
  2491.          Item := First (Context_Items (P));
  2492.  
  2493.          while Present (Item) loop
  2494.             if Nkind (Item) = N_With_Clause
  2495.               and then not Implicit_With (Item)
  2496.             then
  2497.                Entity_Of_Withed := Entity (Name (Item));
  2498.                Check_Categorization_Dependencies (E, Entity_Of_Withed, Item);
  2499.             end if;
  2500.  
  2501.             Item := Next (Item);
  2502.          end loop;
  2503.       end;
  2504.  
  2505.       --  Child depends on parent therefore parent should also
  2506.       --  be categorized and satify the dependecy hierarchy.
  2507.  
  2508.       --  Check if N is a child spec.
  2509.  
  2510.       if (K in N_Generic_Declaration              or else
  2511.           K in N_Generic_Instantiation            or else
  2512.           K in N_Generic_Renaming_Declaration     or else
  2513.           K =  N_Package_Declaration              or else
  2514.           K =  N_Package_Renaming_Declaration     or else
  2515.           K =  N_Subprogram_Declaration           or else
  2516.           K =  N_Subprogram_Renaming_Declaration)
  2517.         and then Present (Parent_Spec (N))
  2518.       then
  2519.          declare
  2520.             Parent_Lib_U  : constant Node_Id   := Parent_Spec (N);
  2521.             Parent_Kind   : constant Node_Kind :=
  2522.                               Nkind (Unit (Parent_Lib_U));
  2523.             Parent_Entity : Entity_Id;
  2524.  
  2525.          begin
  2526.             if        Parent_Kind =  N_Package_Instantiation
  2527.               or else Parent_Kind =  N_Procedure_Instantiation
  2528.               or else Parent_Kind =  N_Function_Instantiation
  2529.               or else Parent_Kind =  N_Package_Renaming_Declaration
  2530.               or else Parent_Kind in N_Generic_Renaming_Declaration
  2531.             then
  2532.                Parent_Entity :=
  2533.                  Defining_Unit_Simple_Name (Unit (Parent_Lib_U));
  2534.  
  2535.             else
  2536.                Parent_Entity :=
  2537.                  Defining_Unit_Simple_Name
  2538.                    (Specification (Unit (Parent_Lib_U)));
  2539.             end if;
  2540.  
  2541.             Check_Categorization_Dependencies (E, Parent_Entity, N);
  2542.  
  2543.             --  Verify that public child of an RCI library unit
  2544.             --  must also be an RCI library unit (RM E.2.3(15)).
  2545.  
  2546.             if Is_Remote_Call_Interface (Parent_Entity)
  2547.               and then not Private_Present (P)
  2548.               and then not Is_Remote_Call_Interface (E)
  2549.             then
  2550.                Error_Msg_N
  2551.                  ("public child of rci unit must also be rci unit", N);
  2552.                return;
  2553.             end if;
  2554.          end;
  2555.       end if;
  2556.  
  2557.    end Validate_Categorization_Dependency;
  2558.  
  2559.    ------------------------------
  2560.    -- Validate_Non_Static_Call --
  2561.    ------------------------------
  2562.  
  2563.    procedure Validate_Non_Static_Call (N : Node_Id) is
  2564.    begin
  2565.       if not Inside_Subprogram_Unit
  2566.         and then Inside_Preelaborated_Unit
  2567.         and then Comes_From_Source (Entity (Name (N)))
  2568.       then
  2569.          --  Check for the case where run time source for tasking
  2570.          --  is making the call. Validation is skipped in this case
  2571.  
  2572.          if Nkind (Parent (N)) = N_Object_Declaration
  2573.            and then not Comes_From_Source (Defining_Identifier (Parent (N)))
  2574.          then
  2575.             return;
  2576.  
  2577.          --  Check for the case where initialization function for
  2578.          --  tagged type is called. Validation is skipped in this case
  2579.  
  2580.          elsif Nkind (Parent (N)) = N_Range
  2581.            and then not Comes_From_Source (Etype (Parent (N)))
  2582.          then
  2583.             return;
  2584.  
  2585.          --  Check for the case where initialization function for
  2586.          --  tagged type is called. Validation is skipped in this case
  2587.  
  2588.          elsif Present (Parameter_Associations (N))
  2589.            and then not Comes_From_Source
  2590.                       (Entity (First (Parameter_Associations (N))))
  2591.          then
  2592.             return;
  2593.  
  2594.          --  Check for subprogram calls in freeze list
  2595.  
  2596.          elsif Present (Parent (N))
  2597.            and then Nkind (Parent (N)) = N_Freeze_Entity
  2598.          then
  2599.             return;
  2600.  
  2601.          end if;
  2602.  
  2603.          Error_Msg_N ("non-static call not allowed in preelaborated unit", N);
  2604.       end if;
  2605.    end Validate_Non_Static_Call;
  2606.  
  2607.    --------------------------------------
  2608.    -- Validate_Null_Statement_Sequence --
  2609.    --------------------------------------
  2610.  
  2611.    procedure Validate_Null_Statement_Sequence (N : Node_Id) is
  2612.       Item : Node_Id;
  2613.  
  2614.    begin
  2615.       if Inside_Preelaborated_Unit then
  2616.          Item := First (Statements (Handled_Statement_Sequence (N)));
  2617.  
  2618.          while Present (Item) loop
  2619.             if Nkind (Item) /= N_Label
  2620.               and then Nkind (Item) /= N_Null_Statement
  2621.             then
  2622.                Error_Msg_N
  2623.                  ("statements not allowed in preelaborated unit", Item);
  2624.                exit;
  2625.             end if;
  2626.  
  2627.             Item := Next (Item);
  2628.          end loop;
  2629.       end if;
  2630.    end Validate_Null_Statement_Sequence;
  2631.  
  2632.    ---------------------------------
  2633.    -- Validate_Object_Declaration --
  2634.    ---------------------------------
  2635.  
  2636.    procedure Validate_Object_Declaration
  2637.      (N   : Node_Id;
  2638.       Id  : Entity_Id;
  2639.       E   : Node_Id;
  2640.       Odf : Node_Id;
  2641.       T   : Entity_Id)
  2642.    is
  2643.    begin
  2644.       --  Verify that any access to subprogram object does not have in its
  2645.       --  subprogram profile access type parameters or limited parameters
  2646.       --  without Read and Write attributes (E.2.3(13)).
  2647.  
  2648.       Validate_RCI_Subprogram_Declaration (N);
  2649.  
  2650.       --  Check that if we are in preelaborated elaboration code, then we
  2651.       --  do not have an instance of a default initialized private, task or
  2652.       --  protected object declaration which would violate (RM 10.2.1(9)).
  2653.       --  Note that constants are never default initialized (and the test
  2654.       --  below also filters out deferred constants). A variable is default
  2655.       --  initialized if it does *not* have an initialization expression.
  2656.  
  2657.       --  Filter out cases that are not declaration of a variable from source.
  2658.  
  2659.       if Nkind (N) /= N_Object_Declaration
  2660.         or else Constant_Present (N)
  2661.         or else not Comes_From_Source (Id)
  2662.       then
  2663.          return;
  2664.       end if;
  2665.  
  2666.       if Inside_Preelaborated_Unit
  2667.         and then not Inside_Subprogram_Unit
  2668.       then
  2669.          if No (E) then
  2670.             declare
  2671.                Ent : Entity_Id;
  2672.  
  2673.             begin
  2674.                --  Object decl. that is of record type and has no default expr.
  2675.                --  should check if there is any non-static default expression
  2676.                --  in component decl. of the record type decl.
  2677.  
  2678.                if Is_Record_Type (T) then
  2679.                   if Nkind (Parent (T)) = N_Full_Type_Declaration then
  2680.                      Check_Non_Static_Default_Expr (Component_Items
  2681.                        (Component_List (Type_Definition (Parent (T)))));
  2682.  
  2683.                   elsif Nkind (Odf) = N_Subtype_Indication then
  2684.                      Check_Non_Static_Default_Expr (Component_Items
  2685.                        (Component_List (Type_Definition (Parent (Entity (
  2686.                          Subtype_Mark (Odf)))))));
  2687.                   end if;
  2688.                end if;
  2689.  
  2690.                --  Similarly, array whose component type is record of component
  2691.                --  declarations with default expression that is non-static
  2692.                --  is a violation.
  2693.  
  2694.                if Is_Array_Type (T) then
  2695.                   if Nkind (Parent (T)) = N_Full_Type_Declaration then
  2696.                      declare
  2697.                         Comp_Type : Entity_Id := Component_Type (T);
  2698.  
  2699.                      begin
  2700.                         while Is_Array_Type (Comp_Type) loop
  2701.                            Comp_Type := Component_Type (Comp_Type);
  2702.                         end loop;
  2703.  
  2704.                         if Is_Record_Type (Comp_Type) then
  2705.                            if Nkind (Parent (Comp_Type)) =
  2706.                              N_Full_Type_Declaration
  2707.                            then
  2708.                               Check_Non_Static_Default_Expr
  2709.                                 (Component_Items
  2710.                                   (Component_List (Type_Definition (Parent
  2711.                                     (Comp_Type)))));
  2712.                            end if;
  2713.                         end if;
  2714.                      end;
  2715.                   end if;
  2716.                end if;
  2717.  
  2718.                if Is_Private_Type (Id)
  2719.                  or else
  2720.                    (Is_Access_Type (T)
  2721.                      and then
  2722.                        Depends_On_Private (Directly_Designated_Type (T)))
  2723.                  or else Depends_On_Private (T)
  2724.                then
  2725.                   Error_Msg_N
  2726.                     ("private object not allowed in preelaborated unit", N);
  2727.                   return;
  2728.  
  2729.                --  Access to Task or Protected type
  2730.  
  2731.                elsif Nkind (Odf) = N_Identifier
  2732.                  and then Present (Etype (Odf))
  2733.                  and then Is_Access_Type (Etype (Odf))
  2734.                then
  2735.                   Ent := Directly_Designated_Type (Etype (Odf));
  2736.  
  2737.                elsif Nkind (Odf) = N_Identifier then
  2738.                   Ent := Entity (Odf);
  2739.  
  2740.                elsif Nkind (Odf) = N_Subtype_Indication then
  2741.                   Ent := Etype (Subtype_Mark (Odf));
  2742.  
  2743.                elsif
  2744.                   Nkind (Odf) = N_Constrained_Array_Definition
  2745.                then
  2746.                   Ent := Etype (Subtype_Indication (Odf));
  2747.  
  2748.                else
  2749.                   return;
  2750.                end if;
  2751.  
  2752.                if Is_Task_Type (Ent)
  2753.                  or else (Is_Protected_Type (Ent) and then Has_Entries (Ent))
  2754.                then
  2755.                   Error_Msg_N
  2756.                     ("concurrent object not allowed in preelaborated unit",
  2757.                      N);
  2758.                   return;
  2759.  
  2760.                end if;
  2761.             end;
  2762.          end if;
  2763.  
  2764.          --  Evaluation of discriminant default expr. is done when obj.
  2765.          --  is created. And it has to be static expr.
  2766.  
  2767.          if Is_Record_Type (Etype (Id)) then
  2768.             declare
  2769.                ET  : constant Entity_Id := Etype (Id);
  2770.                EE  : constant Entity_Id := Etype (Etype (Id));
  2771.                PEE : Node_Id;
  2772.  
  2773.             begin
  2774.                if Has_Discriminants (ET)
  2775.                  and then Present (EE)
  2776.                then
  2777.                   PEE := Parent (EE);
  2778.  
  2779.                   if Nkind (PEE) = N_Full_Type_Declaration
  2780.                     and then not Static_Discriminant_Expr
  2781.                                   (Discriminant_Specifications (PEE))
  2782.                   then
  2783.                      Error_Msg_N
  2784.                        ("non-static discriminant in preelaborated unit",
  2785.                         PEE);
  2786.                   end if;
  2787.                end if;
  2788.             end;
  2789.          end if;
  2790.  
  2791.          --  Similarly, array whose component type is record of component
  2792.          --  declarations with discriminant expression that is non-static
  2793.          --  is a violation.
  2794.  
  2795.          if Is_Array_Type (T) then
  2796.             if Nkind (Parent (T)) = N_Full_Type_Declaration then
  2797.                declare
  2798.                   Comp_Type : Entity_Id := Component_Type (T);
  2799.  
  2800.                begin
  2801.                   while Is_Array_Type (Comp_Type) loop
  2802.                      Comp_Type := Component_Type (Comp_Type);
  2803.                   end loop;
  2804.  
  2805.                   if Is_Record_Type (Comp_Type)
  2806.                     and then Has_Discriminants (Comp_Type)
  2807.                     and then
  2808.                       Nkind (Parent (Comp_Type)) = N_Full_Type_Declaration
  2809.                     and then not Static_Discriminant_Expr
  2810.                       (Discriminant_Specifications (Parent (Comp_Type)))
  2811.                   then
  2812.                      Error_Msg_N
  2813.                        ("non-static discriminant in preelaborated unit",
  2814.                         Comp_Type);
  2815.                   end if;
  2816.                end;
  2817.             end if;
  2818.          end if;
  2819.  
  2820.       end if;
  2821.  
  2822.       --  A pure library_item must not contain the declaration of any
  2823.       --  variable except within  a subprogram, generic subprogram, task
  2824.       --  unit or protected unit (RM 10.2.1(16)).
  2825.  
  2826.       if Inside_Pure_Unit
  2827.         and then not Inside_Subprogram_Task_Protected_Unit
  2828.       then
  2829.          Error_Msg_N ("declaration of variable not allowed in pure unit", N);
  2830.  
  2831.       --  The visible part of an RCI library unit must not contain the
  2832.       --  declaration of a variable (RM E.1.3(9))
  2833.  
  2834.       elsif Inside_Remote_Call_Interface_Unit then
  2835.          Error_Msg_N ("declaration of variable not allowed in rci unit", N);
  2836.  
  2837.       --  The visible part of a Shared Passive library unit must not contain
  2838.       --  the declaration of a variable (RM E.2.2(7))
  2839.  
  2840.       elsif Inside_Remote_Types_Unit then
  2841.          Error_Msg_N
  2842.            ("variable declaration not allowed in remote types unit", N);
  2843.       end if;
  2844.  
  2845.    end Validate_Object_Declaration;
  2846.  
  2847.    -------------------------------------------------
  2848.    -- Validate_RCI_Access_Object_Type_Declaration --
  2849.    -------------------------------------------------
  2850.  
  2851.    procedure Validate_RCI_Access_Object_Type_Declaration (T : Entity_Id) is
  2852.       Direct_Designated_Type : Entity_Id;
  2853.       Designated_Type        : Entity_Id;
  2854.       Primitive_Subprograms  : Elist_Id;
  2855.       Type_Decl              : Node_Id;
  2856.       Subprogram             : Elmt_Id;
  2857.       Subprogram_Node        : Node_Id;
  2858.       Profile                : List_Id;
  2859.       Param_Spec             : Node_Id;
  2860.       Param_Type             : Entity_Id;
  2861.       Limited_Type           : Entity_Id;
  2862.       Limited_Type_Decl      : Node_Id;
  2863.       Item                   : Node_Id;
  2864.       Nm                     : Name_Id;
  2865.       Read_Spec              : Node_Id;
  2866.       Read_Type              : Entity_Id;
  2867.       Write_Spec             : Node_Id;
  2868.       Write_Type             : Entity_Id;
  2869.       Found_Read             : Boolean := False;
  2870.       Found_Write            : Boolean := False;
  2871.  
  2872.    begin
  2873.       --  We are called from Analyze_Type_Declaration, and the Nkind
  2874.       --  of the given node is N_Access_To_Object_Definition.
  2875.  
  2876.       if not Comes_From_Source (T)
  2877.         or else not Inside_Remote_Call_Interface_Unit
  2878.       then
  2879.          return;
  2880.       end if;
  2881.  
  2882.       --  Check RCI unit type declaration. It should not contain the
  2883.       --  declaration of an access-to-object type unless it is a
  2884.       --  general access type that designates a class-wide limited
  2885.       --  private type. There are also constraints about the primitive
  2886.       --  subprograms of the class-wide type (RM E.2.3(14)).
  2887.  
  2888.       if Ekind (T) /= E_General_Access_Type then
  2889.          Error_Msg_N
  2890.            ("must be general access-to-class-wide limited type in rci unit",
  2891.             T);
  2892.          return;
  2893.       end if;
  2894.  
  2895.       Direct_Designated_Type := Directly_Designated_Type (T);
  2896.  
  2897.       if Ekind (Direct_Designated_Type) /= E_Class_Wide_Type then
  2898.          Error_Msg_N
  2899.            ("must be general access-to-class-wide limited type in rci unit",
  2900.             T);
  2901.          return;
  2902.       end if;
  2903.  
  2904.       Designated_Type := Etype (Direct_Designated_Type);
  2905.       Type_Decl       := Parent (Designated_Type);
  2906.  
  2907.       if Nkind (Type_Decl) /= N_Private_Type_Declaration
  2908.         or else not Limited_Present (Type_Decl)
  2909.         or else Primitive_Operations (Designated_Type) = No_Elist
  2910.       then
  2911.          Error_Msg_N
  2912.            ("in rci must be limited private designated type with operation",
  2913.             T);
  2914.          return;
  2915.       end if;
  2916.  
  2917.       Primitive_Subprograms := Primitive_Operations (Designated_Type);
  2918.       Subprogram            := First_Elmt (Primitive_Subprograms);
  2919.  
  2920.       while Subprogram /= No_Elmt loop
  2921.          Subprogram_Node := Node (Subprogram);
  2922.  
  2923.          if not Comes_From_Source (Subprogram_Node) then
  2924.             goto Next_Subprogram;
  2925.          end if;
  2926.  
  2927.          Profile := Parameter_Specifications (Parent (Subprogram_Node));
  2928.  
  2929.          --  Profile must exist, otherwise not primitive operation
  2930.  
  2931.          Param_Spec := First (Profile);
  2932.  
  2933.          while Present (Param_Spec) loop
  2934.  
  2935.             --  Now find out if this parameter is a controlling parameter
  2936.  
  2937.             Param_Type := Parameter_Type (Param_Spec);
  2938.  
  2939.             if Nkind (Param_Type) = N_Identifier
  2940.               and then Etype (Param_Type) = Designated_Type
  2941.             then
  2942.                --  It is indeed a controlling parameter, and since it's not
  2943.                --  an access parameter, this is a violation.
  2944.  
  2945.                Error_Msg_N
  2946.                  ("not access control parameter in rci unit", Param_Spec);
  2947.  
  2948.             elsif Nkind (Param_Type) = N_Access_Definition
  2949.               and then Subtype_Mark (Param_Type) = Designated_Type
  2950.             then
  2951.                --  It is indeed controlling parameter but since it's an
  2952.                --  access parameter, this is not a violation.
  2953.  
  2954.                null;
  2955.  
  2956.             elsif
  2957.               Is_Limited_Type (Etype (Defining_Identifier (Param_Spec)))
  2958.             then
  2959.                --  Not a controlling parameter, so type must have Read
  2960.                --  and Write attributes.
  2961.  
  2962.                if Nkind (Param_Type) = N_Identifier
  2963.                  and then Nkind (Parent (Etype (Param_Type))) =
  2964.                           N_Private_Type_Declaration
  2965.                then
  2966.                   Param_Type := Etype (Param_Type);
  2967.                   Limited_Type_Decl := Parent (Param_Type);
  2968.  
  2969.                   --  Now looking for Read and Write through rest of decl list
  2970.  
  2971.                   Item := Next (Limited_Type_Decl);
  2972.                   while Present (Item) loop
  2973.                      if Nkind (Item) = N_Subprogram_Declaration
  2974.                        and then Present (Parameter_Specifications
  2975.                                               (Specification (Item)))
  2976.                      then
  2977.                         Nm :=
  2978.                           Chars (Defining_Unit_Name (Specification (Item)));
  2979.  
  2980.                         --  If name match read or write then iterate through
  2981.                         --  its list of parameter specifications, looking for
  2982.                         --  a match in the target limited type.
  2983.  
  2984.                         if Nm = Name_Read then
  2985.                            Read_Spec := First (Parameter_Specifications
  2986.                                                 (Specification (Item)));
  2987.  
  2988.                            while Present (Read_Spec) loop
  2989.                               Read_Type :=
  2990.                                 Etype (Defining_Identifier (Read_Spec));
  2991.  
  2992.                               if Read_Type = Param_Type then
  2993.                                  Found_Read := True;
  2994.                               end if;
  2995.  
  2996.                               Read_Spec := Next (Read_Spec);
  2997.                            end loop;
  2998.  
  2999.                         elsif Nm = Name_Write then
  3000.                            Write_Spec := First (Parameter_Specifications
  3001.                                                  (Specification (Item)));
  3002.  
  3003.                            while Present (Write_Spec) loop
  3004.                               Write_Type :=
  3005.                                 Etype (Defining_Identifier (Write_Spec));
  3006.  
  3007.                               if Write_Type = Param_Type then
  3008.                                  Found_Write := True;
  3009.                               end if;
  3010.  
  3011.                               Write_Spec := Next (Write_Spec);
  3012.                            end loop;
  3013.  
  3014.                         end if;
  3015.                      end if;
  3016.  
  3017.                      Item := Next (Item);
  3018.                      exit when Found_Read and then Found_Write;
  3019.                   end loop;
  3020.  
  3021.                   if not Found_Read
  3022.                     or else not Found_Write
  3023.                   then
  3024.                      Error_Msg_N
  3025.                        ("non-control parameter must have read/write in rci",
  3026.                          Param_Spec);
  3027.                   end if;
  3028.                end if;
  3029.             end if;
  3030.  
  3031.             --  Check next parameter in this subprogram
  3032.  
  3033.             Param_Spec  := Next (Param_Spec);
  3034.             Found_Read  := False;
  3035.             Found_Write := False;
  3036.          end loop;
  3037.  
  3038.          <<Next_Subprogram>>
  3039.             Subprogram := Next_Elmt (Subprogram);
  3040.       end loop;
  3041.  
  3042.       --  Now this is an RCI unit access-to-class-wide-limited-private type
  3043.       --  declaration. Set the type entity to be Is_Remote_Call_Interface to
  3044.       --  optimize later checks by avoiding tree traversal to find out if this
  3045.       --  entity is inside an RCI unit.
  3046.  
  3047.       Set_Is_Remote_Call_Interface (T);
  3048.  
  3049.    end Validate_RCI_Access_Object_Type_Declaration;
  3050.  
  3051.    ---------------------------------------------
  3052.    -- Validate_RCI_Limited_Type_Declaration --
  3053.    ---------------------------------------------
  3054.  
  3055.    procedure Validate_RCI_Limited_Type_Declaration (N : Node_Id) is
  3056.    begin
  3057.       --  The visible part of an RCI unit must not contain
  3058.       --  declaration of limited type (RM E.2.3(10))
  3059.  
  3060.       if Inside_Remote_Call_Interface_Unit then
  3061.  
  3062.          --  Called from Analyze_Private_Type_Declaration.
  3063.  
  3064.          if Nkind (N) = N_Private_Type_Declaration
  3065.            and then Limited_Present (N)
  3066.          then
  3067.             Error_Msg_N
  3068.               ("limited type declaration not allowed in rci unit", N);
  3069.  
  3070.          --  Called from Analyze_Task_Type or Analyze_Protected_Type,
  3071.          --  caller check to see type name is from source before calling.
  3072.  
  3073.          else
  3074.             Error_Msg_N
  3075.               ("limited type declaration not allowed in rci unit", N);
  3076.          end if;
  3077.       end if;
  3078.    end Validate_RCI_Limited_Type_Declaration;
  3079.  
  3080.    ---------------------------------------------
  3081.    -- Validate_RCI_Nested_Generic_Declaration --
  3082.    ---------------------------------------------
  3083.  
  3084.    procedure Validate_RCI_Nested_Generic_Declaration (N : Node_Id) is
  3085.    begin
  3086.       --  The visible part of an RCI unit must not contain
  3087.       --  a nested generic_declaration (RM E.2.3(11))
  3088.  
  3089.       if Inside_Remote_Call_Interface_Unit
  3090.         and then Nkind (Parent (N)) /= N_Compilation_Unit
  3091.       then
  3092.          Error_Msg_N
  3093.            ("nested generic declaration not allowed in rci unit", N);
  3094.       end if;
  3095.    end Validate_RCI_Nested_Generic_Declaration;
  3096.  
  3097.    -----------------------------------------
  3098.    -- Validate_RCI_Subprogram_Declaration --
  3099.    -----------------------------------------
  3100.  
  3101.    procedure Validate_RCI_Subprogram_Declaration (N : Node_Id) is
  3102.       K           : Node_Kind := Nkind (N);
  3103.       Profile     : List_Id;
  3104.       Id          : Node_Id;
  3105.       Param_Spec  : Node_Id;
  3106.       Param_Type  : Entity_Id;
  3107.       Type_Decl   : Node_Id;
  3108.       Item        : Node_Id;
  3109.       Nm          : Name_Id;
  3110.       Found_Read  : Boolean := False;
  3111.       Found_Write : Boolean := False;
  3112.       Read_Spec   : Node_Id;
  3113.       Read_Type   : Entity_Id;
  3114.       Write_Spec  : Node_Id;
  3115.       Write_Type  : Entity_Id;
  3116.  
  3117.    begin
  3118.       --  The visible part of an RCI unit must not contain the declaration
  3119.       --  of a subprogram to which a pragma Inline applies RM E.2.3(12).
  3120.  
  3121.       --  There are two possible cases in which this procedure is called:
  3122.  
  3123.       --    1. called from Analyze_Subprogram_Declaration.
  3124.       --    2. called from Validate_Object_Declaration (access to subprogram).
  3125.  
  3126.       if not Inside_Remote_Call_Interface_Unit then
  3127.          return;
  3128.       end if;
  3129.  
  3130.       if K = N_Subprogram_Declaration then
  3131.          Profile := Parameter_Specifications (Specification (N));
  3132.  
  3133.          if Is_Inlined (Defining_Unit_Simple_Name (Specification (N))) then
  3134.             Error_Msg_N
  3135.               ("inlined subprogram cannot be declared in rci unit", N);
  3136.          end if;
  3137.  
  3138.       elsif K = N_Object_Declaration then
  3139.          Id := Defining_Identifier (N);
  3140.  
  3141.          if Nkind (Id) = N_Defining_Identifier
  3142.            and then Nkind (Parent (Etype (Id))) = N_Full_Type_Declaration
  3143.            and then Ekind (Etype (Id)) = E_Access_Subprogram_Type
  3144.          then
  3145.             Profile :=
  3146.               Parameter_Specifications (Type_Definition (Parent (Etype (Id))));
  3147.          else
  3148.             return;
  3149.          end if;
  3150.       end if;
  3151.  
  3152.       --  Iterate through the parameter specification list, checking that
  3153.       --  no access parameter and no limited type paramter in the list.
  3154.  
  3155.       if Present (Profile) then
  3156.          Param_Spec := First (Profile);
  3157.  
  3158.          while Present (Param_Spec) loop
  3159.             Param_Type := Etype (Defining_Identifier (Param_Spec));
  3160.             Type_Decl  := Parent (Param_Type);
  3161.  
  3162.             if Ekind (Param_Type) = E_Anonymous_Access_Type then
  3163.                if K = N_Subprogram_Declaration then
  3164.  
  3165.                   --  Report error only if it is not generated by compiler
  3166.  
  3167.                   if Comes_From_Source (Defining_Unit_Name (Specification
  3168.                     (N)))
  3169.                   then
  3170.                      Error_Msg_N
  3171.                        ("subprogram in rci unit cannot have access parameter",
  3172.                        Param_Spec);
  3173.                   end if;
  3174.                else
  3175.                   Error_Msg_N
  3176.                     ("subprogram in rci unit cannot have access parameter",
  3177.                      N);
  3178.                end if;
  3179.  
  3180.             --  For limited private type parameter, we check only the
  3181.             --  private declaration and ignore full type declaration.
  3182.  
  3183.             elsif Is_Limited_Type (Param_Type)
  3184.               and then Nkind (Type_Decl) = N_Private_Type_Declaration
  3185.             then
  3186.                --  Limited types having user defined Read and Write
  3187.                --  attributes are not violation. RM E.2.3(13)
  3188.                --  Now traverse the rest of the declaration list, looking
  3189.                --  for Read and Write.
  3190.  
  3191.                Item := Next (Type_Decl);
  3192.                while Present (Item) loop
  3193.                   if Nkind (Item) = N_Subprogram_Declaration
  3194.                     and then
  3195.                       Present (Parameter_Specifications (Specification (Item)))
  3196.                   then
  3197.                      Nm := Chars (Defining_Unit_Name (Specification (Item)));
  3198.  
  3199.                      --  If name is read or write then iterate through list
  3200.                      --  of parameter specifications, looking for a match
  3201.                      --  in the target limited type.
  3202.  
  3203.                      if Nm = Name_Read then
  3204.                         Read_Spec := First (Parameter_Specifications
  3205.                                              (Specification (Item)));
  3206.                         while Present (Read_Spec) loop
  3207.                            Read_Type :=
  3208.                              Etype (Defining_Identifier (Read_Spec));
  3209.  
  3210.                            if Read_Type = Param_Type then
  3211.                               Found_Read := True;
  3212.                            end if;
  3213.  
  3214.                            Read_Spec := Next (Read_Spec);
  3215.                         end loop;
  3216.  
  3217.                      elsif Nm = Name_Write then
  3218.                         Write_Spec := First (Parameter_Specifications
  3219.                                               (Specification (Item)));
  3220.                         while Present (Write_Spec) loop
  3221.                            Write_Type :=
  3222.                              Etype (Defining_Identifier (Write_Spec));
  3223.  
  3224.                            if Write_Type = Param_Type then
  3225.                               Found_Write := True;
  3226.                            end if;
  3227.  
  3228.                            Write_Spec := Next (Write_Spec);
  3229.                         end loop;
  3230.  
  3231.                      end if;
  3232.                   end if;
  3233.  
  3234.                   Item := Next (Item);
  3235.                   exit when Found_Read and Found_Write;
  3236.                end loop;
  3237.  
  3238.                if Found_Read
  3239.                  and then Found_Write
  3240.                then
  3241.                   return;
  3242.  
  3243.                else
  3244.                   if K = N_Subprogram_Declaration then
  3245.                      Error_Msg_N
  3246.                        ("limited parameter not allowed in rci unit",
  3247.                         Param_Spec);
  3248.                   else
  3249.                      Error_Msg_N
  3250.                        ("limited parameter not allowed in rci unit", N);
  3251.                   end if;
  3252.                end if;
  3253.             end if;
  3254.  
  3255.             Param_Spec  := Next (Param_Spec);
  3256.             Found_Read  := False;
  3257.             Found_Write := False;
  3258.          end loop;
  3259.       end if;
  3260.    end Validate_RCI_Subprogram_Declaration;
  3261.  
  3262.    -----------------------------------------------
  3263.    -- Validate_Remote_Access_To_Class_Wide_Type --
  3264.    -----------------------------------------------
  3265.  
  3266.    procedure Validate_Remote_Access_To_Class_Wide_Type (N : Node_Id) is
  3267.       K    : constant Node_Kind := Nkind (N);
  3268.       PK   : constant Node_Kind := Nkind (Parent (N));
  3269.       E    : Entity_Id;
  3270.       P    : Node_Id;
  3271.       PtrT : Entity_Id;
  3272.       T    : Entity_Id;
  3273.       Expr : Node_Id;
  3274.  
  3275.    begin
  3276.       --  This subprogram enforces the checks in (RM E.2.2(8)) for
  3277.       --  certain uses of class-wide limited private types.
  3278.  
  3279.       --    Storage_Pool and Storage_Size are not defined for such types
  3280.       --
  3281.       --    The expected type of allocator must not not be such a type.
  3282.  
  3283.       --    The actual parameter of generic instantiation must not
  3284.       --    be such a type.
  3285.  
  3286.       --  On entry, there are four cases
  3287.  
  3288.       --    1. called from sem_attr Analyze_Attribute where attribute
  3289.       --       name is either Storage_Pool or Storage_Size.
  3290.  
  3291.       --    2. called from exp_ch4 Expand_N_Allocator
  3292.  
  3293.       --    3. called from sem_ch12 Analyze_Associations
  3294.  
  3295.       --    4. called from sem_ch4 Analyze_Explicit_Dereference
  3296.  
  3297.       if not Present (N) then
  3298.          return;
  3299.       end if;
  3300.  
  3301.       if K = N_Attribute_Reference then
  3302.          E := Etype (Prefix (N));
  3303.  
  3304.          if Is_Remote_Access_To_Class_Wide_Type (E) then
  3305.             Error_Msg_N ("incorrect attribute of remote operand", N);
  3306.             return;
  3307.          end if;
  3308.  
  3309.       elsif K = N_Allocator then
  3310.          E := Etype (N);
  3311.  
  3312.          if Is_Remote_Access_To_Class_Wide_Type (E) then
  3313.             Error_Msg_N ("incorrect expected remote type of allocator", N);
  3314.             return;
  3315.          end if;
  3316.  
  3317.       elsif K = N_Identifier then
  3318.          E := Entity (N);
  3319.  
  3320.          if Is_Remote_Access_To_Class_Wide_Type (E) then
  3321.             Error_Msg_N ("incorrect remote type generic actual", N);
  3322.             return;
  3323.          end if;
  3324.  
  3325.       --  This subprogram also enforces the checks in E.2.2(13).
  3326.       --  A value of such type must not be explicitly dereferenced
  3327.       --  unless in a dispatching call.
  3328.  
  3329.       elsif K = N_Explicit_Dereference then
  3330.          E := Etype (Prefix (N));
  3331.  
  3332.          if Is_Remote_Access_To_Class_Wide_Type (E)
  3333.            and then PK /= N_Procedure_Call_Statement
  3334.            and then PK /= N_Function_Call
  3335.          then
  3336.             --  The following is to let the compiler generated tags check
  3337.             --  pass through without error message. This is a bit kludgy
  3338.             --  isn't there some better way of making this exclusion ???
  3339.  
  3340.             if (PK = N_Selected_Component
  3341.                  and then Present (Parent (Parent (N)))
  3342.                  and then Nkind (Parent (Parent (N))) = N_Op_Ne)
  3343.               or else (PK = N_Unchecked_Type_Conversion
  3344.                         and then Present (Parent (Parent (N)))
  3345.                         and then
  3346.                           Nkind (Parent (Parent (N))) = N_Selected_Component)
  3347.             then
  3348.                return;
  3349.             end if;
  3350.  
  3351.             --  The following is to let the compiler generated membership
  3352.             --  check and type conversion pass through without error message.
  3353.  
  3354.             if (PK = N_Not_In
  3355.                  and then Present (Parent (Parent (N)))
  3356.                  and then Nkind (Parent (Parent (N))) = N_If_Statement)
  3357.               or else (PK = N_Indexed_Component
  3358.                         and then Present (Parent (Parent (N)))
  3359.                         and then
  3360.                           Nkind (Parent (Parent (N))) = N_Selected_Component)
  3361.             then
  3362.                return;
  3363.             end if;
  3364.  
  3365.             Error_Msg_N ("incorrect remote type dereference", N);
  3366.          end if;
  3367.       end if;
  3368.    end Validate_Remote_Access_To_Class_Wide_Type;
  3369.  
  3370.    ------------------------------------------
  3371.    -- Validate_Remote_Type_Type_Conversion --
  3372.    ------------------------------------------
  3373.  
  3374.    procedure Validate_Remote_Type_Type_Conversion (N : Node_Id) is
  3375.       S  : constant Entity_Id := Etype (N);
  3376.       E  : constant Entity_Id := Etype (Expression (N));
  3377.  
  3378.    begin
  3379.       --  This test is required in the case where a conversion apears
  3380.       --  inside a normal package, it does not necessarily have to be
  3381.       --  inside an RCI, Remote_Types unit (RM E.2.2(9,12)).
  3382.  
  3383.       if Is_Remote_Access_To_Subprogram_Type (E)
  3384.         and then not Is_Remote_Access_To_Subprogram_Type (S)
  3385.       then
  3386.          Error_Msg_N ("incorrect conversion of remote operand", N);
  3387.          return;
  3388.  
  3389.       elsif Is_Remote_Access_To_Class_Wide_Type (E)
  3390.         and then not Is_Remote_Access_To_Class_Wide_Type (S)
  3391.       then
  3392.          Error_Msg_N ("incorrect conversion of remote operand", N);
  3393.          return;
  3394.       end if;
  3395.    end Validate_Remote_Type_Type_Conversion;
  3396.  
  3397.    -----------------------------------------
  3398.    -- Validate_SP_Access_Object_Type_Decl --
  3399.    -----------------------------------------
  3400.  
  3401.    procedure Validate_SP_Access_Object_Type_Decl (T : Entity_Id)
  3402.    is
  3403.  
  3404.       Direct_Designated_Type : Entity_Id;
  3405.  
  3406.       function Has_Entry_Declarations (E : Entity_Id) return Boolean;
  3407.       --  Return true if the protected type designated by T has
  3408.       --  entry declarations.
  3409.  
  3410.       function Has_Entry_Declarations (E : Entity_Id) return Boolean is
  3411.          Ety : Entity_Id;
  3412.  
  3413.       begin
  3414.          if Nkind (Parent (E)) = N_Protected_Type_Declaration then
  3415.             Ety := First_Entity (E);
  3416.             while Present (Ety) loop
  3417.                if Ekind (Ety) = E_Entry then
  3418.                   return True;
  3419.                end if;
  3420.  
  3421.                Ety := Next (Ety);
  3422.             end loop;
  3423.          end if;
  3424.  
  3425.          return False;
  3426.       end Has_Entry_Declarations;
  3427.  
  3428.    --  Start of processing for
  3429.    --  Validate_SP_Access_Object_Type_Decl
  3430.  
  3431.    begin
  3432.       --  We are called from Sem_Ch3.Analyze_Type_Declaration, and the
  3433.       --  Nkind of the given entity is N_Access_To_Object_Definition.
  3434.  
  3435.       if not Comes_From_Source (T)
  3436.         or else not Inside_Shared_Passive_Unit
  3437.         or else Inside_Subprogram_Task_Protected_Unit
  3438.       then
  3439.          return;
  3440.       end if;
  3441.  
  3442.       --  Check Shared Passive unit. It should not contain the declaration
  3443.       --  of an access-to-object type whose designated type is a class-wide
  3444.       --  type, task type or protected type with entry (RM E.2.1(7)).
  3445.  
  3446.       Direct_Designated_Type := Directly_Designated_Type (T);
  3447.  
  3448.       if Ekind (Direct_Designated_Type) = E_Class_Wide_Type then
  3449.          Error_Msg_N
  3450.            ("invalid access-to-class-wide type in shared passive unit", T);
  3451.          return;
  3452.  
  3453.       elsif Ekind (Direct_Designated_Type) in Task_Kind then
  3454.          Error_Msg_N
  3455.            ("invalid access-to-task type in shared passive unit", T);
  3456.          return;
  3457.  
  3458.       elsif Ekind (Direct_Designated_Type) in Protected_Kind
  3459.         and then Has_Entry_Declarations (Direct_Designated_Type)
  3460.       then
  3461.          Error_Msg_N
  3462.            ("invalid access-to-protected type in shared passive unit", T);
  3463.          return;
  3464.       end if;
  3465.    end Validate_SP_Access_Object_Type_Decl;
  3466.  
  3467.    ---------------------------------
  3468.    -- Validate_Static_Object_Name --
  3469.    ---------------------------------
  3470.  
  3471.    procedure Validate_Static_Object_Name (N : Node_Id) is
  3472.  
  3473.       function Assignment_Left_Hand_Side (N : Node_Id) return Boolean;
  3474.       --  Return True if N is on the left hand side of an assignment statement,
  3475.       --  or is the defining id in an object declaration.
  3476.  
  3477.       function Assignment_Left_Hand_Side (N : Node_Id) return Boolean is
  3478.       begin
  3479.          if (Nkind (Parent (N)) = N_Assignment_Statement
  3480.              and then N = Name (Parent (N)))
  3481.            or else (Nkind (Parent (N)) = N_Object_Declaration
  3482.              and then N = Defining_Identifier (Parent (N)))
  3483.          then
  3484.             return True;
  3485.          end if;
  3486.  
  3487.          return False;
  3488.       end Assignment_Left_Hand_Side;
  3489.  
  3490.    --  Start of processing for Validate_Static_Object_Name
  3491.  
  3492.    begin
  3493.  
  3494.       --  Filter out cases that default primary is in a record type component
  3495.       --  decl., record type discriminant specification or primary is a param.
  3496.       --  in a record type implicit init. procedure call.
  3497.  
  3498.       --  Initialization call of internal types.
  3499.  
  3500.       if Nkind (Parent (N)) = N_Procedure_Call_Statement then
  3501.  
  3502.          if Present (Parent (Parent (N)))
  3503.            and then Nkind (Parent (Parent (N))) = N_Freeze_Entity
  3504.          then
  3505.             return;
  3506.          end if;
  3507.  
  3508.          if Nkind (Name (Parent (N))) = N_Identifier
  3509.            and then not Comes_From_Source (Entity (Name (Parent (N))))
  3510.          then
  3511.             return;
  3512.          end if;
  3513.       end if;
  3514.  
  3515.       if Inside_Preelaborated_Unit
  3516.         and then not Inside_Subprogram_Unit
  3517.         and then Comes_From_Source (Entity (N))
  3518.         and then Nkind (Parent (N)) /= N_Component_Declaration
  3519.         and then Nkind (Parent (N)) /= N_Discriminant_Specification
  3520.         and then ((Ekind (Entity (N)) = E_Variable
  3521.                            and then not Assignment_Left_Hand_Side (N))
  3522.                  or else (not Is_Static_Expression (N)
  3523.                            and then Ekind (Entity (N)) = E_Constant))
  3524.       then
  3525.          Error_Msg_N ("non-static object name in preelaborated unit", N);
  3526.       end if;
  3527.    end Validate_Static_Object_Name;
  3528.  
  3529. end Sem_Dist;
  3530.