* config/rs6000/aix61.h (TARGET_DEFAULT): Add MASK_PPC_GPOPT,
[official-gcc.git] / gcc / ada / a-cfdlli.ads
blob67ff3af8f4826ef070e950d5fdb368540874a5cd
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT LIBRARY COMPONENTS --
4 -- --
5 -- ADA.CONTAINERS.FORMAL_DOUBLY_LINKED_LISTS --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2004-2012, 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 ------------------------------------------------------------------------------
32 -- This spec is derived from Ada.Containers.Bounded_Doubly_Linked_Lists in the
33 -- Ada 2012 RM. The modifications are to facilitate formal proofs by making it
34 -- easier to express properties.
36 -- The modifications are:
38 -- A parameter for the container is added to every function reading the
39 -- contents of a container: Next, Previous, Query_Element, Has_Element,
40 -- Iterate, Reverse_Iterate, Element. This change is motivated by the need
41 -- to have cursors which are valid on different containers (typically a
42 -- container C and its previous version C'Old) for expressing properties,
43 -- which is not possible if cursors encapsulate an access to the underlying
44 -- container.
46 -- There are three new functions:
48 -- function Strict_Equal (Left, Right : List) return Boolean;
49 -- function Left (Container : List; Position : Cursor) return List;
50 -- function Right (Container : List; Position : Cursor) return List;
52 -- See detailed specifications for these subprograms
54 private with Ada.Streams;
55 with Ada.Containers;
56 with Ada.Iterator_Interfaces;
58 generic
59 type Element_Type is private;
61 with function "=" (Left, Right : Element_Type)
62 return Boolean is <>;
64 package Ada.Containers.Formal_Doubly_Linked_Lists is
65 pragma Pure;
67 type List (Capacity : Count_Type) is tagged private with
68 Constant_Indexing => Constant_Reference,
69 Default_Iterator => Iterate,
70 Iterator_Element => Element_Type;
71 -- pragma Preelaborable_Initialization (List);
73 type Cursor is private;
74 pragma Preelaborable_Initialization (Cursor);
76 Empty_List : constant List;
78 No_Element : constant Cursor;
80 function Not_No_Element (Position : Cursor) return Boolean;
82 package List_Iterator_Interfaces is new
83 Ada.Iterator_Interfaces (Cursor => Cursor, Has_Element => Not_No_Element);
85 function Iterate (Container : List; Start : Cursor)
86 return List_Iterator_Interfaces.Reversible_Iterator'Class;
88 function Iterate (Container : List)
89 return List_Iterator_Interfaces.Reversible_Iterator'Class;
91 function "=" (Left, Right : List) return Boolean;
93 function Length (Container : List) return Count_Type;
95 function Is_Empty (Container : List) return Boolean;
97 procedure Clear (Container : in out List);
99 procedure Assign (Target : in out List; Source : List);
101 function Copy (Source : List; Capacity : Count_Type := 0) return List;
103 function Element (Container : List; Position : Cursor) return Element_Type;
105 procedure Replace_Element
106 (Container : in out List;
107 Position : Cursor;
108 New_Item : Element_Type);
110 procedure Query_Element
111 (Container : List; Position : Cursor;
112 Process : not null access procedure (Element : Element_Type));
114 procedure Update_Element
115 (Container : in out List;
116 Position : Cursor;
117 Process : not null access procedure (Element : in out Element_Type));
119 procedure Move (Target : in out List; Source : in out List);
121 procedure Insert
122 (Container : in out List;
123 Before : Cursor;
124 New_Item : Element_Type;
125 Count : Count_Type := 1);
127 procedure Insert
128 (Container : in out List;
129 Before : Cursor;
130 New_Item : Element_Type;
131 Position : out Cursor;
132 Count : Count_Type := 1);
134 procedure Insert
135 (Container : in out List;
136 Before : Cursor;
137 Position : out Cursor;
138 Count : Count_Type := 1);
140 procedure Prepend
141 (Container : in out List;
142 New_Item : Element_Type;
143 Count : Count_Type := 1);
145 procedure Append
146 (Container : in out List;
147 New_Item : Element_Type;
148 Count : Count_Type := 1);
150 procedure Delete
151 (Container : in out List;
152 Position : in out Cursor;
153 Count : Count_Type := 1);
155 procedure Delete_First
156 (Container : in out List;
157 Count : Count_Type := 1);
159 procedure Delete_Last
160 (Container : in out List;
161 Count : Count_Type := 1);
163 procedure Reverse_Elements (Container : in out List);
165 procedure Swap
166 (Container : in out List;
167 I, J : Cursor);
169 procedure Swap_Links
170 (Container : in out List;
171 I, J : Cursor);
173 procedure Splice
174 (Target : in out List;
175 Before : Cursor;
176 Source : in out List);
178 procedure Splice
179 (Target : in out List;
180 Before : Cursor;
181 Source : in out List;
182 Position : in out Cursor);
184 procedure Splice
185 (Container : in out List;
186 Before : Cursor;
187 Position : Cursor);
189 function First (Container : List) return Cursor;
191 function First_Element (Container : List) return Element_Type;
193 function Last (Container : List) return Cursor;
195 function Last_Element (Container : List) return Element_Type;
197 function Next (Container : List; Position : Cursor) return Cursor;
199 procedure Next (Container : List; Position : in out Cursor);
201 function Previous (Container : List; Position : Cursor) return Cursor;
203 procedure Previous (Container : List; Position : in out Cursor);
205 function Find
206 (Container : List;
207 Item : Element_Type;
208 Position : Cursor := No_Element) return Cursor;
210 function Reverse_Find
211 (Container : List;
212 Item : Element_Type;
213 Position : Cursor := No_Element) return Cursor;
215 function Contains
216 (Container : List;
217 Item : Element_Type) return Boolean;
219 function Has_Element (Container : List; Position : Cursor) return Boolean;
221 procedure Iterate
222 (Container : List;
223 Process :
224 not null access procedure (Container : List; Position : Cursor));
226 procedure Reverse_Iterate
227 (Container : List;
228 Process :
229 not null access procedure (Container : List; Position : Cursor));
231 generic
232 with function "<" (Left, Right : Element_Type) return Boolean is <>;
233 package Generic_Sorting is
235 function Is_Sorted (Container : List) return Boolean;
237 procedure Sort (Container : in out List);
239 procedure Merge (Target, Source : in out List);
241 end Generic_Sorting;
243 type Constant_Reference_Type
244 (Element : not null access constant Element_Type) is private
245 with
246 Implicit_Dereference => Element;
248 function Constant_Reference
249 (Container : List; -- SHOULD BE ALIASED ???
250 Position : Cursor) return Constant_Reference_Type;
252 function Strict_Equal (Left, Right : List) return Boolean;
253 -- Strict_Equal returns True if the containers are physically equal, i.e.
254 -- they are structurally equal (function "=" returns True) and that they
255 -- have the same set of cursors.
257 function Left (Container : List; Position : Cursor) return List;
258 function Right (Container : List; Position : Cursor) return List;
259 -- Left returns a container containing all elements preceding Position
260 -- (excluded) in Container. Right returns a container containing all
261 -- elements following Position (included) in Container. These two new
262 -- functions can be used to express invariant properties in loops which
263 -- iterate over containers. Left returns the part of the container already
264 -- scanned and Right the part not scanned yet.
266 private
268 type Node_Type is record
269 Prev : Count_Type'Base := -1;
270 Next : Count_Type;
271 Element : aliased Element_Type;
272 end record;
274 function "=" (L, R : Node_Type) return Boolean is abstract;
276 type Node_Array is array (Count_Type range <>) of Node_Type;
277 function "=" (L, R : Node_Array) return Boolean is abstract;
279 type List (Capacity : Count_Type) is tagged record
280 Nodes : Node_Array (1 .. Capacity) := (others => <>);
281 Free : Count_Type'Base := -1;
282 Busy : Natural := 0;
283 Lock : Natural := 0;
284 Length : Count_Type := 0;
285 First : Count_Type := 0;
286 Last : Count_Type := 0;
287 end record;
289 use Ada.Streams;
291 procedure Read
292 (Stream : not null access Root_Stream_Type'Class;
293 Item : out List);
295 for List'Read use Read;
297 procedure Write
298 (Stream : not null access Root_Stream_Type'Class;
299 Item : List);
301 for List'Write use Write;
303 type List_Access is access all List;
304 for List_Access'Storage_Size use 0;
306 type Cursor is record
307 Node : Count_Type := 0;
308 end record;
310 type Constant_Reference_Type
311 (Element : not null access constant Element_Type) is null record;
313 procedure Read
314 (Stream : not null access Root_Stream_Type'Class;
315 Item : out Cursor);
317 for Cursor'Read use Read;
319 procedure Write
320 (Stream : not null access Root_Stream_Type'Class;
321 Item : Cursor);
323 for Cursor'Write use Write;
325 Empty_List : constant List := (0, others => <>);
327 No_Element : constant Cursor := (Node => 0);
329 end Ada.Containers.Formal_Doubly_Linked_Lists;