OSDN Git Service

* gcc-interface/trans.c (call_to_gnu): Use local variable. Make sure
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-ciorse.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT LIBRARY COMPONENTS                          --
4 --                                                                          --
5 --                 ADA.CONTAINERS.INDEFINITE_ORDERED_SETS                   --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 2004-2011, 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 ------------------------------------------------------------------------------
33
34 private with Ada.Containers.Red_Black_Trees;
35 private with Ada.Finalization;
36 with Ada.Streams; use Ada.Streams;
37 with Ada.Iterator_Interfaces;
38
39 generic
40    type Element_Type (<>) is private;
41
42    with function "<" (Left, Right : Element_Type) return Boolean is <>;
43    with function "=" (Left, Right : Element_Type) return Boolean is <>;
44
45 package Ada.Containers.Indefinite_Ordered_Sets is
46    pragma Preelaborate;
47    pragma Remote_Types;
48
49    function Equivalent_Elements (Left, Right : Element_Type) return Boolean;
50
51    type Set is tagged private with
52       Constant_Indexing => Constant_Reference,
53       Variable_Indexing => Reference,
54       Default_Iterator  => Iterate,
55       Iterator_Element  => Element_Type;
56
57    pragma Preelaborable_Initialization (Set);
58
59    type Cursor is private;
60    pragma Preelaborable_Initialization (Cursor);
61
62    Empty_Set : constant Set;
63
64    No_Element : constant Cursor;
65
66    function Has_Element (Position : Cursor) return Boolean;
67
68    package Ordered_Set_Iterator_Interfaces is new
69      Ada.Iterator_Interfaces (Cursor, Has_Element);
70
71    type Constant_Reference_Type
72      (Element : not null access constant Element_Type) is
73    private with
74       Implicit_Dereference => Element;
75
76    procedure Read
77      (Stream : not null access Root_Stream_Type'Class;
78       Item   : out Constant_Reference_Type);
79
80    for Constant_Reference_Type'Read use Read;
81
82    procedure Write
83      (Stream : not null access Root_Stream_Type'Class;
84       Item   : Constant_Reference_Type);
85
86    for Constant_Reference_Type'Write use Write;
87
88    function Constant_Reference
89      (Container : Set;
90       Position  : Cursor) return Constant_Reference_Type;
91
92    type Reference_Type (Element : not null access Element_Type) is private
93    with
94       Implicit_Dereference => Element;
95
96    procedure Write
97      (Stream : not null access Root_Stream_Type'Class;
98       Item   : Reference_Type);
99
100    for Reference_Type'Write use Write;
101
102    procedure Read
103      (Stream : not null access Root_Stream_Type'Class;
104       Item   : out Reference_Type);
105
106    for Reference_Type'Read use Read;
107
108    function Reference
109      (Container : Set; Position : Cursor)
110    return Reference_Type;
111
112    function "=" (Left, Right : Set) return Boolean;
113
114    function Equivalent_Sets (Left, Right : Set) return Boolean;
115
116    function To_Set (New_Item : Element_Type) return Set;
117
118    function Length (Container : Set) return Count_Type;
119
120    function Is_Empty (Container : Set) return Boolean;
121
122    procedure Clear (Container : in out Set);
123
124    function Element (Position : Cursor) return Element_Type;
125
126    procedure Replace_Element
127      (Container : in out Set;
128       Position  : Cursor;
129       New_Item  : Element_Type);
130
131    procedure Query_Element
132      (Position : Cursor;
133       Process  : not null access procedure (Element : Element_Type));
134
135    procedure Move (Target : in out Set; Source : in out Set);
136
137    procedure Insert
138      (Container : in out Set;
139       New_Item  : Element_Type;
140       Position  : out Cursor;
141       Inserted  : out Boolean);
142
143    procedure Insert
144      (Container : in out Set;
145       New_Item  : Element_Type);
146
147    procedure Include
148      (Container : in out Set;
149       New_Item  : Element_Type);
150
151    procedure Replace
152      (Container : in out Set;
153       New_Item  : Element_Type);
154
155    procedure Exclude
156      (Container : in out Set;
157       Item      : Element_Type);
158
159    procedure Delete
160      (Container : in out Set;
161       Item      : Element_Type);
162
163    procedure Delete
164      (Container : in out Set;
165       Position  : in out Cursor);
166
167    procedure Delete_First (Container : in out Set);
168
169    procedure Delete_Last (Container : in out Set);
170
171    procedure Union (Target : in out Set; Source : Set);
172
173    function Union (Left, Right : Set) return Set;
174
175    function "or" (Left, Right : Set) return Set renames Union;
176
177    procedure Intersection (Target : in out Set; Source : Set);
178
179    function Intersection (Left, Right : Set) return Set;
180
181    function "and" (Left, Right : Set) return Set renames Intersection;
182
183    procedure Difference (Target : in out Set; Source : Set);
184
185    function Difference (Left, Right : Set) return Set;
186
187    function "-" (Left, Right : Set) return Set renames Difference;
188
189    procedure Symmetric_Difference (Target : in out Set; Source : Set);
190
191    function Symmetric_Difference (Left, Right : Set) return Set;
192
193    function "xor" (Left, Right : Set) return Set renames Symmetric_Difference;
194
195    function Overlap (Left, Right : Set) return Boolean;
196
197    function Is_Subset (Subset : Set; Of_Set : Set) return Boolean;
198
199    function First (Container : Set) return Cursor;
200
201    function First_Element (Container : Set) return Element_Type;
202
203    function Last (Container : Set) return Cursor;
204
205    function Last_Element (Container : Set) return Element_Type;
206
207    function Next (Position : Cursor) return Cursor;
208
209    procedure Next (Position : in out Cursor);
210
211    function Previous (Position : Cursor) return Cursor;
212
213    procedure Previous (Position : in out Cursor);
214
215    function Find (Container : Set; Item : Element_Type) return Cursor;
216
217    function Floor (Container : Set; Item : Element_Type) return Cursor;
218
219    function Ceiling (Container : Set; Item : Element_Type) return Cursor;
220
221    function Contains (Container : Set; Item : Element_Type) return Boolean;
222
223    function "<" (Left, Right : Cursor) return Boolean;
224
225    function ">" (Left, Right : Cursor) return Boolean;
226
227    function "<" (Left : Cursor; Right : Element_Type) return Boolean;
228
229    function ">" (Left : Cursor; Right : Element_Type) return Boolean;
230
231    function "<" (Left : Element_Type; Right : Cursor) return Boolean;
232
233    function ">" (Left : Element_Type; Right : Cursor) return Boolean;
234
235    procedure Iterate
236      (Container : Set;
237       Process   : not null access procedure (Position : Cursor));
238
239    procedure Reverse_Iterate
240      (Container : Set;
241       Process   : not null access procedure (Position : Cursor));
242
243    function Iterate
244      (Container : Set)
245       return Ordered_Set_Iterator_Interfaces.Reversible_Iterator'class;
246
247    function Iterate
248      (Container : Set;
249       Start     : Cursor)
250       return Ordered_Set_Iterator_Interfaces.Reversible_Iterator'class;
251
252    generic
253       type Key_Type (<>) is private;
254
255       with function Key (Element : Element_Type) return Key_Type;
256
257       with function "<" (Left, Right : Key_Type) return Boolean is <>;
258
259    package Generic_Keys is
260
261       function Equivalent_Keys (Left, Right : Key_Type) return Boolean;
262
263       function Key (Position : Cursor) return Key_Type;
264
265       function Element (Container : Set; Key : Key_Type) return Element_Type;
266
267       procedure Replace
268         (Container : in out Set;
269          Key       : Key_Type;
270          New_Item  : Element_Type);
271
272       procedure Exclude (Container : in out Set; Key : Key_Type);
273
274       procedure Delete (Container : in out Set; Key : Key_Type);
275
276       function Find
277         (Container : Set;
278          Key       : Key_Type) return Cursor;
279
280       function Floor
281         (Container : Set;
282          Key       : Key_Type) return Cursor;
283
284       function Ceiling
285         (Container : Set;
286          Key       : Key_Type) return Cursor;
287
288       function Contains
289         (Container : Set;
290          Key       : Key_Type) return Boolean;
291
292       procedure Update_Element_Preserving_Key
293         (Container : in out Set;
294          Position  : Cursor;
295          Process   : not null access
296                        procedure (Element : in out Element_Type));
297
298    end Generic_Keys;
299
300 private
301
302    pragma Inline (Next);
303    pragma Inline (Previous);
304
305    type Node_Type;
306    type Node_Access is access Node_Type;
307
308    type Element_Access is access Element_Type;
309
310    type Node_Type is limited record
311       Parent  : Node_Access;
312       Left    : Node_Access;
313       Right   : Node_Access;
314       Color   : Red_Black_Trees.Color_Type := Red_Black_Trees.Red;
315       Element : Element_Access;
316    end record;
317
318    package Tree_Types is new Red_Black_Trees.Generic_Tree_Types
319      (Node_Type,
320       Node_Access);
321
322    type Set is new Ada.Finalization.Controlled with record
323       Tree : Tree_Types.Tree_Type;
324    end record;
325
326    overriding procedure Adjust (Container : in out Set);
327
328    overriding procedure Finalize (Container : in out Set) renames Clear;
329
330    use Red_Black_Trees;
331    use Tree_Types;
332    use Ada.Finalization;
333
334    type Set_Access is access all Set;
335    for Set_Access'Storage_Size use 0;
336
337    type Cursor is record
338       Container : Set_Access;
339       Node      : Node_Access;
340    end record;
341
342    procedure Write
343      (Stream : not null access Root_Stream_Type'Class;
344       Item   : Cursor);
345
346    for Cursor'Write use Write;
347
348    procedure Read
349      (Stream : not null access Root_Stream_Type'Class;
350       Item   : out Cursor);
351
352    for Cursor'Read use Read;
353
354    No_Element : constant Cursor := Cursor'(null, null);
355
356    procedure Write
357      (Stream    : not null access Root_Stream_Type'Class;
358       Container : Set);
359
360    for Set'Write use Write;
361
362    procedure Read
363      (Stream    : not null access Root_Stream_Type'Class;
364       Container : out Set);
365
366    for Set'Read use Read;
367
368    type Constant_Reference_Type
369       (Element : not null access constant Element_Type) is null record;
370
371    type Reference_Type
372       (Element : not null access Element_Type) is null record;
373
374    Empty_Set : constant Set :=
375                  (Controlled with Tree => (First  => null,
376                                            Last   => null,
377                                            Root   => null,
378                                            Length => 0,
379                                            Busy   => 0,
380                                            Lock   => 0));
381
382 end Ada.Containers.Indefinite_Ordered_Sets;