13.4 Enumeration Representation Clauses

From OC Systems Wiki!
< Guide:95lrm
Revision as of 23:36, 4 May 2019 by imported>WikiVisor (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

An enumeration_representation_clause specifies the internal codes for enumeration literals.

Syntax

enumeration_representation_clause ::=
    for first_subtype_local_name use enumeration_aggregate;

enumeration_aggregate ::= array_aggregate

Name Resolution Rules

The 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.

Legality Rules

The first_subtype_local_name of an enumeration_representation_clause shall denote an enumeration subtype.

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.

Static Semantics

An 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.

Implementation Requirements

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.

Implementation Advice

The recommended level of support for enumeration_representation_clauses is:

  • An implementation should support at least the internal codes in the range System.Min_Int..System.Max_Int. An implementation need not support enumeration_representation_clauses for boolean types.

Notes

11  Unchecked_Conversion may be used to query the internal codes used for an enumeration type. The attributes of the type, such as Succ, Pred, and Pos, are unaffected by the enumeration_representation_clause. For example, Pos always returns the position number, not the internal integer code that might have been specified in a enumeration_representation_clause.

Examples

Example of an enumeration representation clause:

type Mix_Code is (ADD, SUB, MUL, LDA, STA, STZ);

for Mix_Code use 
    (ADD => 1, SUB => 2, MUL => 3, LDA => 8, STA => 24, STZ =>33);

Copyright © 1992,1993,1994,1995 Intermetrics, Inc.
Copyright © 2000 The MITRE Corporation, Inc. Ada Reference Manual