Contents Index Search Previous Next
10.1.1 Compilation Units - Library Units
is a compilation unit that is the declaration, body, or renaming of a
library unit. Each library unit (except Standard) has a parent unit
which is a library package or generic library package.
library unit is a child
of its parent unit. The root
units are the children of the predefined library package Standard.
| context_clause subunit
A library unit
program unit that is declared by a library_item
When a program unit is a library unit, the prefix ``library'' is used
to refer to it (or ``generic library'' if generic), as well as to its
declaration and body, as in ``library procedure'', ``library package_body
or ``generic library package''.
The term compilation
is used to refer to a compilation_unit
When the meaning is clear from context, the term is also used to refer
to the library_item
of a compilation_unit
or to the proper_body
of a subunit
(that is, the compilation_unit
and the separate
of a library_item
(and of the library unit) is the declaration denoted by the parent_unit_name
if any, of the defining_program_unit_name
of the library_item
there is no parent_unit_name
parent declaration is the declaration of Standard, the library_item
is a root library_item
the library unit (renaming) is a root
library unit (renaming).
The declaration and body of Standard itself have no parent declaration.
The parent unit
of a library_item
or library unit is the library unit declared by its parent declaration.
The children of a library unit occur immediately
within the declarative region of the declaration of the library unit.
of a library unit are itself,
its parent, its parent's parent, and so on. (Standard is an ancestor
of every library unit.)
is the inverse of the ancestor relation.
or a library_unit_renaming_declaration
if the declaration is immediately preceded by the reserved
; it is otherwise public
. A library unit is
private or public according to its declaration.
of a library unit are the library unit itself,
and the public descendants of its public children.
other descendants are private descendants
The parent unit of a library_item
shall be a library package or generic library package.
If a defining_program_unit_name
of a given declaration or body has a parent_unit_name,
then the given declaration or body shall be a library_item.
The body of a program unit shall be a library_item
if and only if the declaration of the program unit is a library_item.
In a library_unit_renaming_declaration,
the (old) name shall denote a library_item.
(which can be used within a defining_program_unit_name
of a library_item and in the separate
clause of a subunit), and each of
its prefixes, shall not denote a
renaming_declaration. On the other
hand, a name that denotes a library_unit_renaming_declaration
is allowed in a with_clause and
other places where the name of a library unit is allowed.
If a library package is an instance of a generic
package, then every child of the library package shall either be itself
an instance or be a renaming of a library unit.
A child of a generic library package shall either
be itself a generic unit or be a renaming of some other child of the
same generic unit. The renaming of a child of a generic package shall
occur only within the declarative region of the generic package.
A child of a parent generic package shall be
instantiated or renamed only within the declarative region of the parent
For each declaration or renaming of a generic
unit as a child of some parent generic package, there is a corresponding
declaration nested immediately within each instance of the parent. This
declaration is visible only within the scope of a with_clause
that mentions the child generic unit.
A library subprogram shall not override a primitive
The defining name of a function that is a compilation
unit shall not be an operator_symbol.
that is a library_unit_renaming_declaration
is a renaming-as-declaration, not a renaming-as-body.
There are two kinds
of dependences among compilation units:
- The semantic dependences (see
below) are the ones needed to check the compile-time rules across compilation
unit boundaries; a compilation unit depends semantically on the other
compilation units needed to determine its legality. The visibility rules
are based on the semantic dependences.
- The elaboration dependences
(see 10.2) determine the order of elaboration
depends semantically upon its parent declaration. A subunit depends semantically
upon its parent body. A library_unit_body
depends semantically upon the corresponding library_unit_declaration
if any. A compilation unit depends semantically upon each library_item
mentioned in a with_clause
compilation unit. In addition, if a given compilation unit contains an
of a type defined
in another compilation unit, then the given compilation unit depends
semantically upon the other compilation unit. The semantic dependence
relationship is transitive.
1 A simple program may
consist of a single compilation unit. A compilation
need not have any compilation units; for example, its text can consist
2 The designator
of a library function cannot be an operator_symbol,
but a nonlibrary renaming_declaration
is allowed to rename a library function as an operator. Within a partition,
two library subprograms are required to have distinct names and hence
cannot overload each other. However, renaming_declarations
are allowed to define overloaded names for such subprograms, and a locally
declared subprogram is allowed to overload a library subprogram. The
expanded name Standard.L can be used to denote a root library unit L
(unless the declaration of Standard is hidden) since root library unit
declarations occur immediately within the declarative region of package
package Rational_Numbers.IO is -- public child of Rational_Numbers, see 7.1
procedure Put(R : in Rational);
procedure Get(R : out Rational);
private procedure Rational_Numbers.Reduce(R : in out Rational);
-- private child of Rational_Numbers
with Rational_Numbers.Reduce; -- refer to a private child
package body Rational_Numbers is
with Rational_Numbers.IO; use Rational_Numbers;
with Ada.Text_io; -- see A.10
procedure Main is -- a root library procedure
R : Rational;
R := 5/3; -- construct a rational number, see 7.1
Ada.Text_IO.Put("The answer is: ");
package Rational_IO renames Rational_Numbers.IO;
-- a library unit renaming declaration
Each of the above library_items
can be submitted to the compiler separately.
Contents Index Search Previous Next Legal