13.4 Enumeration Representation Clauses
This Reference Manual output has not been verified, and may contain omissions or errors. Report any problems on the tracking issue
enumeration_representation_clause specifies the internal codes for enumeration literals.]
Name Resolution Rules4
enumeration_aggregate shall be written as a one-dimensional
array_aggregate, for which the index subtype is the unconstrained subtype of the enumeration type, and each component expression is expected to be of any integer type.
aggregates applies. An others is not allowed — there is no applicable index constraint in this context.
local_name of an
enumeration_representation_clause shall denote an enumeration subtype.
local_nameis required to denote a first subtype.
Each component of the
array_aggregate shall be given by an
expression rather than a <>. The
expressions given in the
array_aggregate shall be static, and shall specify distinct integer codes for each value of the enumeration type; the associated integer codes shall satisfy the predefined ordering relation of the type.
enumeration_representation_clause specifies the coding aspect of representation. The coding consists of the internal code for each enumeration literal, that is, the integral value used internally to represent each literal.
enumeration_representation_clause, not by an
For nonboolean enumeration types, if the coding is not specified for the type, then for each value of the type, the internal code shall be equal to its position number.
The recommended level of support for
- An implementation should support at least the internal codes in the range System.Min_Int .. System.Max_Int. An implementation is not required to support
enumeration_representation_clauses for boolean types.
enumeration_representation_clauses should be followed.
For every discrete subtype S, the following attributes are defined:
- S'Enum_Rep denotes a function with the following specification:
function S'Enum_Rep (Arg : S'Base) return universal_integer
- This function returns the representation value of the value of Arg, as a value of type universal_integer. The representation value is the internal code specified in an enumeration representation clause, if any, for the type corresponding to the value of Arg, and otherwise is the position number of the value.
- S'Enum_Val denotes a function with the following specification:
function S'Enum_Val (Arg : universal_integer) return S'Base
- This function returns a value of the type of S whose representation value equals the value of Arg. For the evaluation of a call on S'Enum_Val, if there is no value in the base range of its type with the given representation value, Constraint_Error is raised.
enumeration_representation_clause. For example, Pos always returns the position number, not an internal integer code that was specified in an
type T1 is (Red, Green, Blue);
subtype S1 is T1 range Red .. Green;
type S2 is new S1;
for S2 use (Red => 10, Green => 20, Blue => 30);
enumeration_representation_clausehas to specify values for all enumerals, even ones that are not in S2 (such as Blue). The Base attribute can be used to get at these values. For example:
for I in S2'Base loop
... -- When I equals Blue, the internal code is 30.
Examples of enumeration representation clauses :
type Mix_Code is (ADD, SUB, MUL, LDA, STA, STZ); 14for Mix_Code use (ADD => 1, SUB => 2, MUL => 3, LDA => 8, STA => 24, STZ =>33); 15/5-- See 3.5.2. for Roman_Digit use ('I' => 1, 'V' => 5, 'X' => 10, 'L' => 50, 'C' => 100, 'D' => 500, 'M' => 1000); 16/5-- For an example of the use of attribute Enum_Rep, see 4.2.1.
Extensions to Ada 83
enumeration_aggregate. The preference rules for the predefined operators of root_integer eliminate any ambiguity.
Wording Changes from Ada 95
enumeration_representation_clause. (<> is newly added to