From: Vadim Godunko Date: Wed, 27 Aug 2025 09:24:57 +0000 (+0400) Subject: ada: Add `Set_[Wide_]Wide_String` subprograms to auxiliary packages. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=062aeef444933a40fccf862f71870b4b799bd423;p=thirdparty%2Fgcc.git ada: Add `Set_[Wide_]Wide_String` subprograms to auxiliary packages. 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. --- diff --git a/gcc/ada/libgnat/a-swunau.adb b/gcc/ada/libgnat/a-swunau.adb index acb9b6df4fe..1ae8e19d0d6 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 ba4ccaa3af9..ea33db01a11 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 fdaf8467e60..2d3366401f1 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 5436e2f0d7e..903b2c9e4df 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 3f90d280298..486ac137bfc 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 dc9b2984883..9fa937e7465 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;