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


3.2.2 Subtype Declarations

(1)
A subtype_declaration declares a subtype of some previously declared type, as defined by a subtype_indication.
Syntax
(2)
       subtype_declaration ::=
          subtype defining_identifier is subtype_indication;
(3)
       subtype_indication ::=  subtype_mark [constraint]
(4)
       subtype_mark ::= subtype_name
(5)
       constraint ::= scalar_constraint | composite_constraint
(6)
       scalar_constraint ::=
            range_constraint | digits_constraint | delta_constraint
(7)
       composite_constraint ::=
            index_constraint | discriminant_constraint
Name Resolution Rules
(8)
A subtype_mark shall resolve to denote a subtype. The type determined by a subtype_mark is the type of the subtype denoted by the subtype_mark.
Dynamic Semantics
(9)
The elaboration of a subtype_declaration consists of the elaboration of the subtype_indication. The elaboration of a subtype_indication creates a new subtype. If the subtype_indication does not include a constraint, the new subtype has the same (possibly null) constraint as that denoted by the subtype_mark. The elaboration of a subtype_indication that includes a constraint proceeds as follows:
(10)
(11)
(12)
The condition imposed by a constraint is the condition obtained after elaboration of the constraint. The rules defining compatibility are given for each form of constraint in the appropriate subclause. These rules are such that if a constraint is compatible with a subtype, then the condition imposed by the constraint cannot contradict any condition already imposed by the subtype on its values. The exception Constraint_Error is raised if any check of compatibility fails.

(13)
Examples
(14)
Examples of subtype declarations:
(15)
       subtype Rainbow   is Color range Red .. Blue;        --  see 3.2.1
       subtype Red_Blue  is Rainbow;
       subtype Int       is Integer;
       subtype Small_Int is Integer range -10 .. 10;
       subtype Up_To_K   is Column range 1 .. K;            --  see 3.2.1
       subtype Square    is Matrix(1 .. 10, 1 .. 10);       --  see 3.6
       subtype Male      is Person(Sex => M);               --  see 3.10.1

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