

                          4   Names and Expressions


1/3 The rules applicable to the different forms of name and expression, and to
their evaluation, are given in this clause.


4.1 Names


1   Names can denote declared entities, whether declared explicitly or
implicitly (see 3.1). Names can also denote objects or subprograms designated
by access values; the results of type_conversions or function_calls;
subcomponents and slices of objects and values; protected subprograms, single
entries, entry families, and entries in families of entries. Finally, names
can denote attributes of any of the foregoing.


                                   Syntax

2/5     name ::= 
             direct_name          | explicit_dereference
           | indexed_component    | slice
           | selected_component   | attribute_reference
           | type_conversion      | function_call
           | character_literal    | qualified_expression
           | generalized_reference | generalized_indexing
           | target_name

3       direct_name ::= identifier | operator_symbol

4       prefix ::= name | implicit_dereference

5       explicit_dereference ::= name.all

6       implicit_dereference ::= name

7/3 Certain forms of name (indexed_components, selected_components, slices,
and attribute_references) include a prefix that is either itself a name that
denotes some related entity, or an implicit_dereference of an access value
that designates some related entity.


                            Name Resolution Rules

8   The name in a dereference (either an implicit_dereference or an
explicit_dereference) is expected to be of any access type.


                              Static Semantics

9/3 If the type of the name in a dereference is some access-to-object type T,
then the dereference denotes a view of an object, the nominal subtype of the
view being the designated subtype of T. If the designated subtype has
unconstrained discriminants, the (actual) subtype of the view is constrained
by the values of the discriminants of the designated object, except when there
is a partial view of the type of the designated subtype that does not have
discriminants, in which case the dereference is not constrained by its
discriminant values.

10  If the type of the name in a dereference is some access-to-subprogram type
S, then the dereference denotes a view of a subprogram, the profile of the
view being the designated profile of S.


                              Dynamic Semantics

11/2 The evaluation of a name determines the entity denoted by the name. This
evaluation has no other effect for a name that is a direct_name or a
character_literal.

12  The evaluation of a name that has a prefix includes the evaluation of the
prefix. The evaluation of a prefix consists of the evaluation of the name or
the implicit_dereference. The prefix denotes the entity denoted by the name or
the implicit_dereference.

13  The evaluation of a dereference consists of the evaluation of the name and
the determination of the object or subprogram that is designated by the value
of the name. A check is made that the value of the name is not the null access
value. Constraint_Error is raised if this check fails. The dereference denotes
the object or subprogram designated by the value of the name.


                                  Examples

14  Examples of direct names:

15      Pi        -- the direct name of a number                 (see 3.3.2)
        Limit     -- the direct name of a constant               (see 3.3.1)
        Count     -- the direct name of a scalar variable        (see 3.3.1)
        Board     -- the direct name of an array variable        (see 3.6.1)
        Matrix    -- the direct name of a type                   (see 3.6)
        Random    -- the direct name of a function               (see 6.1)
        Error     -- the direct name of an exception             (see 11.1)

16  Examples of dereferences:

17      Next_Car.all          
        --  explicit dereference denoting the object designated by
                              --  the access variable Next_Car (see 3.10.1)
        Next_Car.Owner        
        --  selected component with implicit dereference;
                              --  same as Next_Car.all.Owner


4.1.1 Indexed Components


1   An indexed_component denotes either a component of an array or an entry in
a family of entries.


                                   Syntax

2       indexed_component ::= prefix(expression {, expression})


                            Name Resolution Rules

3   The prefix of an indexed_component with a given number of expressions
shall resolve to denote an array (after any implicit dereference) with the
corresponding number of index positions, or shall resolve to denote an entry
family of a task or protected object (in which case there shall be only one
expression).

4   The expected type for each expression is the corresponding index type.


                              Static Semantics

5   When the prefix denotes an array, the indexed_component denotes the
component of the array with the specified index value(s). The nominal subtype
of the indexed_component is the component subtype of the array type.

6   When the prefix denotes an entry family, the indexed_component denotes the
individual entry of the entry family with the specified index value.


                              Dynamic Semantics

7   For the evaluation of an indexed_component, the prefix and the
expressions are evaluated in an arbitrary order. The value of each
expression is converted to the corresponding index type. A check is made that
each index value belongs to the corresponding index range of the array or
entry family denoted by the prefix. Constraint_Error is raised if this check
fails.


                                  Examples

8   Examples of indexed components:

9        My_Schedule(Sat)     --  a component of a one-dimensional array               
        (see 3.6.1)
         Page(10)             --  a component of a one-dimensional array               
        (see 3.6)
         Board(M, J + 1)      --  a component of a two-dimensional array               
        (see 3.6.1)
         Page(10)(20)         --  a component of a component                           
        (see 3.6)
         Request(Medium)      --  an entry in a family of entries                      
        (see 9.1)
         Next_Frame(L)(M, N)  --  a component of a function call                       
        (see 6.1)

        NOTES

10      1  Notes on the examples: Distinct notations are used for components
        of multidimensional arrays (such as Board) and arrays of arrays (such
        as Page). The components of an array of arrays are arrays and can
        therefore be indexed. Thus Page(10)(20) denotes the 20th component of
        Page(10). In the last example Next_Frame(L) is a function call
        returning an access value that designates a two-dimensional array.


4.1.2 Slices


1   A slice denotes a one-dimensional array formed by a sequence of
consecutive components of a one-dimensional array. A slice of a variable is a
variable; a slice of a constant is a constant; a slice of a value is a value.


                                   Syntax

2       slice ::= prefix(discrete_range)


                            Name Resolution Rules

3   The prefix of a slice shall resolve to denote a one-dimensional array
(after any implicit dereference).

4   The expected type for the discrete_range of a slice is the index type of
the array type.


                              Static Semantics

5   A slice denotes a one-dimensional array formed by the sequence of
consecutive components of the array denoted by the prefix, corresponding to
the range of values of the index given by the discrete_range.

6   The type of the slice is that of the prefix. Its bounds are those defined
by the discrete_range.


                              Dynamic Semantics

7   For the evaluation of a slice, the prefix and the discrete_range are
evaluated in an arbitrary order. If the slice is not a null slice (a slice
where the discrete_range is a null range), then a check is made that the
bounds of the discrete_range belong to the index range of the array denoted by
the prefix. Constraint_Error is raised if this check fails.

        NOTES

8       2  A slice is not permitted as the prefix of an Access
        attribute_reference, even if the components or the array as a whole
        are aliased. See 3.10.2.

9       3  For a one-dimensional array A, the slice A(N .. N) denotes an array
        that has only one component; its type is the type of A. On the other
        hand, A(N) denotes a component of the array A and has the
        corresponding component type.


                                  Examples

10  Examples of slices:

11        Stars(1 .. 15)        --  a slice of 15 characters                   
        (see 3.6.3)
          Page(10 .. 10 + Size) --  a slice of 1 + Size components             
        (see 3.6)
          Page(L)(A .. B)       --  a slice of the array Page(L)               
        (see 3.6)
          Stars(1 .. 0)         --  a null slice                               
        (see 3.6.3)
          My_Schedule(Weekday)  --  bounds given by subtype                    
        (see 3.6.1 and 3.5.1)
          Stars(5 .. 15)(K)     --  same as Stars(K)                           
        (see 3.6.3)
                                --  provided that K is in 5 .. 15


4.1.3 Selected Components


1   Selected_components are used to denote components (including
discriminants), entries, entry families, and protected subprograms; they are
also used as expanded names as described below.


                                   Syntax

2       selected_component ::= prefix . selector_name

3       selector_name ::= identifier | character_literal | operator_symbol


                            Name Resolution Rules

4   A selected_component is called an expanded name if, according to the
visibility rules, at least one possible interpretation of its prefix denotes a
package or an enclosing named construct (directly, not through a
subprogram_renaming_declaration or generic_renaming_declaration).

5   A selected_component that is not an expanded name shall resolve to denote
one of the following:

6     * A component (including a discriminant):

7       The prefix shall resolve to denote an object or value of some
        non-array composite type (after any implicit dereference). The
        selector_name shall resolve to denote a discriminant_specification of
        the type, or, unless the type is a protected type, a
        component_declaration of the type. The selected_component denotes the
        corresponding component of the object or value.

8     * A single entry, an entry family, or a protected subprogram:

9       The prefix shall resolve to denote an object or value of some task or
        protected type (after any implicit dereference). The selector_name
        shall resolve to denote an entry_declaration or
        subprogram_declaration occurring (implicitly or explicitly) within the
        visible part of that type. The selected_component denotes the
        corresponding entry, entry family, or protected subprogram.

9.1/2   * A view of a subprogram whose first formal parameter is of a tagged
        type or is an access parameter whose designated type is tagged:

9.2/3   The prefix (after any implicit dereference) shall resolve to denote an
        object or value of a specific tagged type T or class-wide type
        T'Class. The selector_name shall resolve to denote a view of a
        subprogram declared immediately within the declarative region in which
        an ancestor of the type T is declared. The first formal parameter of
        the subprogram shall be of type T, or a class-wide type that covers T,
        or an access parameter designating one of these types. The designator
        of the subprogram shall not be the same as that of a component of the
        tagged type visible at the point of the selected_component. The
        subprogram shall not be an implicitly declared primitive operation of
        type T that overrides an inherited subprogram implemented by an entry
        or protected subprogram visible at the point of the
        selected_component. The selected_component denotes a view of this
        subprogram that omits the first formal parameter. This view is called
        a prefixed view of the subprogram, and the prefix of the
        selected_component (after any implicit dereference) is called the
        prefix of the prefixed view.

10  An expanded name shall resolve to denote a declaration that occurs
immediately within a named declarative region, as follows:

11    * The prefix shall resolve to denote either a package (including the
        current instance of a generic package, or a rename of a package), or
        an enclosing named construct.

12    * The selector_name shall resolve to denote a declaration that occurs
        immediately within the declarative region of the package or enclosing
        construct (the declaration shall be visible at the place of the
        expanded name - see 8.3). The expanded name denotes that declaration.

13    * If the prefix does not denote a package, then it shall be a
        direct_name or an expanded name, and it shall resolve to denote a
        program unit (other than a package), the current instance of a type, a
        block_statement, a loop_statement, or an accept_statement (in the case
        of an accept_statement or entry_body, no family index is allowed); the
        expanded name shall occur within the declarative region of this
        construct. Further, if this construct is a callable construct and the
        prefix denotes more than one such enclosing callable construct, then
        the expanded name is ambiguous, independently of the selector_name.


                               Legality Rules

13.1/5 For a prefixed view of a subprogram whose first parameter is an access
parameter, the prefix shall be legal as the prefix of an Access attribute
reference.

13.2/2 For a subprogram whose first parameter is of mode in out or out, or of
an anonymous access-to-variable type, the prefix of any prefixed view shall
denote a variable.


                              Dynamic Semantics

14  The evaluation of a selected_component includes the evaluation of the
prefix.

15  For a selected_component that denotes a component of a variant, a check is
made that the values of the discriminants are such that the value or object
denoted by the prefix has this component. The exception Constraint_Error is
raised if this check fails.


                                  Examples

16  Examples of selected components:

17/5      Tomorrow.Month     --  a record component                               
        (see 3.8)
          Next_Car.Owner     --  a record component                               
        (see 3.10.1)
          Next_Car.Owner.Age --  a record component                               
        (see 3.10.1)
                             --  the previous two lines involve implicit dereferences
          Writer.Unit        --  a record component (a discriminant)              
        (see 3.8.1)
          Min_Cell(H).Value  --  a record component of the result                 
        (see 6.1)
                             --  of the function call Min_Cell(H)
          Cashier.Append     --  a prefixed view of a procedure                   
        (see 3.9.4)
          Control.Seize      --  an entry of a protected object                   
        (see 9.4)
          Pool(K).Write      --  an entry of the task Pool(K)                     
        (see 9.1)

18  Examples of expanded names:

19        Key_Manager."<"      --  an operator of the visible part of a package           
        (see 7.3.1)
          Dot_Product.Sum      --  a variable declared in a function body                 
        (see 6.1)
          Buffer.Pool          --  a variable declared in a protected unit                
        (see 9.11)
          Buffer.Read          --  an entry of a protected unit                           
        (see 9.11)
          Swap.Temp            --  a variable declared in a block statement               
        (see 5.6)
          Standard.Boolean     --  the name of a predefined type                          
        (see A.1)


4.1.4 Attributes


1   An attribute is a characteristic of an entity that can be queried via an
attribute_reference or a range_attribute_reference.


                                   Syntax

2/5     attribute_reference ::= 
            prefix'attribute_designator
          | reduction_attribute_reference

3/2     attribute_designator ::= 
            identifier[(static_expression)]
          | Access | Delta | Digits | Mod

4       range_attribute_reference ::= prefix'range_attribute_designator

5       range_attribute_designator ::= Range[(static_expression)]


                            Name Resolution Rules

6/5 In an attribute_reference that is not a reduction_attribute_reference, if
the attribute_designator is for an attribute defined for (at least some)
objects of an access type, then the prefix is never interpreted as an
implicit_dereference; otherwise (and for all range_attribute_references and
reduction_attribute_references), if there is a prefix and the type of the
name within the prefix is of an access type, the prefix is interpreted as an
implicit_dereference. Similarly, if the attribute_designator is for an
attribute defined for (at least some) functions, then the prefix is never
interpreted as a parameterless function_call; otherwise (and for all
range_attribute_references and reduction_attribute_references), if there is a
prefix and the prefix consists of a name that denotes a function, it is
interpreted as a parameterless function_call.

7   The expression, if any, in an attribute_designator or
range_attribute_designator is expected to be of any integer type.


                               Legality Rules

8   The expression, if any, in an attribute_designator or
range_attribute_designator shall be static.


                              Static Semantics

9/4 An attribute_reference denotes a value, an object, a subprogram, or some
other kind of program entity. Unless explicitly specified otherwise, for an
attribute_reference that denotes a value or an object, if its type is scalar,
then its nominal subtype is the base subtype of the type; if its type is
tagged, its nominal subtype is the first subtype of the type; otherwise, its
nominal subtype is a subtype of the type without any constraint,
null_exclusion, or predicate. Similarly, unless explicitly specified
otherwise, for an attribute_reference that denotes a function, when its result
type is scalar, its result subtype is the base subtype of the type, when its
result type is tagged, the result subtype is the first subtype of the type,
and when the result type is some other type, the result subtype is a subtype
of the type without any constraint, null_exclusion, or predicate.

10  A range_attribute_reference X'Range(N) is equivalent to the range
X'First(N) .. X'Last(N), except that the prefix is only evaluated once.
Similarly, X'Range is equivalent to X'First .. X'Last, except that the
prefix is only evaluated once.


                              Dynamic Semantics

11/5 The evaluation of a range_attribute_reference or an attribute_reference
that is not a reduction_attribute_reference consists of the evaluation of the
prefix. The evaluation of a reduction_attribute_reference is defined in
4.5.10.


                         Implementation Permissions

12/1 An implementation may provide implementation-defined attributes; the
identifier for an implementation-defined attribute shall differ from those of
the language-defined attributes unless supplied for compatibility with a
previous edition of this International Standard.

        NOTES

13      4  Attributes are defined throughout this International Standard, and
        are summarized in K.2.

14/2    5  In general, the name in a prefix of an attribute_reference (or a
        range_attribute_reference) has to be resolved without using any
        context. However, in the case of the Access attribute, the expected
        type for the attribute_reference has to be a single access type, and
        the resolution of the name can use the fact that the type of the
        object or the profile of the callable entity denoted by the prefix has
        to match the designated type or be type conformant with the designated
        profile of the access type.


                                  Examples

15  Examples of attributes:

16      Color'First        -- minimum value of the enumeration type Color              
        (see 3.5.1)
        Rainbow'Base'First -- same as Color'First                                      
        (see 3.5.1)
        Real'Digits        -- precision of the type Real                               
        (see 3.5.7)
        Board'Last(2)      -- upper bound of the second dimension of Board             
        (see 3.6.1)
        Board'Range(1)     -- index range of the first dimension of Board              
        (see 3.6.1)
        Pool(K)'Terminated -- True if task Pool(K) is terminated                       
        (see 9.1)
        Date'Size          -- number of bits for records of type Date                  
        (see 3.8)
        Message'Address    -- address of the record variable Message                   
        (see 3.7.1)


4.1.5 User-Defined References



                              Static Semantics

1/3 Given a discriminated type T, the following type-related operational
aspect may be specified:

2/3 Implicit_Dereference
                This aspect is specified by a name that denotes an access
                discriminant declared for the type T.

3/3 A (view of a) type with a specified Implicit_Dereference aspect is a
reference type. A reference object is an object of a reference type. The
discriminant named by the Implicit_Dereference aspect is the reference
discriminant of the reference type or reference object. A
generalized_reference is a name that identifies a reference object, and
denotes the object or subprogram designated by the reference discriminant of
the reference object.


                                   Syntax

4/3     generalized_reference ::= reference_object_name


                            Name Resolution Rules

5/3 The expected type for the reference_object_name in a
generalized_reference is any reference type.


                              Static Semantics

5.1/4 The Implicit_Dereference aspect is nonoverridable (see 13.1.1).

6/3 A generalized_reference denotes a view equivalent to that of a dereference
of the reference discriminant of the reference object.

7/5 Given a reference type T, the Implicit_Dereference aspect is inherited by
descendants of type T if not overridden (which is only permitted if
confirming). If a descendant type constrains the value of the reference
discriminant of T by a new discriminant, that new discriminant is the
reference discriminant of the descendant. If the descendant type constrains
the value of the reference discriminant of T by an expression other than the
name of a new discriminant, a generalized_reference that identifies an object
of the descendant type denotes the object or subprogram designated by the
value of this constraining expression.


                              Dynamic Semantics

8/3 The evaluation of a generalized_reference consists of the evaluation of
the reference_object_name and a determination of the object or subprogram
designated by the reference discriminant of the named reference object. A
check is made that the value of the reference discriminant is not the null
access value. Constraint_Error is raised if this check fails. The
generalized_reference denotes the object or subprogram designated by the value
of the reference discriminant of the named reference object.


                                  Examples

9/3     type Barrel is tagged ...  -- holds objects of type Element

10/3    type Ref_Element(Data : access Element) is limited private
           with Implicit_Dereference => Data;
              -- This Ref_Element type is a "reference" type.
              -- "Data" is its reference discriminant.

11/3    function Find (B : aliased in out Barrel; Key : String) return Ref_Element;
           -- Return a reference to an element of a barrel.

12/3    B: aliased Barrel;

13/3    ...

14/3    Find (B, "grape") := Element'(...);  -- Assign through a reference.

15/3    -- This is equivalent to:
        Find (B, "grape").Data.all := Element'(...);


4.1.6 User-Defined Indexing



                              Static Semantics

1/3 Given a tagged type T, the following type-related, operational aspects may
be specified:

2/3 Constant_Indexing
                This aspect shall be specified by a name that denotes one or
                more functions declared immediately within the same
                declaration list in which T is declared. All such functions
                shall have at least two parameters, the first of which is of
                type T or T'Class, or is an access-to-constant parameter with
                designated type T or T'Class.

3/3 Variable_Indexing
                This aspect shall be specified by a name that denotes one or
                more functions declared immediately within the same
                declaration list in which T is declared. All such functions
                shall have at least two parameters, the first of which is of
                type T or T'Class, or is an access parameter with designated
                type T or T'Class. All such functions shall have a return type
                that is a reference type (see 4.1.5), whose reference
                discriminant is of an access-to-variable type.

4/4 These aspects are inherited by descendants of T (including the class-wide
type T'Class).

5/3 An indexable container type is (a view of) a tagged type with at least one
of the aspects Constant_Indexing or Variable_Indexing specified. An indexable
container object is an object of an indexable container type. A
generalized_indexing is a name that denotes the result of calling a function
named by a Constant_Indexing or Variable_Indexing aspect.

5.1/4 The Constant_Indexing and Variable_Indexing aspects are nonoverridable
(see 13.1.1).


                               Legality Rules

6/5 If an ancestor of a type T is an indexable container type, then any
explicit specification of the Constant_Indexing or Variable_Indexing aspects
shall be confirming; that is, the specified name shall match the inherited
aspect (see 13.1.1).

Paragraphs 7 through 8 were deleted.

9/5 In addition to the places where Legality Rules normally apply (see 12.3),
this rule applies also in the private part of an instance of a generic unit.

9.1/5 A generalized_indexing is illegal if the equivalent prefixed view (see
below) is illegal.


                                   Syntax

10/3    generalized_indexing ::= indexable_container_object_prefix
         actual_parameter_part


                            Name Resolution Rules

11/3 The expected type for the indexable_container_object_prefix of a
generalized_indexing is any indexable container type.

12/3 If the Constant_Indexing aspect is specified for the type of the
indexable_container_object_prefix of a generalized_indexing, then the
generalized_indexing is interpreted as a constant indexing under the following
circumstances:

13/3   * when the Variable_Indexing aspect is not specified for the type of
        the indexable_container_object_prefix;

14/3   * when the indexable_container_object_prefix denotes a constant;

15/3   * when the generalized_indexing is used within a primary where a name
        denoting a constant is permitted.

16/3 Otherwise, the generalized_indexing is interpreted as a variable indexing.

17/3 When a generalized_indexing is interpreted as a constant (or variable)
indexing, it is equivalent to a call on a prefixed view of one of the
functions named by the Constant_Indexing (or Variable_Indexing) aspect of the
type of the indexable_container_object_prefix with the given
actual_parameter_part, and with the indexable_container_object_prefix as the
prefix of the prefixed view.

        NOTES

18/4    6  The Constant_Indexing and Variable_Indexing aspects cannot be
        redefined when inherited for a derived type, but the functions that
        they denote can be modified by overriding or overloading.


                                  Examples

19/3    type Indexed_Barrel is tagged ...
          with Variable_Indexing => Find;
          -- Indexed_Barrel is an indexable container type,
          -- Find is the generalized indexing operation.

20/3    function Find (B : aliased in out Indexed_Barrel; Key : String) return Ref_Element;
           -- Return a reference to an element of a barrel (see 4.1.5).

21/3    IB: aliased Indexed_Barrel;

22/3    -- All of the following calls are then equivalent:
        Find (IB,"pear").Data.all := Element'(...); -- Traditional call
        IB.Find ("pear").Data.all := Element'(...); -- Call of prefixed view
        IB.Find ("pear")          := Element'(...); -- Implicit dereference (see 4.1.5
        )
        IB      ("pear")          := Element'(...); -- Implicit indexing and dereference
        IB      ("pear").Data.all := Element'(...); -- Implicit indexing only


4.2 Literals


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


                            Name Resolution Rules

2/2 This paragraph was deleted.

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

4/5 The expected type for a primary that is a string_literal shall be a single
string type or a type with a specified String_Literal aspect (see 4.2.1). In
either case, the string_literal is interpreted to be of its expected type. If
the expected type of an integer literal is a type with a specified
Integer_Literal aspect (see 4.2.1), the literal is interpreted to be of its
expected type; otherwise it is interpreted to be of type universal_integer. If
the expected type of a real literal is a type with a specified Real_Literal
aspect (see 4.2.1), it is interpreted to be of its expected type; otherwise,
it is interpreted to be of type universal_real..


                               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/5 If the expected type for a string_literal is a string type, then for each
character of the string_literal there shall be a corresponding
defining_character_literal of the component type of the expected string type.

7/2 This paragraph was deleted.


                              Static Semantics

8/5 The literal null is of type universal_access.


                              Dynamic Semantics

9/5 If its expected type is a numeric type, the evaluation of a numeric
literal yields the represented value. In other cases, the effect of evaluating
a numeric literal is determined by the Integer_Literal or Real_Literal aspect
that applies (see 4.2.1).

9.1/5 The evaluation of the literal null yields the null value of the expected
type.

10/5 The evaluation of a string_literal that is a primary and has an expected
type that is a string type, 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. In other
cases, the effect of evaluating a string_literal is determined by the
String_Literal aspect that applies (see 4.2.1).

11/5 For the evaluation of a string_literal of a string 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 of a
string type, a check is made that its lower bound is greater than the lower
bound of the base range of the index type. The exception Constraint_Error is
raised if either of these checks fails.

        NOTES

12      7  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 


4.2.1 User-Defined Literals


1/5 Using one or more of the aspects defined below, a type may be specified to
allow the use of one or more kinds of literals as values of the type.


                              Static Semantics

2/5 The following type-related operational aspects (collectively known as
user-defined literal aspects) may be specified for any type T:

3/5 Integer_Literal
                This aspect is specified by a function_name that statically
                denotes a function with a result type of T and one in
                parameter that is of type String and is not explictly aliased.

4/5 Real_Literal
                This aspect is specified by a function_name that statically
                denotes a function with a result type of T and one in
                parameter that is of type String and is not explictly aliased.

5/5 String_Literal
                This aspect is specified by a function_name that statically
                denotes a function with a result type of T and one in
                parameter that is of type Wide_Wide_String and is not
                explictly aliased.

6/5 User-defined literal aspects are inherited according to the rules given in
13.1.

7/5 When a numeric literal is interpreted as a value of a non-numeric type T
or a string_literal is interpreted a value of a type T that is not a string
type (see 4.2), it is equivalent to a call to the subprogram denoted by the
corresponding aspect of T: the Integer_Literal aspect for an integer literal,
the Real_Literal aspect for a real literal, and the String_Literal aspect for
a string_literal. The actual parameter of this notional call is a
string_literal having the textual representation of the original (numeric or
string) literal.

8/5 Such a literal is said to be a user-defined literal.


                               Legality Rules

9/5 The Integer_Literal or Real_Literal aspect shall not be specified for a
type T if the full view of T is a numeric type. The String_Literal aspect
shall not be specified for a type T if the full view of T is a string type.

10/5 For a nonabstract type, the function directly specified for a
user-defined literal aspect shall not be abstract.

11/5 For a tagged type with a partial view, a user-defined literal aspect
shall not be directly specified on the full type.

12/5 If a nonabstract tagged type inherits any user-defined literal aspect,
then each inherited aspect shall be directly specified as a nonabstract
function for the type unless the inherited aspect denotes a nonabstract
function and the type is a null extension.

13/5 In addition to the places where Legality Rules normally apply (see 12.3
), these rules also apply in the private part of an instance of a generic unit.


                          Bounded (Run-Time) Errors

14/5 It is a bounded error if the evaluation of a literal that has an expected
type with a specified user-defined literal aspect propagates an exception.
Either Program_Error or the exception propagated by the evaluation is raised
at the point of use of the value of the literal. If it is recognized prior to
run time that evaluation of such a literal will inevitably (if executed)
result in such a bounded error, then this may be reported as an error prior to
run time.


                                  Examples

15/5    subtype Roman_Character is Character
           with Static_Predicate =>
              Roman_Character in 'I' | 'V' | 'X' | 'L' | 'C' | 'D' | 'M';

16/5    Max_Roman_Number : constant := 3_999;  -- MMMCMXCIX

17/5    type Roman_Number is range 1 .. Max_Roman_Number
           with String_Literal => To_Roman_Number;

18/5    function To_Roman_Number (S : String) return Roman_Number
           with Pre => S'Length > 0 and then
              (for all Char of S => Char in Roman_Character);

19/5    function To_Roman_Number (S : String) return Roman_Number is
           (declare
              R : constant array (Integer range <>) of Integer :=
                 (for D in S'Range => Roman_Digit'Enum_Rep
                     (Roman_Digit'Value (''' & S(D) & '''))); -- See 3.5.2
         and 13.4
            begin
              [for I in R'Range =>
                 (if I < R'Last and then R(I) < R(I + 1) then -1 else 1) * R(I))]
                    'Reduce("+", 0)
           );

20/5    X : Roman_Number := "III" * "IV" * "XII"; -- 144 (that is, CXLIV)


4.3 Aggregates


1   An aggregate combines component values into a composite value of an array
type, record type, or record extension.


                                   Syntax

2/5     aggregate ::= 
            record_aggregate | extension_aggregate | array_aggregate
          | delta_aggregate | container_aggregate


                            Name Resolution Rules

3/5 The expected type for an aggregate shall be a single array type, a single
type with the Aggregate aspect specified, or a single descendant of a record
type or of a record extension.


                               Legality Rules

4/5 A record_aggregate or extension_aggregate shall not be of a class-wide
type.


                              Dynamic Semantics

5   For the evaluation of an aggregate, an anonymous object is created and
values for the components or ancestor part are obtained (as described in the
subsequent subclause for each kind of the aggregate) and assigned into the
corresponding components or ancestor part of the anonymous object. Obtaining
the values and the assignments occur in an arbitrary order. The value of the
aggregate is the value of this object.

6   If an aggregate is of a tagged type, a check is made that its value
belongs to the first subtype of the type. Constraint_Error is raised if this
check fails.


4.3.1 Record Aggregates


1   In a record_aggregate, a value is specified for each component of the
record or record extension value, using either a named or a positional
association.


                                   Syntax

2       record_aggregate ::= (record_component_association_list)

3       record_component_association_list ::= 
            record_component_association {, record_component_association}
          | null record

4/2     record_component_association ::= 
            [component_choice_list =>] expression
           | component_choice_list => <>

5/5     component_choice_list ::= 
             component_selector_name {'|' component_selector_name}
           | others

6       A record_component_association is a named component association if it
        has a component_choice_list; otherwise, it is a positional component
        association. Any positional component associations shall precede any
        named component associations. If there is a named association with a
        component_choice_list of others, it shall come last.

7       In the record_component_association_list for a record_aggregate, if
        there is only one association, it shall be a named association.


                            Name Resolution Rules

8/2 The expected type for a record_aggregate shall be a single record type or
record extension.

9/5 For the record_component_association_list of a record_aggregate, all
components of the composite value defined by the aggregate are needed; for the
association list of an extension_aggregate, only those components not
determined by the ancestor expression or subtype are needed (see 4.3.2). Each
component_selector_name in a record_component_association of a
record_aggregate or extension_aggregate shall denote a needed component
(including possibly a discriminant). Each component_selector_name in a
record_component_association of a record_delta_aggregate (see 4.3.4) shall
denote a nondiscriminant component of the type of the aggregate.

10  The expected type for the expression of a record_component_association is
the type of the associated component(s); the associated component(s) are as
follows:

11    * For a positional association, the component (including possibly a
        discriminant) in the corresponding relative position (in the
        declarative region of the type), counting only the needed components;

12    * For a named association with one or more component_selector_names, the
        named component(s);

13    * For a named association with the reserved word others, all needed
        components that are not associated with some previous association.


                               Legality Rules

14  If the type of a record_aggregate is a record extension, then it shall be
a descendant of a record type, through one or more record extensions (and no
private extensions).

15/5 A record_component_association_list shall be null record only if the list
occurs in a record_aggregate or extension_aggregate, and there are no
components needed for that list.

16/5 For a record_aggregate or extension_aggregate, each
record_component_association other than an others choice with a <> shall have
at least one associated component, and each needed component shall be
associated with exactly one record_component_association. For a
record_delta_aggregate, each component_selector_name of each
component_choice_list shall denote a distinct nondiscriminant component of the
type of the aggregate.

16.1/5 If a record_component_association with an expression has two or more
associated components, all of them shall be of the same type, or all of them
shall be of anonymous access types whose subtypes statically match. In
addition, Legality Rules are enforced separately for each associated component.

17/5 For a record_aggregate or extension_aggregate, if a variant_part P is
nested within a variant V that is not selected by the discriminant value
governing the variant_part enclosing V, then there is no restriction on the
discriminant governing P. Otherwise, the value of the discriminant that
governs P shall be given by a static expression, or by a nonstatic expression
having a constrained static nominal subtype. In this latter case of a
nonstatic expression, there shall be exactly one discrete_choice_list of P
that covers each value that belongs to the nominal subtype and satisfies the
predicates of the subtype, and there shall be at least one such value.

17.1/2 A record_component_association for a discriminant without a
default_expression shall have an expression rather than <>.

17.2/5 A record_component_association of the
record_component_association_list of a record_delta_aggregate shall not:

17.3/5   * use the compound delimiter <> (box) rather than an expression;

17.4/5   * have an expression of a limited type;

17.5/5   * omit the component_choice_list; or

17.6/5   * have a component_choice_list that is an others choice.

17.7/5 For a record_delta_aggregate, no two component_selector_names shall
denote components declared within different variants of the same
variant_part.


                              Dynamic Semantics

18  The evaluation of a record_aggregate consists of the evaluation of the
record_component_association_list.

19/5 For the evaluation of a record_component_association_list, any per-object
constraints (see 3.8) for components specified in the association list are
elaborated and any expressions are evaluated and converted to the subtype of
the associated component. Any constraint elaborations and expression
evaluations (and conversions) occur in an arbitrary order, except that the
expression for a discriminant is evaluated (and converted) prior to the
elaboration of any per-object constraint that depends on it, which in turn
occurs prior to the evaluation and conversion of the expression for the
component with the per-object constraint. If the value of a discriminant that
governs a selected variant_part P is given by a nonstatic expression, and the
evaluation of that expression yields a value that does not belong to the
nominal subtype of the expression, then Constraint_Error is raised.

19.1/2 For a record_component_association with an expression, the expression
defines the value for the associated component(s). For a
record_component_association with <>, if the component_declaration has a
default_expression, that default_expression defines the value for the
associated component(s); otherwise, the associated component(s) are
initialized by default as for a stand-alone object of the component subtype
(see 3.3.1).

20  The expression of a record_component_association is evaluated (and
converted) once for each associated component.

        NOTES

21      8  For a record_aggregate with positional associations, expressions
        specifying discriminant values appear first since the
        known_discriminant_part is given first in the declaration of the type;
        they have to be in the same order as in the known_discriminant_part.


                                  Examples

22  Example of a record aggregate with positional associations:

23      (4, July, 1776)                                       --  see 3.8 

24  Examples of record aggregates with named associations:

25      (Day => 4, Month => July, Year => 1776)
        (Month => July, Day => 4, Year => 1776)

26      (Disk, Closed, Track => 5, Cylinder => 12)            --  see 3.8.1
        (Unit => Disk, Status => Closed, Cylinder => 9, Track => 1)

27/2 Examples of component associations with several choices:

28      (Value => 0, Succ|Pred => new Cell'(0, null, null))          
        --  see 3.10.1

29       --  The allocator is evaluated twice: Succ and Pred designate different cells

29.1/2  (Value => 0, Succ|Pred => <>)                                
        --  see 3.10.1

29.2/2   --  Succ and Pred will be set to null

30  Examples of record aggregates for tagged types (see 3.9 and 3.9.1):

31      Expression'(null record)
        Literal'(Value => 0.0)
        Painted_Point'(0.0, Pi/2.0, Paint => Red)


4.3.2 Extension Aggregates


1   An extension_aggregate specifies a value for a type that is a record
extension by specifying a value or subtype for an ancestor of the type,
followed by associations for any components not determined by the
ancestor_part.


                                   Syntax

2       extension_aggregate ::= 
            (ancestor_part with record_component_association_list)

3       ancestor_part ::= expression | subtype_mark


                            Name Resolution Rules

4/2 The expected type for an extension_aggregate shall be a single type that
is a record extension. If the ancestor_part is an expression, it is expected
to be of any tagged type.


                               Legality Rules

5/3 If the ancestor_part is a subtype_mark, it shall denote a specific tagged
subtype. If the ancestor_part is an expression, it shall not be dynamically
tagged. The type of the extension_aggregate shall be a descendant of the type
of the ancestor_part (the ancestor type), through one or more record
extensions (and no private extensions). If the ancestor_part is a
subtype_mark, the view of the ancestor type from which the type is descended
(see 7.3.1) shall not have unknown discriminants.

5.1/5 If the type of the ancestor_part is limited and at least one component
is needed in the record_component_association_list, then the ancestor_part
shall not have an operative constituent expression (see 4.4) that is a call to
a function with an unconstrained result subtype.


                              Static Semantics

6   For the record_component_association_list of an extension_aggregate, the
only components needed are those of the composite value defined by the
aggregate that are not inherited from the type of the ancestor_part, plus any
inherited discriminants if the ancestor_part is a subtype_mark that denotes an
unconstrained subtype.


                              Dynamic Semantics

7   For the evaluation of an extension_aggregate, the record_component_-
association_list is evaluated. If the ancestor_part is an expression, it is
also evaluated; if the ancestor_part is a subtype_mark, the components of the
value of the aggregate not given by the record_component_association_list are
initialized by default as for an object of the ancestor type. Any implicit
initializations or evaluations are performed in an arbitrary order, except
that the expression for a discriminant is evaluated prior to any other
evaluation or initialization that depends on it.

8/3 If the type of the ancestor_part has discriminants and the ancestor_part
is not a subtype_mark that denotes an unconstrained subtype, then a check is
made that each discriminant determined by the ancestor_part has the value
specified for a corresponding discriminant, if any, either in the record_-
component_association_list, or in the derived_type_definition for some
ancestor of the type of the extension_aggregate. Constraint_Error is raised if
this check fails.

        NOTES

9       9  If all components of the value of the extension_aggregate are
        determined by the ancestor_part, then the record_component_association_-
        list is required to be simply null record.

10      10  If the ancestor_part is a subtype_mark, then its type can be
        abstract. If its type is controlled, then as the last step of
        evaluating the aggregate, the Initialize procedure of the ancestor
        type is called, unless the Initialize procedure is abstract (see 7.6
        ).


                                  Examples

11  Examples of extension aggregates (for types defined in 3.9.1):

12      Painted_Point'(Point with Red)
        (Point'(P) with Paint => Black)

13/5    (Expression with Left =>  new Literal'(Value => 1.2),
                         Right => new Literal'(Value => 3.4))
        Addition'(Binop with null record)
                     -- presuming Binop is of type Binary_Operation


4.3.3 Array Aggregates


1   In an array_aggregate, a value is specified for each component of an
array, either positionally or by its index. For a positional_array_aggregate,
the components are given in increasing-index order, with a final others, if
any, representing any remaining components. For a named_array_aggregate, the
components are identified by the values covered by the discrete_choices.


                                   Syntax

2/5     array_aggregate ::= 
            positional_array_aggregate | null_array_aggregate
         | named_array_aggregate

3/5     positional_array_aggregate ::= 
            (expression, expression {, expression})
          | (expression {, expression}, others => expression)
          | (expression {, expression}, others => <>)
          | '[' expression {, expression}[, others => expression] ']'
          | '[' expression {, expression}, others => <> ']'

3.1/5   null_array_aggregate ::= '[' ']'

4/5     named_array_aggregate ::= 
            (array_component_association_list)
          | '[' array_component_association_list ']'

4.1/5   array_component_association_list ::= 
            array_component_association {, array_component_association}

5/5     array_component_association ::= 
            discrete_choice_list => expression
          | discrete_choice_list => <>
          | iterated_component_association

5.1/5   iterated_component_association ::= 
            for defining_identifier in discrete_choice_list => expression
          | for iterator_specification => expression

6   An n-dimensional array_aggregate is one that is written as n levels of
nested array_aggregates (or at the bottom level, equivalent string_literals).
For the multidimensional case (n >= 2) the array_aggregates (or equivalent
string_literals) at the n-1 lower levels are called subaggregates of the
enclosing n-dimensional array_aggregate. The expressions of the bottom level
subaggregates (or of the array_aggregate itself if one-dimensional) are called
the array component expressions of the enclosing n-dimensional
array_aggregate.

6.1/5 The defining_identifier of an iterated_component_association declares an
index parameter, an object of the corresponding index type.


                            Name Resolution Rules

7/2 The expected type for an array_aggregate (that is not a subaggregate)
shall be a single array type. The component type of this array type is the
expected type for each array component expression of the array_aggregate.

8   The expected type for each discrete_choice in any discrete_choice_list of
a named_array_aggregate is the type of the corresponding index; the
corresponding index for an array_aggregate that is not a subaggregate is the
first index of its type; for an (n-m)-dimensional subaggregate within an
array_aggregate of an n-dimensional type, the corresponding index is the index
in position m+1.


                               Legality Rules

9/5 An array_aggregate of an n-dimensional array type shall be written as an
n-dimensional array_aggregate, or as a null_array_aggregate.

10  An others choice is allowed for an array_aggregate only if an applicable
index constraint applies to the array_aggregate. An applicable index
constraint is a constraint provided by certain contexts where an
array_aggregate is permitted that can be used to determine the bounds of the
array value specified by the aggregate. Each of the following contexts (and
none other) defines an applicable index constraint:

11/4   * For an explicit_actual_parameter, an
        explicit_generic_actual_parameter, the expression of a return
        statement, the return expression of an expression function, the
        initialization expression in an object_declaration, or a default_-
        expression (for a parameter or a component), when the nominal subtype
        of the corresponding formal parameter, generic formal parameter,
        function return object, expression function return object, object, or
        component is a constrained array subtype, the applicable index
        constraint is the constraint of the subtype;

12    * For the expression of an assignment_statement where the name denotes
        an array variable, the applicable index constraint is the constraint
        of the array variable;

13    * For the operand of a qualified_expression whose subtype_mark denotes a
        constrained array subtype, the applicable index constraint is the
        constraint of the subtype;

14    * For a component expression in an aggregate, if the component's nominal
        subtype is a constrained array subtype, the applicable index
        constraint is the constraint of the subtype;

14.1/5   * For the base_expression of a delta_aggregate, if the nominal
        subtype of the delta_aggregate is a constrained array subtype, the
        applicable index constraint is the constraint of the subtype;

15/3   * For a parenthesized expression, the applicable index constraint is
        that, if any, defined for the expression;

15.1/5   * For a conditional_expression (see 4.5.7), the applicable index
        constraint for each dependent_expression is that, if any, defined for
        the conditional_expression;

15.2/5   * For a declare_expression (see 4.5.9), the applicable index
        constraint for the body_expression is that, if any, defined for the
        declare_expression.

16  The applicable index constraint applies to an array_aggregate that appears
in such a context, as well as to any subaggregates thereof. In the case of an
explicit_actual_parameter (or default_expression) for a call on a generic
formal subprogram, no applicable index constraint is defined.

17/5 The discrete_choice_list of an array_component_association (including an
iterated_component_association) is allowed to have a discrete_choice that is a
nonstatic choice_expression or that is a subtype_indication or range that
defines a nonstatic or null range, only if it is the single discrete_choice of
its discrete_choice_list, and either there is only one
array_component_association in the enclosing
array_component_association_list or the enclosing aggregate is an
array_delta_aggregate, not an array_aggregate.

17.1/5 Either all or none of the array_component_associations of an
array_component_association_list shall be iterated_component_associations with
an iterator_specification.

18/3 In a named_array_aggregate where all discrete_choices are static, no two
discrete_choices are allowed to cover the same value (see 3.8.1); if there is
no others choice, the discrete_choices taken together shall exactly cover a
contiguous sequence of values of the corresponding index type.

19  A bottom level subaggregate of a multidimensional array_aggregate of a
given array type is allowed to be a string_literal only if the component type
of the array type is a character type; each character of such a
string_literal shall correspond to a defining_character_literal of the
component type.


                              Static Semantics

20  A subaggregate that is a string_literal is equivalent to one that is a
positional_array_aggregate of the same length, with each expression being the
character_literal for the corresponding character of the string_literal.

20.1/5 The subtype (and nominal subtype) of an index parameter is the
corresponding index subtype.


                              Dynamic Semantics

20.2/5 For an array_aggregate that contains only array_component_associations
that are iterated_component_associations with iterator_specifications,
evaluation proceeds in two steps:

20.3/5 1.
        Each iterator_specification is elaborated (in an arbitrary order) and
        an iteration is performed solely to determine a maximum count for the
        number of values produced by the iteration; all of these counts are
        combined to determine the overall length of the array, and ultimately
        the limits on the bounds of the array (defined below);

20.4/5 2.
        A second iteration is performed for each of the
        iterator_specifications, in the order given in the aggregate, and for
        each value conditionally produced by the iteration (see 5.5 and
        5.5.2), the associated expression is evaluated, its value is converted
        to the component subtype of the array type, and used to define the
        value of the next component of the array starting at the low bound and
        proceeding sequentially toward the high bound. A check is made that
        the second iteration results in an array length no greater than the
        maximum determined by the first iteration; Constraint_Error is raised
        if this check fails.

21/5 The evaluation of any other array_aggregate of a given array type
proceeds in two steps:

22  1.  Any discrete_choices of this aggregate and of its subaggregates are
        evaluated in an arbitrary order, and converted to the corresponding
        index type;

23  2.  The array component expressions of the aggregate are evaluated in an
        arbitrary order and their values are converted to the component
        subtype of the array type; an array component expression is evaluated
        once for each associated component.

23.1/4 Each expression in an array_component_association defines the value for
the associated component(s). For an array_component_association with <>, the
associated component(s) are initialized to the Default_Component_Value of the
array type if this aspect has been specified for the array type; otherwise,
they are initialized by default as for a stand-alone object of the component
subtype (see 3.3.1).

23.2/5 During an evaluation of the expression of an
iterated_component_association with a discrete_choice_list, the value of the
corresponding index parameter is that of the corresponding index of the
corresponding array component. During an evaluation of the expression of an
iterated_component_association with an iterator_specification, the value of
the loop parameter of the iterator_specification is the value produced by the
iteration (as described in 5.5.2).

24  The bounds of the index range of an array_aggregate (including a
subaggregate) are determined as follows:

25    * For an array_aggregate with an others choice, the bounds are those of
        the corresponding index range from the applicable index constraint;

26    * For a positional_array_aggregate (or equivalent string_literal)
        without an others choice, the lower bound is that of the corresponding
        index range in the applicable index constraint, if defined, or that of
        the corresponding index subtype, if not; in either case, the upper
        bound is determined from the lower bound and the number of
        expressions (or the length of the string_literal);

26.1/5   * For a null_array_aggregate, bounds for each dimension are
        determined as for a positional_array_aggregate without an others
        choice that has no expressions for each dimension;

26.2/5   * For a named_array_aggregate containing only
        iterated_component_associations with an iterator_specification, the
        lower bound is determined as for a positional_array_aggregate without
        an others choice, and the upper bound is determined from the lower
        bound and the total number of values produced by the second set of
        iterations;

27/5   * For any other named_array_aggregate without an others choice, the
        bounds are determined by the smallest and largest index values covered
        by any discrete_choice_list.

28  For an array_aggregate, a check is made that the index range defined by
its bounds is compatible with the corresponding index subtype.

29/3 For an array_aggregate with an others choice, a check is made that no
expression or <> is specified for an index value outside the bounds determined
by the applicable index constraint.

30  For a multidimensional array_aggregate, a check is made that all
subaggregates that correspond to the same index have the same bounds.

31  The exception Constraint_Error is raised if any of the above checks fail.


                         Implementation Permissions

32/5 When evaluating iterated_component_associations for an array_aggregate
that contains only iterated_component_associations with
iterator_specifications, the first step of evaluating an
iterated_component_association can be omitted if the implementation can
determine the maximum number of values by some other means.

        NOTES

33/5    11  In an array_aggregate delimited by parentheses, positional
        notation may only be used with two or more expressions; a single
        expression in parentheses is interpreted as a parenthesized
        expression. An array_aggregate delimited by square brackets may be
        used to specify an array with a single component.

34/5    12  An index parameter is a constant object (see 3.3).


                                  Examples

35  Examples of array aggregates with positional associations:

36      (7, 9, 5, 1, 3, 2, 4, 8, 6, 0)
        Table'(5, 8, 4, 1, others => 0)  --  see 3.6 

37  Examples of array aggregates with named associations:

38/5    (1 .. 5 => (1 .. 8 => 0.0))      --  two-dimensional
        [1 .. N => new Cell]             --  N new cells, in particular for N = 0

39/5    Table'(2 | 4 | 10 => 1, others => 0)
        Schedule'(Mon .. Fri => True,  others => False)  --  see 3.6
        Schedule'[Wed | Sun  => False, others => True]
        Vector'(1 => 2.5)                                --  single-component vector

40  Examples of two-dimensional array aggregates:

41      -- Three aggregates for the same value of subtype Matrix(1..2,1..3) (see 3.6
        ):

42/5    ((1.1, 1.2, 1.3), (2.1, 2.2, 2.3))
        (1 => [1.1, 1.2, 1.3], 2 => [2.1, 2.2, 2.3])
        [1 => (1 => 1.1, 2 => 1.2, 3 => 1.3), 2 => (1 => 2.1, 2 => 2.2, 3 => 2.3)]

43  Examples of aggregates as initial values:

44      A : Table := (7, 9, 5, 1, 3, 2, 4, 8, 6, 0);        -- A(1)=7, A(10)=0
        B : Table := (2 | 4 | 10 => 1, others => 0);        -- B(1)=0, B(10)=1
        C : constant Matrix := (1 .. 5 => (1 .. 8 => 0.0)); -- C'Last(1)=5, C'Last(2)=8

45      D : Bit_Vector(M .. N) := (M .. N => True);         -- see 3.6
        E : Bit_Vector(M .. N) := (others => True);
        F : String(1 .. 1) := (1 => 'F');  -- a one component aggregate: same as "F"

46/5    G : constant Matrix :=
            (for I in 1 .. 4 =>
               (for J in 1 .. 4 =>
                  (if I=J then 1.0 else 0.0))); -- Identity matrix

47/5    Empty_Matrix : constant Matrix := []; -- A matrix without elements

48/2 Example of an array aggregate with defaulted others choice and with an
applicable index constraint provided by an enclosing record aggregate:

49/5    Buffer'(Size => 50, Pos => 1, Value => ('x', others => <>))  -- see 3.7


4.3.4 Delta Aggregates


1/5 Evaluating a (record or array) delta aggregate yields a composite value
that starts with a copy of another value of the same type and then assigns to
some (but typically not all) components of the copy.


                                   Syntax

2/5     delta_aggregate ::= record_delta_aggregate | array_delta_aggregate

3/5     record_delta_aggregate ::= 
            (base_expression with delta record_component_association_list)

4/5     array_delta_aggregate ::= 
            (base_expression with delta array_component_association_list)
          | '[' base_expression with delta array_component_association_list
         ']'


                            Name Resolution Rules

5/5 The expected type for a record_delta_aggregate shall be a single
descendant of a record type or record extension.

6/5 The expected type for an array_delta_aggregate shall be a single array
type.

7/5 The expected type for the base_expression of any delta_aggregate is the
type of the enclosing delta_aggregate.

8/5 The Name Resolution Rules and Legality Rules for each
record_component_association of a record_delta_aggregate are as defined in
4.3.1.

9/5 For an array_delta_aggregate, the expected type for each discrete_choice
in an array_component_association is the index type of the type of the
delta_aggregate.

10/5 The expected type of the expression in an array_component_association is
defined as for an array_component_association occurring within an
array_aggregate of the type of the delta_aggregate.


                               Legality Rules

11/5 For an array_delta_aggregate, the array_component_association shall not
use the box symbol <>, and the discrete_choice shall not be others.

12/5 For an array_delta_aggregate, the dimensionality of the type of the
delta_aggregate shall be 1.

13/5 For an array_delta_aggregate, the base_expression and each expression in
every array_component_association shall be of a nonlimited type.


                              Dynamic Semantics

14/5 The evaluation of a delta_aggregate begins with the evaluation of the
base_expression of the delta_aggregate; then that value is used to create and
initialize the anonymous object of the aggregate. The bounds of the anonymous
object of an array_delta_aggregate and the discriminants and tag (if any) of
the anonymous object of a record_delta_aggregate are those of the
base_expression.

15/5 For a record_delta_aggregate, for each component associated with each
record_component_association (in an unspecified order):

16/5   * if the associated component belongs to a variant, a check is made
        that the values of the discriminants are such that the anonymous
        object has this component. The exception Constraint_Error is raised if
        this check fails.

17/5   * the expression of the record_component_association is evaluated,
        converted to the nominal subtype of the associated component, and
        assigned to the component of the anonymous object.

18/5 For an array_delta_aggregate, for each discrete_choice of each
array_component_association (in the order given in the enclosing
discrete_choice_list and array_component_association_list, respectively) the
discrete_choice is evaluated; for each represented index value (in ascending
order, if the discrete_choice represents a range):

19/5   * the index value is converted to the index type of the array type.

20/5   * a check is made that the index value belongs to the index range of
        the anonymous object of the aggregate; Constraint_Error is raised if
        this check fails.

21/5   * the component expression is evaluated, converted to the array
        component subtype, and assigned to the component of the anonymous
        object identified by the index value.


                                  Examples

22/5 Simple use in a postcondition:

23/5    procedure Twelfth (D : in out Date) -- see 3.8 for type Date
           with Post => D = (D'Old with delta Day => 12);

24/5    procedure The_Answer (V : in out Vector; A, B : in Integer) -- see 3.6
         for type Vector
           with Post => V = (V'Old with delta A .. B => 42.0, V'First => 0.0);

25/5 The base expression can be nontrivial:

26/5    New_Cell : Cell := (Min_Cell (Head) with delta Value => 42);
           -- see 3.10.1 for Cell and Head; 6.1 for Min_Cell

27/5    A1 : Vector := ((0 => 1.0, 1 => 2.0, 2 => 3.0)
               with delta Integer(Random * 2.0) => 14.2);
           -- see 3.6 for declaration of type Vector
           -- see 6.1 for declaration of Random

28/5    Tomorrow := ((Yesterday with delta Day => 12) with delta Month => Apr); -- see 3.8

29/5 The base expression may also be class-wide:

30/5    function Translate (P : Point'Class; X, Y : Real) return Point'Class is
           (P with delta X => P.X + X,
                         Y => P.Y + Y); -- see 3.9
         for declaration of type Point


4.3.5 Container Aggregates


1/5 In a container_aggregate, values are specified for elements of a
container; for a positional_container_aggregate, the elements are given
sequentially; for a named_container_aggregate, the elements are specified by a
sequence of key/value pairs, or using an iterator. The Aggregate aspect of the
type of the aggregate determines how the elements are combined to form the
container.

2/5 For a type other than an array type, the following type-related
operational aspect may be specified:

3/5 Aggregate   This aspect is an aggregate of the form:

4/5                    (Empty => name[,
                        Add_Named => procedure_name][,
                        Add_Unnamed => procedure_name][,
                        New_Indexed => function_name,
                        Assign_Indexed => procedure_name])

5/5             The type for which this aspect is specified is known as the
                container type of the Aggregate aspect. A procedure_name shall
                be specified for at least one of Add_Named, Add_Unnamed, or
                Assign_Indexed. If Add_Named is specified, neither Add_Unnamed
                nor Assign_Indexed shall be specified. Either both or neither
                of New_Indexed and Assign_Indexed shall be specified.


                            Name Resolution Rules

6/5 The name specified for Empty for an Aggregate aspect shall denote a
constant of the container type, or denote a function with a result type of the
container type that has no parameters, or that has one in parameter of type
Integer.

7/5 The procedure_name specified for Add_Unnamed for an Aggregate aspect shall
denote a procedure that has two parameters, the first an in out parameter of
the container type, and the second an in parameter of some nonlimited type,
called the element type of the container type.

8/5 The function_name specified for New_Indexed for an Aggregate aspect shall
denote a function with a result type of the container type, and two parameters
of the same discrete type, with that type being the key type of the container
type.

9/5 The procedure_name specified for Add_Named or Assign_Indexed for an
Aggregate aspect shall denote a procedure that has three parameters, the first
an in out parameter of the container type, the second an in parameter of a
nonlimited type (the key type of the container type), and the third, an in
parameter of a nonlimited type that is called the element type of the
container type.


                               Legality Rules

10/5 If the container type of an Aggregate aspect is a private type, the full
type of the container type shall not be an array type. If the container type
is limited, the name specified for Empty shall denote a function rather than a
constant object.

11/5 For an Aggregate aspect, the key type of Assign_Indexed shall be the same
type as that of the parameters of New_Indexed. Additionally, if both
Add_Unnamed and Assign_Indexed are specified, the final parameters shall be of
the same type - the element type of the container type.


                              Static Semantics

12/5 The Aggregate aspect is nonoverridable.


                                   Syntax

13/5    container_aggregate ::= 
            null_container_aggregate
          | positional_container_aggregate
          | named_container_aggregate

14/5    null_container_aggregate ::= '[' ']'

15/5    positional_container_aggregate ::= '[' expression{, expression} ']'

16/5    named_container_aggregate ::= 
        '[' container_element_association_list ']'

17/5    container_element_association_list ::= 
            container_element_association {, container_element_association}

18/5    container_element_association ::= 
            key_choice_list => expression
          | key_choice_list => <>
          | iterated_element_association

19/5    key_choice_list ::= key_choice {'|' key_choice}

20/5    key_choice ::= key_expression | discrete_range

21/5    iterated_element_association ::= 
            for loop_parameter_specification[ use key_expression
        ] => expression
          | for iterator_specification[ use key_expression] => expression


                            Name Resolution Rules

22/5 The expected type for a container_aggregate shall be a type for which the
Aggregate aspect has been specified. The expected type for each expression of
a container_aggregate is the element type of the expected type.

23/5 The expected type for a key_expression, or a discrete_range of a
key_choice, is the key type of the expected type of the aggregate.


                               Legality Rules

24/5 The expected type for a positional_container_aggregate shall have an
Aggregate aspect that includes a specification for an Add_Unnamed procedure or
an Assign_Indexed procedure. The expected type for a
named_container_aggregate that contains one or more
iterated_element_associations with a key_expression shall have an Aggregate
aspect that includes a specification for the Add_Named procedure. The expected
type for a named_container_aggregate that contains one or more
key_choice_lists shall have an Aggregate aspect that includes a specification
for the Add_Named or Assign_Indexed procedure. A null_container_aggregate can
be of any type with an Aggregate aspect.

25/5 A non-null container aggregate is called an indexed aggregate if the
expected type T of the aggregate specifies an Assign_Indexed procedure in its
Aggregate aspect, and either there is no Add_Unnamed procedure specified for
the type, or the aggregate is a named_container_aggregate with a
container_element_association that contains a key_choice_list or a
loop_parameter_specification. The key type of an indexed aggregate is also
called the index type of the aggregate.

26/5 A container_element_association with a <> rather than an expression, or
with a key_choice that is a discrete_range, is permitted only in an indexed
aggregate.

27/5 For an iterated_element_association without a key_expression, if the
aggregate is an indexed aggregate or the expected type of the aggregate
specifies an Add_Named procedure in its Aggregate aspect, then the type of the
loop parameter of the iterated_element_association shall be the same as the
key type of the aggregate.

28/5 For a named_container_aggregate that is an indexed aggregate, all
container_element_associations shall contain either a key_choice_list, or a
loop_parameter_specification without a key_expression or iterator_filter.
Furthermore, for such an aggregate, either:

29/5   * all key_choices shall be static expressions or static ranges, and
        every loop_parameter_specification shall have a
        discrete_subtype_definition that defines a non-null static range, and
        the set of values of the index type covered by the key_choices and the
        discrete_subtype_definitions shall form a contiguous range of values
        with no duplications; or

30/5   * there shall be exactly one container_element_association, and if it
        has a key_choice_list, the list shall have exactly one key_choice.


                              Dynamic Semantics

31/5 The evaluation of a container_aggregate starts by creating an anonymous
object A of the expected type T initialized as follows:

32/5   * if the aggregate is an indexed aggregate, from the result of a call
        on the New_Indexed function; the actual parameters in this call
        represent the lower and upper bound of the aggregate, and are
        determined as follows:

33/5      * if the aggregate is a positional_container_aggregate, the lower
            bound is the low bound of the subtype of the key parameter of the
            Add_Indexed procedure, and the upper bound has a position number
            that is the sum of the position number of the lower bound and one
            less than the number of expressions in the aggregate;

34/5      * if the aggregate is a named_container_aggregate, the lower bound
            is the lowest value covered by a key_choice_list or is the low
            bound of a range defined by a discrete_subtype_definition of a
            loop_parameter_specification; the upper bound is the highest value
            covered by a key_choice_list or is the high bound of a range
            defined by a discrete_subtype_definition of a
            loop_parameter_specification.

35/5   * if the aggregate is not an indexed aggregate, by assignment from the
        Empty constant, or from a call on the Empty function specified in the
        Aggregate aspect. In the case of an Empty function with a formal
        parameter, the actual parameter has the following value:

36/5      * for a null_container_aggregate, the value zero;

37/5      * for a positional_container_aggregate, the number of expressions;

38/5      * for a named_container_aggregate without an
            iterated_element_association, the number of key_expressions;

39/5      * for a named_container_aggregate where every
            iterated_element_association contains a
            loop_parameter_specification, the total number of elements
            specified by all of the container_element_associations;

40/5      * otherwise, to an implementation-defined value.

41/5 The evaluation then proceeds as follows:

42/5   * for a null_container_aggregate, the anonymous object A is the result;

43/5   * for a positional_container_aggregate of a type with a specified
        Add_Unnamed procedure, each expression is evaluated in an arbitrary
        order, and the Add_Unnamed procedure is invoked in sequence with the
        anonymous object A as the first parameter and the result of evaluating
        each expression as the second parameter, in the order of the
        expressions;

44/5   * for a positional_container_aggregate that is an indexed aggregate,
        each expression is evaluated in an arbitrary order, and the
        Assign_Indexed procedure is invoked in sequence with the anonymous
        object A as the first parameter, the key value as the second
        parameter, computed by starting with the low bound of the subtype of
        the key formal parameter of the Assign_Indexed procedure and taking
        the successor of this value for each successive expression, and the
        result of evaluating each expression as the third parameter;

45/5   * for a named_container_aggregate for a type with an Add_Named
        procedure in its Aggregate aspect, the container_element_associations
        are evaluated in an arbitrary order:

46/5      * for a container_element_association with a key_choice_list, for
            each key_choice of the list in an arbitrary order, the
            key_choice is evaluated as is the expression of the
            container_element_association (in an arbitrary order), and the
            Add_Named procedure is invoked once for each value covered by the
            key_choice, with the anonymous object A as the first parameter,
            the value from the key_choice as the second parameter, and the
            result of evaluating the expression as the third parameter;

47/5      * for a container_element_association with an
            iterated_element_association, first the
            iterated_element_association is elaborated, then an iteration is
            performed, and for each value conditionally produced by the
            iteration (see 5.5 and 5.5.2) the Add_Named rocedure is invoked
            with the anonymous object A as the first parameter, the result of
            evaluating the expression as the third parameter, and:

48/5          * if there is a key_expression, the result of evaluating the
                key_expression as the second parameter;

49/5          * otherwise, with the loop parameter as the second parameter;

50/5   * for a named_container_aggregate that is an indexed aggregate, the
        evaluation proceeds as above for the case of Add_Named, but with the
        Assign_Indexed procedure being invoked in its stead; in the case of a
        container_element_association with a <> rather than an expression, the
        corresponding call on Assign_Indexed is not performed, leaving the
        component as it was upon return from the New_Indexed function;

51/5   * for any other named_container_aggregate, the
        container_element_associations (which are necessarily
        iterated_element_associations) are evaluated in the order given; each
        such evaluation comprises two steps:

52/5    1.  the iterated_element_association is elaborated;

53/5    2.  an iteration is performed, and for each value conditionally
            produced by the iteration (see 5.5 and 5.5.2) the Add_Unnamed
            procedure is invoked, with the anonymous object A as the first
            parameter and the result of evaluating the expression as the
            second parameter.


                                  Examples

54/5 Declarations of Set_Type, Map_Type, and Vector_Type:

55/5       --  Set_Type is a set-like container type.
           type Set_Type is private
              with Aggregate => (Empty       => Empty_Set,
                                 Add_Unnamed => Include);
           function Empty_Set return Set_Type;

56/5       subtype Small_Natural is Natural range 0..1000;

57/5       procedure Include (S : in out Set_Type; N : in Small_Natural);

58/5       --  Map_Type is a map-like container type.
           type Map_Type is private
              with Aggregate =>  (Empty     => Empty_Map,
                                  Add_Named => Add_To_Map);

59/5       procedure Add_To_Map (M : in out Map_Type; Key : in Integer; Value : in String);

60/5       Empty_Map : constant Map_Type;

61/5       --  Vector_Type is an extensible array-like container type.
           type Vector_Type is private
              with Aggregate => (Empty          => Empty_Vector,
                                 Add_Unnamed    => Append_One,
                                 New_Indexed    => New_Vector,
                                 Assign_Indexed => Assign_Element);

62/5       function Empty_Vector (Capacity : Count_Type := 0) return Vector_Type;

63/5       procedure Append_One (V : in out Vector_Type; New_Item : in String);

64/5       procedure Assign_Element (V : in out Vector_Type;
                                     Index : in Positive;
                                     Item  : in String);

65/5       function New_Vector (First, Last : Positive) return Vector_Type
              with Pre => First = Positive'First;
              --  Vectors are always indexed starting at the
              --  lower bound of their index subtype.

66/5    -- Private part not shown.

67/5 Examples of container aggregates for Set_Type, Map_Type, and Vector_Type:

68/5    --  Example aggregates using Set_Type.
        S : Set_Type;

69/5    --  Assign the empty set to S:
        S := [];

70/5    --  Is equivalent to:
        S := Empty_Set;

71/5    --  A positional set aggregate:
        S := [1, 2];

72/5    --  Is equivalent to:
        S := Empty_Set;
        Include (S, 1);
        Include (S, 2);

73/5    --  A set aggregate with an iterated_element_association:
        S := [for Item in 1 .. 5 => Item * 2];

74/5    --  Is equivalent to:
        S := Empty_Set;
        for Item in 1 .. 5 loop
           Include (S, Item * 2);
        end loop;

75/5    --  A set aggregate consisting of two iterated_element_associations:
        S := [for Item in 1 .. 5 => Item,
              for Item in 1 .. 5 => -Item];

76/5    --  Is equivalent (assuming set semantics) to:
        S := Empty_Set;
        for Item in -5 .. 5 loop
           if Item /= 0 then
              Include (S, Item);
           end if;
        end loop;

77/5    --  Example aggregates using Map_Type.
        M : Map_Type;

78/5    --  A simple named map aggregate:
        M := [12 => "house", 14 => "beige"];

79/5    --  Is equivalent to:
        M := Empty_Map;
        Add_To_Map (M, 12, "house");
        Add_To_Map (M, 14, "beige");

80/5    --  Define a table of pairs:
        type Pair is record
           Key : Integer;
           Value : access constant String;
        end record;

81/5    Table : constant array(Positive range <>) of Pair :=
           [(Key => 33, Value => new String'("a nice string")),
            (Key => 44, Value => new String'("an even better string"))];

82/5    --  A map aggregate using an iterated_element_association
        --  and a key_expression, built from from a table of key/value pairs:
        M := [for P of Table use P.Key => P.Value.all];

83/5    --  Is equivalent to:
        M := Empty_Map;
        for P of Table loop
           Add_To_Map (M, P.Key, P.Value.all);
        end loop;

84/5    --  Create an image table for an array of integers:
        Keys : constant array(Positive range <>) of Integer := [2, 3, 5, 7, 11];

85/5    --  A map aggregate where the values produced by the
        --  iterated_element_association are of the same type as the key
        --  (eliminating the need for a separate key_expression):
        M := [for Key of Keys => Integer'Image (Key)];

86/5    --  Is equivalent to:
        M := Empty_Map;
        for Key of Keys loop
           Add_To_Map (M, Key, Integer'Image (Key));
        end loop;

87/5    --  Example aggregates using Vector_Type.
        V : Vector_Type;

88/5    --  A positional vector aggregate:
        V := ["abc", "def"];

89/5    --  Is equivalent to:
        V := Empty_Vector (2);
        Append_One (V, "abc");
        Append_One (V, "def");

90/5    --  An indexed vector aggregate:
        V := [1 => "this", 2 => "is", 3 => "a", 4 => "test"];

91/5    --  Is equivalent to:
        V := New_Vector (1, 4);
        Assign_Element (V, 1, "this");
        Assign_Element (V, 2, "is");
        Assign_Element (V, 3, "a");
        Assign_Element (V, 4, "test");

92/5    --  A vector made from the elements of a map:
        V := [for Elem of M => Elem];

93/5    --  Is equivalent to:
        V := Empty_Vector (<estimate of size of M>);
        for Elem of M loop
           Add_Positional (V, Elem);
        end loop;


4.4 Expressions


1/3 An expression is a formula that defines the computation or retrieval of a
value. In this International Standard, the term "expression" refers to a
construct of the syntactic category expression or of any of the following
categories: choice_expression, choice_relation, relation, simple_expression,
term, factor, primary, conditional_expression, quantified_expression.


                                   Syntax

2       expression ::= 
             relation {and relation}  | relation {and then relation}
           | relation {or relation}  | relation {or else relation}
           | relation {xor relation}

2.1/3   choice_expression ::= 
             choice_relation {and choice_relation}
           | choice_relation {or choice_relation}
           | choice_relation {xor choice_relation}
           | choice_relation {and then choice_relation}
           | choice_relation {or else choice_relation}

2.2/3   choice_relation ::= 
             simple_expression [relational_operator simple_expression]

3/4     relation ::= 
             simple_expression [relational_operator simple_expression]
           | tested_simple_expression [not] in membership_choice_list
           | raise_expression

3.1/5   membership_choice_list ::= membership_choice {'|' membership_choice}

3.2/4   membership_choice ::= choice_simple_expression | range
         | subtype_mark

4       simple_expression ::= [unary_adding_operator] term
         {binary_adding_operator term}

5       term ::= factor {multiplying_operator factor}

6       factor ::= primary [** primary] | abs primary | not primary

7/5     primary ::= 
            numeric_literal | null | string_literal | aggregate
          | name | allocator | (expression)
          | (conditional_expression) | (quantified_expression)
          | (declare_expression)


                            Name Resolution Rules

8   A name used as a primary shall resolve to denote an object or a value.


                              Static Semantics

9   Each expression has a type; it specifies the computation or retrieval of a
value of that type.

9.1/5 A primary that is an expression surrounded by ( and ) is known as a
parenthesized expression.

9.2/5 Every name or expression consists of one or more operative constituent
names or expressions, only one of which is evaluated as part of evaluating the
name or expression (the evaluated operative constituent). The operative
constituents are determined as follows, according to the form of the
expression (or name):

9.3/5   * if the expression is a conditional_expression, the operative
        constituents of its dependent_expressions;

9.4/5   * if the expression (or name) is a parenthesized expression, a
        qualified_expression, or a view conversion, the operative
        constituent(s) of its operand;

9.5/5   * if the expression is a declare_expression, the operative
        constituent(s) of its body_expression;

9.6/5   * otherwise, the expression (or name) itself.

9.7/5 In certain contexts, we specify that an operative constituent shall (or
shall not) be newly constructed. This means the operative constituent shall
(or shall not) be an aggregate or a function_call; in either case, a
raise_expression is permitted.


                              Dynamic Semantics

10  The value of a primary that is a name denoting an object is the value of
the object.

10.1/5 An expression of a numeric universal type is evaluated as if it has
type root_integer (for universal_integer) or root_real (otherwise) unless the
context identifies a specific type (in which case that type is used).


                         Implementation Permissions

11  For the evaluation of a primary that is a name denoting an object of an
unconstrained numeric subtype, if the value of the object is outside the base
range of its type, the implementation may either raise Constraint_Error or
return the value of the object.


                                  Examples

12  Examples of primaries:

13      4.0                --  real literal
        Pi                 --  named number
        (1 .. 10 => 0)     --  array aggregate
        Sum                --  variable
        Integer'Last       --  attribute
        Sine(X)            --  function call
        Color'(Blue)       --  qualified expression
        Real(M*N)          --  conversion
        (Line_Count + 10)  --  parenthesized expression 

14  Examples of expressions:

15/2    Volume                      -- primary
        not Destroyed               -- factor
        2*Line_Count                -- term
        -4.0                        -- simple expression
        -4.0 + A                    -- simple expression
        B**2 - 4.0*A*C              -- simple expression
        R*Sin(<Unicode-952>)*Cos(<Unicode-966>
        )             -- simple expression
        Password(1 .. 3) = "Bwv"    -- relation
        Count in Small_Int          -- relation
        Count not in Small_Int      -- relation
        Index = 0 or Item_Hit       -- expression
        (Cold and Sunny) or Warm    -- expression (parentheses are required)
        A**(B**C)                   -- expression (parentheses are required)


4.5 Operators and Expression Evaluation


1   The language defines the following six categories of operators (given in
order of increasing precedence). The corresponding operator_symbols, and only
those, can be used as designators in declarations of functions for
user-defined operators. See 6.6, "Overloading of Operators".


                                   Syntax

2       logical_operator ::=                         and | or  | xor

3       relational_operator ::=                     
         =   | /=  | <   | <= | > | >=

4       binary_adding_operator ::=                   +   | -   | &

5       unary_adding_operator ::=                    +   | -

6       multiplying_operator ::=                     *   | /   | mod | rem

7       highest_precedence_operator ::=              **  | abs | not


                              Static Semantics

8   For a sequence of operators of the same precedence level, the operators
are associated with their operands in textual order from left to right.
Parentheses can be used to impose specific associations.

9   For each form of type definition, certain of the above operators are
predefined; that is, they are implicitly declared immediately after the type
definition. For each such implicit operator declaration, the parameters are
called Left and Right for binary operators; the single parameter is called
Right for unary operators. An expression of the form X op Y, where op is a
binary operator, is equivalent to a function_call of the form "op"(X, Y). An
expression of the form op Y, where op is a unary operator, is equivalent to a
function_call of the form "op"(Y). The predefined operators and their effects
are described in subclauses 4.5.1 through 4.5.6.


                              Dynamic Semantics

10  The predefined operations on integer types either yield the mathematically
correct result or raise the exception Constraint_Error. For implementations
that support the Numerics Annex, the predefined operations on real types yield
results whose accuracy is defined in Annex G, or raise the exception
Constraint_Error.


                         Implementation Requirements

11  The implementation of a predefined operator that delivers a result of an
integer or fixed point type may raise Constraint_Error only if the result is
outside the base range of the result type.

12  The implementation of a predefined operator that delivers a result of a
floating point type may raise Constraint_Error only if the result is outside
the safe range of the result type.


                         Implementation Permissions

13  For a sequence of predefined operators of the same precedence level (and
in the absence of parentheses imposing a specific association), an
implementation may impose any association of the operators with operands so
long as the result produced is an allowed result for the left-to-right
association, but ignoring the potential for failure of language-defined checks
in either the left-to-right or chosen order of association.

        NOTES

14      13  The two operands of an expression of the form X op Y, where op is
        a binary operator, are evaluated in an arbitrary order, as for any
        function_call (see 6.4).


                                  Examples

15  Examples of precedence:

16      not Sunny or Warm    --  same as (not Sunny) or Warm
        X > 4.0 and Y > 0.0  --  same as (X > 4.0) and (Y > 0.0)

17      -4.0*A**2            --  same as -(4.0 * (A**2))
        abs(1 + A) + B       --  same as (abs (1 + A)) + B
        Y**(-3)              --  parentheses are necessary
        A / B * C            --  same as (A/B)*C
        A + (B + C)          --  evaluate B + C before adding it to A 


4.5.1 Logical Operators and Short-circuit Control Forms



                            Name Resolution Rules

1   An expression consisting of two relations connected by and then or or else
(a short-circuit control form) shall resolve to be of some boolean type; the
expected type for both relations is that same boolean type.


                              Static Semantics

2   The following logical operators are predefined for every boolean type T,
for every modular type T, and for every one-dimensional array type T whose
component type is a boolean type:

3       function "and"(Left, Right : T) return T
        function "or" (Left, Right : T) return T
        function "xor"(Left, Right : T) return T

4   For boolean types, the predefined logical operators and, or, and xor
perform the conventional operations of conjunction, inclusive disjunction, and
exclusive disjunction, respectively.

5   For modular types, the predefined logical operators are defined on a
bit-by-bit basis, using the binary representation of the value of the operands
to yield a binary representation for the result, where zero represents False
and one represents True. If this result is outside the base range of the type,
a final subtraction by the modulus is performed to bring the result into the
base range of the type.

6   The logical operators on arrays are performed on a component-by-component
basis on matching components (as for equality - see 4.5.2), using the
predefined logical operator for the component type. The bounds of the
resulting array are those of the left operand.


                              Dynamic Semantics

7   The short-circuit control forms and then and or else deliver the same
result as the corresponding predefined and and or operators for boolean types,
except that the left operand is always evaluated first, and the right operand
is not evaluated if the value of the left operand determines the result.

8   For the logical operators on arrays, a check is made that for each
component of the left operand there is a matching component of the right
operand, and vice versa. Also, a check is made that each component of the
result belongs to the component subtype. The exception Constraint_Error is
raised if either of the above checks fails.

        NOTES

9       14  The conventional meaning of the logical operators is given by the
        following truth table:

10                A                   B                 (A and B)           
            (A or B)                (A xor B)
            
                True                True                True                
            True                    False
                True                False               False               
            True                    True
                False               True                False               
            True                    True
                False               False               False               
            False                   False


                                  Examples

11  Examples of logical operators:

12      Sunny or Warm
        Filter(1 .. 10) and Filter(15 .. 24)   --   see 3.6.1 

13  Examples of short-circuit control forms:

14      Next_Car.Owner /= null and then Next_Car.Owner.Age > 25   --   see 3.10.1
        N = 0 or else A(N) = Hit_Value


4.5.2 Relational Operators and Membership Tests


1   The equality operators = (equals) and /= (not equals) are predefined for
nonlimited types. The other relational_operators are the ordering operators <
(less than), <= (less than or equal), > (greater than), and >= (greater than
or equal). The ordering operators are predefined for scalar types, and for
discrete array types, that is, one-dimensional array types whose components
are of a discrete type.

2/3 A membership test, using in or not in, determines whether or not a value
belongs to any given subtype or range, is equal to any given value, has a tag
that identifies a type that is covered by a given type, or is convertible to
and has an accessibility level appropriate for a given access type. Membership
tests are allowed for all types.


                            Name Resolution Rules

3/3 The tested type of a membership test is determined by the
membership_choices of the membership_choice_list. Either all
membership_choices of the membership_choice_list shall resolve to the same
type, which is the tested type; or each membership_choice shall be of an
elementary type, and the tested type shall be covered by each of these
elementary types.

3.1/4 If the tested type is tagged, then the tested_simple_expression shall
resolve to be of a type that is convertible (see 4.6) to the tested type; if
untagged, the expected type for the tested_simple_expression is the tested
type. The expected type of a choice_simple_expression in a membership_choice,
and of a simple_expression of a range in a membership_choice, is the tested
type of the membership operation.


                               Legality Rules

4/4 For a membership test, if the tested_simple_expression is of a tagged
class-wide type, then the tested type shall be (visibly) tagged.

4.1/5 If a membership test includes one or more choice_simple_expressions and
the tested type of the membership test is limited, then the tested type of the
membership test shall have a visible primitive equality operator; if the
tested type of the membership test is nonlimited with a user-defined primitive
equality operator that is defined at a point where the type is limited, the
tested type shall be a record type or record extension.


                              Static Semantics

5   The result type of a membership test is the predefined type Boolean.

6   The equality operators are predefined for every specific type T that is
not limited, and not an anonymous access type, with the following
specifications:

7       function "=" (Left, Right : T) return Boolean
        function "/="(Left, Right : T) return Boolean

7.1/2 The following additional equality operators for the universal_access
type are declared in package Standard for use with anonymous access types:

7.2/2   function "=" (Left, Right : universal_access) return Boolean
        function "/="(Left, Right : universal_access) return Boolean

8   The ordering operators are predefined for every specific scalar type T,
and for every discrete array type T, with the following specifications:

9       function "<" (Left, Right : T) return Boolean
        function "<="(Left, Right : T) return Boolean
        function ">" (Left, Right : T) return Boolean
        function ">="(Left, Right : T) return Boolean


                            Name Resolution Rules

9.1/2 At least one of the operands of an equality operator for
universal_access shall be of a specific anonymous access type. Unless the
predefined equality operator is identified using an expanded name with
prefix denoting the package Standard, neither operand shall be of an
access-to-object type whose designated type is D or D'Class, where D has a
user-defined primitive equality operator such that:

9.2/2   * its result type is Boolean;

9.3/3   * it is declared immediately within the same declaration list as D or
        any partial or incomplete view of D; and

9.4/2   * at least one of its operands is an access parameter with designated
        type D.


                               Legality Rules

9.5/2 At least one of the operands of the equality operators for
universal_access shall be of type universal_access, or both shall be of
access-to-object types, or both shall be of access-to-subprogram types.
Further:

9.6/2   * When both are of access-to-object types, the designated types shall
        be the same or one shall cover the other, and if the designated types
        are elementary or array types, then the designated subtypes shall
        statically match;

9.7/2   * When both are of access-to-subprogram types, the designated profiles
        shall be subtype conformant.

9.8/5 If the profile of an explicitly declared primitive equality operator of
an untagged record type is type conformant with that of the corresponding
predefined equality operator, the declaration shall occur before the type is
frozen. In addition, no type shall have been derived from the untagged record
type before the declaration of the primitive equality operator. In addition to
the places where Legality Rules normally apply (see 12.3), this rule applies
also in the private part of an instance of a generic unit.


                              Dynamic Semantics

10  For discrete types, the predefined relational operators are defined in
terms of corresponding mathematical operations on the position numbers of the
values of the operands.

11  For real types, the predefined relational operators are defined in terms
of the corresponding mathematical operations on the values of the operands,
subject to the accuracy of the type.

12  Two access-to-object values are equal if they designate the same object,
or if both are equal to the null value of the access type.

13  Two access-to-subprogram values are equal if they are the result of the
same evaluation of an Access attribute_reference, or if both are equal to the
null value of the access type. Two access-to-subprogram values are unequal if
they designate different subprograms. It is unspecified whether two access
values that designate the same subprogram but are the result of distinct
evaluations of Access attribute_references are equal or unequal.

14/3 For a type extension, predefined equality is defined in terms of the
primitive (possibly user-defined) equals operator for the parent type and for
any components that have a record type in the extension part, and predefined
equality for any other components not inherited from the parent type.

14.1/3 For a derived type whose parent is an untagged record type, predefined
equality is defined in terms of the primitive (possibly user-defined) equals
operator of the parent type.

15/5 For a private type, if its full type is a record type or a record
extension, predefined equality is defined in terms of the primitive equals
operator of the full type; otherwise, predefined equality for the private type
is that of its full type.

16  For other composite types, the predefined equality operators (and certain
other predefined operations on composite types - see 4.5.1 and 4.6) are
defined in terms of the corresponding operation on matching components,
defined as follows:

17    * For two composite objects or values of the same non-array type,
        matching components are those that correspond to the same
        component_declaration or discriminant_specification;

18    * For two one-dimensional arrays of the same type, matching components
        are those (if any) whose index values match in the following sense:
        the lower bounds of the index ranges are defined to match, and the
        successors of matching indices are defined to match;

19    * For two multidimensional arrays of the same type, matching components
        are those whose index values match in successive index positions.

20  The analogous definitions apply if the types of the two objects or values
are convertible, rather than being the same.

21  Given the above definition of matching components, the result of the
predefined equals operator for composite types (other than for those composite
types covered earlier) is defined as follows:

22    * If there are no components, the result is defined to be True;

23    * If there are unmatched components, the result is defined to be False;

24/3   * Otherwise, the result is defined in terms of the primitive equals
        operator for any matching components that are records, and the
        predefined equals for any other matching components.

24.1/3 If the primitive equals operator for an untagged record type is
abstract, then Program_Error is raised at the point of any (implicit) call to
that abstract subprogram.

24.2/1 For any composite type, the order in which "=" is called for components
is unspecified. Furthermore, if the result can be determined before calling
"=" on some components, it is unspecified whether "=" is called on those
components.

25  The predefined "/=" operator gives the complementary result to the
predefined "=" operator.

26/3 For a discrete array type, the predefined ordering operators correspond
to lexicographic order using the predefined order relation of the component
type: A null array is lexicographically less than any array having at least
one component. In the case of nonnull arrays, the left operand is
lexicographically less than the right operand if the first component of the
left operand is less than that of the right; otherwise, the left operand is
lexicographically less than the right operand only if their first components
are equal and the tail of the left operand is lexicographically less than that
of the right (the tail consists of the remaining components beyond the first
and can be null).

26.1/3 An individual membership test is the membership test of a single
membership_choice.

27/4 For the evaluation of a membership test using in whose
membership_choice_list has a single membership_choice, the
tested_simple_expression and the membership_choice are evaluated in an arbitrary
order; the result is the result of the individual membership test for the
membership_choice.

27.1/4 For the evaluation of a membership test using in whose
membership_choice_list has more than one membership_choice, the
tested_simple_expression of the membership test is evaluated first and the result of
the operation is equivalent to that of a sequence consisting of an individual
membership test on each membership_choice combined with the short-circuit
control form or else.

28/3 An individual membership test yields the result True if:

28.1/5   * The membership_choice is a choice_simple_expression, and the
        tested_simple_expression is equal to the value of the membership_choice. If
        the tested type is a record type or a record extension, or is limited
        at the point where the membership test occurs, the test uses the
        primitive equality for the type; otherwise, the test uses predefined
        equality.

28.2/4   * The membership_choice is a range and the value of the
        tested_simple_expression belongs to the given range.

29/4   * The membership_choice is a subtype_mark, the tested type is scalar,
        the value of the tested_simple_expression belongs to the range of the
        named subtype, and the value satisfies the predicates of the named
        subtype.

30/4   * The membership_choice is a subtype_mark, the tested type is not
        scalar, the value of the tested_simple_expression satisfies any
        constraints of the named subtype, the value satisfies the predicates
        of the named subtype, and:

30.1/4    * if the type of the tested_simple_expression is class-wide, the
            value has a tag that identifies a type covered by the tested type;

30.2/4    * if the tested type is an access type and the named subtype
            excludes null, the value of the tested_simple_expression is not
            null;

30.3/4    * if the tested type is a general access-to-object type, the type of
            the tested_simple_expression is convertible to the tested type and
            its accessibility level is no deeper than that of the tested type;
            further, if the designated type of the tested type is tagged and
            the tested_simple_expression is nonnull, the tag of the object
            designated by the value of the tested_simple_expression is covered
            by the designated type of the tested type.

31/3 Otherwise, the test yields the result False.

32  A membership test using not in gives the complementary result to the
corresponding membership test using in.


                         Implementation Requirements

32.1/1 For all nonlimited types declared in language-defined packages, the "="
and "/=" operators of the type shall behave as if they were the predefined
equality operators for the purposes of the equality of composite types and
generic formal types.

        NOTES

33/2    This paragraph was deleted.

34      15  If a composite type has components that depend on discriminants,
        two values of this type have matching components if and only if their
        discriminants are equal. Two nonnull arrays have matching components
        if and only if the length of each dimension is the same for both.


                                  Examples

35  Examples of expressions involving relational operators and membership
tests:

36      X /= Y

37/5    S : String := "A";
        "" < S and S < "Aa"         --  True
        S < "Bb" and S < "A  "      --  True

38/3    My_Car = null               -- True if My_Car has been set to null (see 3.10.1
        )
        My_Car = Your_Car           -- True if we both share the same car
        My_Car.all = Your_Car.all   -- True if the two cars are identical

39/3    N not in 1 .. 10            -- range membership test
        Today in Mon .. Fri         -- range membership test
        Today in Weekday            -- subtype membership test (see 3.5.1)
        Card in Clubs | Spades      -- list membership test (see 3.5.1)
        Archive in Disk_Unit        -- subtype membership test (see 3.8.1)
        Tree.all in Addition'Class  -- class membership test (see 3.9.1)


4.5.3 Binary Adding Operators



                              Static Semantics

1   The binary adding operators + (addition) and - (subtraction) are
predefined for every specific numeric type T with their conventional meaning.
They have the following specifications:

2       function "+"(Left, Right : T) return T
        function "-"(Left, Right : T) return T

3   The concatenation operators & are predefined for every nonlimited,
one-dimensional array type T with component type C. They have the following
specifications:

4       function "&"(Left : T; Right : T) return T
        function "&"(Left : T; Right : C) return T
        function "&"(Left : C; Right : T) return T
        function "&"(Left : C; Right : C) return T


                              Dynamic Semantics

5   For the evaluation of a concatenation with result type T, if both operands
are of type T, the result of the concatenation is a one-dimensional array
whose length is the sum of the lengths of its operands, and whose components
comprise the components of the left operand followed by the components of the
right operand. If the left operand is a null array, the result of the
concatenation is the right operand. Otherwise, the lower bound of the result
is determined as follows:

6     * If the ultimate ancestor of the array type was defined by a
        constrained_array_definition, then the lower bound of the result is
        that of the index subtype;

7     * If the ultimate ancestor of the array type was defined by an
        unconstrained_array_definition, then the lower bound of the result is
        that of the left operand.

8   The upper bound is determined by the lower bound and the length. A check
is made that the upper bound of the result of the concatenation belongs to the
range of the index subtype, unless the result is a null array.
Constraint_Error is raised if this check fails.

9   If either operand is of the component type C, the result of the
concatenation is given by the above rules, using in place of such an operand
an array having this operand as its only component (converted to the component
subtype) and having the lower bound of the index subtype of the array type as
its lower bound.

10  The result of a concatenation is defined in terms of an assignment to an
anonymous object, as for any function call (see 6.5).

        NOTES

11      16  As for all predefined operators on modular types, the binary
        adding operators + and - on modular types include a final reduction
        modulo the modulus if the result is outside the base range of the
        type.


                                  Examples

12  Examples of expressions involving binary adding operators:

13      Z + 0.1      --  Z has to be of a real type 

14      "A" & "BCD"  --  concatenation of two string literals
        'A' & "BCD"  --  concatenation of a character literal and a string literal
        'A' & 'A'    --  concatenation of two character literals 


4.5.4 Unary Adding Operators



                              Static Semantics

1   The unary adding operators + (identity) and - (negation) are predefined
for every specific numeric type T with their conventional meaning. They have
the following specifications:

2       function "+"(Right : T) return T
        function "-"(Right : T) return T

        NOTES

3       17  For modular integer types, the unary adding operator -, when given
        a nonzero operand, returns the result of subtracting the value of the
        operand from the modulus; for a zero operand, the result is zero.


4.5.5 Multiplying Operators



                              Static Semantics

1   The multiplying operators * (multiplication), / (division), mod (modulus),
and rem (remainder) are predefined for every specific integer type T:

2       function "*"  (Left, Right : T) return T
        function "/"  (Left, Right : T) return T
        function "mod"(Left, Right : T) return T
        function "rem"(Left, Right : T) return T

3   Signed integer multiplication has its conventional meaning.

4   Signed integer division and remainder are defined by the relation:

5       A = (A/B)*B + (A rem B)

6   where (A rem B) has the sign of A and an absolute value less than the
absolute value of B. Signed integer division satisfies the identity:

7       (-A)/B = -(A/B) = A/(-B)

8/3 The signed integer modulus operator is defined such that the result of A
mod B is either zero, or has the sign of B and an absolute value less than the
absolute value of B; in addition, for some signed integer value N, this result
satisfies the relation:

9       A = B*N + (A mod B)

10  The multiplying operators on modular types are defined in terms of the
corresponding signed integer operators, followed by a reduction modulo the
modulus if the result is outside the base range of the type (which is only
possible for the "*" operator).

11  Multiplication and division operators are predefined for every specific
floating point type T:

12      function "*"(Left, Right : T) return T
        function "/"(Left, Right : T) return T

13  The following multiplication and division operators, with an operand of
the predefined type Integer, are predefined for every specific fixed point
type T:

14      function "*"(Left : T; Right : Integer) return T
        function "*"(Left : Integer; Right : T) return T
        function "/"(Left : T; Right : Integer) return T

15  All of the above multiplying operators are usable with an operand of an
appropriate universal numeric type. The following additional multiplying
operators for root_real are predefined, and are usable when both operands are
of an appropriate universal or root numeric type, and the result is allowed to
be of type root_real, as in a number_declaration:

16      function "*"(Left, Right : root_real) return root_real
        function "/"(Left, Right : root_real) return root_real

17      function "*"(Left : root_real; Right : root_integer) return root_real
        function "*"(Left : root_integer; Right : root_real) return root_real
        function "/"(Left : root_real; Right : root_integer) return root_real

18  Multiplication and division between any two fixed point types are provided
by the following two predefined operators:

19      function "*"(Left, Right : universal_fixed) return universal_fixed
        function "/"(Left, Right : universal_fixed) return universal_fixed


                            Name Resolution Rules

19.1/2 The above two fixed-fixed multiplying operators shall not be used in a
context where the expected type for the result is itself universal_fixed - the
context has to identify some other numeric type to which the result is to be
converted, either explicitly or implicitly. Unless the predefined universal
operator is identified using an expanded name with prefix denoting the package
Standard, an explicit conversion is required on the result when using the
above fixed-fixed multiplication operator if either operand is of a type
having a user-defined primitive multiplication operator such that:

19.2/3   * it is declared immediately within the same declaration list as the
        type or any partial or incomplete view thereof; and

19.3/2   * both of its formal parameters are of a fixed-point type.

19.4/2 A corresponding requirement applies to the universal fixed-fixed
division operator.

Paragraph 20 was deleted.


                              Dynamic Semantics

21  The multiplication and division operators for real types have their
conventional meaning. For floating point types, the accuracy of the result is
determined by the precision of the result type. For decimal fixed point types,
the result is truncated toward zero if the mathematical result is between two
multiples of the small of the specific result type (possibly determined by
context); for ordinary fixed point types, if the mathematical result is
between two multiples of the small, it is unspecified which of the two is the
result.

22  The exception Constraint_Error is raised by integer division, rem, and mod
if the right operand is zero. Similarly, for a real type T with
T'Machine_Overflows True, division by zero raises Constraint_Error.

        NOTES

23      18  For positive A and B, A/B is the quotient and A rem B is the
        remainder when A is divided by B. The following relations are
        satisfied by the rem operator:

24               A  rem (-B) =   A rem B
               (-A) rem   B  = -(A rem B)

25      19  For any signed integer K, the following identity holds:

26             A mod B   =   (A + K*B) mod B

27      The relations between signed integer division, remainder, and modulus
        are illustrated by the following table:

28             A      B   A/B   A rem B  A mod B     A     B    A/B   A rem B   A mod B

29             10     5    2       0        0       -10    5    -2       0         0
               11     5    2       1        1       -11    5    -2      -1         4
               12     5    2       2        2       -12    5    -2      -2         3
               13     5    2       3        3       -13    5    -2      -3         2
               14     5    2       4        4       -14    5    -2      -4         1

30             A      B   A/B   A rem B  A mod B     A     B    A/B   A rem B   A mod B
            
               10    -5   -2       0        0       -10   -5     2       0         0
               11    -5   -2       1       -4       -11   -5     2      -1        -1
               12    -5   -2       2       -3       -12   -5     2      -2        -2
               13    -5   -2       3       -2       -13   -5     2      -3        -3
               14    -5   -2       4       -1       -14   -5     2      -4        -4


                                  Examples

31  Examples of expressions involving multiplying operators:

32      I : Integer := 1;
        J : Integer := 2;
        K : Integer := 3;

33      X : Real := 1.0;                      --     see 3.5.7
        Y : Real := 2.0;

34      F : Fraction := 0.25;                 --     see 3.5.9
        G : Fraction := 0.5;

35      Expression            Value          Result Type
        
        I*J                   2              same as I and J, that is, Integer
        K/J                   1              same as K and J, that is, Integer
        K mod J               1              same as K and J, that is, Integer
        
        X/Y                   0.5            same as X and Y, that is, Real
        F/2                   0.125          same as F, that is, Fraction
        
        3*F                   0.75           same as F, that is, Fraction
        0.75*G                0.375          
        universal_fixed, implicitly convertible
                                             to any fixed point type
        Fraction(F*G)         0.125          
        Fraction, as stated by the conversion
        Real(J)*Y             4.0            
        Real, the type of both operands after
                                             conversion of J


4.5.6 Highest Precedence Operators



                              Static Semantics

1   The highest precedence unary operator abs (absolute value) is predefined
for every specific numeric type T, with the following specification:

2       function "abs"(Right : T) return T

3   The highest precedence unary operator not (logical negation) is predefined
for every boolean type T, every modular type T, and for every one-dimensional
array type T whose components are of a boolean type, with the following
specification:

4       function "not"(Right : T) return T

5   The result of the operator not for a modular type is defined as the
difference between the high bound of the base range of the type and the value
of the operand. For a binary modulus, this corresponds to a bit-wise
complement of the binary representation of the value of the operand.

6   The operator not that applies to a one-dimensional array of boolean
components yields a one-dimensional boolean array with the same bounds; each
component of the result is obtained by logical negation of the corresponding
component of the operand (that is, the component that has the same index
value). A check is made that each component of the result belongs to the
component subtype; the exception Constraint_Error is raised if this check
fails.

7   The highest precedence exponentiation operator ** is predefined for every
specific integer type T with the following specification:

8       function "**"(Left : T; Right : Natural) return T

9   Exponentiation is also predefined for every specific floating point type
as well as root_real, with the following specification (where T is root_real
or the floating point type):

10      function "**"(Left : T; Right : Integer'Base) return T

11/3 The right operand of an exponentiation is the exponent. The value of X**N
with the value of the exponent N positive is the same as the value of X*X*...X
(with N-1 multiplications) except that the multiplications are associated in
an arbitrary order. With N equal to zero, the result is one. With the value of
N negative (only defined for a floating point operand), the result is the
reciprocal of the result using the absolute value of N as the exponent.


                         Implementation Permissions

12  The implementation of exponentiation for the case of a negative exponent
is allowed to raise Constraint_Error if the intermediate result of the
repeated multiplications is outside the safe range of the type, even though
the final result (after taking the reciprocal) would not be. (The best machine
approximation to the final result in this case would generally be 0.0.)

        NOTES

13      20  As implied by the specification given above for exponentiation of
        an integer type, a check is made that the exponent is not negative.
        Constraint_Error is raised if this check fails.


4.5.7 Conditional Expressions


1/3 A conditional_expression selects for evaluation at most one of the
enclosed dependent_expressions, depending on a decision among the
alternatives. One kind of conditional_expression is the if_expression, which
selects for evaluation a dependent_expression depending on the value of one or
more corresponding conditions. The other kind of conditional_expression is the
case_expression, which selects for evaluation one of a number of alternative
dependent_expressions; the chosen alternative is determined by the value of a
selecting_expression.


                                   Syntax

2/3     conditional_expression ::= if_expression | case_expression

3/3     if_expression ::= 
           if condition then dependent_expression
           {elsif condition then dependent_expression}
           [else dependent_expression]

4/3     condition ::= boolean_expression

5/3     case_expression ::= 
            case selecting_expression is
            case_expression_alternative {,
            case_expression_alternative}

6/3     case_expression_alternative ::= 
            when discrete_choice_list =>
                dependent_expression

7/3     Wherever the Syntax Rules allow an expression, a
        conditional_expression may be used in place of the expression, so long
        as it is immediately surrounded by parentheses.


                            Name Resolution Rules

8/3 If a conditional_expression is expected to be of a type T, then each
dependent_expression of the conditional_expression is expected to be of type
T. Similarly, if a conditional_expression is expected to be of some class of
types, then each dependent_expression of the conditional_expression is subject
to the same expectation. If a conditional_expression shall resolve to be of a
type T, then each dependent_expression shall resolve to be of type T.

9/3 The possible types of a conditional_expression are further determined as
follows:

10/3   * If the conditional_expression is the operand of a type conversion,
        the type of the conditional_expression is the target type of the
        conversion; otherwise,

11/3   * If all of the dependent_expressions are of the same type, the type of
        the conditional_expression is that type; otherwise,

12/3   * If a dependent_expression is of an elementary type, the type of the
        conditional_expression shall be covered by that type; otherwise,

13/3   * If the conditional_expression is expected to be of type T or shall
        resolve to type T, then the conditional_expression is of type T.

14/3 A condition is expected to be of any boolean type.

15/3 The expected type for the selecting_expression and the discrete_choices
are as for case statements (see 5.4).


                               Legality Rules

16/3 All of the dependent_expressions shall be convertible (see 4.6) to the
type of the conditional_expression.

17/3 If the expected type of a conditional_expression is a specific tagged
type, all of the dependent_expressions of the conditional_expression shall be
dynamically tagged, or none shall be dynamically tagged. In this case, the
conditional_expression is dynamically tagged if all of the
dependent_expressions are dynamically tagged, is tag-indeterminate if all of the
dependent_expressions are tag-indeterminate, and is statically tagged
otherwise.

18/3 If there is no else dependent_expression, the if_expression shall be of a
boolean type.

19/3 All Legality Rules that apply to the discrete_choices of a
case_statement (see 5.4) also apply to the discrete_choices of a
case_expression except within an instance of a generic unit.


                              Dynamic Semantics

20/3 For the evaluation of an if_expression, the condition specified after if,
and any conditions specified after elsif, are evaluated in succession
(treating a final else as elsif True then), until one evaluates to True or all
conditions are evaluated and yield False. If a condition evaluates to True,
the associated dependent_expression is evaluated, converted to the type of the
if_expression, and the resulting value is the value of the if_expression.
Otherwise (when there is no else clause), the value of the if_expression is
True.

21/3 For the evaluation of a case_expression, the selecting_expression is
first evaluated. If the value of the selecting_expression is covered by the
discrete_choice_list of some case_expression_alternative, then the
dependent_expression of the case_expression_alternative is evaluated, converted to the
type of the case_expression, and the resulting value is the value of the
case_expression. Otherwise (the value is not covered by any
discrete_choice_list, perhaps due to being outside the base range),
Constraint_Error is raised.


                                  Examples

22/5    Put_Line ("Casey is " & (if Casey.Sex = M then "Male" else "Female")); -- see 3.10.1

23/5    function Card_Color (Card : Suit) return Color is -- see 3.5.1
          (case Card is
              when Clubs  | Spades   => Black,
              when Hearts | Diamonds => Red);


4.5.8 Quantified Expressions


0.1/4 Quantified expressions provide a way to write universally and
existentially quantified predicates over containers and arrays.


                                   Syntax

1/3     quantified_expression ::= for quantifier
         loop_parameter_specification => predicate
          | for quantifier iterator_specification => predicate

2/3     quantifier ::= all | some

3/3     predicate ::= boolean_expression

4/3     Wherever the Syntax Rules allow an expression, a
        quantified_expression may be used in place of the expression, so long
        as it is immediately surrounded by parentheses.


                            Name Resolution Rules

5/3 The expected type of a quantified_expression is any Boolean type. The
predicate in a quantified_expression is expected to be of the same type.


                              Dynamic Semantics

6/5 For the evaluation of a quantified_expression, the
loop_parameter_specification or iterator_specification is first elaborated.
The evaluation of a quantified_expression then performs an iteration, and
evaluates the predicate for each value conditionally produced by the iteration
(see 5.5 and 5.5.2).

7/3 The value of the quantified_expression is determined as follows:

8/4   * If the quantifier is all, the expression is False if the evaluation of
        any predicate yields False; evaluation of the quantified_expression
        stops at that point. Otherwise (every predicate has been evaluated and
        yielded True), the expression is True. Any exception raised by
        evaluation of the predicate is propagated.

9/4   * If the quantifier is some, the expression is True if the evaluation of
        any predicate yields True; evaluation of the quantified_expression
        stops at that point. Otherwise (every predicate has been evaluated and
        yielded False), the expression is False. Any exception raised by
        evaluation of the predicate is propagated.


                                  Examples

10/3 The postcondition for a sorting routine on an array A with an index
subtype T can be written:

11/3    Post => (A'Length < 2 or else
           (for all I in A'First .. T'Pred(A'Last) => A (I) <= A (T'Succ (I))))

12/3 The assertion that a positive number is composite (as opposed to prime)
can be written:

13/5    pragma Assert (for some X in 2 .. N when X * X <= N => N mod X = 0);
           -- see iterator_filter in 5.5


4.5.9 Declare Expressions


1/5 Declare expressions provide a way to declare local constants and object
renamings in an expression context.


                                   Syntax

2/5     declare_expression ::= 
            declare {declare_item}
            begin body_expression

3/5     declare_item ::= object_declaration | object_renaming_declaration

4/5     Wherever the Syntax Rules allow an expression, a declare_expression
        may be used in place of the expression, so long as it is immediately
        surrounded by parentheses.


                               Legality Rules

5/5 A declare_item that is an object_declaration shall declare a constant of a
nonlimited type.

6/5 A declare_item that is an object_renaming_declaration (see 8.5.1) shall
not rename an object of a limited type if any operative constituent of the
object_name is a value conversion or is newly constructed (see 4.4).

7/5 The following are not allowed within a declare_expression: a declaration
containing the reserved word aliased; the attribute_designator Access or
Unchecked_Access; or an anonymous access type.


                            Name Resolution Rules

8/5 If a declare_expression is expected to be of a type T, then the
body_expression is expected to be of type T. Similarly, if a declare_expression is
expected to be of some class of types, then the body_expression is subject to
the same expectation. If a declare_expression shall resolve to be of a type T,
then the body_expression shall resolve to be of type T.

9/5 The type of a declare_expression is the type of the body_expression.


                              Dynamic Semantics

10/5 For the evaluation of a declare_expression, the declare_items are
elaborated in order, and then the body_expression is evaluated. The value of
the declare_expression is that of the body_expression.


                                  Examples

11/5 The postcondition for Ada.Containers.Vectors."&" (see A.18.2) could have
been written:

12/5    with Post =>
           (declare
              Result renames Vectors."&"'Result;
              Length : constant Count_Type := Left.Length + Right.Length;
            begin
              Result.Length = Length and then
              not Tampering_With_Elements_Prohibited (Result) and then
              not Tampering_With_Cursors_Prohibited (Result) and then
              Result.Capacity >= Length)


4.5.10 Reduction Expressions


1/5 Reduction expressions provide a way to map or transform a collection of
values into a new set of values, and then summarize the values produced by
applying an operation to reduce the set to a single value result. A reduction
expression is represented as an attribute_reference of the reduction
attributes Reduce or Parallel_Reduce.


                                   Syntax

2/5     reduction_attribute_reference ::= 
            value_sequence'reduction_attribute_designator
          | prefix'reduction_attribute_designator

3/5     value_sequence ::= 
            '[' [parallel[(chunk_specification
        )]] iterated_element_association ']'

4/5     reduction_attribute_designator ::= reduction_identifier
        (reduction_specification)

5/5     reduction_specification ::= reducer_name, initial_value_expression

6/5     The iterated_element_association of a value_sequence shall not have a
        key_expression, nor shall it have a loop_parameter_specification that
        has the reserved word reverse.

7/5     The chunk_specification, if any, of a value_sequence shall be an
        integer_simple_expression.


                            Name Resolution Rules

8/5 The expected type for a reduction_attribute_reference shall be a single
nonlimited type.

9/5 In the remainder of this subclause, we will refer to nonlimited subtypes
Value_Type and Accum_Type of a reduction_attribute_reference. These subtypes
and interpretations of the names and expressions of a
reduction_attribute_reference are determined by the following rules:

10/5   * Accum_Type is a subtype of the expected type of the
        reduction_attribute_reference.

11/5   * A reducer subprogram is either subtype conformant with the following
        specification:

12/5       function Reducer(Accumulator : Accum_Type; Value : Value_Type) return Accum_Type;

13/5    or is subtype conformant with the following specification:

14/5       procedure Reducer(Accumulator : in out Accum_Type; Value : in Value_Type);

15/5   * The reducer_name of a reduction_specification denotes a reducer
        subprogram.

16/5   * The expected type of an initial_value_expression of a
        reduction_specification is that of subtype Accum_Type.

17/5   * The expected type of the expression of the
        iterated_element_association of a value_sequence is that of subtype
        Value_Type.


                               Legality Rules

18/5 If the reduction_attribute_reference has a value_sequence with the
reserved word parallel, the subtypes Accum_Type and Value_Type shall
statically match.

19/5 If the identifier of a reduction_attribute_designator is Parallel_Reduce,
the subtypes Accum_Type and Value_Type shall statically match.


                              Static Semantics

20/5 A reduction_attribute_reference denotes a value, with nominal subtype
being the subtype of the first parameter of the subprogram denoted by the
reducer_name.


                              Dynamic Semantics

21/5 For the evaluation of a value_sequence, the
iterated_element_association is elaborated, then an iteration is performed,
and for each value conditionally produced by the iteration (see 5.5 and
5.5.2), the associated expression is evaluated with the loop parameter having
this value, to produce a result that is converted to Value_Type, and used to
define the next value in the sequence.

22/5 If the value_sequence does not have the reserved word parallel, it is
produced as a single sequence of values by a single logical thread of control.
If the reserved word parallel is present in the value_sequence, the enclosing
reduction_attribute_reference is a parallel construct, and the sequence of
values is generated by a parallel iteration (as defined in 5.5, 5.5.1, and
5.5.2), as a set of non-empty, non-overlapping contiguous chunks
(subsequences) with one logical thread of control (see clause 9) associated
with each subsequence. If there is a chunk_specification, it determines the
maximum number of chunks, as defined in 5.5; otherwise the maximum number of
chunks is implementation defined.

23/5 For a value_sequence V, the following attribute is defined:

24/5 V'Reduce(Reducer, Initial_Value)
                This attribute represents a reduction expression, and is in
                the form of a reduction_attribute_reference.

25/5            The evaluation of a use of this attribute begins by evaluating
                the parts of the reduction_attribute_designator (the
                reducer_name Reducer and the initial_value_expression Initial_Value),
                in an arbitrary order. It then initializes the accumulator of
                the reduction expression to the value of the
                initial_value_expression (the initial value). The value_sequence V is then
                evaluated.

26/5            If the value_sequence does not have the reserved word
                parallel, each value of the value_sequence is passed, in
                order, as the second (Value) parameter to a call on Reducer,
                with the first (Accumulator) parameter being the prior value
                of the accumulator, saving the result as the new value of the
                accumulator. The reduction expression yields the final value
                of the accumulator.

27/5            If the reserved word parallel is present in a value_sequence,
                then the (parallel) reduction expression is a parallel
                construct and the sequence has been partitioned into one or
                more subsequences (see above) each with its own separate
                logical thread of control.

28/5            Each logical thread of control creates a local accumulator for
                processing its subsequence. The accumulator for a subsequence
                is initialized to the first value of the subsequence, and
                calls on Reducer start with the second value of the
                subsequence (if any). The result for the subsequence is the
                final value of its local accumulator.

29/5            After all logical threads of control of a parallel reduction
                expression have completed, Reducer is called for each
                subsequence, in the original sequence order, passing the local
                accumulator for that subsequence as the second (Value)
                parameter, and the overall accumulator (initialized above to
                the initial value) as the first (Accumulator) parameter, with
                the result saved back in the overall accumulator. The parallel
                reduction expression yields the final value of the overall
                accumulator.

30/5            If the evaluation of the value_sequence yields an empty
                sequence of values, the reduction expression yields the
                initial value.

31/5            If an exception is propagated by one of the calls on Reducer,
                that exception is propagated from the reduction expression. If
                different exceptions are propagated in different logical
                threads of control, one is chosen arbitrarily to be propagated
                from the reduction expression as a whole.

32/5 For a prefix X of an array type (after any implicit dereference), or that
denotes an iterable container object (see 5.5.1), the following attributes are
defined:

33/5 X'Reduce(Reducer, Initial_Value)
                X'Reduce is a reduction expression that yields a result
                equivalent to replacing the prefix of the attribute with the
                value_sequence:

33.1/5              [for Item of X => Item]

34/5 X'Parallel_Reduce(Reducer, Initial_Value)
                X'Parallel_Reduce is a reduction expression that yields a
                result equivalent to replacing the attribute identifier with
                Reduce and the prefix of the attribute with the
                value_sequence:

34.1/5              [parallel for Item of X => Item]


                          Bounded (Run-Time) Errors

35/5 For a parallel reduction expression, it is a bounded error if the reducer
subprogram is not associative. That is, for any arbitrary values of subtype
Value_Type A, B, C and a reducer function R, the result of R (A, R (B, C))
should produce a result equal to R (R (A, B), C)). The possible consequences
are Program_Error, or a result that does not match the equivalent sequential
reduction expression due to the order of calls on the reducer subprogram being
unspecified in the overall reduction. Analogous rules apply in the case of a
reduction procedure.


                                  Examples

36/5 An expression function that returns its result as a Reduction Expression:

37/5    function Factorial(N : Natural) return Natural is
           ([for J in 1..N => J]'Reduce("*", 1));

38/5 An expression function that computes the Sine of X using a Taylor
expansion:

39/5    function Sine (X : Float; Num_Terms : Positive := 5) return Float is
           ([for I in 1..Num_Terms => (-1.0)**(I-1) * X**(2*I-1)/Float(Factorial(2*I-1))]
              'Reduce("+", 0.0));

40/5 A reduction expression that outputs the sum of squares:

41/5    Put_Line ("Sum of Squares is" &
                  Integer'Image([for I in 1 .. 10 => I**2]'Reduce("+", 0)));

42/5 An expression function to compute the value of Pi:

43/5    --  See 3.5.7.
        function Pi (Number_Of_Steps : Natural := 10_000) return Real is
          (1.0 / Real (Number_Of_Steps) *
            [for I in 1 .. Number_Of_Steps =>
                (4.0 / (1.0 + ((Real (I) - 0.5) * 
                   (1.0 / Real (Number_Of_Steps)))**2))]
                      'Reduce("+", 0.0));

44/5 Calculate the sum of elements of an array of integers:

45/5    A'Reduce("+",0)  -- See 4.3.3.

46/5 Determine if all elements in a two-dimensional array of booleans are set
to true:

47/5    Grid'Reduce("and", True)  -- See 3.6.

48/5 Calculate the minimum value of an array of integers in parallel:

49/5    A'Parallel_Reduce(Integer'Min, Integer'Last)

50/5 A parallel reduction expression used to calculate the mean of the
elements of a two-dimensional array of subtype Matrix (see 3.6) that are
greater than 100.0:

51/5    type Accumulator is record
           Sum   : Real; -- See 3.5.7.
           Count : Integer;
        end record;

52/5    function Accumulate (L, R : Accumulator) return Accumulator is
          (Sum   => L.Sum   + R.Sum,
           Count => L.Count + R.Count);

53/5    function Average_of_Values_Greater_Than_100 (M : Matrix) return Real is
           (declare
               Acc : constant Accumulator :=
                  [parallel for Val of M when Val > 100.0 => (Val, 1)]
                     'Reduce(Accumulate, (Sum => 0, Count => 0));
            begin
               Acc.Sum / Real(Acc.Count));


4.6 Type Conversions


1/3 Explicit type conversions, both value conversions and view conversions,
are allowed between closely related types as defined below. This subclause
also defines rules for value and view conversions to a particular subtype of a
type, both explicit ones and those implicit in other constructs.


                                   Syntax

2       type_conversion ::= 
            subtype_mark(expression)
          | subtype_mark(name)

3   The target subtype of a type_conversion is the subtype denoted by the
subtype_mark. The operand of a type_conversion is the expression or name
within the parentheses; its type is the operand type.

4/3 One type is convertible to a second type if a type_conversion with the
first type as operand type and the second type as target type is legal
according to the rules of this subclause. Two types are convertible if each is
convertible to the other.

5/2 A type_conversion whose operand is the name of an object is called a view
conversion if both its target type and operand type are tagged, or if it
appears in a call as an actual parameter of mode out or in out; other
type_conversions are called value conversions.


                            Name Resolution Rules

6   The operand of a type_conversion is expected to be of any type.

7   The operand of a view conversion is interpreted only as a name; the
operand of a value conversion is interpreted as an expression.


                               Legality Rules

8/2 In a view conversion for an untagged type, the target type shall be
convertible (back) to the operand type.

Paragraphs 9 through 20 were reorganized and moved below.

21/3 If there is a type (other than a root numeric type) that is an ancestor
of both the target type and the operand type, or both types are class-wide
types, then at least one of the following rules shall apply:

21.1/2   * The target type shall be untagged; or

22    * The operand type shall be covered by or descended from the target
        type; or

23/2   * The operand type shall be a class-wide type that covers the target
        type; or

23.1/2   * The operand and target types shall both be class-wide types and the
        specific type associated with at least one of them shall be an
        interface type.

24/3 If there is no type (other than a root numeric type) that is the ancestor
of both the target type and the operand type, and they are not both class-wide
types, one of the following rules shall apply:

24.1/2   * If the target type is a numeric type, then the operand type shall
        be a numeric type.

24.2/2   * If the target type is an array type, then the operand type shall be
        an array type. Further:

24.3/2    * The types shall have the same dimensionality;

24.4/2    * Corresponding index types shall be convertible;

24.5/2    * The component subtypes shall statically match;

24.6/2    * If the component types are anonymous access types, then the
            accessibility level of the operand type shall not be statically
            deeper than that of the target type;

24.7/2    * Neither the target type nor the operand type shall be limited;

24.8/2    * If the target type of a view conversion has aliased components,
            then so shall the operand type; and

24.9/2    * The operand type of a view conversion shall not have a tagged,
            private, or volatile subcomponent.

24.10/2   * If the target type is universal_access, then the operand type
        shall be an access type.

24.11/2   * If the target type is a general access-to-object type, then the
        operand type shall be universal_access or an access-to-object type.
        Further, if the operand type is not universal_access:

24.12/2   * If the target type is an access-to-variable type, then the operand
            type shall be an access-to-variable type;

24.13/2   * If the target designated type is tagged, then the operand
            designated type shall be convertible to the target designated
            type;

24.14/2   * If the target designated type is not tagged, then the designated
            types shall be the same, and either:

24.15/2       * the designated subtypes shall statically match; or

24.16/2       * the designated type shall be discriminated in its full view
                and unconstrained in any partial view, and one of the
                designated subtypes shall be unconstrained;

24.17/4   * The accessibility level of the operand type shall not be
            statically deeper than that of the target type, unless the target
            type is an anonymous access type of a stand-alone object. If the
            target type is that of such a stand-alone object, the
            accessibility level of the operand type shall not be statically
            deeper than that of the declaration of the stand-alone object.

24.18/2   * If the target type is a pool-specific access-to-object type, then
        the operand type shall be universal_access.

24.19/2   * If the target type is an access-to-subprogram type, then the
        operand type shall be universal_access or an access-to-subprogram
        type. Further, if the operand type is not universal_access:

24.20/3   * The designated profiles shall be subtype conformant.

24.21/4   * The accessibility level of the operand type shall not be
            statically deeper than that of the target type. If the operand
            type is declared within a generic body, the target type shall be
            declared within the generic body.

24.22/5   * If the target type is nonblocking, the operand type shall be
            nonblocking.

24.23/5 In addition to the places where Legality Rules normally apply (see
12.3), these rules apply also in the private part of an instance of a generic
unit.


                              Static Semantics

25  A type_conversion that is a value conversion denotes the value that is the
result of converting the value of the operand to the target subtype.

26/3 A type_conversion that is a view conversion denotes a view of the object
denoted by the operand. This view is a variable of the target type if the
operand denotes a variable; otherwise, it is a constant of the target type.

27  The nominal subtype of a type_conversion is its target subtype.


                              Dynamic Semantics

28  For the evaluation of a type_conversion that is a value conversion, the
operand is evaluated, and then the value of the operand is converted to a
corresponding value of the target type, if any. If there is no value of the
target type that corresponds to the operand value, Constraint_Error is raised;
this can only happen on conversion to a modular type, and only when the
operand value is outside the base range of the modular type. Additional rules
follow:

29    * Numeric Type Conversion

30        * If the target and the operand types are both integer types, then
            the result is the value of the target type that corresponds to the
            same mathematical integer as the operand.

31        * If the target type is a decimal fixed point type, then the result
            is truncated (toward 0) if the value of the operand is not a
            multiple of the small of the target type.

32        * If the target type is some other real type, then the result is
            within the accuracy of the target type (see G.2, "
            Numeric Performance Requirements", for implementations that
            support the Numerics Annex).

33        * If the target type is an integer type and the operand type is
            real, the result is rounded to the nearest integer (away from zero
            if exactly halfway between two integers).

34    * Enumeration Type Conversion

35        * The result is the value of the target type with the same position
            number as that of the operand value.

36    * Array Type Conversion

37        * If the target subtype is a constrained array subtype, then a check
            is made that the length of each dimension of the value of the
            operand equals the length of the corresponding dimension of the
            target subtype. The bounds of the result are those of the target
            subtype.

38        * If the target subtype is an unconstrained array subtype, then the
            bounds of the result are obtained by converting each bound of the
            value of the operand to the corresponding index type of the target
            type. For each nonnull index range, a check is made that the
            bounds of the range belong to the corresponding index subtype.

39        * In either array case, the value of each component of the result is
            that of the matching component of the operand value (see 4.5.2).

39.1/2    * If the component types of the array types are anonymous access
            types, then a check is made that the accessibility level of the
            operand type is not deeper than that of the target type.

40    * Composite (Non-Array) Type Conversion

41        * The value of each nondiscriminant component of the result is that
            of the matching component of the operand value.

42        * The tag of the result is that of the operand. If the operand type
            is class-wide, a check is made that the tag of the operand
            identifies a (specific) type that is covered by or descended from
            the target type.

43        * For each discriminant of the target type that corresponds to a
            discriminant of the operand type, its value is that of the
            corresponding discriminant of the operand value; if it corresponds
            to more than one discriminant of the operand type, a check is made
            that all these discriminants are equal in the operand value.

44        * For each discriminant of the target type that corresponds to a
            discriminant that is specified by the derived_type_definition for
            some ancestor of the operand type (or if class-wide, some ancestor
            of the specific type identified by the tag of the operand), its
            value in the result is that specified by the
            derived_type_definition.

45        * For each discriminant of the operand type that corresponds to a
            discriminant that is specified by the derived_type_definition for
            some ancestor of the target type, a check is made that in the
            operand value it equals the value specified for it.

46        * For each discriminant of the result, a check is made that its
            value belongs to its subtype.

47    * Access Type Conversion

48/3      * For an access-to-object type, a check is made that the
            accessibility level of the operand type is not deeper than that of
            the target type, unless the target type is an anonymous access
            type of a stand-alone object. If the target type is that of such a
            stand-alone object, a check is made that the accessibility level
            of the operand type is not deeper than that of the declaration of
            the stand-alone object; then if the check succeeds, the
            accessibility level of the target type becomes that of the operand
            type.

49/2      * If the operand value is null, the result of the conversion is the
            null value of the target type.

50        * If the operand value is not null, then the result designates the
            same object (or subprogram) as is designated by the operand value,
            but viewed as being of the target designated subtype (or profile);
            any checks associated with evaluating a conversion to the target
            designated subtype are performed.

51/5 After conversion of the value to the target type, if the target subtype
is constrained, a check is performed that the value satisfies this constraint.
If the target subtype excludes null, then a check is made that the value is
not null. If predicate checks are enabled for the target subtype (see 3.2.4),
a check is performed that the value satisfies the predicates of the target
subtype, unless the conversion is:.

51.1/5   * a view conversion that is an actual parameter of mode out; or

51.2/5   * an implicit subtype conversion of an actual parameter of mode out
        to the nominal subtype of its formal parameter.

52  For the evaluation of a view conversion, the operand name is evaluated,
and a new view of the object denoted by the operand is created, whose type is
the target type; if the target type is composite, checks are performed as
above for a value conversion.

53  The properties of this new view are as follows:

54/1   * If the target type is composite, the bounds or discriminants (if any)
        of the view are as defined above for a value conversion; each
        nondiscriminant component of the view denotes the matching component
        of the operand object; the subtype of the view is constrained if
        either the target subtype or the operand object is constrained, or if
        the target subtype is indefinite, or if the operand type is a
        descendant of the target type and has discriminants that were not
        inherited from the target type;

55    * If the target type is tagged, then an assignment to the view assigns
        to the corresponding part of the object denoted by the operand;
        otherwise, an assignment to the view assigns to the object, after
        converting the assigned value to the subtype of the object (which
        might raise Constraint_Error);

56/4   * Reading the value of the view yields the result of converting the
        value of the operand object to the target subtype (which might raise
        Constraint_Error), except if the object is of an elementary type and
        the view conversion is passed as an out parameter; in this latter
        case, the value of the operand object may be used to initialize the
        formal parameter without checking against any constraint of the target
        subtype (as described more precisely in 6.4.1).

57/4 If an Accessibility_Check fails, Program_Error is raised. If a predicate
check fails, the effect is as defined in subclause 3.2.4, "
Subtype Predicates". Any other check associated with a conversion raises
Constraint_Error if it fails.

58  Conversion to a type is the same as conversion to an unconstrained subtype
of the type.

58.1/5 Evaluation of a value conversion of an object either creates a new
anonymous object (similar to the object created by the evaluation of an
aggregate or a function call) or yields a new view of the operand object
without creating a new object:

58.2/4   * If the target type is a by-reference type and there is a type that
        is an ancestor of both the target type and the operand type then no
        new object is created;

58.3/4   * If the target type is an array type having aliased components and
        the operand type is an array type having unaliased components, then a
        new object is created;

58.4/5   * If the target type is an elementary type, then a new object is
        created;

58.5/5   * Otherwise, it is unspecified whether a new object is created.

58.6/5 If a new object is created, then the initialization of that object is
an assignment operation.

        NOTES

59      21  In addition to explicit type_conversions, type conversions are
        performed implicitly in situations where the expected type and the
        actual type of a construct differ, as is permitted by the type
        resolution rules (see 8.6). For example, an integer literal is of the
        type universal_integer, and is implicitly converted when assigned to a
        target of some specific integer type. Similarly, an actual parameter
        of a specific tagged type is implicitly converted when the
        corresponding formal parameter is of a class-wide type.

60      Even when the expected and actual types are the same, implicit subtype
        conversions are performed to adjust the array bounds (if any) of an
        operand to match the desired target subtype, or to raise
        Constraint_Error if the (possibly adjusted) value does not satisfy the
        constraints of the target subtype.

61/2    22  A ramification of the overload resolution rules is that the
        operand of an (explicit) type_conversion cannot be an allocator, an
        aggregate, a string_literal, a character_literal, or an
        attribute_reference for an Access or Unchecked_Access attribute.
        Similarly, such an expression enclosed by parentheses is not allowed.
        A qualified_expression (see 4.7) can be used instead of such a
        type_conversion.

62      23  The constraint of the target subtype has no effect for a
        type_conversion of an elementary type passed as an out parameter.
        Hence, it is recommended that the first subtype be specified as the
        target to minimize confusion (a similar recommendation applies to
        renaming and generic formal in out objects).


                                  Examples

63  Examples of numeric type conversion:

64      Real(2*J)      --  value is converted to floating point
        Integer(1.6)   --  value is 2
        Integer(-0.4)  --  value is 0

65  Example of conversion between derived types:

66      type A_Form is new B_Form;

67      X : A_Form;
        Y : B_Form;

68      X := A_Form(Y);
        Y := B_Form(X);  --  the reverse conversion 

69  Examples of conversions between array types:

70      type Sequence is array (Integer range <>) of Integer;
        subtype Dozen is Sequence(1 .. 12);
        Ledger : array(1 .. 100) of Integer;

71      Sequence(Ledger)            --  bounds are those of Ledger
        Sequence(Ledger(31 .. 42))  --  bounds are 31 and 42
        Dozen(Ledger(31 .. 42))     --  bounds are those of Dozen 


4.7 Qualified Expressions


1   A qualified_expression is used to state explicitly the type, and to verify
the subtype, of an operand that is either an expression or an aggregate.


                                   Syntax

2       qualified_expression ::= 
           subtype_mark'(expression) | subtype_mark'aggregate


                            Name Resolution Rules

3/5 The expected type for the operand (the expression or aggregate) is
determined by the subtype_mark. Furthermore, the operand shall resolve to be
either the specified expected type or a universal type that covers it.


                              Static Semantics

3.1/3 If the operand of a qualified_expression denotes an object, the
qualified_expression denotes a constant view of that object. The nominal
subtype of a qualified_expression is the subtype denoted by the subtype_mark.


                              Dynamic Semantics

4/4 The evaluation of a qualified_expression evaluates the operand (and if of
a universal type, converts it to the type determined by the subtype_mark) and
checks that its value belongs to the subtype denoted by the subtype_mark. The
exception Constraint_Error is raised if this check fails. Furthermore, if
predicate checks are enabled for the subtype denoted by the subtype_mark, a
check is performed as defined in subclause 3.2.4, "Subtype Predicates" that
the value satifies the predicates of the subtype.

        NOTES

5       24  When a given context does not uniquely identify an expected type,
        a qualified_expression can be used to do so. In particular, if an
        overloaded name or aggregate is passed to an overloaded subprogram, it
        might be necessary to qualify the operand to resolve its type.


                                  Examples

6   Examples of disambiguating expressions using qualification:

7       type Mask is (Fix, Dec, Exp, Signif);
        type Code is (Fix, Cla, Dec, Tnz, Sub);

8       Print (Mask'(Dec));  --  Dec is of type Mask
        Print (Code'(Dec));  --  Dec is of type Code 

9       for J in Code'(Fix) .. Code'(Dec) loop ... -- qualification needed for either Fix or Dec
        for J in Code range Fix .. Dec loop ...    -- qualification unnecessary
        for J in Code'(Fix) .. Dec loop ...        -- qualification unnecessary for Dec

10      Dozen'(1 | 3 | 5 | 7 => 2, others => 0) -- see 4.6 


4.8 Allocators


1   The evaluation of an allocator creates an object and yields an access
value that designates the object.


                                   Syntax

2/3     allocator ::= 
           new [subpool_specification] subtype_indication
         | new [subpool_specification] qualified_expression

2.1/3   subpool_specification ::= (subpool_handle_name)

2.2/3   For an allocator with a subtype_indication, the subtype_indication
        shall not specify a null_exclusion.


                            Name Resolution Rules

3/3 The expected type for an allocator shall be a single access-to-object type
with designated type D such that either D covers the type determined by the
subtype_mark of the subtype_indication or qualified_expression, or the
expected type is anonymous and the determined type is D'Class. A
subpool_handle_name is expected to be of any type descended from
Subpool_Handle, which is the type used to identify a subpool, declared in
package System.Storage_Pools.Subpools (see 13.11.4).


                               Legality Rules

4   An initialized allocator is an allocator with a qualified_expression. An
uninitialized allocator is one with a subtype_indication. In the
subtype_indication of an uninitialized allocator, a constraint is permitted
only if the subtype_mark denotes an unconstrained composite subtype; if there
is no constraint, then the subtype_mark shall denote a definite subtype.

5/2 If the type of the allocator is an access-to-constant type, the
allocator shall be an initialized allocator.

5.1/3 If a subpool_specification is given, the type of the storage pool of the
access type shall be a descendant of Root_Storage_Pool_With_Subpools.

5.2/3 If the designated type of the type of the allocator is class-wide, the
accessibility level of the type determined by the subtype_indication or
qualified_expression shall not be statically deeper than that of the type of
the allocator.

5.3/3 If the subtype determined by the subtype_indication or
qualified_expression of the allocator has one or more access discriminants,
then the accessibility level of the anonymous access type of each access
discriminant shall not be statically deeper than that of the type of the
allocator (see 3.10.2).

5.4/3 An allocator shall not be of an access type for which the Storage_Size
has been specified by a static expression with value zero or is defined by the
language to be zero.

5.5/3 If the designated type of the type of the allocator is limited, then the
allocator shall not be used to define the value of an access discriminant,
unless the discriminated type is immutably limited (see 7.5).

5.6/3 In addition to the places where Legality Rules normally apply (see
12.3), these rules apply also in the private part of an instance of a generic
unit.


                              Static Semantics

6/3 If the designated type of the type of the allocator is elementary, then
the subtype of the created object is the designated subtype. If the designated
type is composite, then the subtype of the created object is the designated
subtype when the designated subtype is constrained or there is an ancestor of
the designated type that has a constrained partial view; otherwise, the
created object is constrained by its initial value (even if the designated
subtype is unconstrained with defaults).


                              Dynamic Semantics

7/2 For the evaluation of an initialized allocator, the evaluation of the
qualified_expression is performed first. An object of the designated type is
created and the value of the qualified_expression is converted to the
designated subtype and assigned to the object.

8   For the evaluation of an uninitialized allocator, the elaboration of the
subtype_indication is performed first. Then:

9/2   * If the designated type is elementary, an object of the designated
        subtype is created and any implicit initial value is assigned;

10/2   * If the designated type is composite, an object of the designated type
        is created with tag, if any, determined by the subtype_mark of the
        subtype_indication. This object is then initialized by default (see
        3.3.1) using the subtype_indication to determine its nominal subtype.
        A check is made that the value of the object belongs to the designated
        subtype. Constraint_Error is raised if this check fails. This check
        and the initialization of the object are performed in an arbitrary
        order.

10.1/3 For any allocator, if the designated type of the type of the
allocator is class-wide, then a check is made that the master of the type
determined by the subtype_indication, or by the tag of the value of the
qualified_expression, includes the elaboration of the type of the allocator.
If any part of the subtype determined by the subtype_indication or
qualified_expression of the allocator (or by the tag of the value if the type
of the qualified_expression is class-wide) has one or more access
discriminants, then a check is made that the accessibility level of the
anonymous access type of each access discriminant is not deeper than that of
the type of the allocator. Program_Error is raised if either such check fails.

10.2/2 If the object to be created by an allocator has a controlled or
protected part, and the finalization of the collection of the type of the
allocator (see 7.6.1) has started, Program_Error is raised.

10.3/2 If the object to be created by an allocator contains any tasks, and the
master of the type of the allocator is completed, and all of the dependent
tasks of the master are terminated (see 9.3), then Program_Error is raised.

10.4/3 If the allocator includes a subpool_handle_name, Constraint_Error is
raised if the subpool handle is null. Program_Error is raised if the subpool
does not belong (see 13.11.4) to the storage pool of the access type of the
allocator.

11  If the created object contains any tasks, they are activated (see 9.2).
Finally, an access value that designates the created object is returned.


                          Bounded (Run-Time) Errors

11.1/2  It is a bounded error if the finalization of the collection of the
type (see 7.6.1) of the allocator has started. If the error is detected,
Program_Error is raised. Otherwise, the allocation proceeds normally.

        NOTES

12      25  Allocators cannot create objects of an abstract type. See 3.9.3.

13      26  If any part of the created object is controlled, the
        initialization includes calls on corresponding Initialize or Adjust
        procedures. See 7.6.

14      27  As explained in 13.11, "Storage Management", the storage for an
        object allocated by an allocator comes from a storage pool (possibly
        user defined). The exception Storage_Error is raised by an allocator
        if there is not enough storage. Instances of Unchecked_Deallocation
        may be used to explicitly reclaim storage.

15/3    28  Implementations are permitted, but not required, to provide
        garbage collection.


                                  Examples

16  Examples of allocators:

17      new Cell'(0, null, null)                          -- initialized explicitly, see 3.10.1
        new Cell'(Value => 0, Succ => null, Pred => null) -- initialized explicitly
        new Cell                                          -- not initialized

18      new Matrix(1 .. 10, 1 .. 20)                      -- the bounds only are given
        new Matrix'(1 .. 10 => (1 .. 20 => 0.0))          -- initialized explicitly

19      new Buffer(100)                                   -- the discriminant only is given
        new Buffer'(Size => 80, Pos => 0, Value => (1 .. 80 => 'A')) -- initialized explicitly

20      Expr_Ptr'(new Literal)                  -- allocator for access-to-class-wide type, see 3.9.1
        Expr_Ptr'(new Literal'(Expression with 3.5))      -- initialized explicitly


4.9 Static Expressions and Static Subtypes


1   Certain expressions of a scalar or string type are defined to be static.
Similarly, certain discrete ranges are defined to be static, and certain
scalar and string subtypes are defined to be static subtypes. Static means
determinable at compile time, using the declared properties or values of the
program entities.


                              Static Semantics

2   A static expression is a scalar or string expression that is one of the
following:

3/5   * a numeric_literal of a numeric type;

4     * a string_literal of a static string subtype;

5     * a name that denotes the declaration of a named number or a static
        constant;

6     * a function_call whose function_name or function_prefix statically
        denotes a static function, and whose actual parameters, if any
        (whether given explicitly or by default), are all static expressions;

7     * an attribute_reference that denotes a scalar value, and whose prefix
        denotes a static scalar subtype;

8/5   * an attribute_reference whose prefix statically names a statically
        constrained array object or array subtype, and whose
        attribute_designator is First, Last, or Length, with an optional
        dimension;

8.1/5   * an attribute_reference whose prefix denotes a non-generic entity
        that is not declared in a generic unit, and whose
        attribute_designator is Nonblocking;

9/5   * a type_conversion whose subtype_mark denotes a static (scalar or
        string) subtype, and whose operand is a static expression;

10    * a qualified_expression whose subtype_mark denotes a static (scalar or
        string) subtype, and whose operand is a static expression;

11/4   * a membership test whose tested_simple_expression is a static
        expression, and whose membership_choice_list consists only of
        membership_choices that are either static choice_simple_expressions,
        static ranges, or subtype_marks that denote a static (scalar or
        string) subtype;

12    * a short-circuit control form both of whose relations are static
        expressions;

12.1/3   * a conditional_expression all of whose conditions,
        selecting_expressions, and dependent_expressions are static expressions;

12.2/5   * a declare_expression whose body_expression is static and each of
        whose declarations, if any, is either the declaration of a static
        constant or is an object_renaming_declaration with an object_name that
        statically names the renamed object;

13    * a static expression enclosed in parentheses.

14  A name statically denotes an entity if it denotes the entity and:

15    * It is a direct_name, expanded name, or character_literal, and it
        denotes a declaration other than a renaming_declaration; or

16    * It is an attribute_reference whose prefix statically denotes some
        entity; or

16.1/5   * It is a target_name (see 5.2.1) in an assignment_statement whose
        variable_name statically denotes some entity; or

17    * It denotes a renaming_declaration with a name that statically denotes
        the renamed entity.

17.1/5 A name statically names an object if it:

17.2/5   * statically denotes the declaration of an object (possibly through
        one or more renames);

17.3/5   * is a selected_component whose prefix statically names an object,
        there is no implicit dereference of the prefix, and the
        selector_name does not denote a component_declaration occurring within
        a variant_part; or

17.4/5   * is an indexed_component whose prefix statically names an object,
        there is no implicit dereference of the prefix, the object is
        statically constrained, and the index expressions of the object are
        static and have values that are within the range of the index
        constraint.

17.5/5 For an entity other than an object, a name statically names an entity
if the name statically denotes the entity.

18  A static function is one of the following:

19    * a predefined operator whose parameter and result types are all scalar
        types none of which are descendants of formal scalar types;

19.1/5   * a predefined relational operator whose parameters are of a string
        type that is not a descendant of a formal array type;

20/5   * a predefined concatenation operator whose result type is a string
        type that is not a descendant of a formal array type;

21    * an enumeration literal;

21.1/5   * a static expression function (see 6.8);

22    * a language-defined attribute that is a function, if the prefix denotes
        a static scalar subtype, and if the parameter and result types are
        scalar.

23  In any case, a generic formal subprogram is not a static function.

24/5 A static constant is a constant view declared by a full constant
declaration or an object_renaming_declaration with a static nominal subtype,
having a value defined by a static scalar expression or by a static string
expression.

25  A static range is a range whose bounds are static expressions, or a range_-
attribute_reference that is equivalent to such a range. A static discrete_-
range is one that is a static range or is a subtype_indication that defines a
static scalar subtype. The base range of a scalar type is a static range,
unless the type is a descendant of a formal scalar type.

26/3 A static subtype is either a static scalar subtype or a static string
subtype. A static scalar subtype is an unconstrained scalar subtype whose type
is not a descendant of a formal type, or a constrained scalar subtype formed
by imposing a compatible static constraint on a static scalar subtype. A
static string subtype is an unconstrained string subtype whose index subtype
and component subtype are static, or a constrained string subtype formed by
imposing a compatible static constraint on a static string subtype. In any
case, the subtype of a generic formal object of mode in out, and the result
subtype of a generic formal function, are not static. Also, a subtype is not
static if any Dynamic_Predicate specifications apply to it.

27  The different kinds of static constraint are defined as follows:

28    * A null constraint is always static;

29    * A scalar constraint is static if it has no range_constraint, or one
        with a static range;

30    * An index constraint is static if each discrete_range is static, and
        each index subtype of the corresponding array type is static;

31    * A discriminant constraint is static if each expression of the
        constraint is static, and the subtype of each discriminant is static.

31.1/2 In any case, the constraint of the first subtype of a scalar formal
type is neither static nor null.

32  A subtype is statically constrained if it is constrained, and its
constraint is static. An object is statically constrained if its nominal
subtype is statically constrained, or if it is a static string constant.


                               Legality Rules

32.1/3 An expression is statically unevaluated if it is part of:

32.2/3   * the right operand of a static short-circuit control form whose
        value is determined by its left operand; or

32.3/3   * a dependent_expression of an if_expression whose associated
        condition is static and equals False; or

32.4/3   * a condition or dependent_expression of an if_expression where the
        condition corresponding to at least one preceding
        dependent_expression of the if_expression is static and equals True; or

32.5/3   * a dependent_expression of a case_expression whose
        selecting_expression is static and whose value is not covered by the
        corresponding discrete_choice_list; or

32.6/4   * a choice_simple_expression (or a simple_expression of a range that
        occurs as a membership_choice of a membership_choice_list) of a static
        membership test that is preceded in the enclosing
        membership_choice_list by another item whose individual membership
        test (see 4.5.2) statically yields True.

33/3 A static expression is evaluated at compile time except when it is
statically unevaluated. The compile-time evaluation of a static expression is
performed exactly, without performing Overflow_Checks. For a static expression
that is evaluated:

34/3   * The expression is illegal if its evaluation fails a language-defined
        check other than Overflow_Check. For the purposes of this evaluation,
        the assertion policy is assumed to be Check.

35/2   * If the expression is not part of a larger static expression and the
        expression is expected to be of a single specific type, then its value
        shall be within the base range of its expected type. Otherwise, the
        value may be arbitrarily large or small.

36/2   * If the expression is of type universal_real and its expected type is
        a decimal fixed point type, then its value shall be a multiple of the
        small of the decimal type. This restriction does not apply if the
        expected type is a descendant of a formal scalar type (or a
        corresponding actual type in an instance).

37/2 In addition to the places where Legality Rules normally apply (see 12.3
), the above restrictions also apply in the private part of an instance of a
generic unit.


                         Implementation Requirements

38/2 For a real static expression that is not part of a larger static
expression, and whose expected type is not a descendant of a formal type, the
implementation shall round or truncate the value (according to the
Machine_Rounds attribute of the expected type) to the nearest machine number
of the expected type; if the value is exactly half-way between two machine
numbers, the rounding performed is implementation-defined. If the expected
type is a descendant of a formal type, or if the static expression appears in
the body of an instance of a generic unit and the corresponding expression is
nonstatic in the corresponding generic body, then no special rounding or
truncating is required - normal accuracy rules apply (see Annex G).


                            Implementation Advice

38.1/2 For a real static expression that is not part of a larger static
expression, and whose expected type is not a descendant of a formal type, the
rounding should be the same as the default rounding for the target system.

        NOTES

39      29  An expression can be static even if it occurs in a context where
        staticness is not required.

40      30  A static (or run-time) type_conversion from a real type to an
        integer type performs rounding. If the operand value is exactly
        half-way between two integers, the rounding is performed away from
        zero.


                                  Examples

41  Examples of static expressions:

42      1 + 1       -- 2
        abs(-10)*3  -- 30

43      Kilo : constant := 1000;
        Mega : constant := Kilo*Kilo;   -- 1_000_000
        Long : constant := Float'Digits*2;

44      Half_Pi    : constant := Pi/2;           -- see 3.3.2
        Deg_To_Rad : constant := Half_Pi/90;
        Rad_To_Deg : constant := 1.0/Deg_To_Rad; -- equivalent to 1.0/((3.14159_26536/2)/90)


4.9.1 Statically Matching Constraints and Subtypes



                              Static Semantics

1/2 A constraint statically matches another constraint if:

1.1/2   * both are null constraints;

1.2/2   * both are static and have equal corresponding bounds or discriminant
        values;

1.3/2   * both are nonstatic and result from the same elaboration of a
        constraint of a subtype_indication or the same evaluation of a range
        of a discrete_subtype_definition; or

1.4/2   * both are nonstatic and come from the same formal_type_declaration.

2/5 A subtype statically matches another subtype of the same type if they have
statically matching constraints, all predicate specifications that apply to
them come from the same declarations, Object_Size (see 13.3) has been
specified to have a nonconfirming value for either both or neither, and the
nonconfirming values, if any, are the same, and, for access subtypes, either
both or neither exclude null. Two anonymous access-to-object subtypes
statically match if their designated subtypes statically match, and either
both or neither exclude null, and either both or neither are
access-to-constant. Two anonymous access-to-subprogram subtypes statically
match if their designated profiles are subtype conformant, and either both or
neither exclude null.

3   Two ranges of the same type statically match if both result from the same
evaluation of a range, or if both are static and have equal corresponding
bounds.

4/3 A constraint is statically compatible with a scalar subtype if it
statically matches the constraint of the subtype, or if both are static and
the constraint is compatible with the subtype. A constraint is statically
compatible with an access or composite subtype if it statically matches the
constraint of the subtype, or if the subtype is unconstrained.

5/3 Two statically matching subtypes are statically compatible with each
other. In addition, a subtype S1 is statically compatible with a subtype S2
if:

6/3   * the constraint of S1 is statically compatible with S2, and

7/3   * if S2 excludes null, so does S1, and

8/3   * either:

9/3       * all predicate specifications that apply to S2 apply also to S1, or

10/4      * both subtypes are static, every value that satisfies the
            predicates of S1 also satisfies the predicates of S2, and it is
            not the case that both types each have at least one applicable
            predicate specification, predicate checks are enabled (see
            11.4.2) for S2, and predicate checks are not enabled for S1.


4.10 Image Attributes


1/5 An image of a value is a string representing the value in display form.
The attributes Image, Wide_Image, and Wide_Wide_Image are available to produce
the image of a value as a String, Wide_String, or Wide_Wide_String
(respectively). User-defined images for a given type can be implemented by
overriding the default implementation of the attribute Put_Image.


                              Static Semantics

2/5 For every subtype S of a type T other than universal_real or
universal_fixed, the following type-related operational attribute is defined:

3/5 S'Put_Image S'Put_Image denotes a procedure with the following
                specification:

3.1/5               procedure S'Put_Image
                       (Buffer : in out Ada.Strings.Text_Buffers.Root_Buffer_Type'Class;
                        Arg    : in T);

3.2/5           The default implementation of S'Put_Image writes (using
                Wide_Wide_Put) an image of the value of Arg.

4/5 The Put_Image attribute may be specified for any specific type T either
via an attribute_definition_clause or via an aspect_specification specifying
the Put_Image aspect of the type.

5/5 The behavior of the default implementation of S'Put_Image depends on the
class of T. For an elementary type, the implementation is equivalent to:

6/5     procedure Scalar_Type'Put_Image
          (Buffer : in out Ada.Strings.Text_Buffers.Root_Buffer_Type'Class;
           Arg    : in Scalar_Type) is
        begin
           Buffer.Wide_Wide_Put (<described below>);
        end Scalar_Type'Put_Image;

7/5 where the Wide_Wide_String value written out to the stream is defined as
follows:

8/5 For an integer type, the image written out is the corresponding decimal
literal, without underlines, leading zeros, exponent, or trailing spaces, but
with a single leading character that is either a minus sign or a space.

9/5 For an enumeration type, the image written out is either the corresponding
identifier in upper case or the corresponding character literal (including the
two apostrophes); neither leading nor trailing spaces are included. For a
nongraphic character (a value of a character type that has no enumeration
literal associated with it), the value is a corresponding language-defined
name in upper case (for example, the image of the nongraphic character
identified as nul is "NUL" - the quotes are not part of the image).

10/5 For a floating point type, the image written out is a decimal real
literal best approximating the value (rounded away from zero if halfway
between) with a single leading character that is either a minus sign or a
space, a single digit (that is nonzero unless the value is zero), a decimal
point, S'Digits-1 (see 3.5.8) digits after the decimal point (but one if
S'Digits is one), an upper case E, the sign of the exponent (either + or -),
and two or more digits (with leading zeros if necessary) representing the
exponent. If S'Signed_Zeros is True, then the leading character is a minus
sign for a negatively signed zero.

11/5 For a fixed point type, the image written out is a decimal real literal
best approximating the value (rounded away from zero if halfway between) with
a single leading character that is either a minus sign or a space, one or more
digits before the decimal point (with no redundant leading zeros), a decimal
point, and S'Aft (see 3.5.10) digits after the decimal point.

12/5 For an access type (named or anonymous), the image written out depends on
whether the value is null. If it is null, then the image is "NULL". Otherwise
the image is a left parenthesis followed by "ACCESS", a space, and a sequence
of graphic characters, other than space or right parenthesis, representing the
location of the designated object, followed by a right parenthesis, as in
"(ACCESS FF0012AC)".

13/5 For an array type T, the default implementation of T'Put_Image generates
an image based on (named, not positional) array aggregate syntax (with '[' and
']' as the delimiters) using calls to the Put_Image procedures of the index
type(s) and the element type to generate images for values of those types.

14/5 The case of a null array is handled specially, using ranges for index
bounds and "<>" as a syntactic component-value placeholder.

15/5 The order in which components are written for a composite type is the
same canonical order in which components of a composite type T are written out
by the default implementation of T'Write. This is also the order that is used
in determining the meaning of a positional aggregate of type T.

16/5 For a class-wide type, the default implementation of T'Put_Image
generates an image based on qualified expression syntax.
Wide_Wide_String'Write is called with Wide_Wide_Expanded_Name of Arg'Tag. Then
S'Put_Image is called, where S is the specific type identified by Arg'Tag.

17/5 For a type extension, the default implementation of T'Put_Image depends
on whether there exists a noninterface ancestor of T (other than T itself) for
which the Put_Image aspect has been explicitly specified. If so, then
T'Put_Image will generate an image based on extension aggregate syntax where
the ancestor type of the extension aggregate is the nearest ancestor type
whose Put_Image aspect has been specified.

18/5 If no such ancestor exists, then the default implementation of
T'Put_Image is the same as described below for an untagged record type.

19/5 For an untagged record type, a specific tagged record type other than a
type extension which meets the criteria described in the previous paragraph,
or a protected type, the default implementation of T'Put_Image generates an
image based on (named, not positional) record aggregate syntax (except that
for a protected type, the initial left parenthesis is followed by "PROTECTED
with "). Component names are displayed in upper case, following the rules for
the image of an enumeration value. Component values are displayed via calls to
the component type's Put_Image procedure.

20/5 The image written out for a record having no components (including any
interface type) is "(NULL RECORD)". The image written out for a componentless
protected type is "(PROTECTED NULL RECORD)". In the case of a protected type
T, a call to the default implementation of T'Put_Image begins only one
protected (read-only) action.

21/5 For an undiscriminated task type, the default implementation of
T'Put_Image generates an image of the form "(TASK <task_id_image>)" where
<task_id_image> is the result obtained by calling Task_Identification.Image
with the id of the given task and then passing that String to
Characters.Conversions.To_Wide_Wide_String.

22/5 For a discriminated task type, the default implementation of T'Put_Image
also includes discriminant values, as in:

23/5    "(TASK <task_id_image> with D1 =>  123, D2 =>  456)"

24/5 For every subtype S of a type T, the following attributes are defined:

25/5 S'Wide_Wide_Image
                S'Wide_Wide_Image denotes a function with the following
                specification:

25.1/5              function S'Wide_Wide_Image(Arg : S'Base)
                      return Wide_Wide_String

25.2/5          S'Wide_Wide_Image calls S'Put_Image passing Arg (which will
                typically store a sequence of character values in a text
                buffer) and then returns the result of retrieving the contents
                of that buffer with Wide_Wide_Get. The lower bound of the
                result is one.

26/5 S'Wide_Image
                S'Wide_Image denotes a function with the following
                specification:

27/5                function S'Wide_Image(Arg : S'Base)
                      return Wide_String

28/5            S'Wide_Image calls S'Put_Image passing Arg (which will
                typically store a sequence of character values in a text
                buffer) and then returns the result of retrieving the contents
                of that buffer with Wide_Get. The lower bound of the result is
                one.

29/5 S'Image    S'Image denotes a function with the following specification:

30/5                function S'Image(Arg : S'Base)
                      return String

31/5            S'Image calls S'Put_Image passing Arg (which will typically
                store a sequence of character values in a text buffer) and
                then returns the result of retrieving the contents of that
                buffer with Get. The lower bound of the result is one.

32/5 For a prefix X of a type T other than universal_real or universal_fixed,
the following attributes are defined:

33/5 X'Wide_Wide_Image
                X'Wide_Wide_Image denotes the result of calling function
                S'Wide_Wide_Image with Arg being X, where S is the nominal
                subtype of X.

34/5 X'Wide_Image
                X'Wide_Image denotes the result of calling function
                S'Wide_Image with Arg being X, where S is the nominal subtype
                of X.

35/5 X'Image    X'Image denotes the result of calling function S'Image with
                Arg being X, where S is the nominal subtype of X.


                         Implementation Permissions

36/5 An implementation may transform the image generated by the default
implementation of S'Put_Image for a composite subtype S in the following ways:

37/5   * If S is a composite subtype, the leading character of the image of a
        component value or index value is a space, and the immediately
        preceding character is an open parenthesis or bracket, then the space
        may be omitted. The same transformation is also permitted if the
        leading character of the component image is a space (in which case one
        of the two spaces may be omitted).

38/5   * If S is an array subtype, the low bound of the array in each
        dimension equals the low bound of the corresponding index subtype, and
        the array value is not a null array value, then positional array
        aggregate syntax may be used.

39/5   * If S is an array subtype and the given value can be displayed using
        named_array_aggregate syntax where some discrete_choice_list
        identifies more than one index value by identifying a sequence of one
        or more ranges and values separated by vertical bars, then this image
        may be generated instead; this may involve the reordering of component
        values.

40/5   * Similarly, if S is a record subtype (or a discriminated type) and the
        given value can be displayed using named component association syntax
        where the length of some component_choice_list is greater than one,
        then this image may be generated instead; this may involve the
        reordering of component values.

41/5   * Additional spaces (Wide_Wide_Characters with position 32), and calls
        to the New_Line operation of a text buffer, may be inserted to improve
        readability of the generated image.

42/5 For each language-defined nonscalar type T, T'Put_Image may be specified.


                         Implementation Requirements

43/5 For each language-defined container type T (that is, each of the Vector,
List, Map, Set, Tree, and Holder types defined in the various children of
Ada.Containers), T'Put_Image shall be specified so that T'Image produces a
result consistent with array aggregate syntax (using '[' and ']' as
delimiters) as follows:

44/5   * Vector images shall be consistent with the default image of an array
        type with the same index and component types.

45/5   * Map images shall be consistent with named array aggregate syntax,
        using key value images in place of discrete choice names. For example,
        [Key1 => Value1, Key2 => Value2].

46/5   * Set, List, and Holder images shall be consistent with positional
        array aggregate syntax. List elements shall occur in order within an
        image of a list. The image of an empty holder shall be [].

47/5   * Tree images (and images of subtrees of trees) shall be consistent
        with positional array aggregate syntax. For example, [[1, 2], [111,
        222, 333]].

48/5 For each language-defined nonscalar type T that has a primitive
language-defined Image function whose profile is type conformant with that of
T'Image (for example, Ada.Numerics.Float_Random.State has such an Image
function), T'Put_Image shall be specified so that T'Image yields the same
result as that Image function.


                            Implementation Advice

49/5 For each language-defined private type T, T'Image should generate an
image that would be meaningful based only on the relevant public interfaces,
as opposed to requiring knowledge of the implementation of the private type.

