From: Vadim Godunko <godu...@adacore.com>

gcc/ada/ChangeLog:

        * libgnat/a-swunau.ads (Set_Wide_String): New subprogram.
        * libgnat/a-swunau.adb (Set_Wide_String): Likewise.
        * libgnat/a-swunau__shared.adb (Set_Wide_String): Likewise.
        * libgnat/a-szunau.ads (Set_Wide_Wide_String): Likewise.
        * libgnat/a-szunau.adb (Set_Wide_Wide_String): Likewise.
        * libgnat/a-szunau__shared.adb (Set_Wide_Wide_String): Likewise.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/libgnat/a-swunau.adb         | 13 +++++++++++++
 gcc/ada/libgnat/a-swunau.ads         |  8 ++++++++
 gcc/ada/libgnat/a-swunau__shared.adb | 26 ++++++++++++++++++++++++++
 gcc/ada/libgnat/a-szunau.adb         | 13 +++++++++++++
 gcc/ada/libgnat/a-szunau.ads         |  8 ++++++++
 gcc/ada/libgnat/a-szunau__shared.adb | 26 ++++++++++++++++++++++++++
 6 files changed, 94 insertions(+)

diff --git a/gcc/ada/libgnat/a-swunau.adb b/gcc/ada/libgnat/a-swunau.adb
index acb9b6df4fe5..1ae8e19d0d6e 100644
--- a/gcc/ada/libgnat/a-swunau.adb
+++ b/gcc/ada/libgnat/a-swunau.adb
@@ -62,4 +62,17 @@ package body Ada.Strings.Wide_Unbounded.Aux is
       UP.Last := UP.Reference'Length;
    end Set_Wide_String;
 
+   procedure Set_Wide_String
+     (U      : out Unbounded_Wide_String;
+      Length : Positive;
+      Set    : not null access procedure (S : out Wide_String))
+   is
+      Old : Wide_String_Access := U.Reference;
+   begin
+      U.Last := Length;
+      U.Reference := new Wide_String (1 .. Length);
+      Set (U.Reference.all);
+      Free (Old);
+   end Set_Wide_String;
+
 end Ada.Strings.Wide_Unbounded.Aux;
diff --git a/gcc/ada/libgnat/a-swunau.ads b/gcc/ada/libgnat/a-swunau.ads
index ba4ccaa3af95..ea33db01a11e 100644
--- a/gcc/ada/libgnat/a-swunau.ads
+++ b/gcc/ada/libgnat/a-swunau.ads
@@ -73,4 +73,12 @@ package Ada.Strings.Wide_Unbounded.Aux is
    --  than string. The lower bound of the string value is required to be one,
    --  and this requirement is not checked.
 
+   procedure Set_Wide_String
+     (U      : out Unbounded_Wide_String;
+      Length : Positive;
+      Set    : not null access procedure (S : out Wide_String));
+   pragma Inline (Set_Wide_String);
+   --  Create an unbounded string U with the given Length, using Set to fill
+   --  the contents of U.
+
 end Ada.Strings.Wide_Unbounded.Aux;
diff --git a/gcc/ada/libgnat/a-swunau__shared.adb 
b/gcc/ada/libgnat/a-swunau__shared.adb
index fdaf8467e606..2d3366401f16 100644
--- a/gcc/ada/libgnat/a-swunau__shared.adb
+++ b/gcc/ada/libgnat/a-swunau__shared.adb
@@ -62,4 +62,30 @@ package body Ada.Strings.Wide_Unbounded.Aux is
       Free (X);
    end Set_Wide_String;
 
+   procedure Set_Wide_String
+     (U      : out Unbounded_Wide_String;
+      Length : Positive;
+      Set    : not null access procedure (S : out Wide_String))
+   is
+      TR : constant Shared_Wide_String_Access := U.Reference;
+      DR : Shared_Wide_String_Access;
+   begin
+      --  Try to reuse existing shared string
+
+      if Can_Be_Reused (TR, Length) then
+         Reference (TR);
+         DR := TR;
+
+      --  Otherwise allocate new shared string
+
+      else
+         DR := Allocate (Length);
+         U.Reference := DR;
+      end if;
+
+      Set (DR.Data (1 .. Length));
+      DR.Last := Length;
+      Unreference (TR);
+   end Set_Wide_String;
+
 end Ada.Strings.Wide_Unbounded.Aux;
diff --git a/gcc/ada/libgnat/a-szunau.adb b/gcc/ada/libgnat/a-szunau.adb
index 5436e2f0d7ea..903b2c9e4df0 100644
--- a/gcc/ada/libgnat/a-szunau.adb
+++ b/gcc/ada/libgnat/a-szunau.adb
@@ -62,4 +62,17 @@ package body Ada.Strings.Wide_Wide_Unbounded.Aux is
       UP.Last := UP.Reference'Length;
    end Set_Wide_Wide_String;
 
+   procedure Set_Wide_Wide_String
+     (U      : out Unbounded_Wide_Wide_String;
+      Length : Positive;
+      Set    : not null access procedure (S : out Wide_Wide_String))
+   is
+      Old : Wide_Wide_String_Access := U.Reference;
+   begin
+      U.Last := Length;
+      U.Reference := new Wide_Wide_String (1 .. Length);
+      Set (U.Reference.all);
+      Free (Old);
+   end Set_Wide_Wide_String;
+
 end Ada.Strings.Wide_Wide_Unbounded.Aux;
diff --git a/gcc/ada/libgnat/a-szunau.ads b/gcc/ada/libgnat/a-szunau.ads
index 3f90d2802988..486ac137bfcd 100644
--- a/gcc/ada/libgnat/a-szunau.ads
+++ b/gcc/ada/libgnat/a-szunau.ads
@@ -75,4 +75,12 @@ package Ada.Strings.Wide_Wide_Unbounded.Aux is
    --  than string. The lower bound of the string value is required to be one,
    --  and this requirement is not checked.
 
+   procedure Set_Wide_Wide_String
+     (U      : out Unbounded_Wide_Wide_String;
+      Length : Positive;
+      Set    : not null access procedure (S : out Wide_Wide_String));
+   pragma Inline (Set_Wide_Wide_String);
+   --  Create an unbounded string U with the given Length, using Set to fill
+   --  the contents of U.
+
 end Ada.Strings.Wide_Wide_Unbounded.Aux;
diff --git a/gcc/ada/libgnat/a-szunau__shared.adb 
b/gcc/ada/libgnat/a-szunau__shared.adb
index dc9b2984883a..9fa937e74654 100644
--- a/gcc/ada/libgnat/a-szunau__shared.adb
+++ b/gcc/ada/libgnat/a-szunau__shared.adb
@@ -62,4 +62,30 @@ package body Ada.Strings.Wide_Wide_Unbounded.Aux is
       Free (X);
    end Set_Wide_Wide_String;
 
+   procedure Set_Wide_Wide_String
+     (U      : out Unbounded_Wide_Wide_String;
+      Length : Positive;
+      Set    : not null access procedure (S : out Wide_Wide_String))
+   is
+      TR : constant Shared_Wide_Wide_String_Access := U.Reference;
+      DR : Shared_Wide_Wide_String_Access;
+   begin
+      --  Try to reuse existing shared string
+
+      if Can_Be_Reused (TR, Length) then
+         Reference (TR);
+         DR := TR;
+
+      --  Otherwise allocate new shared string
+
+      else
+         DR := Allocate (Length);
+         U.Reference := DR;
+      end if;
+
+      Set (DR.Data (1 .. Length));
+      DR.Last := Length;
+      Unreference (TR);
+   end Set_Wide_Wide_String;
+
 end Ada.Strings.Wide_Wide_Unbounded.Aux;
-- 
2.43.0

Reply via email to