]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Add `Set_[Wide_]Wide_String` subprograms to auxiliary packages.
authorVadim Godunko <godunko@adacore.com>
Wed, 27 Aug 2025 09:24:57 +0000 (13:24 +0400)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 15 Sep 2025 12:59:25 +0000 (14:59 +0200)
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.

gcc/ada/libgnat/a-swunau.adb
gcc/ada/libgnat/a-swunau.ads
gcc/ada/libgnat/a-swunau__shared.adb
gcc/ada/libgnat/a-szunau.adb
gcc/ada/libgnat/a-szunau.ads
gcc/ada/libgnat/a-szunau__shared.adb

index acb9b6df4fe50e21073cbac5aaf862b0980378a2..1ae8e19d0d6e27a09cf73402376de7f41f58223a 100644 (file)
@@ -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;
index ba4ccaa3af95219b5769e17d88ab523f4e40fa4e..ea33db01a11e06d0947affaafdc526c82400d02a 100644 (file)
@@ -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;
index fdaf8467e606eb41b7776abe5c81feb31adef2b2..2d3366401f16f2c3700d1cff7c1b495ae5fec10e 100644 (file)
@@ -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;
index 5436e2f0d7eadb500552b4c0c188e9838ba942b0..903b2c9e4df04af911c485e5f3d2f8fb98b78d6e 100644 (file)
@@ -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;
index 3f90d280298848ac1e971c108bc3794bc545ae2d..486ac137bfcd0346c6f1e6a978a8738aaea7dda7 100644 (file)
@@ -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;
index dc9b2984883a55f89f1286095c7783d944f1501d..9fa937e74654f9c76ebcbfc744f56c4301229830 100644 (file)
@@ -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;