Go to the first, previous, next, last section, table of contents.
-
A subtype_declaration declares a subtype of some previously declared
type, as defined by a subtype_indication.
Syntax
-
subtype_declaration ::=
subtype defining_identifier is subtype_indication;
-
subtype_indication ::= subtype_mark [constraint]
-
subtype_mark ::= subtype_name
-
constraint ::= scalar_constraint | composite_constraint
-
scalar_constraint ::=
range_constraint | digits_constraint | delta_constraint
-
composite_constraint ::=
index_constraint | discriminant_constraint
Name Resolution Rules
-
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
-
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:
-
The constraint is first elaborated.
-
A check is then made that the constraint is compatible with the subtype
denoted by the subtype_mark.
-
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.
NOTES
-
(4) A scalar_constraint may be applied to a subtype of an appropriate
scalar type, See section 3.5 Scalar Types, See section 3.5.9 Fixed Point Types, and See section J.3 Reduced Accuracy Subtypes, even if the
subtype is already constrained. On the other hand, a
composite_constraint may be applied to a composite subtype (or an
access-to-composite subtype) only if the composite subtype is
unconstrained, See section 3.6.1 Index Constraints and Discrete Ranges and See section 3.7.1 Discriminant Constraints.
Examples
-
Examples of subtype declarations:
-
subtype Rainbow is Color range Red .. Blue; -- See section 3.2.1 Type Declarations
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 section 3.2.1 Type Declarations
subtype Square is Matrix(1 .. 10, 1 .. 10); -- See section 3.6 Array Types
subtype Male is Person(Sex => M); -- See section 3.10.1 Incomplete Type Declarations
Go to the first, previous, next, last section, table of contents.