annotate gcc/ada/libgnat/g-arrspl.ads @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- G N A T . A R R A Y _ S P L I T --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 2002-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -- Useful array-manipulation routines: given a set of separators, split
kono
parents:
diff changeset
33 -- an array wherever the separators appear, and provide direct access
kono
parents:
diff changeset
34 -- to the resulting slices.
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 with Ada.Finalization;
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 generic
kono
parents:
diff changeset
39 type Element is (<>);
kono
parents:
diff changeset
40 -- Element of the array, this must be a discrete type
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 type Element_Sequence is array (Positive range <>) of Element;
kono
parents:
diff changeset
43 -- The array which is a sequence of element
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 type Element_Set is private;
kono
parents:
diff changeset
46 -- This type represent a set of elements. This set does not define a
kono
parents:
diff changeset
47 -- specific order of the elements. The conversion of a sequence to a
kono
parents:
diff changeset
48 -- set and membership tests in the set is performed using the routines
kono
parents:
diff changeset
49 -- To_Set and Is_In defined below.
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 with function To_Set (Sequence : Element_Sequence) return Element_Set;
kono
parents:
diff changeset
52 -- Returns an Element_Set given an Element_Sequence. Duplicate elements
kono
parents:
diff changeset
53 -- can be ignored during this conversion.
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 with function Is_In (Item : Element; Set : Element_Set) return Boolean;
kono
parents:
diff changeset
56 -- Returns True if Item is found in Set, False otherwise
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 package GNAT.Array_Split is
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
59 pragma Preelaborate;
111
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 Index_Error : exception;
kono
parents:
diff changeset
62 -- Raised by all operations below if Index > Field_Count (S)
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 type Separator_Mode is
kono
parents:
diff changeset
65 (Single,
kono
parents:
diff changeset
66 -- In this mode the array is cut at each element in the separator
kono
parents:
diff changeset
67 -- set. If two separators are contiguous the result at that position
kono
parents:
diff changeset
68 -- is an empty slice.
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 Multiple
kono
parents:
diff changeset
71 -- In this mode contiguous separators are handled as a single
kono
parents:
diff changeset
72 -- separator and no empty slice is created.
kono
parents:
diff changeset
73 );
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 type Slice_Set is private;
kono
parents:
diff changeset
76 -- This type uses by-reference semantics. This is a set of slices as
kono
parents:
diff changeset
77 -- returned by Create or Set routines below. The abstraction represents
kono
parents:
diff changeset
78 -- a set of items. Each item is a part of the original array named a
kono
parents:
diff changeset
79 -- Slice. It is possible to access individual slices by using the Slice
kono
parents:
diff changeset
80 -- routine below. The first slice in the Set is at the position/index
kono
parents:
diff changeset
81 -- 1. The total number of slices in the set is returned by Slice_Count.
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 procedure Create
kono
parents:
diff changeset
84 (S : out Slice_Set;
kono
parents:
diff changeset
85 From : Element_Sequence;
kono
parents:
diff changeset
86 Separators : Element_Sequence;
kono
parents:
diff changeset
87 Mode : Separator_Mode := Single);
kono
parents:
diff changeset
88 -- Create a cut array object. From is the source array, and Separators
kono
parents:
diff changeset
89 -- is a sequence of Element along which to split the array. The source
kono
parents:
diff changeset
90 -- array is sliced at separator boundaries. The separators are not
kono
parents:
diff changeset
91 -- included as part of the resulting slices.
kono
parents:
diff changeset
92 --
kono
parents:
diff changeset
93 -- Note that if From is terminated by a separator an extra empty element
kono
parents:
diff changeset
94 -- is added to the slice set. If From only contains a separator the slice
kono
parents:
diff changeset
95 -- set contains two empty elements.
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 procedure Create
kono
parents:
diff changeset
98 (S : out Slice_Set;
kono
parents:
diff changeset
99 From : Element_Sequence;
kono
parents:
diff changeset
100 Separators : Element_Set;
kono
parents:
diff changeset
101 Mode : Separator_Mode := Single);
kono
parents:
diff changeset
102 -- Same as above but using a Element_Set
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 procedure Set
kono
parents:
diff changeset
105 (S : in out Slice_Set;
kono
parents:
diff changeset
106 Separators : Element_Sequence;
kono
parents:
diff changeset
107 Mode : Separator_Mode := Single);
kono
parents:
diff changeset
108 -- Change the set of separators. The source array will be split according
kono
parents:
diff changeset
109 -- to this new set of separators.
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 procedure Set
kono
parents:
diff changeset
112 (S : in out Slice_Set;
kono
parents:
diff changeset
113 Separators : Element_Set;
kono
parents:
diff changeset
114 Mode : Separator_Mode := Single);
kono
parents:
diff changeset
115 -- Same as above but using a Element_Set
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 type Slice_Number is new Natural;
kono
parents:
diff changeset
118 -- Type used to count number of slices
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 function Slice_Count (S : Slice_Set) return Slice_Number;
kono
parents:
diff changeset
121 pragma Inline (Slice_Count);
kono
parents:
diff changeset
122 -- Returns the number of slices (fields) in S
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 function Slice
kono
parents:
diff changeset
125 (S : Slice_Set;
kono
parents:
diff changeset
126 Index : Slice_Number) return Element_Sequence;
kono
parents:
diff changeset
127 pragma Inline (Slice);
kono
parents:
diff changeset
128 -- Returns the slice at position Index. First slice is 1. If Index is 0
kono
parents:
diff changeset
129 -- the whole array is returned including the separators (this is the
kono
parents:
diff changeset
130 -- original source array).
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 type Position is (Before, After);
kono
parents:
diff changeset
133 -- Used to designate position of separator
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 type Slice_Separators is array (Position) of Element;
kono
parents:
diff changeset
136 -- Separators found before and after the slice
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 Array_End : constant Element;
kono
parents:
diff changeset
139 -- This is the separator returned for the start or the end of the array
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 function Separators
kono
parents:
diff changeset
142 (S : Slice_Set;
kono
parents:
diff changeset
143 Index : Slice_Number) return Slice_Separators;
kono
parents:
diff changeset
144 -- Returns the separators used to slice (front and back) the slice at
kono
parents:
diff changeset
145 -- position Index. For slices at start and end of the original array, the
kono
parents:
diff changeset
146 -- Array_End value is returned for the corresponding outer bound. In
kono
parents:
diff changeset
147 -- Multiple mode only the element closest to the slice is returned.
kono
parents:
diff changeset
148 -- if Index = 0, returns (Array_End, Array_End).
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 type Separators_Indexes is array (Positive range <>) of Positive;
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 function Separators (S : Slice_Set) return Separators_Indexes;
kono
parents:
diff changeset
153 -- Returns indexes of all separators used to slice original source array S
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 private
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 Array_End : constant Element := Element'First;
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 type Element_Access is access Element_Sequence;
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 type Indexes_Access is access Separators_Indexes;
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 type Slice_Info is record
kono
parents:
diff changeset
164 Start : Positive;
kono
parents:
diff changeset
165 Stop : Natural;
kono
parents:
diff changeset
166 end record;
kono
parents:
diff changeset
167 -- Starting/Ending position of a slice. This does not include separators
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 type Slices_Indexes is array (Slice_Number range <>) of Slice_Info;
kono
parents:
diff changeset
170 type Slices_Access is access Slices_Indexes;
kono
parents:
diff changeset
171 -- All indexes for fast access to slices. In the Slice_Set we keep only
kono
parents:
diff changeset
172 -- the original array and the indexes where each slice start and stop.
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 type Data is record
kono
parents:
diff changeset
175 Ref_Counter : Natural; -- Reference counter, by-address sem
kono
parents:
diff changeset
176 Source : Element_Access;
kono
parents:
diff changeset
177 N_Slice : Slice_Number := 0; -- Number of slices found
kono
parents:
diff changeset
178 Indexes : Indexes_Access;
kono
parents:
diff changeset
179 Slices : Slices_Access;
kono
parents:
diff changeset
180 end record;
kono
parents:
diff changeset
181 type Data_Access is access all Data;
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 type Slice_Set is new Ada.Finalization.Controlled with record
kono
parents:
diff changeset
184 D : Data_Access;
kono
parents:
diff changeset
185 end record;
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 procedure Initialize (S : in out Slice_Set);
kono
parents:
diff changeset
188 procedure Adjust (S : in out Slice_Set);
kono
parents:
diff changeset
189 procedure Finalize (S : in out Slice_Set);
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 end GNAT.Array_Split;