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


3.4 Derived Types and Classes -- TOC

(1)
A derived_type_definition defines a new type (and its first subtype) whose characteristics are derived from those of a parent type.
Syntax
(2)
       derived_type_definition ::= [abstract] new parent_subtype_indication [record_extension_part]
Legality Rules
(3)
The parent_subtype_indication defines the parent subtype; its type is the parent type.
(4)
A type shall be completely defined (see 3.11.1) prior to being specified as the parent type in a derived_type_definition -- the full_type_declarations for the parent type and any of its subcomponents have to precede the derived_type_definition.
(5)
If there is a record_extension_part, the derived type is called a record extension of the parent type. A record_extension_part shall be provided if and only if the parent type is a tagged type.
Static Semantics
(6)
The first subtype of the derived type is unconstrained if a known_discriminant_part is provided in the declaration of the derived type, or if the parent subtype is unconstrained. Otherwise, the constraint of the first subtype corresponds to that of the parent subtype in the following sense: it is the same as that of the parent subtype except that for a range constraint (implicit or explicit), the value of each bound of its range is replaced by the corresponding value of the derived type.
(7)
The characteristics of the derived type are defined as follows:
(8)
(9)
(10)
(11)
(12)
(13)
(14)
(15)
(16)
(17)
(18)
(19)
(20)
(21)
(22)
(23)
If a primitive subprogram of the parent type is visible at the place of the derived_type_definition, then the corresponding inherited subprogram is implicitly declared immediately after the derived_type_definition. Otherwise, the inherited subprogram is implicitly declared later or not at all, as explained in 7.3.1.
(24)
A derived type can also be defined by a private_extension_declaration (see 7.3) or a formal_derived_type_definition (see 12.5.1). Such a derived type is a partial view of the corresponding full or actual type.
(25)
All numeric types are derived types, in that they are implicitly derived from a corresponding root numeric type (see 3.5.4 and 3.5.6).
Dynamic Semantics
(26)
The elaboration of a derived_type_definition creates the derived type and its first subtype, and consists of the elaboration of the subtype_indication and the record_extension_part, if any. If the subtype_indication depends on a discriminant, then only those expressions that do not depend on a discriminant are evaluated.
(27)
For the execution of a call on an inherited subprogram, a call on the corresponding primitive subprogram of the parent type is performed; the normal conversion of each actual parameter to the subtype of the corresponding formal parameter (see 6.4.1) performs any necessary type conversion as well. If the result type of the inherited subprogram is the derived type, the result of calling the parent's subprogram is converted to the derived type.

(28)
(29)
(30)
(31)
(32)
(33)
(34)
(35)
Examples
(36)
Examples of derived type declarations:
(37)
       type Local_Coordinate is new Coordinate;   --  two different types
       type Midweek is new Day range Tue .. Thu;  --  see 3.5.1
       type Counter is new Positive;              --  same range as Positive
(38)
       type Special_Key is new Key_Manager.Key;   --  see 7.3.1
         -- the inherited subprograms have the following specifications:
         --         procedure Get_Key(K : out Special_Key);
         --         function "<"(X,Y : Special_Key) return Boolean;

Subclauses

  1. Derivation Classes


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