aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/a-cbhase.adb
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/ada/a-cbhase.adb')
-rw-r--r--gcc/ada/a-cbhase.adb51
1 files changed, 40 insertions, 11 deletions
diff --git a/gcc/ada/a-cbhase.adb b/gcc/ada/a-cbhase.adb
index 97a765a6839..cfefc73b6c1 100644
--- a/gcc/ada/a-cbhase.adb
+++ b/gcc/ada/a-cbhase.adb
@@ -34,16 +34,20 @@ with Ada.Containers.Hash_Tables.Generic_Bounded_Keys;
pragma Elaborate_All (Ada.Containers.Hash_Tables.Generic_Bounded_Keys);
with Ada.Containers.Prime_Numbers; use Ada.Containers.Prime_Numbers;
+with Ada.Finalization; use Ada.Finalization;
with System; use type System.Address;
package body Ada.Containers.Bounded_Hashed_Sets is
- type Iterator is new Set_Iterator_Interfaces.Forward_Iterator with record
+ type Iterator is new Limited_Controlled and
+ Set_Iterator_Interfaces.Forward_Iterator with
+ record
Container : Set_Access;
- Position : Cursor;
end record;
+ overriding procedure Finalize (Object : in out Iterator);
+
overriding function First (Object : Iterator) return Cursor;
overriding function Next
@@ -570,6 +574,22 @@ package body Ada.Containers.Bounded_Hashed_Sets is
HT_Ops.Free (Container, X);
end Exclude;
+ --------------
+ -- Finalize --
+ --------------
+
+ procedure Finalize (Object : in out Iterator) is
+ begin
+ if Object.Container /= null then
+ declare
+ B : Natural renames Object.Container.all.Busy;
+
+ begin
+ B := B - 1;
+ end;
+ end if;
+ end Finalize;
+
----------
-- Find --
----------
@@ -596,10 +616,8 @@ package body Ada.Containers.Bounded_Hashed_Sets is
end First;
overriding function First (Object : Iterator) return Cursor is
- Node : constant Count_Type := HT_Ops.First (Object.Container.all);
begin
- return (if Node = 0 then No_Element
- else Cursor'(Object.Container, Node));
+ return Object.Container.First;
end First;
-----------------
@@ -890,7 +908,7 @@ package body Ada.Containers.Bounded_Hashed_Sets is
Process (Cursor'(Container'Unrestricted_Access, Node));
end Process_Node;
- B : Natural renames Container'Unrestricted_Access.Busy;
+ B : Natural renames Container'Unrestricted_Access.all.Busy;
-- Start of processing for Iterate
@@ -909,9 +927,16 @@ package body Ada.Containers.Bounded_Hashed_Sets is
end Iterate;
function Iterate (Container : Set)
- return Set_Iterator_Interfaces.Forward_Iterator'Class is
+ return Set_Iterator_Interfaces.Forward_Iterator'Class
+ is
+ B : Natural renames Container'Unrestricted_Access.all.Busy;
+
begin
- return Iterator'(Container'Unrestricted_Access, First (Container));
+ B := B + 1;
+
+ return It : constant Iterator :=
+ Iterator'(Limited_Controlled with
+ Container => Container'Unrestricted_Access);
end Iterate;
------------
@@ -982,12 +1007,16 @@ package body Ada.Containers.Bounded_Hashed_Sets is
Position : Cursor) return Cursor
is
begin
+ if Position.Container = null then
+ return No_Element;
+ end if;
+
if Position.Container /= Object.Container then
raise Program_Error with
- "Position cursor designates wrong set";
+ "Position cursor of Next designates wrong set";
end if;
- return (if Position.Node = 0 then No_Element else Next (Position));
+ return Next (Position);
end Next;
-------------
@@ -1599,7 +1628,7 @@ package body Ada.Containers.Bounded_Hashed_Sets is
begin
if Node = 0 then
- raise Constraint_Error with "key not in map";
+ raise Constraint_Error with "key not in map"; -- ??? "set"
end if;
return Container.Nodes (Node).Element;