diff options
author | Ed Schonberg <schonberg@adacore.com> | 2011-09-27 10:11:01 +0000 |
---|---|---|
committer | Arnaud Charlet <charlet@gcc.gnu.org> | 2011-09-27 12:11:01 +0200 |
commit | ffb35bbf33cbdac32aa3147cccbbc73076eba66d (patch) | |
tree | c7ec0579749b721790ac4965474b2502ccf80d84 /gcc/ada/a-ciorma.adb | |
parent | 862a84f5cfb3dfda8a55ad84a44f710a6f0e205e (diff) | |
download | gcc-ffb35bbf33cbdac32aa3147cccbbc73076eba66d.zip gcc-ffb35bbf33cbdac32aa3147cccbbc73076eba66d.tar.gz gcc-ffb35bbf33cbdac32aa3147cccbbc73076eba66d.tar.bz2 |
a-cbhase.adb, [...]: Add iterator machinery to bounded sets and indefinite sets.
2011-09-27 Ed Schonberg <schonberg@adacore.com>
* a-cbhase.adb, a-cbhase.ads, a-cborse.adb, a-cborse.ads,
a-cihase.adb, a-cihase.ads, a-ciorse.adb, a-ciorse.ads,
a-coorse.adb, a-coorse.ads: Add iterator machinery to bounded sets and
indefinite sets.
* a-coorma.ads: Minor reformmating.
* einfo.ads: Improve the comment describing the
Directly_Designated_Type function.
* a-ciorma.adb, a-ciorma.ads: Add iterator machinery to indefinite
ordered maps.
* gcc-interface/Makefile.in, gcc-interface/Make-lang.in: Update
dependencies.
From-SVN: r179260
Diffstat (limited to 'gcc/ada/a-ciorma.adb')
-rw-r--r-- | gcc/ada/a-ciorma.adb | 140 |
1 files changed, 139 insertions, 1 deletions
diff --git a/gcc/ada/a-ciorma.adb b/gcc/ada/a-ciorma.adb index 9cfcd3f..c30abd0 100644 --- a/gcc/ada/a-ciorma.adb +++ b/gcc/ada/a-ciorma.adb @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 2004-2010, Free Software Foundation, Inc. -- +-- Copyright (C) 2004-2011, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -37,6 +37,24 @@ pragma Elaborate_All (Ada.Containers.Red_Black_Trees.Generic_Keys); package body Ada.Containers.Indefinite_Ordered_Maps is + type Iterator is new + Map_Iterator_Interfaces.Reversible_Iterator with record + Container : Map_Access; + Node : Node_Access; + end record; + + overriding function First (Object : Iterator) return Cursor; + + overriding function Last (Object : Iterator) return Cursor; + + overriding function Next + (Object : Iterator; + Position : Cursor) return Cursor; + + overriding function Previous + (Object : Iterator; + Position : Cursor) return Cursor; + ----------------------------- -- Node Access Subprograms -- ----------------------------- @@ -305,6 +323,17 @@ package body Ada.Containers.Indefinite_Ordered_Maps is return Node.Color; end Color; + ------------------------ + -- Constant_Reference -- + ------------------------ + + function Constant_Reference + (Container : Map; + Key : Key_Type) return Constant_Reference_Type + is + begin return (Element => Container.Element (Key)'Unrestricted_Access); + end Constant_Reference; + -------------- -- Contains -- -------------- @@ -503,6 +532,18 @@ package body Ada.Containers.Indefinite_Ordered_Maps is return Cursor'(Container'Unrestricted_Access, T.First); end First; + function First (Object : Iterator) return Cursor is + M : constant Map_Access := Object.Container; + N : constant Node_Access := M.Tree.First; + + begin + if N = null then + return No_Element; + else + return Cursor'(Object.Container.all'Unchecked_Access, N); + end if; + end First; + ------------------- -- First_Element -- ------------------- @@ -810,6 +851,24 @@ package body Ada.Containers.Indefinite_Ordered_Maps is B := B - 1; end Iterate; + function Iterate + (Container : Map) return Map_Iterator_Interfaces.Forward_Iterator'class + is + Node : constant Node_Access := Container.Tree.First; + It : constant Iterator := (Container'Unrestricted_Access, Node); + + begin + return It; + end Iterate; + + function Iterate (Container : Map; Start : Cursor) + return Map_Iterator_Interfaces.Reversible_Iterator'class + is + It : constant Iterator := (Container'Unrestricted_Access, Start.Node); + begin + return It; + end Iterate; + --------- -- Key -- --------- @@ -847,6 +906,17 @@ package body Ada.Containers.Indefinite_Ordered_Maps is return Cursor'(Container'Unrestricted_Access, T.Last); end Last; + function Last (Object : Iterator) return Cursor is + M : constant Map_Access := Object.Container; + N : constant Node_Access := M.Tree.Last; + begin + if N = null then + return No_Element; + else + return Cursor'(Object.Container.all'Unchecked_Access, N); + end if; + end Last; + ------------------ -- Last_Element -- ------------------ @@ -941,6 +1011,18 @@ package body Ada.Containers.Indefinite_Ordered_Maps is Position := Next (Position); end Next; + function Next + (Object : Iterator; + Position : Cursor) return Cursor + is + begin + if Position.Node = null then + return No_Element; + else + return (Object.Container, Tree_Operations.Next (Position.Node)); + end if; + end Next; + ------------ -- Parent -- ------------ @@ -984,6 +1066,18 @@ package body Ada.Containers.Indefinite_Ordered_Maps is Position := Previous (Position); end Previous; + function Previous + (Object : Iterator; + Position : Cursor) return Cursor + is + begin + if Position.Node = null then + return No_Element; + else + return (Object.Container, Tree_Operations.Previous (Position.Node)); + end if; + end Previous; + ------------------- -- Query_Element -- ------------------- @@ -1084,6 +1178,35 @@ package body Ada.Containers.Indefinite_Ordered_Maps is raise Program_Error with "attempt to stream map cursor"; end Read; + procedure Read + (Stream : not null access Root_Stream_Type'Class; + Item : out Reference_Type) + is + begin + raise Program_Error with "attempt to stream reference"; + end Read; + + procedure Read + (Stream : not null access Root_Stream_Type'Class; + Item : out Constant_Reference_Type) + is + begin + raise Program_Error with "attempt to stream reference"; + end Read; + + --------------- + -- Reference -- + --------------- + + function Reference + (Container : Map; + Key : Key_Type) + return Reference_Type + is + begin + return (Element => Container.Element (Key)'Unrestricted_Access); + end Reference; + ------------- -- Replace -- ------------- @@ -1359,4 +1482,19 @@ package body Ada.Containers.Indefinite_Ordered_Maps is raise Program_Error with "attempt to stream map cursor"; end Write; + procedure Write + (Stream : not null access Root_Stream_Type'Class; + Item : Reference_Type) + is + begin + raise Program_Error with "attempt to stream reference"; + end Write; + + procedure Write + (Stream : not null access Root_Stream_Type'Class; + Item : Constant_Reference_Type) + is + begin + raise Program_Error with "attempt to stream reference"; + end Write; end Ada.Containers.Indefinite_Ordered_Maps; |