10.1.1 Compilation Units - Library Units
A
library_item
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.
A
library unit is a
child of its parent unit. The
root library
units are the children of the predefined library package Standard.
Syntax
parent_unit_name ::= name
The children of a library unit occur immediately
within the declarative region of the declaration of the library unit.
The
ancestors of a library unit are itself,
its parent, its parent's parent, and so on. (Standard is an ancestor
of every library unit.)
The
descendant relation
is the inverse of the ancestor relation.
A
library_unit_declaration
or a
library_unit_renaming_declaration
is
private if the declaration is immediately preceded by the reserved
word
private; it is otherwise
public. A library unit is
private or public according to its declaration.
The
public descendants of a library unit are the library unit itself,
and the public descendants of its public children.
Its
other descendants are
private descendants.
For each library
package_declaration
in the environment, there is an implicit declaration of a
limited
view of that library package.
The limited view
of a package contains:
There is no syntax for declaring limited views
of packages, because they are always implicit. The implicit declaration
of a limited view of a library package is not the declaration of a library
unit (the library
package_declaration
is); nonetheless, it is a
library_item.
The implicit declaration of the limited view of a library package forms
an (implicit) compilation unit whose
context_clause
is empty.
Legality Rules
The parent unit of a
library_item
shall be a library package or generic library package.
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 generic.
For each child
C of some parent generic package
P, there is a corresponding declaration
C nested immediately
within each instance of
P. For the purposes of this rule, if a
child
C itself has a child
D, each corresponding declaration
for
C has a corresponding child
D. The corresponding declaration
for a child within an instance is visible only within the scope of a
with_clause
that mentions the (original) child generic unit.
A library subprogram shall not override a primitive
subprogram.
The defining name of a function that is a compilation
unit shall not be an
operator_symbol.
Static Semantics
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 of
library_items.
A
library_item
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. The declaration of the limited view of a library package depends
semantically upon the declaration of the limited view of its parent.
The declaration of a library package depends semantically upon the declaration
of its limited view. A compilation unit depends semantically upon each
library_item
mentioned in a
with_clause
of the compilation unit. In addition, if a given compilation unit contains
an
attribute_reference
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.
Dynamic Semantics
The elaboration of the declaration of the limited
view of a package has no effect.
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
of
pragmas.
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
Standard.
Examples
Examples of library
units:
package Rational_Numbers.IO
is --
public child of Rational_Numbers, see 7.1
procedure Put(R :
in Rational);
procedure Get(R :
out Rational);
end Rational_Numbers.IO;
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
...
end Rational_Numbers;
with Rational_Numbers.IO;
use 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;
with Rational_Numbers.IO;
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.