aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnaud Charlet <charlet@adacore.com>2020-06-21 12:36:27 -0400
committerPierre-Marie de Rodat <derodat@adacore.com>2020-10-15 05:39:06 -0400
commitd588b8b40c4da4c9efe9671f0b12dbdf11afe027 (patch)
tree02527a8a2485adf040a7be29e93f99b21a8e96a9
parent40486f926ce9f5c09d6211244c2d8dc46b94f03f (diff)
downloadgcc-d588b8b40c4da4c9efe9671f0b12dbdf11afe027.zip
gcc-d588b8b40c4da4c9efe9671f0b12dbdf11afe027.tar.gz
gcc-d588b8b40c4da4c9efe9671f0b12dbdf11afe027.tar.bz2
[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.
-rw-r--r--gcc/ada/libgnat/g-arrspl.adb26
-rw-r--r--gcc/ada/libgnat/g-arrspl.ads36
2 files changed, 51 insertions, 11 deletions
diff --git a/gcc/ada/libgnat/g-arrspl.adb b/gcc/ada/libgnat/g-arrspl.adb
index e6f0d99..8770030 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 3383f40..099d499 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;