Prev | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help


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)
       subprogram_renaming_declaration ::= 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.
(5)
The profile of a renaming-as-body shall be subtype-conformant with that of the renamed callable entity, and 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 subprogram it declares takes its convention from the renamed subprogram; otherwise the convention of the renamed subprogram shall not be Intrinsic.
(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
(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.

(9)
(10)
(11)
(12)
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

Prev | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help

Ada WWW Home -- Email comments, additions, corrections, gripes, kudos, etc. to:

Magnus Kempe -- Magnus.Kempe@di.epfl.ch
Copyright statement
Page last generated: 95-03-12