Contents Index Previous Next
4.3 Aggregates
1
[
{aggregate} An
aggregate combines component values into a composite value of
an array type, record type, or record extension.]
{literal:
See also aggregate}
Syntax
2
aggregate
::= record_aggregate |
extension_aggregate |
array_aggregate
Name Resolution Rules
3
{expected type (aggregate)
[partial]} The expected type for an
aggregate
shall be a single nonlimited array type, record type, or record extension.
3.a
Legality Rules
4
An aggregate
shall not be of a class-wide type.
4.a
Ramification: When the
expected type in some context is class-wide, an aggregate has to be explicitly
qualified by the specific type of value to be created, so that the expected
type for the aggregate itself is specific.
4.b
Discussion: We used to
disallow aggregates of a type with
unknown discriminants. However, that was unnecessarily restrictive in
the case of an extension aggregate, and irrelevant to a record aggregate
(since a type that is legal for a record aggregate could not possibly
have unknown discriminants) and to an array aggregate (the only specific
types that can have unknown discriminants are private types, private
extensions, and types derived from them).
Dynamic Semantics
5
{evaluation (aggregate) [partial]}
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.
{assignment operation (during evaluation of an aggregate)}
Obtaining the values and the assignments occur in
an arbitrary order. The value of the
aggregate
is the value of this object.
5.a
Discussion: The ancestor
part is the set of components inherited from the ancestor type. The syntactic
category ancestor_part is the expression
or subtype_mark that specifies how
the ancestor part of the anonymous object should be initialized.
5.b
Ramification: The assignment operations
do the necessary value adjustment, as described in 7.6.
Note that the value as a whole is not adjusted -- just the subcomponents (and
ancestor part, if any). 7.6 also describes when this
anonymous object is finalized.
5.c
If the ancestor_part
is a subtype_mark the Initialize procedure
for the ancestor type is applied to the ancestor part after default-initializing
it, unless the procedure is abstract, as described in 7.6.
The Adjust procedure for the ancestor type is not called in this case, since
there is no assignment to the ancestor part as a whole.
6
{Discriminant_Check [partial]}
{check, language-defined (Discriminant_Check)}
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 (raised by failure
of run-time check)} Constraint_Error is
raised if this check fails.
6.a
Ramification: This check ensures
that no values of a tagged type are ever outside the first subtype, as required
for inherited dispatching operations to work properly (see 3.4).
This check will always succeed if the first subtype is unconstrained. This check
is not extended to untagged types to preserve upward compatibility.
Extensions to Ada 83
6.b
{extensions to Ada 83}
We now allow extension_aggregates.
Wording Changes from Ada 83
6.c
We have adopted new wording for
expressing the rule that the type of an aggregate shall be determinable
from the outside, though using the fact that it is nonlimited record
(extension) or array.
6.d
An aggregate
now creates an anonymous object. This is necessary so that controlled types
will work (see 7.6).
Contents Index Previous Next Legal