summaryrefslogtreecommitdiff
path: root/gcc/ada/a-cihase.adb
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/ada/a-cihase.adb')
-rw-r--r--gcc/ada/a-cihase.adb52
1 files changed, 38 insertions, 14 deletions
diff --git a/gcc/ada/a-cihase.adb b/gcc/ada/a-cihase.adb
index e29a204570e..3a93f91f5c2 100644
--- a/gcc/ada/a-cihase.adb
+++ b/gcc/ada/a-cihase.adb
@@ -36,16 +36,18 @@ with Ada.Containers.Hash_Tables.Generic_Keys;
pragma Elaborate_All (Ada.Containers.Hash_Tables.Generic_Keys);
with Ada.Containers.Prime_Numbers;
-
-with System; use type System.Address;
+with System; use type System.Address;
package body Ada.Containers.Indefinite_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
@@ -569,6 +571,18 @@ package body Ada.Containers.Indefinite_Hashed_Sets is
HT_Ops.Finalize (Container.HT);
end Finalize;
+ procedure Finalize (Object : in out Iterator) is
+ begin
+ if Object.Container /= null then
+ declare
+ B : Natural renames Object.Container.all.HT.Busy;
+
+ begin
+ B := B - 1;
+ end;
+ end if;
+ end Finalize;
+
----------
-- Find --
----------
@@ -649,10 +663,8 @@ package body Ada.Containers.Indefinite_Hashed_Sets is
end First;
function First (Object : Iterator) return Cursor is
- Node : constant Node_Access := HT_Ops.First (Object.Container.HT);
begin
- return (if Node = null then No_Element
- else Cursor'(Object.Container, Node));
+ return Object.Container.First;
end First;
----------
@@ -990,7 +1002,7 @@ package body Ada.Containers.Indefinite_Hashed_Sets is
Process (Cursor'(Container'Unrestricted_Access, Node));
end Process_Node;
- B : Natural renames Container'Unrestricted_Access.HT.Busy;
+ B : Natural renames Container'Unrestricted_Access.all.HT.Busy;
-- Start of processing for Iterate
@@ -1009,9 +1021,17 @@ package body Ada.Containers.Indefinite_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.HT.Busy;
+
begin
- return Iterator'(Container'Unrestricted_Access, First (Container));
+ return It : constant Iterator :=
+ Iterator'(Limited_Controlled with
+ Container => Container'Unrestricted_Access)
+ do
+ B := B + 1;
+ end return;
end Iterate;
------------
@@ -1072,12 +1092,16 @@ package body Ada.Containers.Indefinite_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 = null then No_Element else Next (Position));
+ return Next (Position);
end Next;
-------------
@@ -1895,7 +1919,7 @@ package body Ada.Containers.Indefinite_Hashed_Sets is
Key_Keys.Delete_Key_Sans_Free (Container.HT, Key, X);
if X = null then
- raise Constraint_Error with "key not in map";
+ raise Constraint_Error with "key not in map"; -- ??? "set"
end if;
Free (X);
@@ -1913,7 +1937,7 @@ package body Ada.Containers.Indefinite_Hashed_Sets is
begin
if Node = null then
- raise Constraint_Error with "key not in map";
+ raise Constraint_Error with "key not in map"; -- ??? "set"
end if;
return Node.Element.all;