3.5.1 Enumeration Types
1
Syntax
2
3
4
Legality Rules
5/3
5.a/3
Proof: {
AI05-0227-1}
For character literals, this This
is a ramification of the normal disallowance of homographs explicitly
declared immediately in the same declarative region.
5.b/3
Reason: {
AI05-0227-1}
To ease implementation of the attribute Wide_Wide_Value,
we require that all enumeration literals have distinct images.
Static Semantics
6/3
6.a
Reason: This rule defines the profile
of the enumeration literal, which is used in the various types of conformance.
6.b
Ramification: The parameterless function
associated with an enumeration literal is fully defined by the
enumeration_type_definition;
a body is not permitted for it, and it never fails the Elaboration_Check
when called.
6.c/3
Discussion: {
AI05-0006-1}
The result subtype is primarily a concern when
an enumeration literal is used as the expression
of a case statement, due to the full coverage requirement based on the
nominal subtype.
7
Each enumeration literal corresponds to a distinct
value of the enumeration type, and to a distinct position number.
The
position number of the value of the first listed enumeration literal
is zero; the position number of the value of each subsequent enumeration
literal is one more than that of its predecessor in the list.
8
[The predefined order relations between values of
the enumeration type follow the order of corresponding position numbers.]
9
Dynamic Semantics
10
The
elaboration of an
enumeration_type_definition
creates the enumeration type and its first subtype, which is constrained
to the base range of the type.
10.a
Ramification: The first subtype of a
discrete type is always constrained, except in the case of a derived
type whose parent subtype is Whatever'Base.
11
When called, the parameterless function associated
with an enumeration literal returns the corresponding value of the enumeration
type.
12
27 If an enumeration literal occurs in
a context that does not otherwise suffice to determine the type of the
literal, then qualification by the name of the enumeration type is one
way to resolve the ambiguity (see
4.7).
Examples
13
Examples of enumeration
types and subtypes:
14
type Day is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
type Suit is (Clubs, Diamonds, Hearts, Spades);
type Gender is (M, F);
type Level is (Low, Medium, Urgent);
type Color is (White, Red, Yellow, Green, Blue, Brown, Black);
type Light is (Red, Amber, Green); -- Red and Green are overloaded
15
type Hexa is ('A', 'B', 'C', 'D', 'E', 'F');
type Mixed is ('A', 'B', '*', B, None, '?', '%');
16
subtype Weekday is Day range Mon .. Fri;
subtype Major is Suit range Hearts .. Spades;
subtype Rainbow is Color range Red .. Blue; -- the Color Red, not the Light
Wording Changes from Ada 83
16.a
16.b
We emphasize the fact that an enumeration literal
denotes a function, which is called to produce a value.
Incompatibilities With Ada 2005
16.c/3
{
AI05-0227-1}
Correction: Required
that all enumeration literals in a type have distinct images; this might
not be the case since upper case conversion can map distinct characters
to the same upper case character. This can only happen for identifiers
using Unicode characters first allowed by Ada 2005; moreover, the original
definition of Ada 2005 was confused and appeared to require inconsistent
results from the Image attribute, so implementations that allowed problematic
cases are rare; the problematic cases are very rare; so it is expected
that this change would only affect test programs.
Wording Changes from Ada 2005
16.d/3
{
AI05-0006-1}
Correction: Defined the result subtype of
an enumeration literal to close a minor language hole.
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe