public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/guojiufu/heads/personal-branch)] [Ada] AI12-0350 Swap for Indefinite_Holders
@ 2020-06-13 3:00 Jiu Fu Guo
0 siblings, 0 replies; only message in thread
From: Jiu Fu Guo @ 2020-06-13 3:00 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:5052a270c0f685998a3456d87d441a59bc1d67ee
commit 5052a270c0f685998a3456d87d441a59bc1d67ee
Author: Arnaud Charlet <charlet@adacore.com>
Date: Mon Mar 23 04:49:13 2020 -0400
[Ada] AI12-0350 Swap for Indefinite_Holders
2020-06-12 Arnaud Charlet <charlet@adacore.com>
gcc/ada/
* libgnat/a-coinho.ads, libgnat/a-coinho.adb,
libgnat/a-coinho__shared.ads, libgnat/a-coinho__shared.adb
(Swap): New procedure.
Diff:
---
gcc/ada/libgnat/a-coinho.adb | 24 ++++++++++++++++++++++++
gcc/ada/libgnat/a-coinho.ads | 2 ++
gcc/ada/libgnat/a-coinho__shared.adb | 24 ++++++++++++++++++++++++
gcc/ada/libgnat/a-coinho__shared.ads | 2 ++
4 files changed, 52 insertions(+)
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;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-06-13 3:00 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-13 3:00 [gcc(refs/users/guojiufu/heads/personal-branch)] [Ada] AI12-0350 Swap for Indefinite_Holders Jiu Fu Guo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).