Contents   Index   Search   Previous   Next

12.7 Formal Packages

   [{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.]


formal_package_declaration ::=
    with package defining_identifier is new generic_package_name  formal_package_actual_part;
formal_package_actual_part ::=
    (<>) | [generic_actual_part]

Legality Rules

   {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.
   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:
Reason: We can't simply require full conformance between the two actual parameter expressions, because the two expressions are being evaluated at different times.
       {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

   A formal_package_declaration declares a generic formal package.
    {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.
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.
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.
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

{extensions to Ada 83} Formal packages are new to Ada 95.

Contents   Index   Search   Previous   Next   Legal