Contents   Index   Search   Previous   Next


4.2 Literals

1
   [{literal} A literal represents a value literally, that is, by means of notation suited to its kind.] A literal is either a numeric_literal, a character_literal, the literal null, or a string_literal. {constant: See also literal}
1.a
Discussion: An enumeration literal that is an identifier rather than a character_literal is not considered a literal in the above sense, because it involves no special notation ``suited to its kind.'' It might more properly be called an enumeration_identifier, except for historical reasons.

Name Resolution Rules

2
   {expected type (null literal) [partial]} The expected type for a literal null shall be a single access type.
2.a
Discussion: This new wording ("expected type ... shall be a single ... type") replaces the old "shall be determinable" stuff. It reflects an attempt to simplify and unify the description of the rules for resolving aggregates, literals, type conversions, etc. See 8.6, ``The Context of Overload Resolution'' for the details.
3
   {expected type (character_literal) [partial]} {expected profile (character_literal) [partial]} For a name that consists of a character_literal, either its expected type shall be a single character type, in which case it is interpreted as a parameterless function_call that yields the corresponding value of the character type, or its expected profile shall correspond to a parameterless function with a character result type, in which case it is interpreted as the name of the corresponding parameterless function declared as part of the character type's definition (see 3.5.1). In either case, the character_literal denotes the enumeration_literal_specification.
3.a
Discussion: See 4.1.3 for the resolution rules for a selector_name that is a character_literal.
4
   {expected type (string_literal) [partial]} The expected type for a primary that is a string_literal shall be a single string type.

Legality Rules

5
   A character_literal that is a name shall correspond to a defining_character_literal of the expected type, or of the result type of the expected profile.
6
   For each character of a string_literal with a given expected string type, there shall be a corresponding defining_character_literal of the component type of the expected string type.
7
   A literal null shall not be of an anonymous access type[, since such types do not have a null value (see 3.10)].
7.a
Reason: This is a legality rule rather than an overloading rule, to simplify implementations.

Static Semantics

8
   An integer literal is of type universal_integer. A real literal is of type universal_real.

Dynamic Semantics

9
   {evaluation (numeric literal) [partial]} {evaluation (null literal) [partial]} {null access value} {null pointer: See null access value} The evaluation of a numeric literal, or the literal null, yields the represented value.
10
    {evaluation (string_literal) [partial]} The evaluation of a string_literal that is a primary yields an array value containing the value of each character of the sequence of characters of the string_literal, as defined in 2.6. The bounds of this array value are determined according to the rules for positional_array_aggregates (see 4.3.3), except that for a null string literal, the upper bound is the predecessor of the lower bound.
11
    {Range_Check [partial]} {check, language-defined (Range_Check)} For the evaluation of a string_literal of type T, a check is made that the value of each character of the string_literal belongs to the component subtype of T. For the evaluation of a null string literal, a check is made that its lower bound is greater than the lower bound of the base range of the index type. {Constraint_Error (raised by failure of run-time check)} The exception Constraint_Error is raised if either of these checks fails.
11.a
Ramification: The checks on the characters need not involve more than two checks altogether, since one need only check the characters of the string with the lowest and highest position numbers against the range of the component subtype.
NOTES
12
6  Enumeration literals that are identifiers rather than character_literals follow the normal rules for identifiers when used in a name (see 4.1 and 4.1.3). Character_literals used as selector_names follow the normal rules for expanded names (see 4.1.3).

Examples

13
    Examples of literals:
14
3.14159_26536    --  a real literal
1_345            --  an integer literal
'A'              --  a character literal
"Some Text"      --  a string literal 

Incompatibilities With Ada 83

14.a
{incompatibilities with Ada 83} Because character_literals are now treated like other literals, in that they are resolved using context rather than depending on direct visibility, additional qualification might be necessary when passing a character_literal to an overloaded subprogram.

Extensions to Ada 83

14.b
{extensions to Ada 83} Character_literals are now treated analogously to null and string_literals, in that they are resolved using context, rather than their content; the declaration of the corresponding defining_character_literal need not be directly visible.

Wording Changes from Ada 83

14.c
Name Resolution rules for enumeration literals that are not character_literals are not included anymore, since they are neither syntactically nor semantically "literals" but are rather names of parameterless functions.

Contents   Index   Search   Previous   Next   Legal