3.8.1 Variant Parts and Discrete Choices
1
Syntax
2
3
4
5/3
Name Resolution Rules
6
Legality Rules
7
The discriminant of the
variant_part
shall be of a discrete type.
8/3
9
10/3
10.1/3
11/3
12
13
14
The possible values
of the discriminant of a
variant_part
shall be covered as follows:
15/3
If the discriminant is of a static constrained
scalar subtype then, except within an instance of a generic unit, each
non-
others discrete_choice
shall cover only values in that subtype that satisfy its predicate, and
each value of that subtype that satisfies its predicate shall be covered
by some
discrete_choice
(either explicitly or by
others);
16/3
If the type of the discriminant is a descendant
of a generic formal scalar type, then the
variant_part
shall have an
others discrete_choice;
17
Otherwise, each value of the base range of the
type of the discriminant shall be covered (either explicitly or by others).
18
Static Semantics
19
20
Dynamic Semantics
21
21.1/3
22
Examples
23
Example of record
type with a variant part:
24
type Device is (Printer, Disk, Drum);
type State is (Open, Closed);
25
type Peripheral(Unit : Device := Disk) is
record
Status : State;
case Unit is
when Printer =>
Line_Count : Integer range 1 .. Page_Size;
when others =>
Cylinder : Cylinder_Index;
Track : Track_Number;
end case;
end record;
26
Examples of record
subtypes:
27
subtype Drum_Unit is Peripheral(Drum);
subtype Disk_Unit is Peripheral(Disk);
28
Examples of constrained
record variables:
29
Writer : Peripheral(Unit => Printer);
Archive : Disk_Unit;
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe