On 2024-01-10 11:37, Blady wrote:
>
> package Loggings is
> type Logging is tagged record
> Output : Ada.Text_IO.File_Access;
> end record;
> procedure Log (Handler : Logging; Msg : String);
> end Loggings;
> My_Handler : aliased Loggings.Logging := (Output => Ada.Text_IO.Current_Output);
> My_Generic_Handler : access Loggings.Logging'Class := My_Handler'Access;
> procedure My_Log_3 (Msg : String) renames My_Generic_Handler.Log;
My_Generic_Handler.Log is shorthand for My_Generic_Handler.all.Log. According to
AARM 8.5.4(5.e/5) (
http://www.ada-auth.org/standards/22aarm/html/AA-8-5-4.html),
the renaming also renames the prefixing object and passes it to calls to the
renamed subprogram: "The prefix in such a case is essentially renamed and passed
to any calls of the renamed subprogram."
So if I understand this correctly the renaming is roughly equivalent to
<anonymous> : Loggings.Logging renames My_Generic_Handler.all;
procedure My_Log_3 (Handler : Loggings.Logging := <anonymous>; Msg : String)
renames Loggings.Logging.Log;
except that My_Log_3 is called with only a String parameter even when using
positional notation.
Another way to look at it is that
My_Log_3 ("msg");
is implemented as
<anonymous>.Log (Msg => "msg");
> What is happening if My_Generic_Handler change?
>
> type Full_Logging is new Logging with null record;
> procedure Log (Handler : Full_Logging; Msg : String);
> ...
> My_Full_Handler : aliased Loggings.Full_Logging := (Output =>
> Ada.Text_IO.Current_Output);
> ...
> My_Generic_Handler := My_Full_Handler'Access;
>
> Well, logically (?), My_Log_3 follows the change and outputs with Full_Logging.
No, My_Log_3 continues to call Log with My_Handler as the object, IIUC.
> Unfortunately, GNAT claims renaming with several parameters.
> I add:
> procedure Log (Handler : Logging; Msg : String; Err : Natural);
> ...
> procedure My_Log_4 (Msg : String; Err : Natural) renames
> My_Generic_Handler.Log;
>
> I got:
> test_20240110_renproc.adb:47:14: error: too many arguments in call to "log"
>
> Is it a correct or a GNAT issue?
I'm not sure what is going on here. This looks correct to me.
--
Jeff Carter
"Fundamental improvements in performance
are most often made by algorithm changes,
not by tuning."
Elements of Programming Style
201