4.7 Qualified Expressions
Syntax
Name Resolution Rules
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
Dynamic Semantics
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
3.2.4
that the value satifies the predicates of the subtype.
NOTE 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 can be necessary to qualify
the operand to resolve its type.
Examples
Examples of disambiguating
expressions using qualification:
type Mask is (Fix, Dec, Exp, Signif);
type Code is (Fix, Cla, Dec, Tnz, Sub);
Print (Mask'(Dec)); -- Dec is of type Mask
Print (Code'(Dec)); -- Dec is of type Code
for J in Code'(Fix) .. Code'(Dec) loop ... -- qualification is necessary 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
Dozen'(1 | 3 | 5 | 7 => 2,
others => 0)
-- see 4.6
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe