Prev | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help


12.5 Formal Types -- TOC

(1)
A generic formal subtype can be used to pass to a generic unit a subtype whose type is in a certain class of types.
Syntax
(2)
       formal_type_declaration ::=
           type defining_identifier[discriminant_part] is formal_type_definition;
(3)
       formal_type_definition ::=
             formal_private_type_definition
           | formal_derived_type_definition
           | formal_discrete_type_definition
           | formal_signed_integer_type_definition
           | formal_modular_type_definition
           | formal_floating_point_definition
           | formal_ordinary_fixed_point_definition
           | formal_decimal_fixed_point_definition
           | formal_array_type_definition
           | formal_access_type_definition
Legality Rules
(4)
For a generic formal subtype, the actual shall be a subtype_mark; it denotes the (generic) actual subtype.
Static Semantics
(5)
A formal_type_declaration declares a (generic) formal type, and its first subtype, the (generic) formal subtype.
(6)
The form of a formal_type_definition determines a class to which the formal type belongs. For a formal_private_type_definition the reserved words tagged and limited indicate the class (see 12.5.1). For a formal_derived_type_definition the class is the derivation class rooted at the ancestor type. For other formal types, the name of the syntactic category indicates the class; a formal_discrete_type_definition defines a discrete type, and so on.
Legality Rules
(7)
The actual type shall be in the class determined for the formal.
Static Semantics
(8)
The formal type also belongs to each class that contains the determined class. The primitive subprograms of the type are as for any type in the determined class. For a formal type other than a formal derived type, these are the predefined operators of the type; they are implicitly declared immediately after the declaration of the formal type. In an instance, the copy of such an implicit declaration declares a view of the predefined operator of the actual type, even if this operator has been overridden for the actual type. The rules specific to formal derived types are given in 12.5.1.

(9)
(10)
Examples
(11)
Examples of generic formal types:
(12)
       type Item is private;
       type Buffer(Length : Natural) is limited private;
(13)
       type Enum  is (<>);
       type Int   is range <>;
       type Angle is delta <>;
       type Mass  is digits <>;
(14)
       type Table is array (Enum) of Item;
(15)
Example of a generic formal part declaring a formal integer type:
(16)
       generic
          type Rank is range <>;
          First  : Rank := Rank'First;
          Second : Rank := First + 1;  --  the operator "+" of the type Rank

Subclauses

  1. Formal Private and Derived Types
  2. Formal Scalar Types
  3. Formal Array Types
  4. Formal Access Types


Prev | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help

Ada WWW Home -- Email comments, additions, corrections, gripes, kudos, etc. to:

Magnus Kempe -- Magnus.Kempe@di.epfl.ch
Copyright statement
Page last generated: 95-03-12