3.2.3 Classification of Operations
Static Semantics
{
AI95-00416-01}
An operation
operates on a type T if
it yields a value of type
T, if it has an operand whose expected
type (see
8.6) is
T, or if it has an
access parameter or access result type (see
6.1)
designating
T.
A predefined operator, or other
language-defined operation such as assignment or a membership test, that
operates on a type, is called a
predefined operation of the type.
The
primitive operations of a type are the
predefined operations of the type, plus any user-defined primitive subprograms.
Glossary entry: The primitive operations
of a type are the operations (such as subprograms) declared together
with the type declaration. They are inherited by other types in the same
class of types. For a tagged type, the primitive subprograms are dispatching
subprograms, providing run-time polymorphism. A dispatching subprogram
may be called with statically tagged operands, in which case the subprogram
body invoked is determined at compile time. Alternatively, a dispatching
subprogram may be called using a dispatching call, in which case the
subprogram body invoked is determined at run time.
To be honest: Protected subprograms are
not considered to be “primitive subprograms,” even though
they are subprograms, and they are inherited by derived types.
Discussion: We use the term “primitive
subprogram” in most of the rest of the manual. The term “primitive
operation” is used mostly in conceptual discussions.
The
primitive subprograms of a specific type are defined as follows:
The predefined operators of the type (see
4.5);
For a derived type, the inherited (see
3.4)
user-defined subprograms;
For an enumeration type, the enumeration literals
(which are considered parameterless functions — see
3.5.1);
For a specific type declared immediately within
a
package_specification,
any subprograms (in addition to the enumeration literals) that are explicitly
declared immediately within the same
package_specification
and that operate on the type;
{
AI05-0128-1}
For a specific type with an explicitly declared primitive "="
operator whose result type is Boolean, the corresponding "/="
operator (see
6.6);
{
AI95-00200-01}
For a nonformal type, any subprograms not covered
above [that are explicitly declared immediately within the same declarative
region as the type] and that override (see
8.3)
other implicitly declared primitive subprograms of the type.
Discussion: In Ada 83, only subprograms
declared in the visible part were “primitive” (i.e. derivable).
In Ada 95, mostly because of child library units, we include all operations
declared in the private part as well, and all operations that override
implicit declarations.
Ramification: It is possible for a subprogram
to be primitive for more than one type, though it is illegal for a subprogram
to be primitive for more than one tagged type. See
3.9.
Discussion: The order of the implicit
declarations when there are both predefined operators and inherited subprograms
is described in
3.4, “
Derived
Types and Classes”.
Ramification: {
AI95-00200-01}
Subprograms declared in a generic package specification are never primitive
for a formal type, even if they happen to override an operation of the
formal type. This includes formal subprograms, which are never primitive
operations (that's true even for an abstract formal subprogram).
A primitive subprogram whose
designator is an
operator_symbol
is called a
primitive operator.
Incompatibilities With Ada 83
The attribute S'Base is
no longer defined for nonscalar subtypes. Since this was only permitted
as the prefix of another attribute, and there are no interesting nonscalar
attributes defined for an unconstrained composite or access subtype,
this should not affect any existing programs.
Extensions to Ada 83
The primitive subprograms
(derivable subprograms) include subprograms declared in the private part
of a package specification as well, and those that override implicitly
declared subprograms, even if declared in a body.
Wording Changes from Ada 83
We have dropped the confusing term operation
of a type in favor of the more useful primitive operation of a
type and the phrase operates on a type.
The description of S'Base has been moved to
3.5, “
Scalar Types”
because it is now defined only for scalar types.
Wording Changes from Ada 95
{
AI95-00200-01}
Clarified that a formal subprogram that happens to override a primitive
operation of a formal type is not a primitive operation (and thus not
a dispatching operation) of the formal type.
{
AI95-00416-01}
Added wording to include access result types in the kinds of operations
that operate on a type T.
Wording Changes from Ada 2005
{
AI05-0128-1}
Correction: The implicitly declared "/=" for a primitive
"=" operator is also primitive; this makes it eligible to be
made visible by a
use type clause.
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe