8.3.1 Overriding Indicators
Syntax
Legality Rules
the operation shall be a primitive operation for
some type;
if the
overriding_indicator
is
overriding, then the operation shall override a homograph at
the place of the declaration or body;
To be honest: {
AI05-0005-1}
This doesn't require that the overriding happen at precisely the place
of the declaration or body; it only requires that the region in which
the overriding is known to have happened includes this place. That is,
the overriding can happen at or before the place of the declaration or
body.
if the
overriding_indicator
is
not overriding, then the operation shall not override any homograph
(at any place).
In addition to the places where
Legality Rules normally apply, these rules also apply in the private
part of an instance of a generic unit.
Discussion: The overriding and
not overriding rules differ slightly. For overriding, we
want the indicator to reflect the overriding state at the place of the
declaration; otherwise the indicator would be “lying”. Whether
a homograph is implicitly declared after the declaration (see 7.3.1 to
see how this can happen) has no impact on this check. However, not
overriding is different; “lying” would happen if a homograph
declared later actually is overriding. So, we require this check to take
into account later overridings. That can be implemented either by looking
ahead, or by rechecking when additional operations are declared.
Examples
{
AI95-00433-01}
The use of
overriding_indicators
allows the detection of errors at compile-time that otherwise might not
be detected at all. For instance, we might declare a security queue derived
from the Queue interface of 3.9.4 as:
type Security_Queue is new Queue with record ...;
overriding
procedure Append(Q : in out Security_Queue; Person : in Person_Name);
overriding
procedure Remove_First(Q : in out Security_Queue; Person : in Person_Name);
overriding
function Cur_Count(Q : in Security_Queue) return Natural;
overriding
function Max_Count(Q : in Security_Queue) return Natural;
not overriding
procedure Arrest(Q : in out Security_Queue; Person : in Person_Name);
The first four subprogram declarations guarantee
that these subprograms will override the four subprograms inherited from
the Queue interface. A misspelling in one of these subprograms will be
detected by the implementation. Conversely, the declaration of Arrest
guarantees that this is a new operation.
Discussion: In this case, the subprograms
are abstract, so misspellings will get detected anyway. But for other
subprograms (especially when deriving from concrete types), the error
might never be detected, and a body other than the one the programmer
intended might be executed without warning. Thus our new motto: “Overriding
indicators — don't derive a type without them!”
Extensions to Ada 95
{
AI95-00218-03}
Overriding_indicators
are new. These let the programmer state her overriding intentions to
the compiler; if the compiler disagrees, an error will be produced rather
than a hard to find bug.
Wording Changes from Ada 2005
{
AI95-0177-1}
Expression functions can have overriding indicators.
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe