--  Renamings read and written by nested subprograms (an up-level object through its
--  renaming): of a whole object, of a component and of an array element; and a generic
--  formal object `in out`, which renames its actual (RM 12.4(10)).
with Ada.Text_IO;
procedure Main is
   type Pair is record
      A, B : Integer := 0;
   end record;
   type Row is array (1 .. 3) of Integer;
   T : Integer := 0;
   P : Pair;
   R : Row := (others => 0);
   Total : Integer renames T;
   Second : Integer renames P.B;
   Middle : Integer renames R (2);
   procedure Bump is
   begin
      if Total < 1000 then
         Total := Total + 1;
      end if;
      if Second < 1000 then
         Second := Second + 2;
      end if;
      if Middle < 1000 then
         Middle := Middle + 3;
      end if;
   end Bump;
   generic
      Count : in out Integer;
   procedure Add_Ten;
   procedure Add_Ten is
   begin
      if Count < 1000 then
         Count := Count + 10;
      end if;
   end Add_Ten;
   procedure Add_Ten_To_T is new Add_Ten (T);
begin
   Bump;
   Add_Ten_To_T;
   Ada.Text_IO.Put_Line (Integer'Image (T) & Integer'Image (P.B) & Integer'Image (R (2)));
end Main;
