context_clause library_item
| context_clause subunit
| library_unit_body
| [private] library_unit_renaming_declaration
subprogram_declaration | package_declaration
| generic_declaration | generic_instantiation
package_renaming_declaration
| generic_renaming_declaration
| subprogram_renaming_declaration
package P is
...
end P;
private
package B is
package C is
end C;
private
end B;
end A;
16.c 1. We want all source code that can depend on information from the private part of a library unit to be inside the "subsystem" rooted at the library unit. If an instance of a generic unit were allowed to have a noninstance as a child, the source code of that child might depend on information from the private part of the generic unit, even though it is outside the subsystem rooted at the generic unit.
16.d 2. Disallowing noninstance children simplifies the description of the semantics of children of generic packages.
procedure Put(R : in Rational);
procedure Get(R : out Rational);
end Rational_Numbers.IO;
-- private child of Rational_Numbers
package body Rational_Numbers is
...
end Rational_Numbers;
with Ada.Text_io; -- see A.10
procedure Main is -- a root library procedure
R : Rational;
begin
R := 5/3; -- construct a rational number, see 7.1
Ada.Text_IO.Put("The answer is: ");
IO.Put(R);
Ada.Text_IO.New_Line;
end Main;
package Rational_IO renames Rational_Numbers.IO;
-- a library unit renaming declaration
type Element is private;
with function Image(E : Element) return String;
package Generic_Bags is
type Bag is limited private; --A bag of Elements.
procedure Add(B : in out Bag; E : Element);
function Bag_Image(B : Bag) return String;
private
type Bag is ...;
end Generic_Bags;
package Generic_Bags.Generic_Iterators is
... --various additional operations on Bags.
with procedure Use_Element(E : in Element);
--Called once per bag element.
procedure Iterate(B : in Bag);
end Generic_Bags.Generic_Iterators;
with Generic_Bags.Generic_Iterators;
package My_Abstraction is
type My_Type is ...;
function Image(X : My_Type) return String;
package Bags_Of_My_Type is new Generic_Bags(My_Type, Image);
package Iterators_Of_Bags_Of_My_Type is new Bags_Of_My_Type.Generic_Iterators;
end My_Abstraction;
package body Generic_Bags is
procedure Add(B : in out Bag; E : Element) is ... end Add;
Buffer : String(1..10_000);
Last : Integer := 0;
Im : constant String := Image(E);
begin
if Last /= 0 then --Insert a comma.
Last := Last + 1;
Buffer(Last) := ',';
end if;
Buffer(Last+1 .. Last+Im'Length) := Im;
Last := Last + Im'Length;
end Append_Image;
begin
Append_All(B);
return Buffer(1..Last);
end Bag_Image;
end Generic_Bags;
end A.B.C;
end A.B.C.D;
private package A.B.X is
end A.B.X;
end A.B.Y;
package body A.B.Y is
end A.B.Y;
procedure Inner;
end Parent;
package body Parent is
Variable : String := "Hello, there.";
procedure Inner is
begin
Ada.Text_IO.Put_Line(Variable);
end Inner;
end Parent;
Variable : String := "Hello, there.";
procedure Inner is separate;
end Parent;
separate(Parent)
procedure Inner is
begin
Ada.Text_IO.Put_Line(Variable);
end Inner;