H.7.1 The Use_Formal and Dispatching Aspects
{
AI12-0380-1}
The Use_Formal and Dispatching aspects are provided
to more precisely describe the use of generic formal parameters and dispatching
calls within the execution of an operation, enabling more precise checking
of conformance with the Nonblocking and global aspects that apply at
the point of invocation of the operation.
{
AI12-0079-3}
{
AI12-0380-1}
For any declaration within a generic unit for which
a global or Nonblocking aspect may be specified, other than a generic_formal_parameter_declaration,
the following aspect may be specified to indicate which generic formal
parameters are used by the associated entity:
The aspect is specified with a formal_parameter_set,
with the following form:
Aspect Description
for Use_Formal: Generic
formal parameters used in the implementation of an entity.
formal_group_designator ::= null | all
formal_parameter_name ::=
formal_subtype_mark
| formal_subprogram_name
| formal_access_to_subprogram_object_name
{
AI12-0079-3}
{
AI12-0380-1}
For any declaration for which a global or Nonblocking
aspect may be specified, other than for a library package, a generic
library package, or a generic formal, the following aspect may be specified:
The aspect is specified with a dispatching_operation_set,
with the following form:
Aspect Description
for Dispatching: Generic
formal parameters used in the implementation of an entity.
dispatching_operation_specifier ::=
dispatching_operation_name (object_name)
Name Resolution Rules
{
AI12-0380-1}
A formal_parameter_name
in a Use_Formal aspect shall resolve to statically denote a formal subtype,
a formal subprogram, or a formal object of an anonymous access-to-subprogram
type[ of an enclosing generic unit or visible formal package].
Static Semantics
{
AI12-0380-1}
{
AI12-0439-1}
The formal parameter set
is identified by a set of formal_parameter_names.
Alternatively, the reserved word null may be used to indicate
none of the generic formal parameters, or all to indicate all
of the generic formal parameters, of any enclosing generic unit (or visible
formal package) can be used within the execution of the operation. If
there is no formal parameter set specified for an entity declared within
a generic unit, it defaults to all.
Ramification: The
object "controlling the call" is not necessarily a controlling
parameter of the call if the call is a function with a controlling result
or has parameters that is such a function. It is one of the objects that
provide the dispatching tag used for the call; that could, for example,
be a parameter of a function used as a parameter to the call, or an object
being assigned to, or a parameter of an enclosing call.
{
AI12-0380-1}
{
AI12-0404-1}
In the absence of any dispatching_operation_specifiers,
or if none of them match a dispatching call C within an operation
P, Nonblocking and global aspects checks are performed at the
point of the call C within P using the Nonblocking and
Global'Class aspects that apply to the dispatching operation named in
call C. If there is a match, any global access or potential blocking
within the subprogram body invoked by the call C is ignored at
the point of call within P. Instead, when the operation P
itself is invoked, Nonblocking and global aspect checks are performed
presuming each named dispatching operation is called at least once (with
the named object controlling the call), but similarly ignoring those
dispatching calls that would match a dispatching_operation_specifier
applicable at the point of invocation of P.
Legality Rules
{
AI12-0380-1}
Within an operation to which a Use_Formal aspect
applies, if the formal parameter set is anything but all, then
the only generic formal subtypes that may be used, the only formal subprograms
that may be called, and the only formal objects of an anonymous access-to-subprogram
type that may be dereferenced as part of a call or passed as the actual
for an access parameter, are those included in the formal parameter set.
{
AI12-0380-1}
When an operation (or instance thereof) to which
a Use_Formal aspect applies is invoked, Nonblocking and global aspect
checks are performed presuming each generic formal parameter (or corresponding
actual parameter) of the formal parameter set is used at least once.
Examples
{
AI12-0430-1}
An example of use of the Dispatching aspect:
procedure My_Write( -- see 13.13.2
Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Item : My_Integer'Base)
with Dispatching => Write(Stream);
for My_Integer'Write use My_Write;
{
AI12-0430-1}
For examples of use of the Use_Formal aspect,
see the Element functions of Hashed_Sets in A.18.8.
Extensions to Ada 2012
{
AI12-0079-3}
The aspects Use_Formal and
Dispatching are new.
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe