OSDN Git Service

2010-01-04 Tobias Burnus <burnus@net-b.de>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-cidlli.adb
index becdae2..0d01502 100644 (file)
@@ -2,34 +2,27 @@
 --                                                                          --
 --                         GNAT LIBRARY COMPONENTS                          --
 --                                                                          --
---                      A D A . C O N T A I N E R S .                       --
---        I N D E F I N I T E _ D O U B L Y _ L I N K E D _ L I S T S       --
+--               ADA.CONTAINERS.INDEFINITE_DOUBLY_LINKED_LISTS              --
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 2004-2005 Free Software Foundation, Inc.          --
---                                                                          --
--- This specification is derived from the Ada Reference Manual for use with --
--- GNAT. The copyright notice above, and the license provisions that follow --
--- apply solely to the  contents of the part following the private keyword. --
+--          Copyright (C) 2004-2009, 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- --
--- ware  Foundation;  either version 2,  or (at your option) any later ver- --
+-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
--- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
--- for  more details.  You should have  received  a copy of the GNU General --
--- Public License  distributed with GNAT;  see file COPYING.  If not, write --
--- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
--- Boston, MA 02110-1301, USA.                                              --
+-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
+--                                                                          --
+-- As a special exception under Section 7 of GPL version 3, you are granted --
+-- additional permissions described in the GCC Runtime Library Exception,   --
+-- version 3.1, as published by the Free Software Foundation.               --
 --                                                                          --
--- As a special exception,  if other files  instantiate  generics from this --
--- unit, or you link  this unit with other files  to produce an executable, --
--- this  unit  does not  by itself cause  the resulting  executable  to  be --
--- covered  by the  GNU  General  Public  License.  This exception does not --
--- however invalidate  any other reasons why  the executable file  might be --
--- covered by the  GNU Public License.                                      --
+-- You should have received a copy of the GNU General Public License and    --
+-- a copy of the GCC Runtime Library Exception along with this program;     --
+-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
+-- <http://www.gnu.org/licenses/>.                                          --
 --                                                                          --
 -- This unit was originally developed by Matthew J Heaney.                  --
 ------------------------------------------------------------------------------
@@ -166,6 +159,7 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
 
    procedure Clear (Container : in out List) is
       X : Node_Access;
+      pragma Warnings (Off, X);
 
    begin
       if Container.Length = 0 then
@@ -180,7 +174,8 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
       pragma Assert (Container.Last.Next = null);
 
       if Container.Busy > 0 then
-         raise Program_Error;
+         raise Program_Error with
+           "attempt to tamper with elements (list is busy)";
       end if;
 
       while Container.Length > 1 loop
@@ -211,7 +206,8 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
 
    function Contains
      (Container : List;
-      Item      : Element_Type) return Boolean is
+      Item      : Element_Type) return Boolean
+   is
    begin
       return Find (Container, Item) /= No_Element;
    end Contains;
@@ -228,28 +224,37 @@ 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;
+         raise Constraint_Error with
+           "Position cursor has no element";
+      end if;
+
+      if Position.Node.Element = null then
+         raise Program_Error with
+           "Position cursor has no element";
       end if;
 
       if Position.Container /= Container'Unrestricted_Access then
-         raise Program_Error;
+         raise Program_Error with
+           "Position cursor designates wrong container";
       end if;
 
+      pragma Assert (Vet (Position), "bad cursor in Delete");
+
       if Position.Node = Container.First then
          Delete_First (Container, Count);
-         Position := First (Container);
+         Position := No_Element;  --  Post-York behavior
          return;
       end if;
 
       if Count = 0 then
+         Position := No_Element;  --  Post-York behavior
          return;
       end if;
 
       if Container.Busy > 0 then
-         raise Program_Error;
+         raise Program_Error with
+           "attempt to tamper with elements (list is busy)";
       end if;
 
       for Index in 1 .. Count loop
@@ -273,6 +278,8 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
 
          Free (X);
       end loop;
+
+      Position := No_Element;  --  Post-York behavior
    end Delete;
 
    ------------------
@@ -296,7 +303,8 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
       end if;
 
       if Container.Busy > 0 then
-         raise Program_Error;
+         raise Program_Error with
+           "attempt to tamper with elements (list is busy)";
       end if;
 
       for I in 1 .. Count loop
@@ -333,7 +341,8 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
       end if;
 
       if Container.Busy > 0 then
-         raise Program_Error;
+         raise Program_Error with
+           "attempt to tamper with elements (list is busy)";
       end if;
 
       for I in 1 .. Count loop
@@ -355,12 +364,18 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
 
    function Element (Position : Cursor) return Element_Type is
    begin
-      pragma Assert (Vet (Position), "bad cursor in Element");
-
       if Position.Node = null then
-         raise Constraint_Error;
+         raise Constraint_Error with
+           "Position cursor has no element";
+      end if;
+
+      if Position.Node.Element = null then
+         raise Program_Error with
+           "Position cursor has no element";
       end if;
 
+      pragma Assert (Vet (Position), "bad cursor in Element");
+
       return Position.Node.Element.all;
    end Element;
 
@@ -380,11 +395,16 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
          Node := Container.First;
 
       else
-         pragma Assert (Vet (Position), "bad cursor in Find");
+         if Node.Element = null then
+            raise Program_Error;
+         end if;
 
          if Position.Container /= Container'Unrestricted_Access then
-            raise Program_Error;
+            raise Program_Error with
+              "Position cursor designates wrong container";
          end if;
+
+         pragma Assert (Vet (Position), "bad cursor in Find");
       end if;
 
       while Node /= null loop
@@ -418,7 +438,7 @@ 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;
+         raise Constraint_Error with "list is empty";
       end if;
 
       return Container.First.Element.all;
@@ -481,31 +501,43 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
         (Target : in out List;
          Source : in out List)
       is
-         LI : Cursor;
-         RI : Cursor;
+         LI, RI : Cursor;
 
       begin
          if Target'Address = Source'Address then
             return;
          end if;
 
-         if Target.Busy > 0
-           or else Source.Busy > 0
-         then
-            raise Program_Error;
+         if Target.Busy > 0 then
+            raise Program_Error with
+              "attempt to tamper with elements of Target (list is busy)";
+         end if;
+
+         if Source.Busy > 0 then
+            raise Program_Error with
+              "attempt to tamper with elements of Source (list is busy)";
          end if;
 
          LI := First (Target);
          RI := First (Source);
          while RI.Node /= null loop
+            pragma Assert (RI.Node.Next = null
+                             or else not (RI.Node.Next.Element.all <
+                                          RI.Node.Element.all));
+
             if LI.Node = null then
                Splice (Target, No_Element, Source);
                return;
             end if;
 
+            pragma Assert (LI.Node.Next = null
+                             or else not (LI.Node.Next.Element.all <
+                                          LI.Node.Element.all));
+
             if RI.Node.Element.all < LI.Node.Element.all then
                declare
                   RJ : Cursor := RI;
+                  pragma Warnings (Off, RJ);
                begin
                   RI.Node := RI.Node.Next;
                   Splice (Target, LI, Source, RJ);
@@ -573,15 +605,9 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
          ----------
 
          procedure Sort (Front, Back : Node_Access) is
-            Pivot : Node_Access;
-
+            Pivot : constant Node_Access :=
+                      (if Front = null then Container.First else Front.Next);
          begin
-            if Front = null then
-               Pivot := Container.First;
-            else
-               Pivot := Front.Next;
-            end if;
-
             if Pivot /= Back then
                Partition (Pivot, Back);
                Sort (Front, Pivot);
@@ -600,7 +626,8 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
          pragma Assert (Container.Last.Next = null);
 
          if Container.Busy > 0 then
-            raise Program_Error;
+            raise Program_Error with
+              "attempt to tamper with elements (list is busy)";
          end if;
 
          Sort (Front => null, Back => null);
@@ -635,12 +662,20 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
       New_Node : Node_Access;
 
    begin
-      pragma Assert (Vet (Before), "bad cursor in Insert");
+      if Before.Container /= null then
+         if Before.Container /= Container'Unrestricted_Access then
+            raise Program_Error with
+              "attempt to tamper with elements (list is busy)";
+         end if;
 
-      if Before.Container /= null
-        and then Before.Container /= Container'Unrestricted_Access
-      then
-         raise Program_Error;
+         if Before.Node = null
+           or else Before.Node.Element = null
+         then
+            raise Program_Error with
+              "Before cursor has no element";
+         end if;
+
+         pragma Assert (Vet (Before), "bad cursor in Insert");
       end if;
 
       if Count = 0 then
@@ -649,11 +684,12 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
       end if;
 
       if Container.Length > Count_Type'Last - Count then
-         raise Constraint_Error;
+         raise Constraint_Error with "new length exceeds maximum";
       end if;
 
       if Container.Busy > 0 then
-         raise Program_Error;
+         raise Program_Error with
+           "attempt to tamper with elements (list is busy)";
       end if;
 
       declare
@@ -692,6 +728,7 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
       Count     : Count_Type := 1)
    is
       Position : Cursor;
+      pragma Unreferenced (Position);
    begin
       Insert (Container, Before, New_Item, Position, Count);
    end Insert;
@@ -759,7 +796,7 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
 
    procedure Iterate
      (Container : List;
-      Process   : not null access procedure (Position : in Cursor))
+      Process   : not null access procedure (Position : Cursor))
    is
       C : List renames Container'Unrestricted_Access.all;
       B : Natural renames C.Busy;
@@ -803,7 +840,7 @@ 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;
+         raise Constraint_Error with "list is empty";
       end if;
 
       return Container.Last.Element.all;
@@ -829,7 +866,8 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
       end if;
 
       if Source.Busy > 0 then
-         raise Program_Error;
+         raise Program_Error with
+           "attempt to tamper with elements of Source (list is busy)";
       end if;
 
       Clear (Target);
@@ -850,27 +888,17 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
 
    procedure Next (Position : in out Cursor) is
    begin
-      pragma Assert (Vet (Position), "bad cursor in procedure Next");
-
-      if Position.Node = null then
-         return;
-      end if;
-
-      Position.Node := Position.Node.Next;
-
-      if Position.Node = null then
-         Position.Container := null;
-      end if;
+      Position := Next (Position);
    end Next;
 
    function Next (Position : Cursor) return Cursor is
    begin
-      pragma Assert (Vet (Position), "bad cursor in function Next");
-
       if Position.Node = null then
          return No_Element;
       end if;
 
+      pragma Assert (Vet (Position), "bad cursor in Next");
+
       declare
          Next_Node : constant Node_Access := Position.Node.Next;
       begin
@@ -901,27 +929,17 @@ 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
-         return;
-      end if;
-
-      Position.Node := Position.Node.Prev;
-
-      if Position.Node = null then
-         Position.Container := null;
-      end if;
+      Position := Previous (Position);
    end Previous;
 
    function Previous (Position : Cursor) return Cursor is
    begin
-      pragma Assert (Vet (Position), "bad cursor in function Previous");
-
       if Position.Node = null then
          return No_Element;
       end if;
 
+      pragma Assert (Vet (Position), "bad cursor in Previous");
+
       declare
          Prev_Node : constant Node_Access := Position.Node.Prev;
       begin
@@ -939,15 +957,21 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
 
    procedure Query_Element
      (Position : Cursor;
-      Process  : not null access procedure (Element : in Element_Type))
+      Process  : not null access procedure (Element : Element_Type))
    is
    begin
-      pragma Assert (Vet (Position), "bad cursor in Query_Element");
-
       if Position.Node = null then
-         raise Constraint_Error;
+         raise Constraint_Error with
+           "Position cursor has no element";
+      end if;
+
+      if Position.Node.Element = null then
+         raise Program_Error with
+           "Position cursor has no element";
       end if;
 
+      pragma Assert (Vet (Position), "bad cursor in Query_Element");
+
       declare
          C : List renames Position.Container.all'Unrestricted_Access.all;
          B : Natural renames C.Busy;
@@ -976,7 +1000,7 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
    ----------
 
    procedure Read
-     (Stream : access Root_Stream_Type'Class;
+     (Stream : not null access Root_Stream_Type'Class;
       Item   : out List)
    is
       N   : Count_Type'Base;
@@ -1024,102 +1048,59 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
       end loop;
    end Read;
 
+   procedure Read
+     (Stream : not null access Root_Stream_Type'Class;
+      Item   : out Cursor)
+   is
+   begin
+      raise Program_Error with "attempt to stream list cursor";
+   end Read;
+
    ---------------------
    -- Replace_Element --
    ---------------------
 
    procedure Replace_Element
-     (Position : Cursor;
-      By       : Element_Type)
+     (Container : in out List;
+      Position  : Cursor;
+      New_Item  : Element_Type)
    is
    begin
-      pragma Assert (Vet (Position), "bad cursor in Replace_Element");
-
       if Position.Container = null then
-         raise Constraint_Error;
+         raise Constraint_Error with "Position cursor has no element";
       end if;
 
-      if Position.Container.Lock > 0 then
-         raise Program_Error;
+      if Position.Container /= Container'Unchecked_Access then
+         raise Program_Error with
+           "Position cursor designates wrong container";
       end if;
 
-      declare
-         X : Element_Access := Position.Node.Element;
-      begin
-         Position.Node.Element := new Element_Type'(By);
-         Free (X);
-      end;
-   end Replace_Element;
-
-   ------------------
-   -- Reverse_Find --
-   ------------------
-
-   function Reverse_Find
-     (Container : List;
-      Item      : Element_Type;
-      Position  : Cursor := No_Element) return Cursor
-   is
-      Node : Node_Access := Position.Node;
-
-   begin
-      if Node = null then
-         Node := Container.Last;
-
-      else
-         pragma Assert (Vet (Position), "bad cursor in Reverse_Find");
-
-         if Position.Container /= Container'Unrestricted_Access then
-            raise Program_Error;
-         end if;
+      if Container.Lock > 0 then
+         raise Program_Error with
+           "attempt to tamper with cursors (list is locked)";
       end if;
 
-      while Node /= null loop
-         if Node.Element.all = Item then
-            return Cursor'(Container'Unchecked_Access, Node);
-         end if;
-
-         Node := Node.Prev;
-      end loop;
-
-      return No_Element;
-   end Reverse_Find;
-
-   ---------------------
-   -- Reverse_Iterate --
-   ---------------------
-
-   procedure Reverse_Iterate
-     (Container : List;
-      Process   : not null access procedure (Position : in Cursor))
-   is
-      C : List renames Container'Unrestricted_Access.all;
-      B : Natural renames C.Busy;
+      if Position.Node.Element = null then
+         raise Program_Error with
+           "Position cursor has no element";
+      end if;
 
-      Node : Node_Access := Container.Last;
+      pragma Assert (Vet (Position), "bad cursor in Replace_Element");
 
-   begin
-      B := B + 1;
+      declare
+         X : Element_Access := Position.Node.Element;
 
       begin
-         while Node /= null loop
-            Process (Cursor'(Container'Unchecked_Access, Node));
-            Node := Node.Prev;
-         end loop;
-      exception
-         when others =>
-            B := B - 1;
-            raise;
+         Position.Node.Element := new Element_Type'(New_Item);
+         Free (X);
       end;
+   end Replace_Element;
 
-      B := B - 1;
-   end Reverse_Iterate;
-
-   ------------------
-   -- Reverse_List --
-   ------------------
+   ----------------------
+   -- Reverse_Elements --
+   ----------------------
 
-   procedure Reverse_List (Container : in out List) is
+   procedure Reverse_Elements (Container : in out List) is
       I : Node_Access := Container.First;
       J : Node_Access := Container.Last;
 
@@ -1163,7 +1144,7 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
          end if;
       end Swap;
 
-   --  Start of processing for Reverse_List
+   --  Start of processing for Reverse_Elements
 
    begin
       if Container.Length <= 1 then
@@ -1174,7 +1155,8 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
       pragma Assert (Container.Last.Next = null);
 
       if Container.Busy > 0 then
-         raise Program_Error;
+         raise Program_Error with
+           "attempt to tamper with elements (list is busy)";
       end if;
 
       Container.First := J;
@@ -1199,7 +1181,76 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
 
       pragma Assert (Container.First.Prev = null);
       pragma Assert (Container.Last.Next = null);
-   end Reverse_List;
+   end Reverse_Elements;
+
+   ------------------
+   -- Reverse_Find --
+   ------------------
+
+   function Reverse_Find
+     (Container : List;
+      Item      : Element_Type;
+      Position  : Cursor := No_Element) return Cursor
+   is
+      Node : Node_Access := Position.Node;
+
+   begin
+      if Node = null then
+         Node := Container.Last;
+
+      else
+         if Node.Element = null then
+            raise Program_Error with "Position cursor has no element";
+         end if;
+
+         if Position.Container /= Container'Unrestricted_Access then
+            raise Program_Error with
+              "Position cursor designates wrong container";
+         end if;
+
+         pragma Assert (Vet (Position), "bad cursor in Reverse_Find");
+      end if;
+
+      while Node /= null loop
+         if Node.Element.all = Item then
+            return Cursor'(Container'Unchecked_Access, Node);
+         end if;
+
+         Node := Node.Prev;
+      end loop;
+
+      return No_Element;
+   end Reverse_Find;
+
+   ---------------------
+   -- Reverse_Iterate --
+   ---------------------
+
+   procedure Reverse_Iterate
+     (Container : List;
+      Process   : not null access procedure (Position : Cursor))
+   is
+      C : List renames Container'Unrestricted_Access.all;
+      B : Natural renames C.Busy;
+
+      Node : Node_Access := Container.Last;
+
+   begin
+      B := B + 1;
+
+      begin
+         while Node /= null loop
+            Process (Cursor'(Container'Unchecked_Access, Node));
+            Node := Node.Prev;
+         end loop;
+      exception
+         when others =>
+            B := B - 1;
+            raise;
+      end;
+
+      B := B - 1;
+   end Reverse_Iterate;
 
    ------------
    -- Splice --
@@ -1211,12 +1262,20 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
       Source : in out List)
    is
    begin
-      pragma Assert (Vet (Before), "bad cursor in Splice");
+      if Before.Container /= null then
+         if Before.Container /= Target'Unrestricted_Access then
+            raise Program_Error with
+              "Before cursor designates wrong container";
+         end if;
 
-      if Before.Container /= null
-        and then Before.Container /= Target'Unrestricted_Access
-      then
-         raise Program_Error;
+         if Before.Node = null
+           or else Before.Node.Element = null
+         then
+            raise Program_Error with
+              "Before cursor has no element";
+         end if;
+
+         pragma Assert (Vet (Before), "bad cursor in Splice");
       end if;
 
       if Target'Address = Source'Address
@@ -1229,13 +1288,17 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
       pragma Assert (Source.Last.Next = null);
 
       if Target.Length > Count_Type'Last - Source.Length then
-         raise Constraint_Error;
+         raise Constraint_Error with "new length exceeds maximum";
       end if;
 
-      if Target.Busy > 0
-        or else Source.Busy > 0
-      then
-         raise Program_Error;
+      if Target.Busy > 0 then
+         raise Program_Error with
+           "attempt to tamper with elements of Target (list is busy)";
+      end if;
+
+      if Source.Busy > 0 then
+         raise Program_Error with
+           "attempt to tamper with elements of Source (list is busy)";
       end if;
 
       if Target.Length = 0 then
@@ -1279,87 +1342,102 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
    end Splice;
 
    procedure Splice
-     (Target   : in out List;
-      Before   : Cursor;
-      Position : Cursor)
+     (Container : in out List;
+      Before    : Cursor;
+      Position  : Cursor)
    is
    begin
-      pragma Assert (Vet (Before), "bad Before cursor in Splice");
-      pragma Assert (Vet (Position), "bad Position cursor in Splice");
+      if Before.Container /= null then
+         if Before.Container /= Container'Unchecked_Access then
+            raise Program_Error with
+              "Before cursor designates wrong container";
+         end if;
 
-      if Before.Container /= null
-        and then Before.Container /= Target'Unchecked_Access
-      then
-         raise Program_Error;
+         if Before.Node = null
+           or else Before.Node.Element = null
+         then
+            raise Program_Error with
+              "Before cursor has no element";
+         end if;
+
+         pragma Assert (Vet (Before), "bad Before cursor in Splice");
       end if;
 
       if Position.Node = null then
-         raise Constraint_Error;
+         raise Constraint_Error with "Position cursor has no element";
       end if;
 
-      if Position.Container /= Target'Unrestricted_Access then
-         raise Program_Error;
+      if Position.Node.Element = null then
+         raise Program_Error with "Position cursor has no element";
       end if;
 
+      if Position.Container /= Container'Unrestricted_Access then
+         raise Program_Error with
+           "Position cursor designates wrong container";
+      end if;
+
+      pragma Assert (Vet (Position), "bad Position cursor in Splice");
+
       if Position.Node = Before.Node
         or else Position.Node.Next = Before.Node
       then
          return;
       end if;
 
-      pragma Assert (Target.Length >= 2);
+      pragma Assert (Container.Length >= 2);
 
-      if Target.Busy > 0 then
-         raise Program_Error;
+      if Container.Busy > 0 then
+         raise Program_Error with
+           "attempt to tamper with elements (list is busy)";
       end if;
 
       if Before.Node = null then
-         pragma Assert (Position.Node /= Target.Last);
+         pragma Assert (Position.Node /= Container.Last);
 
-         if Position.Node = Target.First then
-            Target.First := Position.Node.Next;
-            Target.First.Prev := null;
+         if Position.Node = Container.First then
+            Container.First := Position.Node.Next;
+            Container.First.Prev := null;
          else
             Position.Node.Prev.Next := Position.Node.Next;
             Position.Node.Next.Prev := Position.Node.Prev;
          end if;
 
-         Target.Last.Next := Position.Node;
-         Position.Node.Prev := Target.Last;
+         Container.Last.Next := Position.Node;
+         Position.Node.Prev := Container.Last;
 
-         Target.Last := Position.Node;
-         Target.Last.Next := null;
+         Container.Last := Position.Node;
+         Container.Last.Next := null;
 
          return;
       end if;
 
-      if Before.Node = Target.First then
-         pragma Assert (Position.Node /= Target.First);
+      if Before.Node = Container.First then
+         pragma Assert (Position.Node /= Container.First);
 
-         if Position.Node = Target.Last then
-            Target.Last := Position.Node.Prev;
-            Target.Last.Next := null;
+         if Position.Node = Container.Last then
+            Container.Last := Position.Node.Prev;
+            Container.Last.Next := null;
          else
             Position.Node.Prev.Next := Position.Node.Next;
             Position.Node.Next.Prev := Position.Node.Prev;
          end if;
 
-         Target.First.Prev := Position.Node;
-         Position.Node.Next := Target.First;
+         Container.First.Prev := Position.Node;
+         Position.Node.Next := Container.First;
 
-         Target.First := Position.Node;
-         Target.First.Prev := null;
+         Container.First := Position.Node;
+         Container.First.Prev := null;
 
          return;
       end if;
 
-      if Position.Node = Target.First then
-         Target.First := Position.Node.Next;
-         Target.First.Prev := null;
+      if Position.Node = Container.First then
+         Container.First := Position.Node.Next;
+         Container.First.Prev := null;
 
-      elsif Position.Node = Target.Last then
-         Target.Last := Position.Node.Prev;
-         Target.Last.Next := null;
+      elsif Position.Node = Container.Last then
+         Container.Last := Position.Node.Prev;
+         Container.Last.Next := null;
 
       else
          Position.Node.Prev.Next := Position.Node.Next;
@@ -1372,8 +1450,8 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
       Before.Node.Prev := Position.Node;
       Position.Node.Next := Before.Node;
 
-      pragma Assert (Target.First.Prev = null);
-      pragma Assert (Target.Last.Next = null);
+      pragma Assert (Container.First.Prev = null);
+      pragma Assert (Container.Last.Next = null);
    end Splice;
 
    procedure Splice
@@ -1388,31 +1466,50 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
          return;
       end if;
 
-      pragma Assert (Vet (Before), "bad Before cursor in Splice");
-      pragma Assert (Vet (Position), "bad Position cursor in Splice");
+      if Before.Container /= null then
+         if Before.Container /= Target'Unrestricted_Access then
+            raise Program_Error with
+              "Before cursor designates wrong container";
+         end if;
 
-      if Before.Container /= null
-        and then Before.Container /= Target'Unrestricted_Access
-      then
-         raise Program_Error;
+         if Before.Node = null
+           or else Before.Node.Element = null
+         then
+            raise Program_Error with
+              "Before cursor has no element";
+         end if;
+
+         pragma Assert (Vet (Before), "bad Before cursor in Splice");
       end if;
 
       if Position.Node = null then
-         raise Constraint_Error;
+         raise Constraint_Error with "Position cursor has no element";
+      end if;
+
+      if Position.Node.Element = null then
+         raise Program_Error with
+           "Position cursor has no element";
       end if;
 
       if Position.Container /= Source'Unrestricted_Access then
-         raise Program_Error;
+         raise Program_Error with
+           "Position cursor designates wrong container";
       end if;
 
+      pragma Assert (Vet (Position), "bad Position cursor in Splice");
+
       if Target.Length = Count_Type'Last then
-         raise Constraint_Error;
+         raise Constraint_Error with "Target is full";
       end if;
 
-      if Target.Busy > 0
-        or else Source.Busy > 0
-      then
-         raise Program_Error;
+      if Target.Busy > 0 then
+         raise Program_Error with
+           "attempt to tamper with elements of Target (list is busy)";
+      end if;
+
+      if Source.Busy > 0 then
+         raise Program_Error with
+           "attempt to tamper with elements of Source (list is busy)";
       end if;
 
       if Position.Node = Source.First then
@@ -1484,31 +1581,42 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
    -- Swap --
    ----------
 
-   procedure Swap (I, J : Cursor) is
+   procedure Swap
+     (Container : in out List;
+      I, J      : Cursor)
+   is
    begin
-      pragma Assert (Vet (I), "bad I cursor in Swap");
-      pragma Assert (Vet (J), "bad J cursor in Swap");
+      if I.Node = null then
+         raise Constraint_Error with "I cursor has no element";
+      end if;
 
-      if I.Node = null
-        or else J.Node = null
-      then
-         raise Constraint_Error;
+      if J.Node = null then
+         raise Constraint_Error with "J cursor has no element";
+      end if;
+
+      if I.Container /= Container'Unchecked_Access then
+         raise Program_Error with "I cursor designates wrong container";
       end if;
 
-      if I.Container /= J.Container then
-         raise Program_Error;
+      if J.Container /= Container'Unchecked_Access then
+         raise Program_Error with "J cursor designates wrong container";
       end if;
 
       if I.Node = J.Node then
          return;
       end if;
 
-      if I.Container.Lock > 0 then
-         raise Program_Error;
+      if Container.Lock > 0 then
+         raise Program_Error with
+           "attempt to tamper with cursors (list is locked)";
       end if;
 
+      pragma Assert (Vet (I), "bad I cursor in Swap");
+      pragma Assert (Vet (J), "bad J cursor in Swap");
+
       declare
          EI_Copy : constant Element_Access := I.Node.Element;
+
       begin
          I.Node.Element := J.Node.Element;
          J.Node.Element := EI_Copy;
@@ -1524,19 +1632,20 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
       I, J      : Cursor)
    is
    begin
-      pragma Assert (Vet (I), "bad I cursor in Swap_Links");
-      pragma Assert (Vet (J), "bad J cursor in Swap_Links");
+      if I.Node = null then
+         raise Constraint_Error with "I cursor has no element";
+      end if;
 
-      if I.Node = null
-        or else J.Node = null
-      then
-         raise Constraint_Error;
+      if J.Node = null then
+         raise Constraint_Error with "J cursor has no element";
       end if;
 
-      if I.Container /= Container'Unrestricted_Access
-        or else I.Container /= J.Container
-      then
-         raise Program_Error;
+      if I.Container /= Container'Unrestricted_Access then
+         raise Program_Error with "I cursor designates wrong container";
+      end if;
+
+      if J.Container /= Container'Unrestricted_Access then
+         raise Program_Error with "J cursor designates wrong container";
       end if;
 
       if I.Node = J.Node then
@@ -1544,9 +1653,13 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
       end if;
 
       if Container.Busy > 0 then
-         raise Program_Error;
+         raise Program_Error with
+           "attempt to tamper with elements (list is busy)";
       end if;
 
+      pragma Assert (Vet (I), "bad I cursor in Swap_Links");
+      pragma Assert (Vet (J), "bad J cursor in Swap_Links");
+
       declare
          I_Next : constant Cursor := Next (I);
 
@@ -1557,6 +1670,7 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
          else
             declare
                J_Next : constant Cursor := Next (J);
+
             begin
                if J_Next = I then
                   Splice (Container, Before => J, Position => I);
@@ -1580,20 +1694,30 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
    --------------------
 
    procedure Update_Element
-     (Position : Cursor;
-      Process  : not null access procedure (Element : in out Element_Type))
+     (Container : in out List;
+      Position  : Cursor;
+      Process   : not null access procedure (Element : in out Element_Type))
    is
    begin
-      pragma Assert (Vet (Position), "bad cursor in Update_Element");
-
       if Position.Node = null then
-         raise Constraint_Error;
+         raise Constraint_Error with "Position cursor has no element";
+      end if;
+
+      if Position.Node.Element = null then
+         raise Program_Error with
+           "Position cursor has no element";
       end if;
 
+      if Position.Container /= Container'Unchecked_Access then
+         raise Program_Error with
+           "Position cursor designates wrong container";
+      end if;
+
+      pragma Assert (Vet (Position), "bad cursor in Update_Element");
+
       declare
-         C : List renames Position.Container.all'Unrestricted_Access.all;
-         B : Natural renames C.Busy;
-         L : Natural renames C.Lock;
+         B : Natural renames Container.Busy;
+         L : Natural renames Container.Lock;
 
       begin
          B := B + 1;
@@ -1761,7 +1885,7 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
    -----------
 
    procedure Write
-     (Stream : access Root_Stream_Type'Class;
+     (Stream : not null access Root_Stream_Type'Class;
       Item   : List)
    is
       Node : Node_Access := Item.First;
@@ -1770,9 +1894,17 @@ package body Ada.Containers.Indefinite_Doubly_Linked_Lists is
       Count_Type'Base'Write (Stream, Item.Length);
 
       while Node /= null loop
-         Element_Type'Output (Stream, Node.Element.all);  --  X.all
+         Element_Type'Output (Stream, Node.Element.all);
          Node := Node.Next;
       end loop;
    end Write;
 
+   procedure Write
+     (Stream : not null access Root_Stream_Type'Class;
+      Item   : Cursor)
+   is
+   begin
+      raise Program_Error with "attempt to stream list cursor";
+   end Write;
+
 end Ada.Containers.Indefinite_Doubly_Linked_Lists;