Annotated Ada Reference ManualLegal Information
Contents   Index   References   Search   Previous   Next 

3.2.3 Classification of Operations

Static Semantics

1/2
{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.
1.a
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.
1.b
To be honest: Protected subprograms are not considered to be “primitive subprograms,” even though they are subprograms, and they are inherited by derived types. 
1.c
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. 
2
The primitive subprograms of a specific type are defined as follows:
3
The predefined operators of the type (see 4.5);
4
For a derived type, the inherited (see 3.4) user-defined subprograms;
5
For an enumeration type, the enumeration literals (which are considered parameterless functions — see 3.5.1);
6
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;
6.1/3
{AI05-0128-1} For a specific type with an explicitly declared primitive "=" operator whose result type is Boolean, the corresponding "/=" operator (see 6.6);
7/2
{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. 
7.a
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. 
7.b
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.
7.c
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”. 
7.d/2
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). 
8
A primitive subprogram whose designator is an operator_symbol is called a primitive operator.

Incompatibilities With Ada 83

8.a
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

8.b
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

8.c
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.
8.d
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

8.e/2
{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.
8.f/2
{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

8.g/3
{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. 

Contents   Index   References   Search   Previous   Next 
Ada-Europe Ada 2005 and 2012 Editions sponsored in part by Ada-Europe