Contents Index Search Previous Next
12.7 Formal Packages
1
[
{generic formal package}
{formal package, generic}
Formal packages can be used to pass packages to a
generic unit. The
formal_package_declaration
declares that the formal package is an instance of a given generic package.
Upon instantiation, the actual package has to be an instance of that
generic package.]
Syntax
2
formal_package_declaration
::=
with package defining_identifier is new generic_package_name formal_package_actual_part;
3
formal_package_actual_part
::=
(<>) | [
generic_actual_part]
Legality Rules
4
{template (for a formal package)}
The
generic_package_name
shall denote a generic package (the
template for the formal package);
the formal package is an instance of the template.
5
The actual shall
be an instance of the template. If the formal_package_actual_part
is (<>), [then the actual may be any instance of the template];
otherwise, each actual parameter of the actual instance shall match the
corresponding actual parameter of the formal package [(whether the actual
parameter is given explicitly or by default)], as follows:
6
- For a formal object of mode in
the actuals match if they are static expressions with the same value,
or if they statically denote the same constant, or if they are both the
literal null.
6.a
Reason: We can't simply
require full conformance between the two actual parameter expressions,
because the two expressions are being evaluated at different times.
7
- For a formal subtype, the actuals
match if they denote statically matching subtypes. {statically
matching (required) [partial]}
8
- For other kinds of formals, the actuals
match if they statically denote the same entity.
8.1/1
{
8652/0039}
For the purposes of matching, any actual parameter that is the name
of a formal object of mode in is replaced by the formal object's
actual expression (recursively).
Static Semantics
9
A formal_package_declaration
declares a generic formal package.
10
{visible part (of a formal
package) [partial]} The visible part of
a formal package includes the first list of
basic_declarative_items
of the
package_specification. In
addition, if the
formal_package_actual_part
is (<>), it also includes the
generic_formal_part
of the template for the formal package.
10.a
Ramification: If the
formal_package_actual_part is (<>),
then the declarations that occur immediately within the generic_formal_part
of the template for the formal package are visible outside the formal
package, and can be denoted by expanded names outside the formal package.
10.b
Reason: We always want
either the actuals or the formals of an instance to be namable from outside,
but never both. If both were namable, one would get some funny anomalies
since they denote the same entity, but, in the case of types at least,
they might have different and inconsistent sets of primitive operators
due to predefined operator ``reemergence.'' Formal derived types exacerbate
the difference. We want the implicit declarations of the generic_formal_part
as well as the explicit declarations, so we get operations on the formal
types.
10.c
Ramification: A generic
formal package is a package, and is an instance. Hence, it is possible
to pass a generic formal package as an actual to another generic formal
package.
Extensions to Ada 83
10.d
{extensions to Ada 83}
Formal packages are new to Ada 95.
Contents Index Search Previous Next Legal