From: Arnaud Charlet Date: Mon, 23 Mar 2020 08:49:13 +0000 (-0400) Subject: [Ada] AI12-0350 Swap for Indefinite_Holders X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5052a270c0f685998a3456d87d441a59bc1d67ee;p=gcc.git [Ada] AI12-0350 Swap for Indefinite_Holders 2020-06-12 Arnaud Charlet gcc/ada/ * libgnat/a-coinho.ads, libgnat/a-coinho.adb, libgnat/a-coinho__shared.ads, libgnat/a-coinho__shared.adb (Swap): New procedure. --- diff --git a/gcc/ada/libgnat/a-coinho.adb b/gcc/ada/libgnat/a-coinho.adb index ef58e9e556d..c5da9432dd9 100644 --- a/gcc/ada/libgnat/a-coinho.adb +++ b/gcc/ada/libgnat/a-coinho.adb @@ -304,6 +304,30 @@ package body Ada.Containers.Indefinite_Holders is end; end Replace_Element; + ---------- + -- Swap -- + ---------- + + procedure Swap (Left, Right : in out Holder) is + begin + if Left.Busy /= 0 then + raise Program_Error with "attempt to tamper with elements"; + end if; + + if Right.Busy /= 0 then + raise Program_Error with "attempt to tamper with elements"; + end if; + + if Left.Element /= Right.Element then + declare + Tmp : constant Element_Access := Left.Element; + begin + Left.Element := Right.Element; + Right.Element := Tmp; + end; + end if; + end Swap; + --------------- -- To_Holder -- --------------- diff --git a/gcc/ada/libgnat/a-coinho.ads b/gcc/ada/libgnat/a-coinho.ads index af22cbf70e5..bf6165e954d 100644 --- a/gcc/ada/libgnat/a-coinho.ads +++ b/gcc/ada/libgnat/a-coinho.ads @@ -92,6 +92,8 @@ package Ada.Containers.Indefinite_Holders is procedure Move (Target : in out Holder; Source : in out Holder); + procedure Swap (Left, Right : in out Holder); + private use Ada.Finalization; diff --git a/gcc/ada/libgnat/a-coinho__shared.adb b/gcc/ada/libgnat/a-coinho__shared.adb index bfeb6adfc65..43f5d52f7db 100644 --- a/gcc/ada/libgnat/a-coinho__shared.adb +++ b/gcc/ada/libgnat/a-coinho__shared.adb @@ -426,6 +426,30 @@ package body Ada.Containers.Indefinite_Holders is end if; end Replace_Element; + ---------- + -- Swap -- + ---------- + + procedure Swap (Left, Right : in out Holder) is + begin + if Left.Busy /= 0 then + raise Program_Error with "attempt to tamper with elements"; + end if; + + if Right.Busy /= 0 then + raise Program_Error with "attempt to tamper with elements"; + end if; + + if Left.Reference /= Right.Reference then + declare + Tmp : constant Shared_Holder_Access := Left.Reference; + begin + Left.Reference := Right.Reference; + Right.Reference := Tmp; + end; + end if; + end Swap; + --------------- -- To_Holder -- --------------- diff --git a/gcc/ada/libgnat/a-coinho__shared.ads b/gcc/ada/libgnat/a-coinho__shared.ads index af2e7e0e343..0345b5ee0db 100644 --- a/gcc/ada/libgnat/a-coinho__shared.ads +++ b/gcc/ada/libgnat/a-coinho__shared.ads @@ -96,6 +96,8 @@ package Ada.Containers.Indefinite_Holders is procedure Move (Target : in out Holder; Source : in out Holder); + procedure Swap (Left, Right : in out Holder); + private use Ada.Finalization;