This patch updates the Put_Image facilities in the Big_Numbers packages
to match the actual implementation of Put_Image.
Tested on x86_64-pc-linux-gnu, committed on trunk
2020-06-12 Bob Duff <d...@adacore.com>
gcc/ada/
* libgnat/a-nbnbin.adb, libgnat/a-nbnbin.ads,
libgnat/a-nbnbin__gmp.adb, libgnat/a-nbnbre.adb,
libgnat/a-nbnbre.ads: Update Put_Image, and uncomment the aspect
specification. Add pragmas Ada_2020.
* libgnat/a-stouut.ads, libgnat/a-stteou.ads: Add Preelaborate,
because the Big_Numbers packages have Preelaborate, and now
depend on these Text_Output packages.
--- gcc/ada/libgnat/a-nbnbin.adb
+++ gcc/ada/libgnat/a-nbnbin.adb
@@ -29,8 +29,10 @@
-- --
------------------------------------------------------------------------------
+pragma Ada_2020;
+
with Ada.Unchecked_Deallocation;
-with Ada.Characters.Conversions; use Ada.Characters.Conversions;
+with Ada.Strings.Text_Output.Utils;
with Interfaces; use Interfaces;
@@ -290,11 +292,12 @@ package body Ada.Numerics.Big_Numbers.Big_Integers is
-- Put_Image --
---------------
- procedure Put_Image
- (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
- Arg : Big_Integer) is
+ procedure Put_Image (S : in out Sink'Class; V : Big_Integer) is
+ -- This is implemented in terms of To_String. It might be more elegant
+ -- and more efficient to do it the other way around, but this is the
+ -- most expedient implementation for now.
begin
- Wide_Wide_String'Write (Stream, To_Wide_Wide_String (To_String (Arg)));
+ Strings.Text_Output.Utils.Put_UTF_8 (S, To_String (V));
end Put_Image;
---------
--- gcc/ada/libgnat/a-nbnbin.ads
+++ gcc/ada/libgnat/a-nbnbin.ads
@@ -13,7 +13,9 @@
-- --
------------------------------------------------------------------------------
-with Ada.Streams;
+pragma Ada_2020;
+
+with Ada.Strings.Text_Output; use Ada.Strings.Text_Output;
private with Ada.Finalization;
private with System;
@@ -24,9 +26,9 @@ private with System;
package Ada.Numerics.Big_Numbers.Big_Integers
with Preelaborate
is
- type Big_Integer is private;
- -- with Integer_Literal => From_String,
- -- Put_Image => Put_Image;
+ type Big_Integer is private with
+ -- Integer_Literal => From_String,
+ Put_Image => Put_Image;
function Is_Valid (Arg : Big_Integer) return Boolean
with Convention => Intrinsic;
@@ -95,9 +97,7 @@ is
function From_String (Arg : String) return Big_Integer;
- procedure Put_Image
- (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
- Arg : Big_Integer);
+ procedure Put_Image (S : in out Sink'Class; V : Big_Integer);
function "+" (L : Big_Integer) return Big_Integer;
--- gcc/ada/libgnat/a-nbnbin__gmp.adb
+++ gcc/ada/libgnat/a-nbnbin__gmp.adb
@@ -31,11 +31,13 @@
-- This is the GMP version of this package
+pragma Ada_2020;
+
with Ada.Unchecked_Conversion;
with Ada.Unchecked_Deallocation;
with Interfaces.C; use Interfaces.C;
with Interfaces.C.Strings; use Interfaces.C.Strings;
-with Ada.Characters.Conversions; use Ada.Characters.Conversions;
+with Ada.Strings.Text_Output.Utils;
with Ada.Characters.Handling; use Ada.Characters.Handling;
package body Ada.Numerics.Big_Numbers.Big_Integers is
@@ -403,11 +405,12 @@ package body Ada.Numerics.Big_Numbers.Big_Integers is
-- Put_Image --
---------------
- procedure Put_Image
- (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
- Arg : Big_Integer) is
+ procedure Put_Image (S : in out Sink'Class; V : Big_Real) is
+ -- This is implemented in terms of To_String. It might be more elegant
+ -- and more efficient to do it the other way around, but this is the
+ -- most expedient implementation for now.
begin
- Wide_Wide_String'Write (Stream, To_Wide_Wide_String (To_String (Arg)));
+ Strings.Text_Output.Utils.Put_UTF_8 (S, To_String (V));
end Put_Image;
---------
--- gcc/ada/libgnat/a-nbnbre.adb
+++ gcc/ada/libgnat/a-nbnbre.adb
@@ -31,7 +31,9 @@
-- This is the default version of this package, based on Big_Integers only.
-with Ada.Characters.Conversions; use Ada.Characters.Conversions;
+pragma Ada_2020;
+
+with Ada.Strings.Text_Output.Utils;
package body Ada.Numerics.Big_Numbers.Big_Reals is
@@ -399,11 +401,12 @@ package body Ada.Numerics.Big_Numbers.Big_Reals is
-- Put_Image --
---------------
- procedure Put_Image
- (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
- Arg : Big_Real) is
+ procedure Put_Image (S : in out Sink'Class; V : Big_Real) is
+ -- This is implemented in terms of To_String. It might be more elegant
+ -- and more efficient to do it the other way around, but this is the
+ -- most expedient implementation for now.
begin
- Wide_Wide_String'Write (Stream, To_Wide_Wide_String (To_String (Arg)));
+ Strings.Text_Output.Utils.Put_UTF_8 (S, To_String (V));
end Put_Image;
---------
--- gcc/ada/libgnat/a-nbnbre.ads
+++ gcc/ada/libgnat/a-nbnbre.ads
@@ -13,8 +13,11 @@
-- --
------------------------------------------------------------------------------
+pragma Ada_2020;
+
with Ada.Numerics.Big_Numbers.Big_Integers;
-with Ada.Streams;
+
+with Ada.Strings.Text_Output; use Ada.Strings.Text_Output;
-- Note that some Ada 2020 aspects are commented out since they are not
-- supported yet.
@@ -22,9 +25,9 @@ with Ada.Streams;
package Ada.Numerics.Big_Numbers.Big_Reals
with Preelaborate
is
- type Big_Real is private;
--- with Real_Literal => From_String,
--- Put_Image => Put_Image;
+ type Big_Real is private with
+-- Real_Literal => From_String,
+ Put_Image => Put_Image;
function Is_Valid (Arg : Big_Real) return Boolean
with Convention => Intrinsic;
@@ -105,9 +108,7 @@ is
function From_Quotient_String (Arg : String) return Big_Real;
- procedure Put_Image
- (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
- Arg : Big_Real);
+ procedure Put_Image (S : in out Sink'Class; V : Big_Real);
function "+" (L : Big_Real) return Big_Real;
--- gcc/ada/libgnat/a-stouut.ads
+++ gcc/ada/libgnat/a-stouut.ads
@@ -31,7 +31,7 @@
pragma Ada_2020;
-package Ada.Strings.Text_Output.Utils is
+package Ada.Strings.Text_Output.Utils with Preelaborate is
-- This package provides utility functions on Sink'Class. These are
-- intended for use by Put_Image attributes, both the default versions
--- gcc/ada/libgnat/a-stteou.ads
+++ gcc/ada/libgnat/a-stteou.ads
@@ -33,7 +33,7 @@ pragma Ada_2020;
with Ada.Strings.UTF_Encoding;
with Ada.Strings.UTF_Encoding.Wide_Wide_Strings;
-package Ada.Strings.Text_Output is
+package Ada.Strings.Text_Output with Preelaborate is
-- This package provides a "Sink" abstraction, to which characters of type
-- Character, Wide_Character, and Wide_Wide_Character can be sent. This