aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/a-comutr.adb
diff options
context:
space:
mode:
authorArnaud Charlet <charlet@gcc.gnu.org>2011-09-27 11:58:53 +0200
committerArnaud Charlet <charlet@gcc.gnu.org>2011-09-27 11:58:53 +0200
commit706a4067b883765331b693caded5f08a43eb2645 (patch)
treeedb9b39b6c8e1f86a407fffec5385b70e1182935 /gcc/ada/a-comutr.adb
parent05c1e7d2ef07639da130ff1aa8e723f2a35d4801 (diff)
downloadgcc-706a4067b883765331b693caded5f08a43eb2645.zip
gcc-706a4067b883765331b693caded5f08a43eb2645.tar.gz
gcc-706a4067b883765331b693caded5f08a43eb2645.tar.bz2
[multiple changes]
2011-09-27 Robert Dewar <dewar@adacore.com> * exp_ch9.adb: Minor comment fixes. 2011-09-27 Ed Schonberg <schonberg@adacore.com> * a-comutr.adb, a-comutr.ads: Add children iterators on multiway trees. From-SVN: r179257
Diffstat (limited to 'gcc/ada/a-comutr.adb')
-rw-r--r--gcc/ada/a-comutr.adb77
1 files changed, 75 insertions, 2 deletions
diff --git a/gcc/ada/a-comutr.adb b/gcc/ada/a-comutr.adb
index e3e2557..0fcb3d6 100644
--- a/gcc/ada/a-comutr.adb
+++ b/gcc/ada/a-comutr.adb
@@ -40,11 +40,28 @@ package body Ada.Containers.Multiway_Trees is
From_Root : Boolean;
end record;
+ type Child_Iterator is new Tree_Iterator_Interfaces.Reversible_Iterator with
+ record
+ Container : Tree_Access;
+ Position : Cursor;
+ end record;
+
overriding function First (Object : Iterator) return Cursor;
overriding function Next
(Object : Iterator;
Position : Cursor) return Cursor;
+ overriding function First (Object : Child_Iterator) return Cursor;
+ overriding function Next
+ (Object : Child_Iterator;
+ Position : Cursor) return Cursor;
+
+ overriding function Previous
+ (Object : Child_Iterator;
+ Position : Cursor) return Cursor;
+
+ overriding function Last (Object : Child_Iterator) return Cursor;
+
-----------------------
-- Local Subprograms --
-----------------------
@@ -912,6 +929,11 @@ package body Ada.Containers.Multiway_Trees is
return Object.Position;
end First;
+ function First (Object : Child_Iterator) return Cursor is
+ begin
+ return (Object.Container, Object.Position.Node.Children.First);
+ end First;
+
-----------------
-- First_Child --
-----------------
@@ -1412,6 +1434,16 @@ package body Ada.Containers.Multiway_Trees is
end loop;
end Iterate_Children;
+ function Iterate_Children
+ (Container : Tree;
+ Parent : Cursor)
+ return Tree_Iterator_Interfaces.Reversible_Iterator'Class
+ is
+ pragma Unreferenced (Container);
+ begin
+ return Child_Iterator'(Parent.Container, Parent);
+ end Iterate_Children;
+
---------------------
-- Iterate_Subtree --
---------------------
@@ -1468,13 +1500,21 @@ package body Ada.Containers.Multiway_Trees is
Iterate_Children (Container, Subtree, Process);
end Iterate_Subtree;
+ ----------
+ -- Last --
+ ----------
+
+ overriding function Last (Object : Child_Iterator) return Cursor is
+ begin
+ return (Object.Container, Object.Position.Node.Children.Last);
+ end Last;
+
----------------
-- Last_Child --
----------------
function Last_Child (Parent : Cursor) return Cursor is
Node : Tree_Node_Access;
-
begin
if Parent = No_Element then
raise Constraint_Error with "Parent cursor has no element";
@@ -1588,13 +1628,27 @@ package body Ada.Containers.Multiway_Trees is
end if;
else
-
-- If an internal node, return its first child.
return (Object.Container, N.Children.First);
end if;
end Next;
+ function Next
+ (Object : Child_Iterator;
+ Position : Cursor) return Cursor
+ is
+ C : constant Tree_Node_Access := Position.Node.Next;
+
+ begin
+ if C = null then
+ return No_Element;
+
+ else
+ return (Object.Container, C);
+ end if;
+ end Next;
+
------------------
-- Next_Sibling --
------------------
@@ -1714,6 +1768,25 @@ package body Ada.Containers.Multiway_Trees is
Container.Count := Container.Count + Count;
end Prepend_Child;
+ --------------
+ -- Previous --
+ --------------
+
+ overriding function Previous
+ (Object : Child_Iterator;
+ Position : Cursor) return Cursor
+ is
+ C : constant Tree_Node_Access := Position.Node.Prev;
+
+ begin
+ if C = null then
+ return No_Element;
+
+ else
+ return (Object.Container, C);
+ end if;
+ end Previous;
+
----------------------
-- Previous_Sibling --
----------------------