record
component_list
end record
component_list ::=
component_declaration {component_declaration}
| {component_declaration} variant_part
| null
;
identifier_list : component_subtype_definition [:= expression];
null
and there is no discriminant part, then the record type has no components and all records of the type are null records.
type
DATE is
record
DAY : INTEGER range
1 .. 31;
MONTH : MONTH_NAME;
YEAR : INTEGER range
0 .. 4000;
end record
;
type
COMPLEX is
record
RE : REAL := 0.0;
IM : REAL := 0.0;
end record
;
TOMORROW, YESTERDAY : DATE;
A, B, C : COMPLEX;
-- initialized to zero
(discriminant_specification {; discriminant_specification})
discriminant_specification ::=
identifier_list : type_mark [:= expression]
in out
or out
, or as a generic actual parameter of mode in out
. The only allowed way to change the value of a discriminant of a variable is to assign a (complete) value to the variable itself. Similarly, an assignment to the variable itself is the only allowed way to change the constraint of one of its components, if the component subtype definition depends on a discriminant of the variable.
type
BUFFER(SIZE : BUFFER_SIZE := 100) is
-- see 3.5.4
record
POS : BUFFER_SIZE := 0;
VALUE : STRING(1 .. SIZE);
end record
;
type
SQUARE(SIDE : INTEGER) is
record
MAT : MATRIX(1 .. SIDE, 1 .. SIDE); -- see 3.6
end record
;
type
DOUBLE_SQUARE(NUMBER : INTEGER) is
record
LEFT : SQUARE(NUMBER);
RIGHT : SQUARE(NUMBER);
end record
;
type
ITEM(NUMBER : POSITIVE) is
record
CONTENT : INTEGER;
-- no component depends on the discriminant
end record
;
(discriminant_association {, discriminant_association})
discriminant_association ::=
[discriminant_simple_name
{| discriminant_simple_name} =>] expression
in
.
in
or if the subtype of the formal parameter is constrained.)
in out
, the discriminants are those of the renamed object or of the corresponding generic actual parameter.
LARGE : BUFFER(200); -- constrained, always 200 characters
-- (explicit discriminant value)
MESSAGE : BUFFER; -- unconstrained, initially 100 characters
-- (default discriminant value)
ILLEGAL : SQUARE; -- illegal, a SQUARE must be constrained
case
discriminant_simple_name is
variant
{variant}
end case
;
variant ::=
when
choice {| choice} =>
component_list
| discrete_range | others
| component_simple_name
others
is only allowed for the last variant and as its only choice; it stands for all values (possibly none) not given in the choices of previous variants. A component simple name is not allowed as a choice of a variant (although it is part of the syntax of choice).
null
, the variant has no components.
type
DEVICE is
(PRINTER, DISK, DRUM);
type
STATE is
(OPEN, CLOSED);
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
;
subtype
DRUM_UNIT is
PERIPHERAL(DRUM);
subtype
DISK_UNIT is
PERIPHERAL(DISK);
WRITER : PERIPHERAL(UNIT => PRINTER);
ARCHIVE : DISK_UNIT;
Yields the value TRUE if the discriminant constraint applies to the object A, or if the object is a constant (including a formal parameter or generic formal parameter of mode in
); yields the value FALSE otherwise. If A is a generic formal parameter of mode in out
, or if A is a formal parameter of mode in out
or out
and the type mark given in the corresponding parameter specification denotes an unconstrained type with discriminants, then the value of this attribute is obtained from that of the corresponding actual parameter. The value of this attri- bute is of the predefined type BOOLEAN.