diff options
author | Matthew Heaney <heaney@adacore.com> | 2006-02-15 10:32:52 +0100 |
---|---|---|
committer | Arnaud Charlet <charlet@gcc.gnu.org> | 2006-02-15 10:32:52 +0100 |
commit | ffabcde5e102cd7cc8a283ddc89861a727226913 (patch) | |
tree | 39a55d293e0dcbbc8992be624d0eb85bc7be0307 /gcc/ada/a-cohase.adb | |
parent | 738819cdce8e966e04a3e83d305db2cfa9bdaa75 (diff) | |
download | gcc-ffabcde5e102cd7cc8a283ddc89861a727226913.zip gcc-ffabcde5e102cd7cc8a283ddc89861a727226913.tar.gz gcc-ffabcde5e102cd7cc8a283ddc89861a727226913.tar.bz2 |
a-rbtgso.adb, [...]: All explicit raise statements now include an exception message.
2006-02-13 Matthew Heaney <heaney@adacore.com>
* a-rbtgso.adb, a-crbtgo.adb, a-crbtgk.adb, a-coorse.adb,
a-cohama.adb, a-ciorse.adb, a-cihama.adb, a-cihase.adb,
a-cohase.adb: All explicit raise statements now include an exception
message.
* a-ciormu.ads, a-ciormu.adb, a-coormu.ads, a-coormu.adb
(Update_Element_Preserving_Key): renamed op to just Update_Element.
Explicit raise statements now include an exception message
* a-cihase.ads, a-cohase.ads: Removed comment.
* a-stboha.ads, a-stboha.adb, a-stfiha.ads, a-envvar.adb,
a-envvar.ads, a-swbwha.ads, a-swbwha.adb, a-swfwha.ads, a-szbzha.ads,
a-szbzha.adb, a-szfzha.ads: New files.
From-SVN: r111035
Diffstat (limited to 'gcc/ada/a-cohase.adb')
-rw-r--r-- | gcc/ada/a-cohase.adb | 151 |
1 files changed, 91 insertions, 60 deletions
diff --git a/gcc/ada/a-cohase.adb b/gcc/ada/a-cohase.adb index afb2190..a54683e 100644 --- a/gcc/ada/a-cohase.adb +++ b/gcc/ada/a-cohase.adb @@ -207,7 +207,7 @@ package body Ada.Containers.Hashed_Sets is Element_Keys.Delete_Key_Sans_Free (Container.HT, Item, X); if X = null then - raise Constraint_Error; + raise Constraint_Error with "attempt to delete element not in set"; end if; Free (X); @@ -218,20 +218,21 @@ package body Ada.Containers.Hashed_Sets is Position : in out Cursor) is begin - pragma Assert (Vet (Position), "bad cursor in Delete"); - if Position.Node = null then - raise Constraint_Error; + raise Constraint_Error with "Position cursor equals No_Element"; end if; if Position.Container /= Container'Unrestricted_Access then - raise Program_Error; + raise Program_Error with "Position cursor designates wrong set"; end if; if Container.HT.Busy > 0 then - raise Program_Error; + raise Program_Error with + "attempt to tamper with elements (set is busy)"; end if; + pragma Assert (Vet (Position), "bad cursor in Delete"); + HT_Ops.Delete_Node_Sans_Free (Container.HT, Position.Node); Free (Position.Node); @@ -254,12 +255,13 @@ package body Ada.Containers.Hashed_Sets is return; end if; - if Source.Length = 0 then + if Source.HT.Length = 0 then return; end if; if Target.HT.Busy > 0 then - raise Program_Error; + raise Program_Error with + "attempt to tamper with elements (set is busy)"; end if; -- TODO: This can be written in terms of a loop instead as @@ -291,11 +293,11 @@ package body Ada.Containers.Hashed_Sets is return Empty_Set; end if; - if Left.Length = 0 then + if Left.HT.Length = 0 then return Empty_Set; end if; - if Right.Length = 0 then + if Right.HT.Length = 0 then return Left; end if; @@ -353,12 +355,12 @@ package body Ada.Containers.Hashed_Sets is function Element (Position : Cursor) return Element_Type is begin - pragma Assert (Vet (Position), "bad cursor in function Element"); - if Position.Node = null then - raise Constraint_Error; + raise Constraint_Error with "Position cursor equals No_Element"; end if; + pragma Assert (Vet (Position), "bad cursor in function Element"); + return Position.Node.Element; end Element; @@ -378,39 +380,47 @@ package body Ada.Containers.Hashed_Sets is function Equivalent_Elements (Left, Right : Cursor) return Boolean is begin - pragma Assert (Vet (Left), "bad Left cursor in Equivalent_Keys"); - pragma Assert (Vet (Right), "bad Right cursor in Equivalent_Keys"); + if Left.Node = null then + raise Constraint_Error with + "Left cursor of Equivalent_Elements equals No_Element"; + end if; - if Left.Node = null - or else Right.Node = null - then - raise Constraint_Error; + if Right.Node = null then + raise Constraint_Error with + "Right cursor of Equivalent_Elements equals No_Element"; end if; + pragma Assert (Vet (Left), "bad Left cursor in Equivalent_Elements"); + pragma Assert (Vet (Right), "bad Right cursor in Equivalent_Elements"); + return Equivalent_Elements (Left.Node.Element, Right.Node.Element); end Equivalent_Elements; function Equivalent_Elements (Left : Cursor; Right : Element_Type) return Boolean is begin - pragma Assert (Vet (Left), "bad Left cursor in Equivalent_Keys"); - if Left.Node = null then - raise Constraint_Error; + raise Constraint_Error with + "Left cursor of Equivalent_Elements equals No_Element"; end if; + pragma Assert (Vet (Left), "Left cursor in Equivalent_Elements is bad"); + return Equivalent_Elements (Left.Node.Element, Right); end Equivalent_Elements; function Equivalent_Elements (Left : Element_Type; Right : Cursor) return Boolean is begin - pragma Assert (Vet (Right), "bad Right cursor in Equivalent_Keys"); - if Right.Node = null then - raise Constraint_Error; + raise Constraint_Error with + "Right cursor of Equivalent_Elements equals No_Element"; end if; + pragma Assert + (Vet (Right), + "Right cursor of Equivalent_Elements is bad"); + return Equivalent_Elements (Left, Right.Node.Element); end Equivalent_Elements; @@ -584,7 +594,8 @@ package body Ada.Containers.Hashed_Sets is if not Inserted then if Container.HT.Lock > 0 then - raise Program_Error; + raise Program_Error with + "attempt to tamper with cursors (set is locked)"; end if; Position.Node.Element := New_Item; @@ -617,7 +628,8 @@ package body Ada.Containers.Hashed_Sets is Insert (Container, New_Item, Position, Inserted); if not Inserted then - raise Constraint_Error; + raise Constraint_Error with + "attempt to insert element already in set"; end if; end Insert; @@ -679,7 +691,8 @@ package body Ada.Containers.Hashed_Sets is end if; if Target.HT.Busy > 0 then - raise Program_Error; + raise Program_Error with + "attempt to tamper with elements (set is busy)"; end if; -- TODO: optimize this to use an explicit @@ -880,12 +893,12 @@ package body Ada.Containers.Hashed_Sets is 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 HT : Hash_Table_Type renames Position.Container.HT; Node : constant Node_Access := HT_Ops.Next (HT, Position.Node); @@ -940,12 +953,13 @@ package body Ada.Containers.Hashed_Sets is 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 of Query_Element equals No_Element"; end if; + pragma Assert (Vet (Position), "bad cursor in Query_Element"); + declare HT : Hash_Table_Type renames Position.Container.HT; @@ -987,7 +1001,7 @@ package body Ada.Containers.Hashed_Sets is Item : out Cursor) is begin - raise Program_Error; + raise Program_Error with "attempt to stream set cursor"; end Read; --------------- @@ -1021,11 +1035,13 @@ package body Ada.Containers.Hashed_Sets is begin if Node = null then - raise Constraint_Error; + raise Constraint_Error with + "attempt to replace element not in set"; end if; if Container.HT.Lock > 0 then - raise Program_Error; + raise Program_Error with + "attempt to tamper with cursors (set is locked)"; end if; Node.Element := New_Item; @@ -1045,7 +1061,8 @@ package body Ada.Containers.Hashed_Sets is pragma Assert (Hash (Node.Element) = Hash (New_Item)); if HT.Lock > 0 then - raise Program_Error; + raise Program_Error with + "attempt to tamper with cursors (set is locked)"; end if; Node.Element := New_Item; -- Note that this assignment can fail @@ -1053,7 +1070,8 @@ package body Ada.Containers.Hashed_Sets is end if; if HT.Busy > 0 then - raise Program_Error; + raise Program_Error with + "attempt to tamper with elements (set is busy)"; end if; HT_Ops.Delete_Node_Sans_Free (HT, Node); @@ -1129,7 +1147,7 @@ package body Ada.Containers.Hashed_Sets is null; end Reinsert_Old_Element; - raise Program_Error; + raise Program_Error with "attempt to replace existing element"; end Replace_Element; procedure Replace_Element @@ -1138,16 +1156,18 @@ package body Ada.Containers.Hashed_Sets is New_Item : Element_Type) is begin - pragma Assert (Vet (Position), "bad cursor in Replace_Element"); - if Position.Node = null then - raise Constraint_Error; + raise Constraint_Error with + "Position cursor equals No_Element"; end if; if Position.Container /= Container'Unrestricted_Access then - raise Program_Error; + raise Program_Error with + "Position cursor designates wrong set"; end if; + pragma Assert (Vet (Position), "bad cursor in Replace_Element"); + Replace_Element (Container.HT, Position.Node, New_Item); end Replace_Element; @@ -1187,7 +1207,8 @@ package body Ada.Containers.Hashed_Sets is end if; if Target.HT.Busy > 0 then - raise Program_Error; + raise Program_Error with + "attempt to tamper with elements (set is busy)"; end if; declare @@ -1452,7 +1473,8 @@ package body Ada.Containers.Hashed_Sets is end if; if Target.HT.Busy > 0 then - raise Program_Error; + raise Program_Error with + "attempt to tamper with elements (set is busy)"; end if; declare @@ -1634,7 +1656,7 @@ package body Ada.Containers.Hashed_Sets is Item : Cursor) is begin - raise Program_Error; + raise Program_Error with "attempt to stream set cursor"; end Write; ---------------- @@ -1699,7 +1721,7 @@ package body Ada.Containers.Hashed_Sets is Key_Keys.Delete_Key_Sans_Free (Container.HT, Key, X); if X = null then - raise Constraint_Error; + raise Constraint_Error with "attempt to delete key not in set"; end if; Free (X); @@ -1716,6 +1738,10 @@ package body Ada.Containers.Hashed_Sets is Node : constant Node_Access := Key_Keys.Find (Container.HT, Key); begin + if Node = null then + raise Constraint_Error with "key not in map"; + end if; + return Node.Element; end Element; @@ -1770,12 +1796,13 @@ package body Ada.Containers.Hashed_Sets is function Key (Position : Cursor) return Key_Type is begin - pragma Assert (Vet (Position), "bad cursor in function Key"); - if Position.Node = null then - raise Constraint_Error; + raise Constraint_Error with + "Position cursor equals No_Element"; end if; + pragma Assert (Vet (Position), "bad cursor in function Key"); + return Key (Position.Node.Element); end Key; @@ -1793,7 +1820,8 @@ package body Ada.Containers.Hashed_Sets is begin if Node = null then - raise Constraint_Error; + raise Constraint_Error with + "attempt to replace key not in set"; end if; Replace_Element (Container.HT, Node, New_Item); @@ -1813,16 +1841,14 @@ package body Ada.Containers.Hashed_Sets is Indx : Hash_Type; begin - pragma Assert - (Vet (Position), - "bad cursor in Update_Element_Preserving_Key"); - if Position.Node = null then - raise Constraint_Error; + raise Constraint_Error with + "Position cursor equals No_Element"; end if; if Position.Container /= Container'Unrestricted_Access then - raise Program_Error; + raise Program_Error with + "Position cursor designates wrong set"; end if; if HT.Buckets = null @@ -1830,9 +1856,13 @@ package body Ada.Containers.Hashed_Sets is or else HT.Length = 0 or else Position.Node.Next = Position.Node then - raise Program_Error; + raise Program_Error with "Position cursor is bad (set is empty)"; end if; + pragma Assert + (Vet (Position), + "bad cursor in Update_Element_Preserving_Key"); + Indx := HT_Ops.Index (HT, Position.Node); declare @@ -1876,7 +1906,8 @@ package body Ada.Containers.Hashed_Sets is Prev := Prev.Next; if Prev = null then - raise Program_Error; + raise Program_Error with + "Position cursor is bad (node not found)"; end if; end loop; @@ -1893,7 +1924,7 @@ package body Ada.Containers.Hashed_Sets is Free (X); end; - raise Program_Error; + raise Program_Error with "key was modified"; end Update_Element_Preserving_Key; end Generic_Keys; |