summaryrefslogtreecommitdiff
path: root/gcc/ada/a-cohama.adb
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/ada/a-cohama.adb')
-rw-r--r--gcc/ada/a-cohama.adb68
1 files changed, 43 insertions, 25 deletions
diff --git a/gcc/ada/a-cohama.adb b/gcc/ada/a-cohama.adb
index 351030d3a7b..8c92a303076 100644
--- a/gcc/ada/a-cohama.adb
+++ b/gcc/ada/a-cohama.adb
@@ -39,11 +39,13 @@ with System; use type System.Address;
package body Ada.Containers.Hashed_Maps is
- type Iterator is new
- Map_Iterator_Interfaces.Forward_Iterator with record
- Container : Map_Access;
- Node : Node_Access;
- end record;
+ type Iterator is new Limited_Controlled and
+ Map_Iterator_Interfaces.Forward_Iterator with
+ record
+ Container : Map_Access;
+ end record;
+
+ overriding procedure Finalize (Object : in out Iterator);
overriding function First (Object : Iterator) return Cursor;
@@ -386,6 +388,18 @@ package body Ada.Containers.Hashed_Maps 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 --
----------
@@ -398,7 +412,7 @@ package body Ada.Containers.Hashed_Maps is
return No_Element;
end if;
- return Cursor'(Container'Unchecked_Access, Node);
+ return Cursor'(Container'Unrestricted_Access, Node);
end Find;
--------------------
@@ -436,18 +450,12 @@ package body Ada.Containers.Hashed_Maps is
return No_Element;
end if;
- return Cursor'(Container'Unchecked_Access, Node);
+ return Cursor'(Container'Unrestricted_Access, Node);
end First;
function First (Object : Iterator) return Cursor is
- M : constant Map_Access := Object.Container;
- N : constant Node_Access := HT_Ops.First (M.HT);
begin
- if N = null then
- return No_Element;
- end if;
-
- return Cursor'(Object.Container.all'Unchecked_Access, N);
+ return Object.Container.First;
end First;
----------
@@ -553,7 +561,7 @@ package body Ada.Containers.Hashed_Maps is
HT_Ops.Reserve_Capacity (HT, HT.Length);
end if;
- Position.Container := Container'Unchecked_Access;
+ Position.Container := Container'Unrestricted_Access;
end Insert;
procedure Insert
@@ -595,7 +603,7 @@ package body Ada.Containers.Hashed_Maps is
HT_Ops.Reserve_Capacity (HT, HT.Length);
end if;
- Position.Container := Container'Unchecked_Access;
+ Position.Container := Container'Unrestricted_Access;
end Insert;
procedure Insert
@@ -645,10 +653,10 @@ package body Ada.Containers.Hashed_Maps is
procedure Process_Node (Node : Node_Access) is
begin
- Process (Cursor'(Container'Unchecked_Access, Node));
+ 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
@@ -667,12 +675,17 @@ package body Ada.Containers.Hashed_Maps is
end Iterate;
function Iterate
- (Container : Map) return Map_Iterator_Interfaces.Forward_Iterator'class
+ (Container : Map) return Map_Iterator_Interfaces.Forward_Iterator'Class
is
- Node : constant Node_Access := HT_Ops.First (Container.HT);
- It : constant Iterator := (Container'Unrestricted_Access, Node);
+ B : Natural renames Container'Unrestricted_Access.all.HT.Busy;
+
begin
- return It;
+ return It : constant Iterator :=
+ (Limited_Controlled with
+ Container => Container'Unrestricted_Access)
+ do
+ B := B + 1;
+ end return;
end Iterate;
---------
@@ -752,11 +765,16 @@ package body Ada.Containers.Hashed_Maps is
Position : Cursor) return Cursor
is
begin
- if Position.Node = null then
+ if Position.Container = null then
return No_Element;
- else
- return (Object.Container, Next (Position).Node);
end if;
+
+ if Position.Container /= Object.Container then
+ raise Program_Error with
+ "Position cursor of Next designates wrong map";
+ end if;
+
+ return Next (Position);
end Next;
-------------------