diff options
Diffstat (limited to 'gcc/ada/a-convec.adb')
-rw-r--r-- | gcc/ada/a-convec.adb | 81 |
1 files changed, 54 insertions, 27 deletions
diff --git a/gcc/ada/a-convec.adb b/gcc/ada/a-convec.adb index 79071810182..a94f11c9f93 100644 --- a/gcc/ada/a-convec.adb +++ b/gcc/ada/a-convec.adb @@ -29,7 +29,6 @@ with Ada.Containers.Generic_Array_Sort; with Ada.Unchecked_Deallocation; - with System; use type System.Address; package body Ada.Containers.Vectors is @@ -37,12 +36,15 @@ package body Ada.Containers.Vectors is procedure Free is new Ada.Unchecked_Deallocation (Elements_Type, Elements_Access); - type Iterator is new Vector_Iterator_Interfaces.Reversible_Iterator with + type Iterator is new Limited_Controlled and + Vector_Iterator_Interfaces.Reversible_Iterator with record Container : Vector_Access; Index : Index_Type; end record; + overriding procedure Finalize (Object : in out Iterator); + overriding function First (Object : Iterator) return Cursor; overriding function Last (Object : Iterator) return Cursor; overriding function Next @@ -778,6 +780,18 @@ package body Ada.Containers.Vectors is Free (X); end Finalize; + procedure Finalize (Object : in out Iterator) is + begin + if Object.Container /= null then + declare + B : Natural renames Object.Container.all.Busy; + + begin + B := B - 1; + end; + end if; + end Finalize; + ---------- -- Find -- ---------- @@ -800,7 +814,7 @@ package body Ada.Containers.Vectors is for J in Position.Index .. Container.Last loop if Container.Elements.EA (J) = Item then - return (Container'Unchecked_Access, J); + return (Container'Unrestricted_Access, J); end if; end loop; @@ -835,7 +849,7 @@ package body Ada.Containers.Vectors is if Is_Empty (Container) then return No_Element; else - return (Container'Unchecked_Access, Index_Type'First); + return (Container'Unrestricted_Access, Index_Type'First); end if; end First; @@ -1500,7 +1514,7 @@ package body Ada.Containers.Vectors is begin if Before.Container /= null - and then Before.Container /= Container'Unchecked_Access + and then Before.Container /= Container'Unrestricted_Access then raise Program_Error with "Before cursor denotes wrong container"; end if; @@ -1536,7 +1550,7 @@ package body Ada.Containers.Vectors is begin if Before.Container /= null - and then Before.Container /= Container'Unchecked_Access + and then Before.Container /= Container'Unrestricted_Access then raise Program_Error with "Before cursor denotes wrong container"; end if; @@ -1547,7 +1561,7 @@ package body Ada.Containers.Vectors is then Position := No_Element; else - Position := (Container'Unchecked_Access, Before.Index); + Position := (Container'Unrestricted_Access, Before.Index); end if; return; @@ -1569,7 +1583,7 @@ package body Ada.Containers.Vectors is Insert (Container, Index, New_Item); - Position := (Container'Unchecked_Access, Index); + Position := (Container'Unrestricted_Access, Index); end Insert; procedure Insert @@ -1582,7 +1596,7 @@ package body Ada.Containers.Vectors is begin if Before.Container /= null - and then Before.Container /= Container'Unchecked_Access + and then Before.Container /= Container'Unrestricted_Access then raise Program_Error with "Before cursor denotes wrong container"; end if; @@ -1619,7 +1633,7 @@ package body Ada.Containers.Vectors is begin if Before.Container /= null - and then Before.Container /= Container'Unchecked_Access + and then Before.Container /= Container'Unrestricted_Access then raise Program_Error with "Before cursor denotes wrong container"; end if; @@ -1630,7 +1644,7 @@ package body Ada.Containers.Vectors is then Position := No_Element; else - Position := (Container'Unchecked_Access, Before.Index); + Position := (Container'Unrestricted_Access, Before.Index); end if; return; @@ -1652,7 +1666,7 @@ package body Ada.Containers.Vectors is Insert (Container, Index, New_Item, Count); - Position := (Container'Unchecked_Access, Index); + Position := (Container'Unrestricted_Access, Index); end Insert; procedure Insert @@ -2036,7 +2050,7 @@ package body Ada.Containers.Vectors is begin if Before.Container /= null - and then Before.Container /= Container'Unchecked_Access + and then Before.Container /= Container'Unrestricted_Access then raise Program_Error with "Before cursor denotes wrong container"; end if; @@ -2047,7 +2061,7 @@ package body Ada.Containers.Vectors is then Position := No_Element; else - Position := (Container'Unchecked_Access, Before.Index); + Position := (Container'Unrestricted_Access, Before.Index); end if; return; @@ -2069,7 +2083,7 @@ package body Ada.Containers.Vectors is Insert_Space (Container, Index, Count => Count); - Position := (Container'Unchecked_Access, Index); + Position := (Container'Unrestricted_Access, Index); end Insert_Space; -------------- @@ -2089,15 +2103,14 @@ package body Ada.Containers.Vectors is (Container : Vector; Process : not null access procedure (Position : Cursor)) is - V : Vector renames Container'Unrestricted_Access.all; - B : Natural renames V.Busy; + B : Natural renames Container'Unrestricted_Access.all.Busy; begin B := B + 1; begin for Indx in Index_Type'First .. Container.Last loop - Process (Cursor'(Container'Unchecked_Access, Indx)); + Process (Cursor'(Container'Unrestricted_Access, Indx)); end loop; exception when others => @@ -2112,9 +2125,16 @@ package body Ada.Containers.Vectors is (Container : Vector) return Vector_Iterator_Interfaces.Reversible_Iterator'Class is - It : constant Iterator := (Container'Unchecked_Access, Index_Type'First); + B : Natural renames Container'Unrestricted_Access.all.Busy; + begin - return It; + return It : constant Iterator := + (Limited_Controlled with + Container => Container'Unrestricted_Access, + Index => Index_Type'First) + do + B := B + 1; + end return; end Iterate; function Iterate @@ -2122,9 +2142,16 @@ package body Ada.Containers.Vectors is Start : Cursor) return Vector_Iterator_Interfaces.Reversible_Iterator'class is - It : constant Iterator := (Container'Unchecked_Access, Start.Index); + B : Natural renames Container'Unrestricted_Access.all.Busy; + begin - return It; + return It : constant Iterator := + (Limited_Controlled with + Container => Container'Unrestricted_Access, + Index => Start.Index) + do + B := B + 1; + end return; end Iterate; ---------- @@ -2136,7 +2163,7 @@ package body Ada.Containers.Vectors is if Is_Empty (Container) then return No_Element; else - return (Container'Unchecked_Access, Container.Last); + return (Container'Unrestricted_Access, Container.Last); end if; end Last; @@ -2903,7 +2930,7 @@ package body Ada.Containers.Vectors is begin if Position.Container /= null - and then Position.Container /= Container'Unchecked_Access + and then Position.Container /= Container'Unrestricted_Access then raise Program_Error with "Position cursor denotes wrong container"; end if; @@ -2915,7 +2942,7 @@ package body Ada.Containers.Vectors is for Indx in reverse Index_Type'First .. Last loop if Container.Elements.EA (Indx) = Item then - return (Container'Unchecked_Access, Indx); + return (Container'Unrestricted_Access, Indx); end if; end loop; @@ -2960,7 +2987,7 @@ package body Ada.Containers.Vectors is begin for Indx in reverse Index_Type'First .. Container.Last loop - Process (Cursor'(Container'Unchecked_Access, Indx)); + Process (Cursor'(Container'Unrestricted_Access, Indx)); end loop; exception when others => @@ -3061,7 +3088,7 @@ package body Ada.Containers.Vectors is if Index not in Index_Type'First .. Container.Last then return No_Element; else - return (Container'Unchecked_Access, Index); + return (Container'Unrestricted_Access, Index); end if; end To_Cursor; |