3.8.1 Variant Parts and Discrete Choices
1
Syntax
2
3
4
5
Name Resolution Rules
6
Legality Rules
7
The discriminant of the
variant_part
shall be of a discrete type.
8
9
10
11
12
13
14
The possible values
of the discriminant of a
variant_part
shall be covered as follows:
15
- If the discriminant is of a static
constrained scalar subtype, then each non-others discrete_choice
shall cover only values in that subtype, and each value of that subtype
shall be covered by some discrete_choice
(either explicitly or by others);
16
- 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
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;