diff options
author | Matthew Heaney <heaney@adacore.com> | 2005-09-05 10:05:32 +0200 |
---|---|---|
committer | Arnaud Charlet <charlet@gcc.gnu.org> | 2005-09-05 10:05:32 +0200 |
commit | ba355842e8ff8cbcb8552b99f6098b333512cc81 (patch) | |
tree | 7b4be4425a576dfefafcfd6533af08d710bea8f0 /gcc/ada/a-cidlli.adb | |
parent | c1cd0d96753eff81ceba44eaa371931e993e539d (diff) | |
download | gcc-ba355842e8ff8cbcb8552b99f6098b333512cc81.tar.gz |
a-cihase.adb, [...]: Synchronized with latest draft (Draft 13, August 2005) of Ada Amendment 1.
2005-09-01 Matthew Heaney <heaney@adacore.com>
* a-cihase.adb, a-coorse.ads, a-coorse.adb, a-cohama.adb,
a-ciorse.ads, a-ciorse.adb, a-cihama.adb, a-cdlili.adb,
a-cidlli.adb, a-chtgop.adb, a-cihase.adb, a-cihase.ads,
a-cohase.adb, a-cohase.adb, a-cohase.ads: Synchronized with latest
draft (Draft 13, August 2005) of Ada Amendment 1.
From-SVN: r103892
Diffstat (limited to 'gcc/ada/a-cidlli.adb')
-rw-r--r-- | gcc/ada/a-cidlli.adb | 845 |
1 files changed, 343 insertions, 502 deletions
diff --git a/gcc/ada/a-cidlli.adb b/gcc/ada/a-cidlli.adb index d9bdf8f8986..becdae2ecb5 100644 --- a/gcc/ada/a-cidlli.adb +++ b/gcc/ada/a-cidlli.adb @@ -40,20 +40,21 @@ with Ada.Unchecked_Deallocation; package body Ada.Containers.Indefinite_Doubly_Linked_Lists is procedure Free is - new Ada.Unchecked_Deallocation (Node_Type, Node_Access); - - procedure Free is new Ada.Unchecked_Deallocation (Element_Type, Element_Access); ----------------------- -- Local Subprograms -- ----------------------- + procedure Free (X : in out Node_Access); + procedure Insert_Internal (Container : in out List; Before : Node_Access; New_Node : Node_Access); + function Vet (Position : Cursor) return Boolean; + --------- -- "=" -- --------- @@ -188,18 +189,8 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is Container.First := X.Next; Container.First.Prev := null; - Container.Length := Container.Length - 1; - - X.Next := null; -- prevent mischief - begin - Free (X.Element); - exception - when others => - X.Element := null; - Free (X); - raise; - end; + Container.Length := Container.Length - 1; Free (X); end loop; @@ -211,15 +202,6 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is Container.Last := null; Container.Length := 0; - begin - Free (X.Element); - exception - when others => - X.Element := null; - Free (X); - raise; - end; - Free (X); end Clear; @@ -246,28 +228,16 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is X : Node_Access; begin + pragma Assert (Vet (Position), "bad cursor in Delete"); + if Position.Node = null then raise Constraint_Error; end if; - if Position.Container /= List_Access'(Container'Unchecked_Access) then + if Position.Container /= Container'Unrestricted_Access then raise Program_Error; end if; - pragma Assert (Container.Length > 0); - pragma Assert (Container.First.Prev = null); - pragma Assert (Container.Last.Next = null); - - pragma Assert (Position.Node.Element /= null); - pragma Assert (Position.Node.Prev = null - or else Position.Node.Prev.Next = Position.Node); - pragma Assert (Position.Node.Next = null - or else Position.Node.Next.Prev = Position.Node); - pragma Assert (Position.Node.Prev /= null - or else Position.Node = Container.First); - pragma Assert (Position.Node.Next /= null - or else Position.Node = Container.Last); - if Position.Node = Container.First then Delete_First (Container, Count); Position := First (Container); @@ -292,17 +262,6 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is Container.Last := X.Prev; Container.Last.Next := null; - X.Prev := null; -- prevent mischief - - begin - Free (X.Element); - exception - when others => - X.Element := null; - Free (X); - raise; - end; - Free (X); return; end if; @@ -312,18 +271,6 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is X.Next.Prev := X.Prev; X.Prev.Next := X.Next; - X.Prev := null; - X.Next := null; - - begin - Free (X.Element); - exception - when others => - X.Element := null; - Free (X); - raise; - end; - Free (X); end loop; end Delete; @@ -361,17 +308,6 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is Container.Length := Container.Length - 1; - X.Next := null; -- prevent mischief - - begin - Free (X.Element); - exception - when others => - X.Element := null; - Free (X); - raise; - end; - Free (X); end loop; end Delete_First; @@ -409,17 +345,6 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is Container.Length := Container.Length - 1; - X.Prev := null; -- prevent mischief - - begin - Free (X.Element); - exception - when others => - X.Element := null; - Free (X); - raise; - end; - Free (X); end loop; end Delete_Last; @@ -430,21 +355,11 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is function Element (Position : Cursor) return Element_Type is begin - pragma Assert (Position.Container /= null); - pragma Assert (Position.Container.Length > 0); - pragma Assert (Position.Container.First.Prev = null); - pragma Assert (Position.Container.Last.Next = null); - - pragma Assert (Position.Node /= null); - pragma Assert (Position.Node.Element /= null); - pragma Assert (Position.Node.Prev = null - or else Position.Node.Prev.Next = Position.Node); - pragma Assert (Position.Node.Next = null - or else Position.Node.Next.Prev = Position.Node); - pragma Assert (Position.Node.Prev /= null - or else Position.Node = Position.Container.First); - pragma Assert (Position.Node.Next /= null - or else Position.Node = Position.Container.Last); + pragma Assert (Vet (Position), "bad cursor in Element"); + + if Position.Node = null then + raise Constraint_Error; + end if; return Position.Node.Element.all; end Element; @@ -465,23 +380,11 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is Node := Container.First; else - if Position.Container /= List_Access'(Container'Unchecked_Access) then + pragma Assert (Vet (Position), "bad cursor in Find"); + + if Position.Container /= Container'Unrestricted_Access then raise Program_Error; end if; - - pragma Assert (Container.Length > 0); - pragma Assert (Container.First.Prev = null); - pragma Assert (Container.Last.Next = null); - - pragma Assert (Position.Node.Element /= null); - pragma Assert (Position.Node.Prev = null - or else Position.Node.Prev.Next = Position.Node); - pragma Assert (Position.Node.Next = null - or else Position.Node.Next.Prev = Position.Node); - pragma Assert (Position.Node.Prev /= null - or else Position.Node = Container.First); - pragma Assert (Position.Node.Next /= null - or else Position.Node = Container.Last); end if; while Node /= null loop @@ -514,9 +417,37 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is function First_Element (Container : List) return Element_Type is begin + if Container.First = null then + raise Constraint_Error; + end if; + return Container.First.Element.all; end First_Element; + ---------- + -- Free -- + ---------- + + procedure Free (X : in out Node_Access) is + procedure Deallocate is + new Ada.Unchecked_Deallocation (Node_Type, Node_Access); + + begin + X.Next := X; + X.Prev := X; + + begin + Free (X.Element); + exception + when others => + X.Element := null; + Deallocate (X); + raise; + end; + + Deallocate (X); + end Free; + --------------------- -- Generic_Sorting -- --------------------- @@ -686,27 +617,8 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is function Has_Element (Position : Cursor) return Boolean is begin - if Position.Node = null then - pragma Assert (Position.Container = null); - return False; - end if; - - pragma Assert (Position.Container /= null); - pragma Assert (Position.Container.Length > 0); - pragma Assert (Position.Container.First.Prev = null); - pragma Assert (Position.Container.Last.Next = null); - - pragma Assert (Position.Node.Element /= null); - pragma Assert (Position.Node.Prev = null - or else Position.Node.Prev.Next = Position.Node); - pragma Assert (Position.Node.Next = null - or else Position.Node.Next.Prev = Position.Node); - pragma Assert (Position.Node.Prev /= null - or else Position.Node = Position.Container.First); - pragma Assert (Position.Node.Next /= null - or else Position.Node = Position.Container.Last); - - return True; + pragma Assert (Vet (Position), "bad cursor in Has_Element"); + return Position.Node /= null; end Has_Element; ------------ @@ -723,24 +635,12 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is New_Node : Node_Access; begin - if Before.Node /= null then - if Before.Container /= List_Access'(Container'Unchecked_Access) then - raise Program_Error; - end if; - - pragma Assert (Container.Length > 0); - pragma Assert (Container.First.Prev = null); - pragma Assert (Container.Last.Next = null); + pragma Assert (Vet (Before), "bad cursor in Insert"); - pragma Assert (Before.Node.Element /= null); - pragma Assert (Before.Node.Prev = null - or else Before.Node.Prev.Next = Before.Node); - pragma Assert (Before.Node.Next = null - or else Before.Node.Next.Prev = Before.Node); - pragma Assert (Before.Node.Prev /= null - or else Before.Node = Container.First); - pragma Assert (Before.Node.Next /= null - or else Before.Node = Container.Last); + if Before.Container /= null + and then Before.Container /= Container'Unrestricted_Access + then + raise Program_Error; end if; if Count = 0 then @@ -884,32 +784,6 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is end Iterate; ---------- - -- Move -- - ---------- - - procedure Move (Target : in out List; Source : in out List) is - begin - if Target'Address = Source'Address then - return; - end if; - - if Source.Busy > 0 then - raise Program_Error; - end if; - - Clear (Target); - - Target.First := Source.First; - Source.First := null; - - Target.Last := Source.Last; - Source.Last := null; - - Target.Length := Source.Length; - Source.Length := 0; - end Move; - - ---------- -- Last -- ---------- @@ -928,6 +802,10 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is function Last_Element (Container : List) return Element_Type is begin + if Container.Last = null then + raise Constraint_Error; + end if; + return Container.Last.Element.all; end Last_Element; @@ -941,31 +819,43 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is end Length; ---------- + -- Move -- + ---------- + + procedure Move (Target : in out List; Source : in out List) is + begin + if Target'Address = Source'Address then + return; + end if; + + if Source.Busy > 0 then + raise Program_Error; + end if; + + Clear (Target); + + Target.First := Source.First; + Source.First := null; + + Target.Last := Source.Last; + Source.Last := null; + + Target.Length := Source.Length; + Source.Length := 0; + end Move; + + ---------- -- Next -- ---------- procedure Next (Position : in out Cursor) is begin + pragma Assert (Vet (Position), "bad cursor in procedure Next"); + if Position.Node = null then - pragma Assert (Position.Container = null); return; end if; - pragma Assert (Position.Container /= null); - pragma Assert (Position.Container.Length > 0); - pragma Assert (Position.Container.First.Prev = null); - pragma Assert (Position.Container.Last.Next = null); - - pragma Assert (Position.Node.Element /= null); - pragma Assert (Position.Node.Prev = null - or else Position.Node.Prev.Next = Position.Node); - pragma Assert (Position.Node.Next = null - or else Position.Node.Next.Prev = Position.Node); - pragma Assert (Position.Node.Prev /= null - or else Position.Node = Position.Container.First); - pragma Assert (Position.Node.Next /= null - or else Position.Node = Position.Container.Last); - Position.Node := Position.Node.Next; if Position.Node = null then @@ -975,26 +865,12 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is function Next (Position : Cursor) return Cursor is begin + pragma Assert (Vet (Position), "bad cursor in function Next"); + if Position.Node = null then - pragma Assert (Position.Container = null); return No_Element; end if; - pragma Assert (Position.Container /= null); - pragma Assert (Position.Container.Length > 0); - pragma Assert (Position.Container.First.Prev = null); - pragma Assert (Position.Container.Last.Next = null); - - pragma Assert (Position.Node.Element /= null); - pragma Assert (Position.Node.Prev = null - or else Position.Node.Prev.Next = Position.Node); - pragma Assert (Position.Node.Next = null - or else Position.Node.Next.Prev = Position.Node); - pragma Assert (Position.Node.Prev /= null - or else Position.Node = Position.Container.First); - pragma Assert (Position.Node.Next /= null - or else Position.Node = Position.Container.Last); - declare Next_Node : constant Node_Access := Position.Node.Next; begin @@ -1025,26 +901,12 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is procedure Previous (Position : in out Cursor) is begin + pragma Assert (Vet (Position), "bad cursor in procedure Previous"); + if Position.Node = null then - pragma Assert (Position.Container = null); return; end if; - pragma Assert (Position.Container /= null); - pragma Assert (Position.Container.Length > 0); - pragma Assert (Position.Container.First.Prev = null); - pragma Assert (Position.Container.Last.Next = null); - - pragma Assert (Position.Node.Element /= null); - pragma Assert (Position.Node.Prev = null - or else Position.Node.Prev.Next = Position.Node); - pragma Assert (Position.Node.Next = null - or else Position.Node.Next.Prev = Position.Node); - pragma Assert (Position.Node.Prev /= null - or else Position.Node = Position.Container.First); - pragma Assert (Position.Node.Next /= null - or else Position.Node = Position.Container.Last); - Position.Node := Position.Node.Prev; if Position.Node = null then @@ -1054,26 +916,12 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is function Previous (Position : Cursor) return Cursor is begin + pragma Assert (Vet (Position), "bad cursor in function Previous"); + if Position.Node = null then - pragma Assert (Position.Container = null); return No_Element; end if; - pragma Assert (Position.Container /= null); - pragma Assert (Position.Container.Length > 0); - pragma Assert (Position.Container.First.Prev = null); - pragma Assert (Position.Container.Last.Next = null); - - pragma Assert (Position.Node.Element /= null); - pragma Assert (Position.Node.Prev = null - or else Position.Node.Prev.Next = Position.Node); - pragma Assert (Position.Node.Next = null - or else Position.Node.Next.Prev = Position.Node); - pragma Assert (Position.Node.Prev /= null - or else Position.Node = Position.Container.First); - pragma Assert (Position.Node.Next /= null - or else Position.Node = Position.Container.Last); - declare Prev_Node : constant Node_Access := Position.Node.Prev; begin @@ -1093,43 +941,34 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is (Position : Cursor; Process : not null access procedure (Element : in Element_Type)) is - pragma Assert (Position.Container /= null); - pragma Assert (Position.Container.Length > 0); - pragma Assert (Position.Container.First.Prev = null); - pragma Assert (Position.Container.Last.Next = null); - - pragma Assert (Position.Node /= null); - pragma Assert (Position.Node.Element /= null); - pragma Assert (Position.Node.Prev = null - or else Position.Node.Prev.Next = Position.Node); - pragma Assert (Position.Node.Next = null - or else Position.Node.Next.Prev = Position.Node); - pragma Assert (Position.Node.Prev /= null - or else Position.Node = Position.Container.First); - pragma Assert (Position.Node.Next /= null - or else Position.Node = Position.Container.Last); - - E : Element_Type renames Position.Node.Element.all; - - C : List renames Position.Container.all'Unrestricted_Access.all; - B : Natural renames C.Busy; - L : Natural renames C.Lock; - begin - B := B + 1; - L := L + 1; + pragma Assert (Vet (Position), "bad cursor in Query_Element"); + + if Position.Node = null then + raise Constraint_Error; + end if; + + declare + C : List renames Position.Container.all'Unrestricted_Access.all; + B : Natural renames C.Busy; + L : Natural renames C.Lock; begin - Process (E); - exception - when others => - L := L - 1; - B := B - 1; - raise; - end; + B := B + 1; + L := L + 1; - L := L - 1; - B := B - 1; + begin + Process (Position.Node.Element.all); + exception + when others => + L := L - 1; + B := B - 1; + raise; + end; + + L := L - 1; + B := B - 1; + end; end Query_Element; ---------- @@ -1193,31 +1032,23 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is (Position : Cursor; By : Element_Type) is - pragma Assert (Position.Container /= null); - pragma Assert (Position.Container.Length > 0); - pragma Assert (Position.Container.First.Prev = null); - pragma Assert (Position.Container.Last.Next = null); - - pragma Assert (Position.Node /= null); - pragma Assert (Position.Node.Element /= null); - pragma Assert (Position.Node.Prev = null - or else Position.Node.Prev.Next = Position.Node); - pragma Assert (Position.Node.Next = null - or else Position.Node.Next.Prev = Position.Node); - pragma Assert (Position.Node.Prev /= null - or else Position.Node = Position.Container.First); - pragma Assert (Position.Node.Next /= null - or else Position.Node = Position.Container.Last); - - X : Element_Access := Position.Node.Element; - begin + pragma Assert (Vet (Position), "bad cursor in Replace_Element"); + + if Position.Container = null then + raise Constraint_Error; + end if; + if Position.Container.Lock > 0 then raise Program_Error; end if; - Position.Node.Element := new Element_Type'(By); - Free (X); + declare + X : Element_Access := Position.Node.Element; + begin + Position.Node.Element := new Element_Type'(By); + Free (X); + end; end Replace_Element; ------------------ @@ -1236,23 +1067,11 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is Node := Container.Last; else - if Position.Container /= List_Access'(Container'Unchecked_Access) then + pragma Assert (Vet (Position), "bad cursor in Reverse_Find"); + + if Position.Container /= Container'Unrestricted_Access then raise Program_Error; end if; - - pragma Assert (Container.Length > 0); - pragma Assert (Container.First.Prev = null); - pragma Assert (Container.Last.Next = null); - - pragma Assert (Position.Node.Element /= null); - pragma Assert (Position.Node.Prev = null - or else Position.Node.Prev.Next = Position.Node); - pragma Assert (Position.Node.Next = null - or else Position.Node.Next.Prev = Position.Node); - pragma Assert (Position.Node.Prev /= null - or else Position.Node = Container.First); - pragma Assert (Position.Node.Next /= null - or else Position.Node = Container.Last); end if; while Node /= null loop @@ -1392,24 +1211,12 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is Source : in out List) is begin - if Before.Node /= null then - if Before.Container /= List_Access'(Target'Unchecked_Access) then - raise Program_Error; - end if; - - pragma Assert (Target.Length >= 1); - pragma Assert (Target.First.Prev = null); - pragma Assert (Target.Last.Next = null); + pragma Assert (Vet (Before), "bad cursor in Splice"); - pragma Assert (Before.Node.Element /= null); - pragma Assert (Before.Node.Prev = null - or else Before.Node.Prev.Next = Before.Node); - pragma Assert (Before.Node.Next = null - or else Before.Node.Next.Prev = Before.Node); - pragma Assert (Before.Node.Prev /= null - or else Before.Node = Target.First); - pragma Assert (Before.Node.Next /= null - or else Before.Node = Target.Last); + if Before.Container /= null + and then Before.Container /= Target'Unrestricted_Access + then + raise Program_Error; end if; if Target'Address = Source'Address @@ -1477,48 +1284,23 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is Position : Cursor) is begin - if Before.Node /= null then - if Before.Container /= List_Access'(Target'Unchecked_Access) then - raise Program_Error; - end if; - - pragma Assert (Target.Length >= 1); - pragma Assert (Target.First.Prev = null); - pragma Assert (Target.Last.Next = null); + pragma Assert (Vet (Before), "bad Before cursor in Splice"); + pragma Assert (Vet (Position), "bad Position cursor in Splice"); - pragma Assert (Before.Node.Element /= null); - pragma Assert (Before.Node.Prev = null - or else Before.Node.Prev.Next = Before.Node); - pragma Assert (Before.Node.Next = null - or else Before.Node.Next.Prev = Before.Node); - pragma Assert (Before.Node.Prev /= null - or else Before.Node = Target.First); - pragma Assert (Before.Node.Next /= null - or else Before.Node = Target.Last); + if Before.Container /= null + and then Before.Container /= Target'Unchecked_Access + then + raise Program_Error; end if; if Position.Node = null then raise Constraint_Error; end if; - if Position.Container /= List_Access'(Target'Unchecked_Access) then + if Position.Container /= Target'Unrestricted_Access then raise Program_Error; end if; - pragma Assert (Target.Length >= 1); - pragma Assert (Target.First.Prev = null); - pragma Assert (Target.Last.Next = null); - - pragma Assert (Position.Node.Element /= null); - pragma Assert (Position.Node.Prev = null - or else Position.Node.Prev.Next = Position.Node); - pragma Assert (Position.Node.Next = null - or else Position.Node.Next.Prev = Position.Node); - pragma Assert (Position.Node.Prev /= null - or else Position.Node = Target.First); - pragma Assert (Position.Node.Next /= null - or else Position.Node = Target.Last); - if Position.Node = Before.Node or else Position.Node.Next = Before.Node then @@ -1606,48 +1388,23 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is return; end if; - if Before.Node /= null then - if Before.Container /= List_Access'(Target'Unchecked_Access) then - raise Program_Error; - end if; - - pragma Assert (Target.Length >= 1); - pragma Assert (Target.First.Prev = null); - pragma Assert (Target.Last.Next = null); + pragma Assert (Vet (Before), "bad Before cursor in Splice"); + pragma Assert (Vet (Position), "bad Position cursor in Splice"); - pragma Assert (Before.Node.Element /= null); - pragma Assert (Before.Node.Prev = null - or else Before.Node.Prev.Next = Before.Node); - pragma Assert (Before.Node.Next = null - or else Before.Node.Next.Prev = Before.Node); - pragma Assert (Before.Node.Prev /= null - or else Before.Node = Target.First); - pragma Assert (Before.Node.Next /= null - or else Before.Node = Target.Last); + if Before.Container /= null + and then Before.Container /= Target'Unrestricted_Access + then + raise Program_Error; end if; if Position.Node = null then raise Constraint_Error; end if; - if Position.Container /= List_Access'(Source'Unchecked_Access) then + if Position.Container /= Source'Unrestricted_Access then raise Program_Error; end if; - pragma Assert (Source.Length >= 1); - pragma Assert (Source.First.Prev = null); - pragma Assert (Source.Last.Next = null); - - pragma Assert (Position.Node.Element /= null); - pragma Assert (Position.Node.Prev = null - or else Position.Node.Prev.Next = Position.Node); - pragma Assert (Position.Node.Next = null - or else Position.Node.Next.Prev = Position.Node); - pragma Assert (Position.Node.Prev /= null - or else Position.Node = Source.First); - pragma Assert (Position.Node.Next /= null - or else Position.Node = Source.Last); - if Target.Length = Count_Type'Last then raise Constraint_Error; end if; @@ -1660,12 +1417,14 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is if Position.Node = Source.First then Source.First := Position.Node.Next; - Source.First.Prev := null; if Position.Node = Source.Last then pragma Assert (Source.First = null); pragma Assert (Source.Length = 1); Source.Last := null; + + else + Source.First.Prev := null; end if; elsif Position.Node = Source.Last then @@ -1727,8 +1486,11 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is procedure Swap (I, J : Cursor) is begin - if I.Container = null - or else J.Container = null + pragma Assert (Vet (I), "bad I cursor in Swap"); + pragma Assert (Vet (J), "bad J cursor in Swap"); + + if I.Node = null + or else J.Node = null then raise Constraint_Error; end if; @@ -1737,50 +1499,19 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is raise Program_Error; end if; - declare - C : List renames I.Container.all; - begin - pragma Assert (C.Length > 0); - pragma Assert (C.First.Prev = null); - pragma Assert (C.Last.Next = null); - - pragma Assert (I.Node /= null); - pragma Assert (I.Node.Element /= null); - pragma Assert (I.Node.Prev = null - or else I.Node.Prev.Next = I.Node); - pragma Assert (I.Node.Next = null - or else I.Node.Next.Prev = I.Node); - pragma Assert (I.Node.Prev /= null - or else I.Node = C.First); - pragma Assert (I.Node.Next /= null - or else I.Node = C.Last); - - if I.Node = J.Node then - return; - end if; + if I.Node = J.Node then + return; + end if; - pragma Assert (C.Length > 1); - pragma Assert (J.Node /= null); - pragma Assert (J.Node.Element /= null); - pragma Assert (J.Node.Prev = null - or else J.Node.Prev.Next = J.Node); - pragma Assert (J.Node.Next = null - or else J.Node.Next.Prev = J.Node); - pragma Assert (J.Node.Prev /= null - or else J.Node = C.First); - pragma Assert (J.Node.Next /= null - or else J.Node = C.Last); - - if C.Lock > 0 then - raise Program_Error; - end if; + if I.Container.Lock > 0 then + raise Program_Error; + end if; - declare - EI_Copy : constant Element_Access := I.Node.Element; - begin - I.Node.Element := J.Node.Element; - J.Node.Element := EI_Copy; - end; + declare + EI_Copy : constant Element_Access := I.Node.Element; + begin + I.Node.Element := J.Node.Element; + J.Node.Element := EI_Copy; end; end Swap; @@ -1793,51 +1524,25 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is I, J : Cursor) is begin - if I.Container = null - or else J.Container = null + pragma Assert (Vet (I), "bad I cursor in Swap_Links"); + pragma Assert (Vet (J), "bad J cursor in Swap_Links"); + + if I.Node = null + or else J.Node = null then raise Constraint_Error; end if; - if I.Container /= List_Access'(Container'Unchecked_Access) then - raise Program_Error; - end if; - - if J.Container /= I.Container then + if I.Container /= Container'Unrestricted_Access + or else I.Container /= J.Container + then raise Program_Error; end if; - pragma Assert (Container.Length >= 1); - pragma Assert (Container.First.Prev = null); - pragma Assert (Container.Last.Next = null); - - pragma Assert (I.Node /= null); - pragma Assert (I.Node.Element /= null); - pragma Assert (I.Node.Prev = null - or else I.Node.Prev.Next = I.Node); - pragma Assert (I.Node.Next = null - or else I.Node.Next.Prev = I.Node); - pragma Assert (I.Node.Prev /= null - or else I.Node = Container.First); - pragma Assert (I.Node.Next /= null - or else I.Node = Container.Last); - if I.Node = J.Node then return; end if; - pragma Assert (Container.Length >= 2); - pragma Assert (J.Node /= null); - pragma Assert (J.Node.Element /= null); - pragma Assert (J.Node.Prev = null - or else J.Node.Prev.Next = J.Node); - pragma Assert (J.Node.Next = null - or else J.Node.Next.Prev = J.Node); - pragma Assert (J.Node.Prev /= null - or else J.Node = Container.First); - pragma Assert (J.Node.Next /= null - or else J.Node = Container.Last); - if Container.Busy > 0 then raise Program_Error; end if; @@ -1878,45 +1583,179 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is (Position : Cursor; Process : not null access procedure (Element : in out Element_Type)) is - pragma Assert (Position.Container /= null); - pragma Assert (Position.Container.Length > 0); - pragma Assert (Position.Container.First.Prev = null); - pragma Assert (Position.Container.Last.Next = null); - - pragma Assert (Position.Node /= null); - pragma Assert (Position.Node.Element /= null); - pragma Assert (Position.Node.Prev = null - or else Position.Node.Prev.Next = Position.Node); - pragma Assert (Position.Node.Next = null - or else Position.Node.Next.Prev = Position.Node); - pragma Assert (Position.Node.Prev /= null - or else Position.Node = Position.Container.First); - pragma Assert (Position.Node.Next /= null - or else Position.Node = Position.Container.Last); - - E : Element_Type renames Position.Node.Element.all; - - C : List renames Position.Container.all'Unrestricted_Access.all; - B : Natural renames C.Busy; - L : Natural renames C.Lock; - begin - B := B + 1; - L := L + 1; + pragma Assert (Vet (Position), "bad cursor in Update_Element"); + + if Position.Node = null then + raise Constraint_Error; + end if; + + declare + C : List renames Position.Container.all'Unrestricted_Access.all; + B : Natural renames C.Busy; + L : Natural renames C.Lock; begin - Process (E); - exception - when others => - L := L - 1; - B := B - 1; - raise; - end; + B := B + 1; + L := L + 1; - L := L - 1; - B := B - 1; + begin + Process (Position.Node.Element.all); + exception + when others => + L := L - 1; + B := B - 1; + raise; + end; + + L := L - 1; + B := B - 1; + end; end Update_Element; + --------- + -- Vet -- + --------- + + function Vet (Position : Cursor) return Boolean is + begin + if Position.Node = null then + return Position.Container = null; + end if; + + if Position.Container = null then + return False; + end if; + + if Position.Node.Next = Position.Node then + return False; + end if; + + if Position.Node.Prev = Position.Node then + return False; + end if; + + if Position.Node.Element = null then + return False; + end if; + + declare + L : List renames Position.Container.all; + begin + if L.Length = 0 then + return False; + end if; + + if L.First = null then + return False; + end if; + + if L.Last = null then + return False; + end if; + + if L.First.Prev /= null then + return False; + end if; + + if L.Last.Next /= null then + return False; + end if; + + if Position.Node.Prev = null + and then Position.Node /= L.First + then + return False; + end if; + + if Position.Node.Next = null + and then Position.Node /= L.Last + then + return False; + end if; + + if L.Length = 1 then + return L.First = L.Last; + end if; + + if L.First = L.Last then + return False; + end if; + + if L.First.Next = null then + return False; + end if; + + if L.Last.Prev = null then + return False; + end if; + + if L.First.Next.Prev /= L.First then + return False; + end if; + + if L.Last.Prev.Next /= L.Last then + return False; + end if; + + if L.Length = 2 then + if L.First.Next /= L.Last then + return False; + end if; + + if L.Last.Prev /= L.First then + return False; + end if; + + return True; + end if; + + if L.First.Next = L.Last then + return False; + end if; + + if L.Last.Prev = L.First then + return False; + end if; + + if Position.Node = L.First then + return True; + end if; + + if Position.Node = L.Last then + return True; + end if; + + if Position.Node.Next = null then + return False; + end if; + + if Position.Node.Prev = null then + return False; + end if; + + if Position.Node.Next.Prev /= Position.Node then + return False; + end if; + + if Position.Node.Prev.Next /= Position.Node then + return False; + end if; + + if L.Length = 3 then + if L.First.Next /= Position.Node then + return False; + end if; + + if L.Last.Prev /= Position.Node then + return False; + end if; + end if; + + return True; + end; + end Vet; + ----------- -- Write -- ----------- @@ -1926,8 +1765,10 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is Item : List) is Node : Node_Access := Item.First; + begin Count_Type'Base'Write (Stream, Item.Length); + while Node /= null loop Element_Type'Output (Stream, Node.Element.all); -- X.all Node := Node.Next; |