Ada Reference ManualLegal Information
Contents   Index   References   Search   Previous   Next 

8.5.4 Subprogram Renaming Declarations

1
A subprogram_renaming_declaration can serve as the completion of a subprogram_declaration; such a renaming_declaration is called a renaming-as-body. A subprogram_renaming_declaration that is not a completion is called a renaming-as-declaration, and is used to rename a subprogram (possibly an enumeration literal) or an entry. 

Syntax

2/2
subprogram_renaming_declaration ::= 
    [overriding_indicator]
    subprogram_specification renames callable_entity_name;

Name Resolution Rules

3
The expected profile for the callable_entity_name is the profile given in the subprogram_specification.

Legality Rules

4
The profile of a renaming-as-declaration shall be mode-conformant with that of the renamed callable entity.
4.1/2
  For a parameter or result subtype of the subprogram_specification that has an explicit null_exclusion:
4.2/2
4.3/2
5/1
The profile of a renaming-as-body shall conform fully to that of the declaration it completes. If the renaming-as-body completes that declaration before the subprogram it declares is frozen, the profile shall be mode-conformant with that of the renamed callable entity and the subprogram it declares takes its convention from the renamed subprogram; otherwise, the profile shall be subtype-conformant with that of the renamed callable entity and the convention of the renamed subprogram shall not be Intrinsic. A renaming-as-body is illegal if the declaration occurs before the subprogram whose declaration it completes is frozen, and the renaming renames the subprogram itself, through one or more subprogram renaming declarations, none of whose subprograms has been frozen. 
5.1/2
  The callable_entity_name of a renaming shall not denote a subprogram that requires overriding (see 3.9.3). 
5.2/2
  The callable_entity_name of a renaming-as-body shall not denote an abstract subprogram. 
6
A name that denotes a formal parameter of the subprogram_specification is not allowed within the callable_entity_name.

Static Semantics

7
A renaming-as-declaration declares a new view of the renamed entity. The profile of this new view takes its subtypes, parameter modes, and calling convention from the original profile of the callable entity, while taking the formal parameter names and default_expressions from the profile given in the subprogram_renaming_declaration. The new view is a function or procedure, never an entry. 

Dynamic Semantics

7.1/1
  For a call to a subprogram whose body is given as a renaming-as-body, the execution of the renaming-as-body is equivalent to the execution of a subprogram_body that simply calls the renamed subprogram with its formal parameters as the actual parameters and, if it is a function, returns the value of the call. 
8
For a call on a renaming of a dispatching subprogram that is overridden, if the overriding occurred before the renaming, then the body executed is that of the overriding declaration, even if the overriding declaration is not visible at the place of the renaming; otherwise, the inherited or predefined subprogram is called. 

Bounded (Run-Time) Errors

8.1/1
  If a subprogram directly or indirectly renames itself, then it is a bounded error to call that subprogram. Possible consequences are that Program_Error or Storage_Error is raised, or that the call results in infinite recursion.
NOTES
9
12  A procedure can only be renamed as a procedure. A function whose defining_designator is either an identifier or an operator_symbol can be renamed with either an identifier or an operator_symbol; for renaming as an operator, the subprogram specification given in the renaming_declaration is subject to the rules given in 6.6 for operator declarations. Enumeration literals can be renamed as functions; similarly, attribute_references that denote functions (such as references to Succ and Pred) can be renamed as functions. An entry can only be renamed as a procedure; the new name is only allowed to appear in contexts that allow a procedure name. An entry of a family can be renamed, but an entry family cannot be renamed as a whole.
10
13  The operators of the root numeric types cannot be renamed because the types in the profile are anonymous, so the corresponding specifications cannot be written; the same holds for certain attributes, such as Pos.
11
14  Calls with the new name of a renamed entry are procedure_call_statements and are not allowed at places where the syntax requires an entry_call_statement in conditional_ and timed_entry_calls, nor in an asynchronous_select; similarly, the Count attribute is not available for the new name.
12
15  The primitiveness of a renaming-as-declaration is determined by its profile, and by where it occurs, as for any declaration of (a view of) a subprogram; primitiveness is not determined by the renamed view. In order to perform a dispatching call, the subprogram name has to denote a primitive subprogram, not a non-primitive renaming of a primitive subprogram. 

Examples

13
Examples of subprogram renaming declarations: 
14
procedure My_Write(C : in Character) renames Pool(K).Write; --  see 4.1.3
15
function Real_Plus(Left, Right : Real   ) return Real    renames "+";
function Int_Plus (Left, Right : Integer) return Integer renames "+";
16
function Rouge return Color renames Red;  --  see 3.5.1
function Rot   return Color renames Red;
function Rosso return Color renames Rouge;
17
function Next(X : Color) return Color renames Color'Succ; -- see 3.5.1
18
Example of a subprogram renaming declaration with new parameter names: 
19
function "*" (X,Y : Vector) return Real renames Dot_Product; -- see 6.1
20
Example of a subprogram renaming declaration with a new default expression: 
21
function Minimum(L : Link := Head) return Cell renames Min_Cell; -- see 6.1

Contents   Index   References   Search   Previous   Next 
Ada-Europe Sponsored by Ada-Europe