libgo: correct golang_org Makefile variables not used on all systems
[official-gcc.git] / gcc / ada / a-cborma.ads
blob7aa6e6c4ef687957f94fa5f7d02d76a25054556d
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT LIBRARY COMPONENTS --
4 -- --
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 --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2004-2015, Free Software Foundation, Inc. --
10 -- --
11 -- This specification is derived from the Ada Reference Manual for use with --
12 -- GNAT. The copyright notice above, and the license provisions that follow --
13 -- apply solely to the contents of the part following the private keyword. --
14 -- --
15 -- GNAT is free software; you can redistribute it and/or modify it under --
16 -- terms of the GNU General Public License as published by the Free Soft- --
17 -- ware Foundation; either version 3, or (at your option) any later ver- --
18 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
19 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
20 -- or FITNESS FOR A PARTICULAR PURPOSE. --
21 -- --
22 -- As a special exception under Section 7 of GPL version 3, you are granted --
23 -- additional permissions described in the GCC Runtime Library Exception, --
24 -- version 3.1, as published by the Free Software Foundation. --
25 -- --
26 -- You should have received a copy of the GNU General Public License and --
27 -- a copy of the GCC Runtime Library Exception along with this program; --
28 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
29 -- <http://www.gnu.org/licenses/>. --
30 -- --
31 -- This unit was originally developed by Matthew J Heaney. --
32 ------------------------------------------------------------------------------
34 with Ada.Iterator_Interfaces;
36 private with Ada.Containers.Red_Black_Trees;
37 private with Ada.Streams;
38 private with Ada.Finalization;
40 generic
41 type Key_Type is private;
42 type Element_Type is private;
44 with function "<" (Left, Right : Key_Type) return Boolean is <>;
45 with function "=" (Left, Right : Element_Type) return Boolean is <>;
47 package Ada.Containers.Bounded_Ordered_Maps is
48 pragma Annotate (CodePeer, Skip_Analysis);
49 pragma Pure;
50 pragma Remote_Types;
52 function Equivalent_Keys (Left, Right : Key_Type) return Boolean;
54 type Map (Capacity : Count_Type) is tagged private with
55 Constant_Indexing => Constant_Reference,
56 Variable_Indexing => Reference,
57 Default_Iterator => Iterate,
58 Iterator_Element => Element_Type;
60 pragma Preelaborable_Initialization (Map);
62 type Cursor is private;
63 pragma Preelaborable_Initialization (Cursor);
65 Empty_Map : constant Map;
67 No_Element : constant Cursor;
69 function Has_Element (Position : Cursor) return Boolean;
71 package Map_Iterator_Interfaces is new
72 Ada.Iterator_Interfaces (Cursor, Has_Element);
74 function "=" (Left, Right : Map) return Boolean;
76 function Length (Container : Map) return Count_Type;
78 function Is_Empty (Container : Map) return Boolean;
80 procedure Clear (Container : in out Map);
82 function Key (Position : Cursor) return Key_Type;
84 function Element (Position : Cursor) return Element_Type;
86 procedure Replace_Element
87 (Container : in out Map;
88 Position : Cursor;
89 New_Item : Element_Type);
91 procedure Query_Element
92 (Position : Cursor;
93 Process : not null access
94 procedure (Key : Key_Type; Element : Element_Type));
96 procedure Update_Element
97 (Container : in out Map;
98 Position : Cursor;
99 Process : not null access
100 procedure (Key : Key_Type; Element : in out Element_Type));
102 type Constant_Reference_Type
103 (Element : not null access constant Element_Type) is private
104 with
105 Implicit_Dereference => Element;
107 type Reference_Type (Element : not null access Element_Type) is private
108 with
109 Implicit_Dereference => Element;
111 function Constant_Reference
112 (Container : aliased Map;
113 Position : Cursor) return Constant_Reference_Type;
115 function Reference
116 (Container : aliased in out Map;
117 Position : Cursor) return Reference_Type;
119 function Constant_Reference
120 (Container : aliased Map;
121 Key : Key_Type) return Constant_Reference_Type;
123 function Reference
124 (Container : aliased in out Map;
125 Key : Key_Type) return Reference_Type;
127 procedure Assign (Target : in out Map; Source : Map);
129 function Copy (Source : Map; Capacity : Count_Type := 0) return Map;
131 procedure Move (Target : in out Map; Source : in out Map);
133 procedure Insert
134 (Container : in out Map;
135 Key : Key_Type;
136 New_Item : Element_Type;
137 Position : out Cursor;
138 Inserted : out Boolean);
140 procedure Insert
141 (Container : in out Map;
142 Key : Key_Type;
143 Position : out Cursor;
144 Inserted : out Boolean);
146 procedure Insert
147 (Container : in out Map;
148 Key : Key_Type;
149 New_Item : Element_Type);
151 procedure Include
152 (Container : in out Map;
153 Key : Key_Type;
154 New_Item : Element_Type);
156 procedure Replace
157 (Container : in out Map;
158 Key : Key_Type;
159 New_Item : Element_Type);
161 procedure Exclude (Container : in out Map; Key : Key_Type);
163 procedure Delete (Container : in out Map; Key : Key_Type);
165 procedure Delete (Container : in out Map; Position : in out Cursor);
167 procedure Delete_First (Container : in out Map);
169 procedure Delete_Last (Container : in out Map);
171 function First (Container : Map) return Cursor;
173 function First_Element (Container : Map) return Element_Type;
175 function First_Key (Container : Map) return Key_Type;
177 function Last (Container : Map) return Cursor;
179 function Last_Element (Container : Map) return Element_Type;
181 function Last_Key (Container : Map) return Key_Type;
183 function Next (Position : Cursor) return Cursor;
185 procedure Next (Position : in out Cursor);
187 function Previous (Position : Cursor) return Cursor;
189 procedure Previous (Position : in out Cursor);
191 function Find (Container : Map; Key : Key_Type) return Cursor;
193 function Element (Container : Map; Key : Key_Type) return Element_Type;
195 function Floor (Container : Map; Key : Key_Type) return Cursor;
197 function Ceiling (Container : Map; Key : Key_Type) return Cursor;
199 function Contains (Container : Map; Key : Key_Type) return Boolean;
201 function "<" (Left, Right : Cursor) return Boolean;
203 function ">" (Left, Right : Cursor) return Boolean;
205 function "<" (Left : Cursor; Right : Key_Type) return Boolean;
207 function ">" (Left : Cursor; Right : Key_Type) return Boolean;
209 function "<" (Left : Key_Type; Right : Cursor) return Boolean;
211 function ">" (Left : Key_Type; Right : Cursor) return Boolean;
213 procedure Iterate
214 (Container : Map;
215 Process : not null access procedure (Position : Cursor));
217 procedure Reverse_Iterate
218 (Container : Map;
219 Process : not null access procedure (Position : Cursor));
221 function Iterate
222 (Container : Map)
223 return Map_Iterator_Interfaces.Reversible_Iterator'Class;
225 function Iterate
226 (Container : Map;
227 Start : Cursor)
228 return Map_Iterator_Interfaces.Reversible_Iterator'Class;
230 private
232 use Ada.Finalization;
233 pragma Inline (Next);
234 pragma Inline (Previous);
236 type Node_Type is record
237 Parent : Count_Type;
238 Left : Count_Type;
239 Right : Count_Type;
240 Color : Red_Black_Trees.Color_Type := Red_Black_Trees.Red;
241 Key : Key_Type;
242 Element : aliased Element_Type;
243 end record;
245 package Tree_Types is
246 new Red_Black_Trees.Generic_Bounded_Tree_Types (Node_Type);
248 type Map (Capacity : Count_Type) is
249 new Tree_Types.Tree_Type (Capacity) with null record;
251 use Red_Black_Trees;
252 use Tree_Types, Tree_Types.Implementation;
253 use Ada.Streams;
255 procedure Write
256 (Stream : not null access Root_Stream_Type'Class;
257 Container : Map);
259 for Map'Write use Write;
261 procedure Read
262 (Stream : not null access Root_Stream_Type'Class;
263 Container : out Map);
265 for Map'Read use Read;
267 type Map_Access is access all Map;
268 for Map_Access'Storage_Size use 0;
270 type Cursor is record
271 Container : Map_Access;
272 Node : Count_Type := 0;
273 end record;
275 procedure Write
276 (Stream : not null access Root_Stream_Type'Class;
277 Item : Cursor);
279 for Cursor'Write use Write;
281 procedure Read
282 (Stream : not null access Root_Stream_Type'Class;
283 Item : out Cursor);
285 for Cursor'Read use Read;
287 subtype Reference_Control_Type is Implementation.Reference_Control_Type;
288 -- It is necessary to rename this here, so that the compiler can find it
290 type Constant_Reference_Type
291 (Element : not null access constant Element_Type) is
292 record
293 Control : Reference_Control_Type :=
294 raise Program_Error with "uninitialized reference";
295 -- The RM says, "The default initialization of an object of
296 -- type Constant_Reference_Type or Reference_Type propagates
297 -- Program_Error."
298 end record;
300 procedure Read
301 (Stream : not null access Root_Stream_Type'Class;
302 Item : out Constant_Reference_Type);
304 for Constant_Reference_Type'Read use Read;
306 procedure Write
307 (Stream : not null access Root_Stream_Type'Class;
308 Item : Constant_Reference_Type);
310 for Constant_Reference_Type'Write use Write;
312 type Reference_Type (Element : not null access Element_Type) is record
313 Control : Reference_Control_Type :=
314 raise Program_Error with "uninitialized reference";
315 -- The RM says, "The default initialization of an object of
316 -- type Constant_Reference_Type or Reference_Type propagates
317 -- Program_Error."
318 end record;
320 procedure Read
321 (Stream : not null access Root_Stream_Type'Class;
322 Item : out Reference_Type);
324 for Reference_Type'Read use Read;
326 procedure Write
327 (Stream : not null access Root_Stream_Type'Class;
328 Item : Reference_Type);
330 for Reference_Type'Write use Write;
332 -- Three operations are used to optimize in the expansion of "for ... of"
333 -- loops: the Next(Cursor) procedure in the visible part, and the following
334 -- Pseudo_Reference and Get_Element_Access functions. See Sem_Ch5 for
335 -- details.
337 function Pseudo_Reference
338 (Container : aliased Map'Class) return Reference_Control_Type;
339 pragma Inline (Pseudo_Reference);
340 -- Creates an object of type Reference_Control_Type pointing to the
341 -- container, and increments the Lock. Finalization of this object will
342 -- decrement the Lock.
344 type Element_Access is access all Element_Type with
345 Storage_Size => 0;
347 function Get_Element_Access
348 (Position : Cursor) return not null Element_Access;
349 -- Returns a pointer to the element designated by Position.
351 Empty_Map : constant Map := Map'(Tree_Type with Capacity => 0);
353 No_Element : constant Cursor := Cursor'(null, 0);
355 type Iterator is new Limited_Controlled and
356 Map_Iterator_Interfaces.Reversible_Iterator with
357 record
358 Container : Map_Access;
359 Node : Count_Type;
360 end record
361 with Disable_Controlled => not T_Check;
363 overriding procedure Finalize (Object : in out Iterator);
365 overriding function First (Object : Iterator) return Cursor;
366 overriding function Last (Object : Iterator) return Cursor;
368 overriding function Next
369 (Object : Iterator;
370 Position : Cursor) return Cursor;
372 overriding function Previous
373 (Object : Iterator;
374 Position : Cursor) return Cursor;
376 end Ada.Containers.Bounded_Ordered_Maps;