In Ada 2022, you can redefine
'Image attribute for your type,
though the syntax to do this has been changed several times. Let's see
how it works in GNAT Community 2021.
'Image is supported by
GNAT Community Edition 2021 (using
GNAT Community Edition 2020 (using
GCC 11 (using
In our example, let's redefine the
'Image attribute for a
location in source code. To do this, we provide a new
aspect for the type:
What's the Root_Buffer_Type?
Let's see how it's defined in the
type Root_Buffer_Type is abstract tagged limited private; procedure Put (Buffer : in out Root_Buffer_Type; Item : in String) is abstract;
In addition to
Put, there are also
Outdated draft implementation
GNAT Community Edition 2020 and GCC 11 both provide a draft
implementation that's incompatible with the Ada 2022 specification.
For those versions,
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;