In Ada 2022 you can redefine
'Image attribute for your type.
Corresponding syntax has been changed several times. Let's see how
does it work in GNAT Community 2021.
'Image redefinition is supported by
GNAT Community Edition 2021 (using Text_Buffers)
GNAT Community Edition 2020 (using Text_Output.Utils)
GCC 11 (using Text_Output.Utils)
As an example, let's redefine
'Image attribute for the location
in a source code. To do this we should provide a new
aspect on the type:
What's the Root_Buffer_Type?¶
Let's see how it is defined in
type Root_Buffer_Type is abstract tagged limited private; procedure Put (Buffer : in out Root_Buffer_Type; Item : in String) is abstract;
Put there are also
Outdated draft implementation¶
GNAT Community Edition 2020 and GCC 11 both provide the draft
implementation that is incompatible with Ada 2022 specification.
In that case
My_Put_Image looks like:
procedure My_Put_Image (Sink : in out Ada.Strings.Text_Output.Sink'Class; Value : Source_Location) is Line : constant String := Value.Line'Image; Column : constant String := Value.Column'Image; Result : constant String := Line (2 .. Line'Last) & ':' & Column (2 .. Column'Last); begin Ada.Strings.Text_Output.Utils.Put_UTF_8 (Sink, Result); end My_Put_Image;