cfgexpand: Expand comment on when non-var clobbers can show up
[official-gcc.git] / gcc / ada / libgnat / a-cidlli.ads
blobd1df98b16021d080f3e6af86483a420a37ede9c3
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT LIBRARY COMPONENTS --
4 -- --
5 -- ADA.CONTAINERS.INDEFINITE_DOUBLY_LINKED_LISTS --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2004-2024, 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 with Ada.Containers.Helpers;
37 private with Ada.Finalization;
38 private with Ada.Streams;
39 private with Ada.Strings.Text_Buffers;
41 generic
42 type Element_Type (<>) is private;
44 with function "=" (Left, Right : Element_Type)
45 return Boolean is <>;
47 package Ada.Containers.Indefinite_Doubly_Linked_Lists with
48 SPARK_Mode => Off
50 pragma Annotate (CodePeer, Skip_Analysis);
51 pragma Preelaborate;
52 pragma Remote_Types;
54 type List is tagged private with
55 Constant_Indexing => Constant_Reference,
56 Variable_Indexing => Reference,
57 Default_Iterator => Iterate,
58 Iterator_Element => Element_Type,
59 Aggregate => (Empty => Empty,
60 Add_Unnamed => Append);
62 pragma Preelaborable_Initialization (List);
64 type Cursor is private;
65 pragma Preelaborable_Initialization (Cursor);
67 Empty_List : constant List;
69 function Empty return List;
70 pragma Ada_2022 (Empty);
72 No_Element : constant Cursor;
74 function Has_Element (Position : Cursor) return Boolean;
76 package List_Iterator_Interfaces is new
77 Ada.Iterator_Interfaces (Cursor, Has_Element);
79 function "=" (Left, Right : List) return Boolean;
81 function Length (Container : List) return Count_Type;
83 function Is_Empty (Container : List) return Boolean;
85 procedure Clear (Container : in out List);
87 function Element (Position : Cursor) return Element_Type;
89 procedure Replace_Element
90 (Container : in out List;
91 Position : Cursor;
92 New_Item : Element_Type);
94 procedure Query_Element
95 (Position : Cursor;
96 Process : not null access procedure (Element : Element_Type));
98 procedure Update_Element
99 (Container : in out List;
100 Position : Cursor;
101 Process : not null access procedure (Element : in out Element_Type));
103 type Constant_Reference_Type
104 (Element : not null access constant Element_Type) is private
105 with
106 Implicit_Dereference => Element;
108 type Reference_Type
109 (Element : not null access Element_Type) is private
110 with
111 Implicit_Dereference => Element;
113 function Constant_Reference
114 (Container : aliased List;
115 Position : Cursor) return Constant_Reference_Type;
116 pragma Inline (Constant_Reference);
118 function Reference
119 (Container : aliased in out List;
120 Position : Cursor) return Reference_Type;
121 pragma Inline (Reference);
123 procedure Assign (Target : in out List; Source : List);
125 function Copy (Source : List) return List;
127 procedure Move
128 (Target : in out List;
129 Source : in out List);
131 procedure Insert
132 (Container : in out List;
133 Before : Cursor;
134 New_Item : Element_Type;
135 Count : Count_Type := 1);
137 procedure Insert
138 (Container : in out List;
139 Before : Cursor;
140 New_Item : Element_Type;
141 Position : out Cursor;
142 Count : Count_Type := 1);
144 procedure Prepend
145 (Container : in out List;
146 New_Item : Element_Type;
147 Count : Count_Type := 1);
149 procedure Append
150 (Container : in out List;
151 New_Item : Element_Type;
152 Count : Count_Type);
154 procedure Append
155 (Container : in out List;
156 New_Item : Element_Type);
158 procedure Delete
159 (Container : in out List;
160 Position : in out Cursor;
161 Count : Count_Type := 1);
163 procedure Delete_First
164 (Container : in out List;
165 Count : Count_Type := 1);
167 procedure Delete_Last
168 (Container : in out List;
169 Count : Count_Type := 1);
171 procedure Reverse_Elements (Container : in out List);
173 procedure Swap (Container : in out List; I, J : Cursor);
175 procedure Swap_Links (Container : in out List; I, J : Cursor);
177 procedure Splice
178 (Target : in out List;
179 Before : Cursor;
180 Source : in out List);
182 procedure Splice
183 (Target : in out List;
184 Before : Cursor;
185 Source : in out List;
186 Position : in out Cursor);
188 procedure Splice
189 (Container : in out List;
190 Before : Cursor;
191 Position : Cursor);
193 function First (Container : List) return Cursor;
195 function First_Element (Container : List) return Element_Type;
197 function Last (Container : List) return Cursor;
199 function Last_Element (Container : List) return Element_Type;
201 function Next (Position : Cursor) return Cursor;
203 procedure Next (Position : in out Cursor);
205 function Previous (Position : Cursor) return Cursor;
207 procedure Previous (Position : in out Cursor);
209 function Find
210 (Container : List;
211 Item : Element_Type;
212 Position : Cursor := No_Element) return Cursor;
214 function Reverse_Find
215 (Container : List;
216 Item : Element_Type;
217 Position : Cursor := No_Element) return Cursor;
219 function Contains
220 (Container : List;
221 Item : Element_Type) return Boolean;
223 procedure Iterate
224 (Container : List;
225 Process : not null access procedure (Position : Cursor));
227 procedure Reverse_Iterate
228 (Container : List;
229 Process : not null access procedure (Position : Cursor));
231 function Iterate
232 (Container : List)
233 return List_Iterator_Interfaces.Reversible_Iterator'class;
235 function Iterate
236 (Container : List;
237 Start : Cursor)
238 return List_Iterator_Interfaces.Reversible_Iterator'class;
240 generic
241 with function "<" (Left, Right : Element_Type) return Boolean is <>;
242 package Generic_Sorting is
244 function Is_Sorted (Container : List) return Boolean;
246 procedure Sort (Container : in out List);
248 procedure Merge (Target, Source : in out List);
250 end Generic_Sorting;
252 private
254 pragma Inline (Next);
255 pragma Inline (Previous);
257 use Ada.Containers.Helpers;
258 package Implementation is new Generic_Implementation;
259 use Implementation;
261 type Node_Type;
262 type Node_Access is access Node_Type;
264 type Element_Access is access all Element_Type;
266 type Node_Type is
267 limited record
268 Element : Element_Access;
269 Next : Node_Access;
270 Prev : Node_Access;
271 end record;
273 use Ada.Finalization;
274 use Ada.Streams;
276 type List is
277 new Controlled with record
278 First : Node_Access := null;
279 Last : Node_Access := null;
280 Length : Count_Type := 0;
281 TC : aliased Tamper_Counts;
282 end record with Put_Image => Put_Image;
284 procedure Put_Image
285 (S : in out Ada.Strings.Text_Buffers.Root_Buffer_Type'Class; V : List);
287 overriding procedure Adjust (Container : in out List);
289 overriding procedure Finalize (Container : in out List) renames Clear;
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
307 record
308 Container : List_Access;
309 Node : Node_Access;
310 end record;
312 procedure Read
313 (Stream : not null access Root_Stream_Type'Class;
314 Item : out Cursor);
316 for Cursor'Read use Read;
318 procedure Write
319 (Stream : not null access Root_Stream_Type'Class;
320 Item : Cursor);
322 for Cursor'Write use Write;
324 subtype Reference_Control_Type is Implementation.Reference_Control_Type;
325 -- It is necessary to rename this here, so that the compiler can find it
327 type Constant_Reference_Type
328 (Element : not null access constant Element_Type) is
329 record
330 Control : Reference_Control_Type :=
331 raise Program_Error with "uninitialized reference";
332 -- The RM says, "The default initialization of an object of
333 -- type Constant_Reference_Type or Reference_Type propagates
334 -- Program_Error."
335 end record;
337 procedure Write
338 (Stream : not null access Root_Stream_Type'Class;
339 Item : Constant_Reference_Type);
341 for Constant_Reference_Type'Write use Write;
343 procedure Read
344 (Stream : not null access Root_Stream_Type'Class;
345 Item : out Constant_Reference_Type);
347 for Constant_Reference_Type'Read use Read;
349 type Reference_Type
350 (Element : not null access Element_Type) is
351 record
352 Control : Reference_Control_Type :=
353 raise Program_Error with "uninitialized reference";
354 -- The RM says, "The default initialization of an object of
355 -- type Constant_Reference_Type or Reference_Type propagates
356 -- Program_Error."
357 end record;
359 procedure Write
360 (Stream : not null access Root_Stream_Type'Class;
361 Item : Reference_Type);
363 for Reference_Type'Write use Write;
365 procedure Read
366 (Stream : not null access Root_Stream_Type'Class;
367 Item : out Reference_Type);
369 for Reference_Type'Read use Read;
371 -- See Ada.Containers.Vectors for documentation on the following
373 procedure _Next (Position : in out Cursor) renames Next;
374 procedure _Previous (Position : in out Cursor) renames Previous;
376 function Pseudo_Reference
377 (Container : aliased List'Class) return Reference_Control_Type;
378 pragma Inline (Pseudo_Reference);
379 -- Creates an object of type Reference_Control_Type pointing to the
380 -- container, and increments the Lock. Finalization of this object will
381 -- decrement the Lock.
383 function Get_Element_Access
384 (Position : Cursor) return not null Element_Access;
385 -- Returns a pointer to the element designated by Position.
387 Empty_List : constant List := List'(Controlled with others => <>);
388 function Empty return List is (Empty_List);
390 No_Element : constant Cursor := Cursor'(null, null);
392 type Iterator is new Limited_Controlled and
393 List_Iterator_Interfaces.Reversible_Iterator with
394 record
395 Container : List_Access;
396 Node : Node_Access;
397 end record
398 with Disable_Controlled => not T_Check;
400 overriding procedure Finalize (Object : in out Iterator);
402 overriding function First (Object : Iterator) return Cursor;
403 overriding function Last (Object : Iterator) return Cursor;
405 overriding function Next
406 (Object : Iterator;
407 Position : Cursor) return Cursor;
409 overriding function Previous
410 (Object : Iterator;
411 Position : Cursor) return Cursor;
413 end Ada.Containers.Indefinite_Doubly_Linked_Lists;