X-Git-Url: http://git.sourceforge.jp/view?p=pf3gnuchains%2Fgcc-fork.git;a=blobdiff_plain;f=gcc%2Fada%2Fa-cbhama.adb;h=b14383e321cacec0e5838cd276c04a93c9482eec;hp=d52aea053767321ca134c62c7bb5f00d3eeba042;hb=1f5a839c957bc03e63b234ccf1cd7dca437b5482;hpb=6ccc084d6821be9284cfcf7e62f61262979763eb diff --git a/gcc/ada/a-cbhama.adb b/gcc/ada/a-cbhama.adb index d52aea05376..b14383e321c 100644 --- a/gcc/ada/a-cbhama.adb +++ b/gcc/ada/a-cbhama.adb @@ -190,6 +190,53 @@ package body Ada.Containers.Bounded_Hashed_Maps is HT_Ops.Clear (Container); end Clear; + ------------------------ + -- Constant_Reference -- + ------------------------ + + function Constant_Reference + (Container : aliased Map; + Position : Cursor) return Constant_Reference_Type + is + begin + if Position.Container = null then + raise Constraint_Error with + "Position cursor has no element"; + end if; + + if Position.Container /= Container'Unrestricted_Access then + raise Program_Error with + "Position cursor designates wrong map"; + end if; + + pragma Assert (Vet (Position), + "Position cursor in Constant_Reference is bad"); + + declare + N : Node_Type renames Container.Nodes (Position.Node); + begin + return (Element => N.Element'Access); + end; + end Constant_Reference; + + function Constant_Reference + (Container : Map; + Key : Key_Type) return Constant_Reference_Type + is + Node : constant Count_Type := Key_Ops.Find (Container, Key); + + begin + if Node = 0 then + raise Constraint_Error with "key not in map"; + end if; + + declare + N : Node_Type renames Container.Nodes (Node); + begin + return (Element => N.Element'Access); + end; + end Constant_Reference; + -------------- -- Contains -- -------------- @@ -916,16 +963,47 @@ package body Ada.Containers.Bounded_Hashed_Maps is -- Reference -- --------------- - function Constant_Reference (Container : Map; Key : Key_Type) - return Constant_Reference_Type is + function Reference + (Container : aliased in out Map; + Position : Cursor) return Reference_Type + is begin - return (Element => Container.Element (Key)'Unrestricted_Access); - end Constant_Reference; + if Position.Container = null then + raise Constraint_Error with + "Position cursor has no element"; + end if; + + if Position.Container /= Container'Unrestricted_Access then + raise Program_Error with + "Position cursor designates wrong map"; + end if; + + pragma Assert (Vet (Position), + "Position cursor in function Reference is bad"); + + declare + N : Node_Type renames Container.Nodes (Position.Node); + begin + return (Element => N.Element'Access); + end; + end Reference; + + function Reference + (Container : aliased in out Map; + Key : Key_Type) return Reference_Type + is + Node : constant Count_Type := Key_Ops.Find (Container, Key); - function Reference (Container : Map; Key : Key_Type) - return Reference_Type is begin - return (Element => Container.Element (Key)'Unrestricted_Access); + if Node = 0 then + raise Constraint_Error with "key not in map"; + end if; + + declare + N : Node_Type renames Container.Nodes (Node); + begin + return (Element => N.Element'Access); + end; end Reference; -------------