generic_specification ::=
generic_formal_part subprogram_specification
| generic_formal_part package_specification
generic
{generic_parameter_declaration}
identifier_list : [in
[out
]] type_mark [:= expression];
| type
identifier is
generic_type_definition;
| private_type_declaration
| with
subprogram_specification [is
name];
| with
subprogram_specification [is
<>];
(<>) | range
<> | digits
<> | delta
<>
| array_type_definition | access_type_definition
generic
-- parameterless generic
SIZE : NATURAL; -- formal object generic
LENGTH : INTEGER := 200; -- formal object with a default
-- expression
AREA : INTEGER := LENGTH*LENGTH; -- formal object with a
-- default expression
generic
type
ITEM is private
; -- formal type
type
INDEX is
(<>); -- formal type
type
ROW is array
(INDEX range
<>) of
ITEM; -- formal type
with function
"<"(X, Y : ITEM) return
BOOLEAN; -- formal
-- subprogram
generic
type
ELEM is private
;
procedure
EXCHANGE(U, V : in out
ELEM); generic
type
ITEM is private
;
with
function
"*"(U, V : ITEM) return
ITEM is
<>;
function
SQUARING(X : ITEM) return
ITEM;
generic
type
ITEM is private
;
type
VECTOR is array
(POSITIVE range <>) of
ITEM;
with
function
SUM(X, Y : ITEM) return
ITEM;
package
ON_VECTORS is
function
SUM (A, B : VECTOR) return
VECTOR;
function
SIGMA(A : VECTOR) return
ITEM;
LENGTH_ERROR : exception
;
end
;
new
in a (recursive) generic instantiation.
in
, or a constituent of an entry name given as default name for a formal subprogram, or the default expression for a parameter of a formal subprogram. Default expressions for generic formal objects and default names for formal subprograms are only evaluated for generic instantiations that use such defaults. Default expressions for parameters of formal subprograms are only evaluated for calls of the formal subprograms that use such defaults. (The usual visibility rules apply to any name used in a default expression: the denoted entity must therefore be visible at the place of the expression.)
in
or in out
. In the absence of an explicit mode indication in a generic parameter declaration, the mode in is assumed; otherwise the mode is the one indicated. If a generic parameter declaration ends with an expression, the expression is the default expression of the generic formal parameter. A default expression is only allowed if the mode is in
(whether this mode is indicated explicitly or implicitly). The type of a default expression must be that of the corresponding generic formal parameter.
in
is a constant whose value is a copy of the value supplied as the matching generic actual parameter in a generic instantiation, as described in section 12.3. The type of a generic formal object of mode in
must not be a limited type; the subtype of such a generic formal object is the subtype denoted by the type mark given in the generic parameter declaration.
in out
is a variable and denotes the object supplied as the matching generic actual parameter in a generic instantiation, as described in section 12.3. The constraints that apply to the generic formal object are those of the corresponding generic actual parameter.
in out
are those of the corresponding generic actual parameter (not those implied by the type mark that appears in the generic parameter declaration). Whenever possible (to avoid confusion) it is recommended that the name of a base type be used for the declaration of such a formal object. If, however, the base type is anonymous, it is recommended that the subtype name defined by the type declaration for the base type be used.
The available operations are the operations common to enumeration and integer types; these are defined in section 3.5.5.
range
<>
The available operations are the operations of integer types defined in section 3.5.5.
digits
<>
The available operations are those defined in section 3.5.8.
delta
<>
The available operations are those defined in section 3.5.10.
type
ITEM is private
;
type
BUFFER(LENGTH : NATURAL) is limited private
; type
ENUM is
(<>); type
INT is range
<>; type
ANGLE is delta
<>; type
MASS is digits
<>; type
TABLE is array
(ENUM) of
ITEM;
generic
type
RANK is range
<>;
FIRST : RANK := RANK'FIRST;
SECOND : RANK := FIRST + 1; -- the operator "+" of the
-- type RANK
is
and either a box or the name of a subprogram or entry. The matching rules for these defaults are explained in section 12.3.6.
with function
INCREASE(X : INTEGER) return
INTEGER; with function
SUM(X, Y : ITEM) return
ITEM; with function
"+"(X, Y : ITEM) return
ITEM is
<>; with function
IMAGE(X : ENUM) return
STRING is
ENUM'IMAGE; with procedure
UPDATE is
DEFAULT_UPDATE;