From: Arnaud Charlet Date: Sun, 21 Jun 2020 16:36:27 +0000 (-0400) Subject: [Ada] Add iterators over GNAT.Array_Split.Slice_Set X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d588b8b40c4da4c9efe9671f0b12dbdf11afe027;p=gcc.git [Ada] Add iterators over GNAT.Array_Split.Slice_Set gcc/ada/ * libgnat/g-arrspl.ads, libgnat/g-arrspl.adb (Create, First_Cursor, Advance, Has_Element): New. --- diff --git a/gcc/ada/libgnat/g-arrspl.adb b/gcc/ada/libgnat/g-arrspl.adb index e6f0d99d301..877003077fa 100644 --- a/gcc/ada/libgnat/g-arrspl.adb +++ b/gcc/ada/libgnat/g-arrspl.adb @@ -49,7 +49,7 @@ package body GNAT.Array_Split is -- Adjust -- ------------ - procedure Adjust (S : in out Slice_Set) is + overriding procedure Adjust (S : in out Slice_Set) is begin S.D.Ref_Counter := S.D.Ref_Counter + 1; end Adjust; @@ -68,6 +68,16 @@ package body GNAT.Array_Split is Create (S, From, To_Set (Separators), Mode); end Create; + function Create + (From : Element_Sequence; + Separators : Element_Sequence; + Mode : Separator_Mode := Single) return Slice_Set is + begin + return Ret : Slice_Set do + Create (Ret, From, Separators, Mode); + end return; + end Create; + ------------ -- Create -- ------------ @@ -85,6 +95,16 @@ package body GNAT.Array_Split is S := Result; end Create; + function Create + (From : Element_Sequence; + Separators : Element_Set; + Mode : Separator_Mode := Single) return Slice_Set is + begin + return Ret : Slice_Set do + Create (Ret, From, Separators, Mode); + end return; + end Create; + ----------- -- Count -- ----------- @@ -108,7 +128,7 @@ package body GNAT.Array_Split is -- Finalize -- -------------- - procedure Finalize (S : in out Slice_Set) is + overriding procedure Finalize (S : in out Slice_Set) is procedure Free is new Ada.Unchecked_Deallocation (Element_Sequence, Element_Access); @@ -139,7 +159,7 @@ package body GNAT.Array_Split is -- Initialize -- ---------------- - procedure Initialize (S : in out Slice_Set) is + overriding procedure Initialize (S : in out Slice_Set) is begin S.D := new Data'(1, null, 0, null, null); end Initialize; diff --git a/gcc/ada/libgnat/g-arrspl.ads b/gcc/ada/libgnat/g-arrspl.ads index 3383f40d368..099d499d13f 100644 --- a/gcc/ada/libgnat/g-arrspl.ads +++ b/gcc/ada/libgnat/g-arrspl.ads @@ -72,7 +72,12 @@ package GNAT.Array_Split is -- separator and no empty slice is created. ); - type Slice_Set is private; + type Slice_Set is private + with Iterable => (First => First_Cursor, + Next => Advance, + Has_Element => Has_Element, + Element => Slice); + -- This type uses by-reference semantics. This is a set of slices as -- returned by Create or Set routines below. The abstraction represents -- a set of items. Each item is a part of the original array named a @@ -85,6 +90,10 @@ package GNAT.Array_Split is From : Element_Sequence; Separators : Element_Sequence; Mode : Separator_Mode := Single); + function Create + (From : Element_Sequence; + Separators : Element_Sequence; + Mode : Separator_Mode := Single) return Slice_Set; -- Create a cut array object. From is the source array, and Separators -- is a sequence of Element along which to split the array. The source -- array is sliced at separator boundaries. The separators are not @@ -99,6 +108,10 @@ package GNAT.Array_Split is From : Element_Sequence; Separators : Element_Set; Mode : Separator_Mode := Single); + function Create + (From : Element_Sequence; + Separators : Element_Set; + Mode : Separator_Mode := Single) return Slice_Set; -- Same as above but using a Element_Set procedure Set @@ -117,14 +130,21 @@ package GNAT.Array_Split is type Slice_Number is new Natural; -- Type used to count number of slices - function Slice_Count (S : Slice_Set) return Slice_Number; - pragma Inline (Slice_Count); + function Slice_Count (S : Slice_Set) return Slice_Number with Inline; -- Returns the number of slices (fields) in S + function First_Cursor (Unused : Slice_Set) return Slice_Number is (1); + function Advance + (Unused : Slice_Set; Position : Slice_Number) return Slice_Number + is (Position + 1); + function Has_Element + (Cont : Slice_Set; Position : Slice_Number) return Boolean + is (Position <= Slice_Count (Cont)); + -- Functions used to iterate over a Slice_Set + function Slice (S : Slice_Set; - Index : Slice_Number) return Element_Sequence; - pragma Inline (Slice); + Index : Slice_Number) return Element_Sequence with Inline; -- Returns the slice at position Index. First slice is 1. If Index is 0 -- the whole array is returned including the separators (this is the -- original source array). @@ -184,8 +204,8 @@ private D : Data_Access; end record; - procedure Initialize (S : in out Slice_Set); - procedure Adjust (S : in out Slice_Set); - procedure Finalize (S : in out Slice_Set); + overriding procedure Initialize (S : in out Slice_Set); + overriding procedure Adjust (S : in out Slice_Set); + overriding procedure Finalize (S : in out Slice_Set); end GNAT.Array_Split;