annotate gcc/ada/libgnat/a-cborma.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 LIBRARY COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- A D A . C O N T A I N E R S . B O U N D E D _ O R D E R E D _ M A P S --
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) 2004-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- This specification is derived from the Ada Reference Manual for use with --
kono
parents:
diff changeset
12 -- GNAT. The copyright notice above, and the license provisions that follow --
kono
parents:
diff changeset
13 -- apply solely to the contents of the part following the private keyword. --
kono
parents:
diff changeset
14 -- --
kono
parents:
diff changeset
15 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
16 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
17 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
18 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
19 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
20 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
23 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
24 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
25 -- --
kono
parents:
diff changeset
26 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
27 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
28 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
29 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
30 -- --
kono
parents:
diff changeset
31 -- This unit was originally developed by Matthew J Heaney. --
kono
parents:
diff changeset
32 ------------------------------------------------------------------------------
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 with Ada.Iterator_Interfaces;
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 private with Ada.Containers.Red_Black_Trees;
kono
parents:
diff changeset
37 private with Ada.Streams;
kono
parents:
diff changeset
38 private with Ada.Finalization;
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 generic
kono
parents:
diff changeset
41 type Key_Type is private;
kono
parents:
diff changeset
42 type Element_Type is private;
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 with function "<" (Left, Right : Key_Type) return Boolean is <>;
kono
parents:
diff changeset
45 with function "=" (Left, Right : Element_Type) return Boolean is <>;
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 package Ada.Containers.Bounded_Ordered_Maps is
kono
parents:
diff changeset
48 pragma Annotate (CodePeer, Skip_Analysis);
kono
parents:
diff changeset
49 pragma Pure;
kono
parents:
diff changeset
50 pragma Remote_Types;
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 function Equivalent_Keys (Left, Right : Key_Type) return Boolean;
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 type Map (Capacity : Count_Type) is tagged private with
kono
parents:
diff changeset
55 Constant_Indexing => Constant_Reference,
kono
parents:
diff changeset
56 Variable_Indexing => Reference,
kono
parents:
diff changeset
57 Default_Iterator => Iterate,
kono
parents:
diff changeset
58 Iterator_Element => Element_Type;
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 pragma Preelaborable_Initialization (Map);
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 type Cursor is private;
kono
parents:
diff changeset
63 pragma Preelaborable_Initialization (Cursor);
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 Empty_Map : constant Map;
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 No_Element : constant Cursor;
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 function Has_Element (Position : Cursor) return Boolean;
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 package Map_Iterator_Interfaces is new
kono
parents:
diff changeset
72 Ada.Iterator_Interfaces (Cursor, Has_Element);
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 function "=" (Left, Right : Map) return Boolean;
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 function Length (Container : Map) return Count_Type;
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 function Is_Empty (Container : Map) return Boolean;
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 procedure Clear (Container : in out Map);
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 function Key (Position : Cursor) return Key_Type;
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 function Element (Position : Cursor) return Element_Type;
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 procedure Replace_Element
kono
parents:
diff changeset
87 (Container : in out Map;
kono
parents:
diff changeset
88 Position : Cursor;
kono
parents:
diff changeset
89 New_Item : Element_Type);
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 procedure Query_Element
kono
parents:
diff changeset
92 (Position : Cursor;
kono
parents:
diff changeset
93 Process : not null access
kono
parents:
diff changeset
94 procedure (Key : Key_Type; Element : Element_Type));
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 procedure Update_Element
kono
parents:
diff changeset
97 (Container : in out Map;
kono
parents:
diff changeset
98 Position : Cursor;
kono
parents:
diff changeset
99 Process : not null access
kono
parents:
diff changeset
100 procedure (Key : Key_Type; Element : in out Element_Type));
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 type Constant_Reference_Type
kono
parents:
diff changeset
103 (Element : not null access constant Element_Type) is private
kono
parents:
diff changeset
104 with
kono
parents:
diff changeset
105 Implicit_Dereference => Element;
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 type Reference_Type (Element : not null access Element_Type) is private
kono
parents:
diff changeset
108 with
kono
parents:
diff changeset
109 Implicit_Dereference => Element;
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 function Constant_Reference
kono
parents:
diff changeset
112 (Container : aliased Map;
kono
parents:
diff changeset
113 Position : Cursor) return Constant_Reference_Type;
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 function Reference
kono
parents:
diff changeset
116 (Container : aliased in out Map;
kono
parents:
diff changeset
117 Position : Cursor) return Reference_Type;
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 function Constant_Reference
kono
parents:
diff changeset
120 (Container : aliased Map;
kono
parents:
diff changeset
121 Key : Key_Type) return Constant_Reference_Type;
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 function Reference
kono
parents:
diff changeset
124 (Container : aliased in out Map;
kono
parents:
diff changeset
125 Key : Key_Type) return Reference_Type;
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 procedure Assign (Target : in out Map; Source : Map);
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 function Copy (Source : Map; Capacity : Count_Type := 0) return Map;
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 procedure Move (Target : in out Map; Source : in out Map);
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 procedure Insert
kono
parents:
diff changeset
134 (Container : in out Map;
kono
parents:
diff changeset
135 Key : Key_Type;
kono
parents:
diff changeset
136 New_Item : Element_Type;
kono
parents:
diff changeset
137 Position : out Cursor;
kono
parents:
diff changeset
138 Inserted : out Boolean);
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 procedure Insert
kono
parents:
diff changeset
141 (Container : in out Map;
kono
parents:
diff changeset
142 Key : Key_Type;
kono
parents:
diff changeset
143 Position : out Cursor;
kono
parents:
diff changeset
144 Inserted : out Boolean);
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 procedure Insert
kono
parents:
diff changeset
147 (Container : in out Map;
kono
parents:
diff changeset
148 Key : Key_Type;
kono
parents:
diff changeset
149 New_Item : Element_Type);
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 procedure Include
kono
parents:
diff changeset
152 (Container : in out Map;
kono
parents:
diff changeset
153 Key : Key_Type;
kono
parents:
diff changeset
154 New_Item : Element_Type);
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 procedure Replace
kono
parents:
diff changeset
157 (Container : in out Map;
kono
parents:
diff changeset
158 Key : Key_Type;
kono
parents:
diff changeset
159 New_Item : Element_Type);
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 procedure Exclude (Container : in out Map; Key : Key_Type);
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 procedure Delete (Container : in out Map; Key : Key_Type);
kono
parents:
diff changeset
164
kono
parents:
diff changeset
165 procedure Delete (Container : in out Map; Position : in out Cursor);
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 procedure Delete_First (Container : in out Map);
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 procedure Delete_Last (Container : in out Map);
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 function First (Container : Map) return Cursor;
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 function First_Element (Container : Map) return Element_Type;
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 function First_Key (Container : Map) return Key_Type;
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 function Last (Container : Map) return Cursor;
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 function Last_Element (Container : Map) return Element_Type;
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 function Last_Key (Container : Map) return Key_Type;
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 function Next (Position : Cursor) return Cursor;
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 procedure Next (Position : in out Cursor);
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 function Previous (Position : Cursor) return Cursor;
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 procedure Previous (Position : in out Cursor);
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 function Find (Container : Map; Key : Key_Type) return Cursor;
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 function Element (Container : Map; Key : Key_Type) return Element_Type;
kono
parents:
diff changeset
194
kono
parents:
diff changeset
195 function Floor (Container : Map; Key : Key_Type) return Cursor;
kono
parents:
diff changeset
196
kono
parents:
diff changeset
197 function Ceiling (Container : Map; Key : Key_Type) return Cursor;
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 function Contains (Container : Map; Key : Key_Type) return Boolean;
kono
parents:
diff changeset
200
kono
parents:
diff changeset
201 function "<" (Left, Right : Cursor) return Boolean;
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 function ">" (Left, Right : Cursor) return Boolean;
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 function "<" (Left : Cursor; Right : Key_Type) return Boolean;
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207 function ">" (Left : Cursor; Right : Key_Type) return Boolean;
kono
parents:
diff changeset
208
kono
parents:
diff changeset
209 function "<" (Left : Key_Type; Right : Cursor) return Boolean;
kono
parents:
diff changeset
210
kono
parents:
diff changeset
211 function ">" (Left : Key_Type; Right : Cursor) return Boolean;
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 procedure Iterate
kono
parents:
diff changeset
214 (Container : Map;
kono
parents:
diff changeset
215 Process : not null access procedure (Position : Cursor));
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 procedure Reverse_Iterate
kono
parents:
diff changeset
218 (Container : Map;
kono
parents:
diff changeset
219 Process : not null access procedure (Position : Cursor));
kono
parents:
diff changeset
220
kono
parents:
diff changeset
221 function Iterate
kono
parents:
diff changeset
222 (Container : Map)
kono
parents:
diff changeset
223 return Map_Iterator_Interfaces.Reversible_Iterator'Class;
kono
parents:
diff changeset
224
kono
parents:
diff changeset
225 function Iterate
kono
parents:
diff changeset
226 (Container : Map;
kono
parents:
diff changeset
227 Start : Cursor)
kono
parents:
diff changeset
228 return Map_Iterator_Interfaces.Reversible_Iterator'Class;
kono
parents:
diff changeset
229
kono
parents:
diff changeset
230 private
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 use Ada.Finalization;
kono
parents:
diff changeset
233 pragma Inline (Next);
kono
parents:
diff changeset
234 pragma Inline (Previous);
kono
parents:
diff changeset
235
kono
parents:
diff changeset
236 type Node_Type is record
kono
parents:
diff changeset
237 Parent : Count_Type;
kono
parents:
diff changeset
238 Left : Count_Type;
kono
parents:
diff changeset
239 Right : Count_Type;
kono
parents:
diff changeset
240 Color : Red_Black_Trees.Color_Type := Red_Black_Trees.Red;
kono
parents:
diff changeset
241 Key : Key_Type;
kono
parents:
diff changeset
242 Element : aliased Element_Type;
kono
parents:
diff changeset
243 end record;
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 package Tree_Types is
kono
parents:
diff changeset
246 new Red_Black_Trees.Generic_Bounded_Tree_Types (Node_Type);
kono
parents:
diff changeset
247
kono
parents:
diff changeset
248 type Map (Capacity : Count_Type) is
kono
parents:
diff changeset
249 new Tree_Types.Tree_Type (Capacity) with null record;
kono
parents:
diff changeset
250
kono
parents:
diff changeset
251 use Red_Black_Trees;
kono
parents:
diff changeset
252 use Tree_Types, Tree_Types.Implementation;
kono
parents:
diff changeset
253 use Ada.Streams;
kono
parents:
diff changeset
254
kono
parents:
diff changeset
255 procedure Write
kono
parents:
diff changeset
256 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
257 Container : Map);
kono
parents:
diff changeset
258
kono
parents:
diff changeset
259 for Map'Write use Write;
kono
parents:
diff changeset
260
kono
parents:
diff changeset
261 procedure Read
kono
parents:
diff changeset
262 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
263 Container : out Map);
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 for Map'Read use Read;
kono
parents:
diff changeset
266
kono
parents:
diff changeset
267 type Map_Access is access all Map;
kono
parents:
diff changeset
268 for Map_Access'Storage_Size use 0;
kono
parents:
diff changeset
269
kono
parents:
diff changeset
270 type Cursor is record
kono
parents:
diff changeset
271 Container : Map_Access;
kono
parents:
diff changeset
272 Node : Count_Type := 0;
kono
parents:
diff changeset
273 end record;
kono
parents:
diff changeset
274
kono
parents:
diff changeset
275 procedure Write
kono
parents:
diff changeset
276 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
277 Item : Cursor);
kono
parents:
diff changeset
278
kono
parents:
diff changeset
279 for Cursor'Write use Write;
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 procedure Read
kono
parents:
diff changeset
282 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
283 Item : out Cursor);
kono
parents:
diff changeset
284
kono
parents:
diff changeset
285 for Cursor'Read use Read;
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 subtype Reference_Control_Type is Implementation.Reference_Control_Type;
kono
parents:
diff changeset
288 -- It is necessary to rename this here, so that the compiler can find it
kono
parents:
diff changeset
289
kono
parents:
diff changeset
290 type Constant_Reference_Type
kono
parents:
diff changeset
291 (Element : not null access constant Element_Type) is
kono
parents:
diff changeset
292 record
kono
parents:
diff changeset
293 Control : Reference_Control_Type :=
kono
parents:
diff changeset
294 raise Program_Error with "uninitialized reference";
kono
parents:
diff changeset
295 -- The RM says, "The default initialization of an object of
kono
parents:
diff changeset
296 -- type Constant_Reference_Type or Reference_Type propagates
kono
parents:
diff changeset
297 -- Program_Error."
kono
parents:
diff changeset
298 end record;
kono
parents:
diff changeset
299
kono
parents:
diff changeset
300 procedure Read
kono
parents:
diff changeset
301 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
302 Item : out Constant_Reference_Type);
kono
parents:
diff changeset
303
kono
parents:
diff changeset
304 for Constant_Reference_Type'Read use Read;
kono
parents:
diff changeset
305
kono
parents:
diff changeset
306 procedure Write
kono
parents:
diff changeset
307 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
308 Item : Constant_Reference_Type);
kono
parents:
diff changeset
309
kono
parents:
diff changeset
310 for Constant_Reference_Type'Write use Write;
kono
parents:
diff changeset
311
kono
parents:
diff changeset
312 type Reference_Type (Element : not null access Element_Type) is record
kono
parents:
diff changeset
313 Control : Reference_Control_Type :=
kono
parents:
diff changeset
314 raise Program_Error with "uninitialized reference";
kono
parents:
diff changeset
315 -- The RM says, "The default initialization of an object of
kono
parents:
diff changeset
316 -- type Constant_Reference_Type or Reference_Type propagates
kono
parents:
diff changeset
317 -- Program_Error."
kono
parents:
diff changeset
318 end record;
kono
parents:
diff changeset
319
kono
parents:
diff changeset
320 procedure Read
kono
parents:
diff changeset
321 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
322 Item : out Reference_Type);
kono
parents:
diff changeset
323
kono
parents:
diff changeset
324 for Reference_Type'Read use Read;
kono
parents:
diff changeset
325
kono
parents:
diff changeset
326 procedure Write
kono
parents:
diff changeset
327 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
328 Item : Reference_Type);
kono
parents:
diff changeset
329
kono
parents:
diff changeset
330 for Reference_Type'Write use Write;
kono
parents:
diff changeset
331
kono
parents:
diff changeset
332 -- Three operations are used to optimize in the expansion of "for ... of"
kono
parents:
diff changeset
333 -- loops: the Next(Cursor) procedure in the visible part, and the following
kono
parents:
diff changeset
334 -- Pseudo_Reference and Get_Element_Access functions. See Sem_Ch5 for
kono
parents:
diff changeset
335 -- details.
kono
parents:
diff changeset
336
kono
parents:
diff changeset
337 function Pseudo_Reference
kono
parents:
diff changeset
338 (Container : aliased Map'Class) return Reference_Control_Type;
kono
parents:
diff changeset
339 pragma Inline (Pseudo_Reference);
kono
parents:
diff changeset
340 -- Creates an object of type Reference_Control_Type pointing to the
kono
parents:
diff changeset
341 -- container, and increments the Lock. Finalization of this object will
kono
parents:
diff changeset
342 -- decrement the Lock.
kono
parents:
diff changeset
343
kono
parents:
diff changeset
344 type Element_Access is access all Element_Type with
kono
parents:
diff changeset
345 Storage_Size => 0;
kono
parents:
diff changeset
346
kono
parents:
diff changeset
347 function Get_Element_Access
kono
parents:
diff changeset
348 (Position : Cursor) return not null Element_Access;
kono
parents:
diff changeset
349 -- Returns a pointer to the element designated by Position.
kono
parents:
diff changeset
350
kono
parents:
diff changeset
351 Empty_Map : constant Map := Map'(Tree_Type with Capacity => 0);
kono
parents:
diff changeset
352
kono
parents:
diff changeset
353 No_Element : constant Cursor := Cursor'(null, 0);
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 type Iterator is new Limited_Controlled and
kono
parents:
diff changeset
356 Map_Iterator_Interfaces.Reversible_Iterator with
kono
parents:
diff changeset
357 record
kono
parents:
diff changeset
358 Container : Map_Access;
kono
parents:
diff changeset
359 Node : Count_Type;
kono
parents:
diff changeset
360 end record
kono
parents:
diff changeset
361 with Disable_Controlled => not T_Check;
kono
parents:
diff changeset
362
kono
parents:
diff changeset
363 overriding procedure Finalize (Object : in out Iterator);
kono
parents:
diff changeset
364
kono
parents:
diff changeset
365 overriding function First (Object : Iterator) return Cursor;
kono
parents:
diff changeset
366 overriding function Last (Object : Iterator) return Cursor;
kono
parents:
diff changeset
367
kono
parents:
diff changeset
368 overriding function Next
kono
parents:
diff changeset
369 (Object : Iterator;
kono
parents:
diff changeset
370 Position : Cursor) return Cursor;
kono
parents:
diff changeset
371
kono
parents:
diff changeset
372 overriding function Previous
kono
parents:
diff changeset
373 (Object : Iterator;
kono
parents:
diff changeset
374 Position : Cursor) return Cursor;
kono
parents:
diff changeset
375
kono
parents:
diff changeset
376 end Ada.Containers.Bounded_Ordered_Maps;