[COMMITTED,03/27] ada: Add `Set_[Wide_]Wide_String` subprograms to auxiliary packages.
Commit Message
From: Vadim Godunko <godunko@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(+)
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;