aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Duff <duff@adacore.com>2022-05-23 09:47:18 -0400
committerPierre-Marie de Rodat <derodat@adacore.com>2022-07-04 07:45:53 +0000
commita8a1da109efe9b12183353faa87b113f6992898f (patch)
tree17cd94e9ec1f0f7da1d0d7063300ab919cc45a55
parent2e9b2ab3b5bf6e4a0bdabfeb7358206b18253e3c (diff)
downloadgcc-a8a1da109efe9b12183353faa87b113f6992898f.zip
gcc-a8a1da109efe9b12183353faa87b113f6992898f.tar.gz
gcc-a8a1da109efe9b12183353faa87b113f6992898f.tar.bz2
[Ada] Add Ada 2022 features to sets containers
This patch adds some Ada 2022 features to the set children of Ada.Containers. gcc/ada/ * libgnat/a-cbhase.adb, libgnat/a-cbhase.ads, libgnat/a-cborse.adb, libgnat/a-cborse.ads, libgnat/a-cihase.adb, libgnat/a-cihase.ads, libgnat/a-ciorse.adb, libgnat/a-ciorse.ads, libgnat/a-cohase.adb, libgnat/a-cohase.ads, libgnat/a-conhel.adb, libgnat/a-conhel.ads, libgnat/a-coorse.adb, libgnat/a-coorse.ads: Add Has_Element, Element, Query_Element, and Next subprograms that take a Set parameter. Add Tampering_With_Cursors_Prohibited function. These are all new in Ada 2022.
-rw-r--r--gcc/ada/libgnat/a-cbhase.adb58
-rw-r--r--gcc/ada/libgnat/a-cbhase.ads19
-rw-r--r--gcc/ada/libgnat/a-cborse.adb56
-rw-r--r--gcc/ada/libgnat/a-cborse.ads19
-rw-r--r--gcc/ada/libgnat/a-cihase.adb58
-rw-r--r--gcc/ada/libgnat/a-cihase.ads19
-rw-r--r--gcc/ada/libgnat/a-ciorse.adb55
-rw-r--r--gcc/ada/libgnat/a-ciorse.ads19
-rw-r--r--gcc/ada/libgnat/a-cohase.adb58
-rw-r--r--gcc/ada/libgnat/a-cohase.ads19
-rw-r--r--gcc/ada/libgnat/a-conhel.adb8
-rw-r--r--gcc/ada/libgnat/a-conhel.ads28
-rw-r--r--gcc/ada/libgnat/a-coorse.adb55
-rw-r--r--gcc/ada/libgnat/a-coorse.ads19
14 files changed, 482 insertions, 8 deletions
diff --git a/gcc/ada/libgnat/a-cbhase.adb b/gcc/ada/libgnat/a-cbhase.adb
index 9076d8e..b83ab80 100644
--- a/gcc/ada/libgnat/a-cbhase.adb
+++ b/gcc/ada/libgnat/a-cbhase.adb
@@ -1599,6 +1599,64 @@ is
raise Program_Error with "attempt to stream reference";
end Write;
+ -- Ada 2022 features:
+
+ function Has_Element (Container : Set; Position : Cursor) return Boolean is
+ begin
+ pragma Assert (Vet (Position), "bad cursor in Has_Element");
+ pragma Assert ((Position.Container = null) = (Position.Node = 0),
+ "bad nullity in Has_Element");
+ return Position.Container = Container'Unrestricted_Access;
+ end Has_Element;
+
+ function Tampering_With_Cursors_Prohibited
+ (Container : Set) return Boolean
+ is
+ begin
+ return Is_Busy (Container.TC);
+ end Tampering_With_Cursors_Prohibited;
+
+ function Element (Container : Set; Position : Cursor) return Element_Type is
+ begin
+ if Checks and then not Has_Element (Container, Position) then
+ raise Program_Error with "Position for wrong Container";
+ end if;
+
+ return Element (Position);
+ end Element;
+
+ procedure Query_Element
+ (Container : Set;
+ Position : Cursor;
+ Process : not null access procedure (Element : Element_Type)) is
+ begin
+ if Checks and then not Has_Element (Container, Position) then
+ raise Program_Error with "Position for wrong Container";
+ end if;
+
+ Query_Element (Position, Process);
+ end Query_Element;
+
+ function Next (Container : Set; Position : Cursor) return Cursor is
+ begin
+ if Checks and then
+ not (Position = No_Element or else Has_Element (Container, Position))
+ then
+ raise Program_Error with "Position for wrong Container";
+ end if;
+
+ return Next (Position);
+ end Next;
+
+ procedure Next (Container : Set; Position : in out Cursor) is
+ begin
+ Position := Next (Container, Position);
+ end Next;
+
+ ------------------
+ -- Generic_Keys --
+ ------------------
+
package body Generic_Keys is
-----------------------
diff --git a/gcc/ada/libgnat/a-cbhase.ads b/gcc/ada/libgnat/a-cbhase.ads
index c30a364..7079c51 100644
--- a/gcc/ada/libgnat/a-cbhase.ads
+++ b/gcc/ada/libgnat/a-cbhase.ads
@@ -369,6 +369,25 @@ is
(Container : Set)
return Set_Iterator_Interfaces.Forward_Iterator'Class;
+ -- Ada 2022 features:
+
+ function Has_Element (Container : Set; Position : Cursor) return Boolean;
+
+ function Tampering_With_Cursors_Prohibited (Container : Set) return Boolean;
+
+ function Element (Container : Set; Position : Cursor) return Element_Type;
+
+ procedure Query_Element
+ (Container : Set;
+ Position : Cursor;
+ Process : not null access procedure (Element : Element_Type));
+
+ function Next (Container : Set; Position : Cursor) return Cursor;
+
+ procedure Next (Container : Set; Position : in out Cursor);
+
+ ----------------
+
generic
type Key_Type (<>) is private;
diff --git a/gcc/ada/libgnat/a-cborse.adb b/gcc/ada/libgnat/a-cborse.adb
index 55eca40..bc52b45 100644
--- a/gcc/ada/libgnat/a-cborse.adb
+++ b/gcc/ada/libgnat/a-cborse.adb
@@ -688,6 +688,62 @@ is
else Cursor'(Container'Unrestricted_Access, Node));
end Floor;
+ -- Ada 2022 features:
+
+ function Has_Element (Container : Set; Position : Cursor) return Boolean is
+ begin
+ pragma Assert
+ (Position.Container = null or else Vet (Container, Position.Node),
+ "bad cursor in Has_Element");
+ pragma Assert ((Position.Container = null) = (Position.Node = 0),
+ "bad nullity in Has_Element");
+ return Position.Container = Container'Unrestricted_Access;
+ end Has_Element;
+
+ function Tampering_With_Cursors_Prohibited
+ (Container : Set) return Boolean
+ is
+ begin
+ return Is_Busy (Container.TC);
+ end Tampering_With_Cursors_Prohibited;
+
+ function Element (Container : Set; Position : Cursor) return Element_Type is
+ begin
+ if Checks and then not Has_Element (Container, Position) then
+ raise Program_Error with "Position for wrong Container";
+ end if;
+
+ return Element (Position);
+ end Element;
+
+ procedure Query_Element
+ (Container : Set;
+ Position : Cursor;
+ Process : not null access procedure (Element : Element_Type)) is
+ begin
+ if Checks and then not Has_Element (Container, Position) then
+ raise Program_Error with "Position for wrong Container";
+ end if;
+
+ Query_Element (Position, Process);
+ end Query_Element;
+
+ function Next (Container : Set; Position : Cursor) return Cursor is
+ begin
+ if Checks and then
+ not (Position = No_Element or else Has_Element (Container, Position))
+ then
+ raise Program_Error with "Position for wrong Container";
+ end if;
+
+ return Next (Position);
+ end Next;
+
+ procedure Next (Container : Set; Position : in out Cursor) is
+ begin
+ Position := Next (Container, Position);
+ end Next;
+
------------------
-- Generic_Keys --
------------------
diff --git a/gcc/ada/libgnat/a-cborse.ads b/gcc/ada/libgnat/a-cborse.ads
index ceaf885..be22c25 100644
--- a/gcc/ada/libgnat/a-cborse.ads
+++ b/gcc/ada/libgnat/a-cborse.ads
@@ -230,6 +230,25 @@ is
Start : Cursor)
return Set_Iterator_Interfaces.Reversible_Iterator'class;
+ -- Ada 2022 features:
+
+ function Has_Element (Container : Set; Position : Cursor) return Boolean;
+
+ function Tampering_With_Cursors_Prohibited (Container : Set) return Boolean;
+
+ function Element (Container : Set; Position : Cursor) return Element_Type;
+
+ procedure Query_Element
+ (Container : Set;
+ Position : Cursor;
+ Process : not null access procedure (Element : Element_Type));
+
+ function Next (Container : Set; Position : Cursor) return Cursor;
+
+ procedure Next (Container : Set; Position : in out Cursor);
+
+ ----------------
+
generic
type Key_Type (<>) is private;
diff --git a/gcc/ada/libgnat/a-cihase.adb b/gcc/ada/libgnat/a-cihase.adb
index 090d01c..0a9aabd 100644
--- a/gcc/ada/libgnat/a-cihase.adb
+++ b/gcc/ada/libgnat/a-cihase.adb
@@ -2031,6 +2031,64 @@ is
Element_Type'Output (Stream, Node.Element.all);
end Write_Node;
+ -- Ada 2022 features:
+
+ function Has_Element (Container : Set; Position : Cursor) return Boolean is
+ begin
+ pragma Assert (Vet (Position), "bad cursor in Has_Element");
+ pragma Assert ((Position.Container = null) = (Position.Node = null),
+ "bad nullity in Has_Element");
+ return Position.Container = Container'Unrestricted_Access;
+ end Has_Element;
+
+ function Tampering_With_Cursors_Prohibited
+ (Container : Set) return Boolean
+ is
+ begin
+ return Is_Busy (Container.HT.TC);
+ end Tampering_With_Cursors_Prohibited;
+
+ function Element (Container : Set; Position : Cursor) return Element_Type is
+ begin
+ if Checks and then not Has_Element (Container, Position) then
+ raise Program_Error with "Position for wrong Container";
+ end if;
+
+ return Element (Position);
+ end Element;
+
+ procedure Query_Element
+ (Container : Set;
+ Position : Cursor;
+ Process : not null access procedure (Element : Element_Type)) is
+ begin
+ if Checks and then not Has_Element (Container, Position) then
+ raise Program_Error with "Position for wrong Container";
+ end if;
+
+ Query_Element (Position, Process);
+ end Query_Element;
+
+ function Next (Container : Set; Position : Cursor) return Cursor is
+ begin
+ if Checks and then
+ not (Position = No_Element or else Has_Element (Container, Position))
+ then
+ raise Program_Error with "Position for wrong Container";
+ end if;
+
+ return Next (Position);
+ end Next;
+
+ procedure Next (Container : Set; Position : in out Cursor) is
+ begin
+ Position := Next (Container, Position);
+ end Next;
+
+ ------------------
+ -- Generic_Keys --
+ ------------------
+
package body Generic_Keys is
-----------------------
diff --git a/gcc/ada/libgnat/a-cihase.ads b/gcc/ada/libgnat/a-cihase.ads
index cff713d..dcd1d6a 100644
--- a/gcc/ada/libgnat/a-cihase.ads
+++ b/gcc/ada/libgnat/a-cihase.ads
@@ -355,6 +355,25 @@ is
function Iterate (Container : Set)
return Set_Iterator_Interfaces.Forward_Iterator'Class;
+ -- Ada 2022 features:
+
+ function Has_Element (Container : Set; Position : Cursor) return Boolean;
+
+ function Tampering_With_Cursors_Prohibited (Container : Set) return Boolean;
+
+ function Element (Container : Set; Position : Cursor) return Element_Type;
+
+ procedure Query_Element
+ (Container : Set;
+ Position : Cursor;
+ Process : not null access procedure (Element : Element_Type));
+
+ function Next (Container : Set; Position : Cursor) return Cursor;
+
+ procedure Next (Container : Set; Position : in out Cursor);
+
+ ----------------
+
generic
type Key_Type (<>) is private;
diff --git a/gcc/ada/libgnat/a-ciorse.adb b/gcc/ada/libgnat/a-ciorse.adb
index b23b252..d5502ea 100644
--- a/gcc/ada/libgnat/a-ciorse.adb
+++ b/gcc/ada/libgnat/a-ciorse.adb
@@ -721,6 +721,61 @@ is
Deallocate (X);
end Free;
+ -- Ada 2022 features:
+
+ function Has_Element (Container : Set; Position : Cursor) return Boolean is
+ begin
+ pragma Assert
+ (Vet (Container.Tree, Position.Node), "bad cursor in Has_Element");
+ pragma Assert ((Position.Container = null) = (Position.Node = null),
+ "bad nullity in Has_Element");
+ return Position.Container = Container'Unrestricted_Access;
+ end Has_Element;
+
+ function Tampering_With_Cursors_Prohibited
+ (Container : Set) return Boolean
+ is
+ begin
+ return Is_Busy (Container.Tree.TC);
+ end Tampering_With_Cursors_Prohibited;
+
+ function Element (Container : Set; Position : Cursor) return Element_Type is
+ begin
+ if Checks and then not Has_Element (Container, Position) then
+ raise Program_Error with "Position for wrong Container";
+ end if;
+
+ return Element (Position);
+ end Element;
+
+ procedure Query_Element
+ (Container : Set;
+ Position : Cursor;
+ Process : not null access procedure (Element : Element_Type)) is
+ begin
+ if Checks and then not Has_Element (Container, Position) then
+ raise Program_Error with "Position for wrong Container";
+ end if;
+
+ Query_Element (Position, Process);
+ end Query_Element;
+
+ function Next (Container : Set; Position : Cursor) return Cursor is
+ begin
+ if Checks and then
+ not (Position = No_Element or else Has_Element (Container, Position))
+ then
+ raise Program_Error with "Position for wrong Container";
+ end if;
+
+ return Next (Position);
+ end Next;
+
+ procedure Next (Container : Set; Position : in out Cursor) is
+ begin
+ Position := Next (Container, Position);
+ end Next;
+
------------------
-- Generic_Keys --
------------------
diff --git a/gcc/ada/libgnat/a-ciorse.ads b/gcc/ada/libgnat/a-ciorse.ads
index 13272e2..d053ac7 100644
--- a/gcc/ada/libgnat/a-ciorse.ads
+++ b/gcc/ada/libgnat/a-ciorse.ads
@@ -238,6 +238,25 @@ is
Start : Cursor)
return Set_Iterator_Interfaces.Reversible_Iterator'class;
+ -- Ada 2022 features:
+
+ function Has_Element (Container : Set; Position : Cursor) return Boolean;
+
+ function Tampering_With_Cursors_Prohibited (Container : Set) return Boolean;
+
+ function Element (Container : Set; Position : Cursor) return Element_Type;
+
+ procedure Query_Element
+ (Container : Set;
+ Position : Cursor;
+ Process : not null access procedure (Element : Element_Type));
+
+ function Next (Container : Set; Position : Cursor) return Cursor;
+
+ procedure Next (Container : Set; Position : in out Cursor);
+
+ ----------------
+
generic
type Key_Type (<>) is private;
diff --git a/gcc/ada/libgnat/a-cohase.adb b/gcc/ada/libgnat/a-cohase.adb
index 986b354..4656868 100644
--- a/gcc/ada/libgnat/a-cohase.adb
+++ b/gcc/ada/libgnat/a-cohase.adb
@@ -1844,6 +1844,64 @@ is
Element_Type'Write (Stream, Node.Element);
end Write_Node;
+ -- Ada 2022 features:
+
+ function Has_Element (Container : Set; Position : Cursor) return Boolean is
+ begin
+ pragma Assert (Vet (Position), "bad cursor in Has_Element");
+ pragma Assert ((Position.Container = null) = (Position.Node = null),
+ "bad nullity in Has_Element");
+ return Position.Container = Container'Unrestricted_Access;
+ end Has_Element;
+
+ function Tampering_With_Cursors_Prohibited
+ (Container : Set) return Boolean
+ is
+ begin
+ return Is_Busy (Container.HT.TC);
+ end Tampering_With_Cursors_Prohibited;
+
+ function Element (Container : Set; Position : Cursor) return Element_Type is
+ begin
+ if Checks and then not Has_Element (Container, Position) then
+ raise Program_Error with "Position for wrong Container";
+ end if;
+
+ return Element (Position);
+ end Element;
+
+ procedure Query_Element
+ (Container : Set;
+ Position : Cursor;
+ Process : not null access procedure (Element : Element_Type)) is
+ begin
+ if Checks and then not Has_Element (Container, Position) then
+ raise Program_Error with "Position for wrong Container";
+ end if;
+
+ Query_Element (Position, Process);
+ end Query_Element;
+
+ function Next (Container : Set; Position : Cursor) return Cursor is
+ begin
+ if Checks and then
+ not (Position = No_Element or else Has_Element (Container, Position))
+ then
+ raise Program_Error with "Position for wrong Container";
+ end if;
+
+ return Next (Position);
+ end Next;
+
+ procedure Next (Container : Set; Position : in out Cursor) is
+ begin
+ Position := Next (Container, Position);
+ end Next;
+
+ ------------------
+ -- Generic_Keys --
+ ------------------
+
package body Generic_Keys is
-----------------------
diff --git a/gcc/ada/libgnat/a-cohase.ads b/gcc/ada/libgnat/a-cohase.ads
index ada212c..9f562d8 100644
--- a/gcc/ada/libgnat/a-cohase.ads
+++ b/gcc/ada/libgnat/a-cohase.ads
@@ -367,6 +367,25 @@ is
function Iterate
(Container : Set) return Set_Iterator_Interfaces.Forward_Iterator'Class;
+ -- Ada 2022 features:
+
+ function Has_Element (Container : Set; Position : Cursor) return Boolean;
+
+ function Tampering_With_Cursors_Prohibited (Container : Set) return Boolean;
+
+ function Element (Container : Set; Position : Cursor) return Element_Type;
+
+ procedure Query_Element
+ (Container : Set;
+ Position : Cursor;
+ Process : not null access procedure (Element : Element_Type));
+
+ function Next (Container : Set; Position : Cursor) return Cursor;
+
+ procedure Next (Container : Set; Position : in out Cursor);
+
+ ----------------
+
generic
type Key_Type (<>) is private;
diff --git a/gcc/ada/libgnat/a-conhel.adb b/gcc/ada/libgnat/a-conhel.adb
index b24be67..46f1bcc 100644
--- a/gcc/ada/libgnat/a-conhel.adb
+++ b/gcc/ada/libgnat/a-conhel.adb
@@ -36,8 +36,6 @@ package body Ada.Containers.Helpers is
package body Generic_Implementation is
- use type SAC.Atomic_Unsigned;
-
------------
-- Adjust --
------------
@@ -133,7 +131,7 @@ package body Ada.Containers.Helpers is
procedure TC_Check (T_Counts : Tamper_Counts) is
begin
if T_Check then
- if T_Counts.Busy > 0 then
+ if Is_Busy (T_Counts) then
raise Program_Error with
"attempt to tamper with cursors";
end if;
@@ -144,7 +142,7 @@ package body Ada.Containers.Helpers is
-- Thus if the busy count is zero, then the lock count
-- must also be zero.
- pragma Assert (T_Counts.Lock = 0);
+ pragma Assert (not Is_Locked (T_Counts));
end if;
end TC_Check;
@@ -154,7 +152,7 @@ package body Ada.Containers.Helpers is
procedure TE_Check (T_Counts : Tamper_Counts) is
begin
- if T_Check and then T_Counts.Lock > 0 then
+ if T_Check and then Is_Locked (T_Counts) then
raise Program_Error with
"attempt to tamper with elements";
end if;
diff --git a/gcc/ada/libgnat/a-conhel.ads b/gcc/ada/libgnat/a-conhel.ads
index 47811f5..92e23d0 100644
--- a/gcc/ada/libgnat/a-conhel.ads
+++ b/gcc/ada/libgnat/a-conhel.ads
@@ -121,9 +121,31 @@ package Ada.Containers.Helpers is
pragma Inline (TE_Check);
-- Tampering-with-elements check
- -----------------
- -- RAII Types --
- -----------------
+ ---------------------------------------
+ -- Queries of busy and locked status --
+ ---------------------------------------
+
+ -- These are never called when tampering checks are suppressed.
+
+ use type SAC.Atomic_Unsigned;
+
+ pragma Warnings (Off);
+ -- Otherwise, the -gnatw.n switch triggers unwanted warnings on the
+ -- references to atomic variables below.
+
+ function Is_Busy (T_Counts : Tamper_Counts) return Boolean is
+ (if T_Check then T_Counts.Busy > 0 else raise Program_Error);
+ pragma Inline (Is_Busy);
+
+ function Is_Locked (T_Counts : Tamper_Counts) return Boolean is
+ (if T_Check then T_Counts.Lock > 0 else raise Program_Error);
+ pragma Inline (Is_Locked);
+
+ pragma Warnings (On);
+
+ ----------------
+ -- RAII Types --
+ ----------------
-- Initialize of With_Busy increments the Busy count, and Finalize
-- decrements it. Thus, to prohibit tampering with elements within a
diff --git a/gcc/ada/libgnat/a-coorse.adb b/gcc/ada/libgnat/a-coorse.adb
index 7998ee8..848022e 100644
--- a/gcc/ada/libgnat/a-coorse.adb
+++ b/gcc/ada/libgnat/a-coorse.adb
@@ -643,6 +643,61 @@ is
end if;
end Free;
+ -- Ada 2022 features:
+
+ function Has_Element (Container : Set; Position : Cursor) return Boolean is
+ begin
+ pragma Assert
+ (Vet (Container.Tree, Position.Node), "bad cursor in Has_Element");
+ pragma Assert ((Position.Container = null) = (Position.Node = null),
+ "bad nullity in Has_Element");
+ return Position.Container = Container'Unrestricted_Access;
+ end Has_Element;
+
+ function Tampering_With_Cursors_Prohibited
+ (Container : Set) return Boolean
+ is
+ begin
+ return Is_Busy (Container.Tree.TC);
+ end Tampering_With_Cursors_Prohibited;
+
+ function Element (Container : Set; Position : Cursor) return Element_Type is
+ begin
+ if Checks and then not Has_Element (Container, Position) then
+ raise Program_Error with "Position for wrong Container";
+ end if;
+
+ return Element (Position);
+ end Element;
+
+ procedure Query_Element
+ (Container : Set;
+ Position : Cursor;
+ Process : not null access procedure (Element : Element_Type)) is
+ begin
+ if Checks and then not Has_Element (Container, Position) then
+ raise Program_Error with "Position for wrong Container";
+ end if;
+
+ Query_Element (Position, Process);
+ end Query_Element;
+
+ function Next (Container : Set; Position : Cursor) return Cursor is
+ begin
+ if Checks and then
+ not (Position = No_Element or else Has_Element (Container, Position))
+ then
+ raise Program_Error with "Position for wrong Container";
+ end if;
+
+ return Next (Position);
+ end Next;
+
+ procedure Next (Container : Set; Position : in out Cursor) is
+ begin
+ Position := Next (Container, Position);
+ end Next;
+
------------------
-- Generic_Keys --
------------------
diff --git a/gcc/ada/libgnat/a-coorse.ads b/gcc/ada/libgnat/a-coorse.ads
index 1833336..9619599 100644
--- a/gcc/ada/libgnat/a-coorse.ads
+++ b/gcc/ada/libgnat/a-coorse.ads
@@ -231,6 +231,25 @@ is
Start : Cursor)
return Set_Iterator_Interfaces.Reversible_Iterator'class;
+ -- Ada 2022 features:
+
+ function Has_Element (Container : Set; Position : Cursor) return Boolean;
+
+ function Tampering_With_Cursors_Prohibited (Container : Set) return Boolean;
+
+ function Element (Container : Set; Position : Cursor) return Element_Type;
+
+ procedure Query_Element
+ (Container : Set;
+ Position : Cursor;
+ Process : not null access procedure (Element : Element_Type));
+
+ function Next (Container : Set; Position : Cursor) return Cursor;
+
+ procedure Next (Container : Set; Position : in out Cursor);
+
+ ----------------
+
generic
type Key_Type (<>) is private;