aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/a-cihama.adb
diff options
context:
space:
mode:
authorJeff Law <law@redhat.com>2011-11-30 05:16:36 +0000
committerJeff Law <law@redhat.com>2011-11-30 05:16:36 +0000
commit7b5177cc9956a68a50825c443a6d396fdc1af2b5 (patch)
treea6b80dca8f72a2e7640e4d535901e42325b2a954 /gcc/ada/a-cihama.adb
parent6377b0d9b395f395e25bd4a030a9056171433061 (diff)
parentee4a734e5eece9824adc2a26e518c99bbdbe802e (diff)
Weekly merge from trunk. No regressions.reload-v2a
git-svn-id: https://gcc.gnu.org/svn/gcc/branches/reload-v2a@181834 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/a-cihama.adb')
-rw-r--r--gcc/ada/a-cihama.adb67
1 files changed, 42 insertions, 25 deletions
diff --git a/gcc/ada/a-cihama.adb b/gcc/ada/a-cihama.adb
index b90c5426481..e9b9cc05d91 100644
--- a/gcc/ada/a-cihama.adb
+++ b/gcc/ada/a-cihama.adb
@@ -34,7 +34,6 @@ with Ada.Containers.Hash_Tables.Generic_Keys;
pragma Elaborate_All (Ada.Containers.Hash_Tables.Generic_Keys);
with Ada.Unchecked_Deallocation;
-
with System; use type System.Address;
package body Ada.Containers.Indefinite_Hashed_Maps is
@@ -45,11 +44,13 @@ package body Ada.Containers.Indefinite_Hashed_Maps is
procedure Free_Element is
new Ada.Unchecked_Deallocation (Element_Type, Element_Access);
- 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;
@@ -422,6 +423,18 @@ package body Ada.Containers.Indefinite_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 --
----------
@@ -434,7 +447,7 @@ package body Ada.Containers.Indefinite_Hashed_Maps is
return No_Element;
end if;
- return Cursor'(Container'Unchecked_Access, Node);
+ return Cursor'(Container'Unrestricted_Access, Node);
end Find;
--------------------
@@ -472,18 +485,12 @@ package body Ada.Containers.Indefinite_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;
- else
- return Cursor'(Object.Container.all'Unchecked_Access, N);
- end if;
+ return Object.Container.First;
end First;
----------
@@ -694,10 +701,10 @@ package body Ada.Containers.Indefinite_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 Iterate
@@ -715,13 +722,18 @@ package body Ada.Containers.Indefinite_Hashed_Maps is
B := B - 1;
end Iterate;
- function Iterate (Container : Map)
- return Map_Iterator_Interfaces.Forward_Iterator'class
+ function Iterate
+ (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;
---------
@@ -809,11 +821,16 @@ package body Ada.Containers.Indefinite_Hashed_Maps is
function Next (Object : Iterator; 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;
-------------------