annotate gcc/ada/libgnat/a-cimutr.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 -- ADA.CONTAINERS.INDEFINITE_MULTIWAY_TREES --
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 with Ada.Containers.Helpers;
kono
parents:
diff changeset
37 private with Ada.Finalization;
kono
parents:
diff changeset
38 private with Ada.Streams;
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 generic
kono
parents:
diff changeset
41 type Element_Type (<>) is private;
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 with function "=" (Left, Right : Element_Type) return Boolean is <>;
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 package Ada.Containers.Indefinite_Multiway_Trees is
kono
parents:
diff changeset
46 pragma Annotate (CodePeer, Skip_Analysis);
kono
parents:
diff changeset
47 pragma Preelaborate;
kono
parents:
diff changeset
48 pragma Remote_Types;
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 type Tree is tagged private
kono
parents:
diff changeset
51 with Constant_Indexing => Constant_Reference,
kono
parents:
diff changeset
52 Variable_Indexing => Reference,
kono
parents:
diff changeset
53 Default_Iterator => Iterate,
kono
parents:
diff changeset
54 Iterator_Element => Element_Type;
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 pragma Preelaborable_Initialization (Tree);
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 type Cursor is private;
kono
parents:
diff changeset
59 pragma Preelaborable_Initialization (Cursor);
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 Empty_Tree : constant Tree;
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 No_Element : constant Cursor;
kono
parents:
diff changeset
64 function Has_Element (Position : Cursor) return Boolean;
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 package Tree_Iterator_Interfaces is new
kono
parents:
diff changeset
67 Ada.Iterator_Interfaces (Cursor, Has_Element);
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 function Equal_Subtree
kono
parents:
diff changeset
70 (Left_Position : Cursor;
kono
parents:
diff changeset
71 Right_Position : Cursor) return Boolean;
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 function "=" (Left, Right : Tree) return Boolean;
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 function Is_Empty (Container : Tree) return Boolean;
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 function Node_Count (Container : Tree) return Count_Type;
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 function Subtree_Node_Count (Position : Cursor) return Count_Type;
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 function Depth (Position : Cursor) return Count_Type;
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 function Is_Root (Position : Cursor) return Boolean;
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 function Is_Leaf (Position : Cursor) return Boolean;
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 function Root (Container : Tree) return Cursor;
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 procedure Clear (Container : in out Tree);
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 function Element (Position : Cursor) return Element_Type;
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 procedure Replace_Element
kono
parents:
diff changeset
94 (Container : in out Tree;
kono
parents:
diff changeset
95 Position : Cursor;
kono
parents:
diff changeset
96 New_Item : Element_Type);
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 procedure Query_Element
kono
parents:
diff changeset
99 (Position : Cursor;
kono
parents:
diff changeset
100 Process : not null access procedure (Element : Element_Type));
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 procedure Update_Element
kono
parents:
diff changeset
103 (Container : in out Tree;
kono
parents:
diff changeset
104 Position : Cursor;
kono
parents:
diff changeset
105 Process : not null access procedure (Element : in out Element_Type));
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 type Constant_Reference_Type
kono
parents:
diff changeset
108 (Element : not null access constant Element_Type) is private
kono
parents:
diff changeset
109 with Implicit_Dereference => Element;
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 type Reference_Type
kono
parents:
diff changeset
112 (Element : not null access Element_Type) is private
kono
parents:
diff changeset
113 with Implicit_Dereference => Element;
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 function Constant_Reference
kono
parents:
diff changeset
116 (Container : aliased Tree;
kono
parents:
diff changeset
117 Position : Cursor) return Constant_Reference_Type;
kono
parents:
diff changeset
118 pragma Inline (Constant_Reference);
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 function Reference
kono
parents:
diff changeset
121 (Container : aliased in out Tree;
kono
parents:
diff changeset
122 Position : Cursor) return Reference_Type;
kono
parents:
diff changeset
123 pragma Inline (Reference);
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 procedure Assign (Target : in out Tree; Source : Tree);
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 function Copy (Source : Tree) return Tree;
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 procedure Move (Target : in out Tree; Source : in out Tree);
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 procedure Delete_Leaf
kono
parents:
diff changeset
132 (Container : in out Tree;
kono
parents:
diff changeset
133 Position : in out Cursor);
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 procedure Delete_Subtree
kono
parents:
diff changeset
136 (Container : in out Tree;
kono
parents:
diff changeset
137 Position : in out Cursor);
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 procedure Swap
kono
parents:
diff changeset
140 (Container : in out Tree;
kono
parents:
diff changeset
141 I, J : Cursor);
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 function Find
kono
parents:
diff changeset
144 (Container : Tree;
kono
parents:
diff changeset
145 Item : Element_Type) return Cursor;
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 -- This version of the AI:
kono
parents:
diff changeset
148 -- 10-06-02 AI05-0136-1/07
kono
parents:
diff changeset
149 -- declares Find_In_Subtree this way:
kono
parents:
diff changeset
150 --
kono
parents:
diff changeset
151 -- function Find_In_Subtree
kono
parents:
diff changeset
152 -- (Container : Tree;
kono
parents:
diff changeset
153 -- Item : Element_Type;
kono
parents:
diff changeset
154 -- Position : Cursor) return Cursor;
kono
parents:
diff changeset
155 --
kono
parents:
diff changeset
156 -- It seems that the Container parameter is there by mistake, but we need
kono
parents:
diff changeset
157 -- an official ruling from the ARG. ???
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 function Find_In_Subtree
kono
parents:
diff changeset
160 (Position : Cursor;
kono
parents:
diff changeset
161 Item : Element_Type) return Cursor;
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 -- This version of the AI:
kono
parents:
diff changeset
164 -- 10-06-02 AI05-0136-1/07
kono
parents:
diff changeset
165 -- declares Ancestor_Find this way:
kono
parents:
diff changeset
166 --
kono
parents:
diff changeset
167 -- function Ancestor_Find
kono
parents:
diff changeset
168 -- (Container : Tree;
kono
parents:
diff changeset
169 -- Item : Element_Type;
kono
parents:
diff changeset
170 -- Position : Cursor) return Cursor;
kono
parents:
diff changeset
171 --
kono
parents:
diff changeset
172 -- It seems that the Container parameter is there by mistake, but we need
kono
parents:
diff changeset
173 -- an official ruling from the ARG. ???
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 function Ancestor_Find
kono
parents:
diff changeset
176 (Position : Cursor;
kono
parents:
diff changeset
177 Item : Element_Type) return Cursor;
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 function Contains
kono
parents:
diff changeset
180 (Container : Tree;
kono
parents:
diff changeset
181 Item : Element_Type) return Boolean;
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 procedure Iterate
kono
parents:
diff changeset
184 (Container : Tree;
kono
parents:
diff changeset
185 Process : not null access procedure (Position : Cursor));
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 procedure Iterate_Subtree
kono
parents:
diff changeset
188 (Position : Cursor;
kono
parents:
diff changeset
189 Process : not null access procedure (Position : Cursor));
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 function Iterate (Container : Tree)
kono
parents:
diff changeset
192 return Tree_Iterator_Interfaces.Forward_Iterator'Class;
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 function Iterate_Subtree (Position : Cursor)
kono
parents:
diff changeset
195 return Tree_Iterator_Interfaces.Forward_Iterator'Class;
kono
parents:
diff changeset
196
kono
parents:
diff changeset
197 function Iterate_Children
kono
parents:
diff changeset
198 (Container : Tree;
kono
parents:
diff changeset
199 Parent : Cursor)
kono
parents:
diff changeset
200 return Tree_Iterator_Interfaces.Reversible_Iterator'Class;
kono
parents:
diff changeset
201
kono
parents:
diff changeset
202 function Child_Count (Parent : Cursor) return Count_Type;
kono
parents:
diff changeset
203
kono
parents:
diff changeset
204 function Child_Depth (Parent, Child : Cursor) return Count_Type;
kono
parents:
diff changeset
205
kono
parents:
diff changeset
206 procedure Insert_Child
kono
parents:
diff changeset
207 (Container : in out Tree;
kono
parents:
diff changeset
208 Parent : Cursor;
kono
parents:
diff changeset
209 Before : Cursor;
kono
parents:
diff changeset
210 New_Item : Element_Type;
kono
parents:
diff changeset
211 Count : Count_Type := 1);
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 procedure Insert_Child
kono
parents:
diff changeset
214 (Container : in out Tree;
kono
parents:
diff changeset
215 Parent : Cursor;
kono
parents:
diff changeset
216 Before : Cursor;
kono
parents:
diff changeset
217 New_Item : Element_Type;
kono
parents:
diff changeset
218 Position : out Cursor;
kono
parents:
diff changeset
219 Count : Count_Type := 1);
kono
parents:
diff changeset
220
kono
parents:
diff changeset
221 procedure Prepend_Child
kono
parents:
diff changeset
222 (Container : in out Tree;
kono
parents:
diff changeset
223 Parent : Cursor;
kono
parents:
diff changeset
224 New_Item : Element_Type;
kono
parents:
diff changeset
225 Count : Count_Type := 1);
kono
parents:
diff changeset
226
kono
parents:
diff changeset
227 procedure Append_Child
kono
parents:
diff changeset
228 (Container : in out Tree;
kono
parents:
diff changeset
229 Parent : Cursor;
kono
parents:
diff changeset
230 New_Item : Element_Type;
kono
parents:
diff changeset
231 Count : Count_Type := 1);
kono
parents:
diff changeset
232
kono
parents:
diff changeset
233 procedure Delete_Children
kono
parents:
diff changeset
234 (Container : in out Tree;
kono
parents:
diff changeset
235 Parent : Cursor);
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 procedure Copy_Subtree
kono
parents:
diff changeset
238 (Target : in out Tree;
kono
parents:
diff changeset
239 Parent : Cursor;
kono
parents:
diff changeset
240 Before : Cursor;
kono
parents:
diff changeset
241 Source : Cursor);
kono
parents:
diff changeset
242
kono
parents:
diff changeset
243 procedure Splice_Subtree
kono
parents:
diff changeset
244 (Target : in out Tree;
kono
parents:
diff changeset
245 Parent : Cursor;
kono
parents:
diff changeset
246 Before : Cursor;
kono
parents:
diff changeset
247 Source : in out Tree;
kono
parents:
diff changeset
248 Position : in out Cursor);
kono
parents:
diff changeset
249
kono
parents:
diff changeset
250 procedure Splice_Subtree
kono
parents:
diff changeset
251 (Container : in out Tree;
kono
parents:
diff changeset
252 Parent : Cursor;
kono
parents:
diff changeset
253 Before : Cursor;
kono
parents:
diff changeset
254 Position : Cursor);
kono
parents:
diff changeset
255
kono
parents:
diff changeset
256 procedure Splice_Children
kono
parents:
diff changeset
257 (Target : in out Tree;
kono
parents:
diff changeset
258 Target_Parent : Cursor;
kono
parents:
diff changeset
259 Before : Cursor;
kono
parents:
diff changeset
260 Source : in out Tree;
kono
parents:
diff changeset
261 Source_Parent : Cursor);
kono
parents:
diff changeset
262
kono
parents:
diff changeset
263 procedure Splice_Children
kono
parents:
diff changeset
264 (Container : in out Tree;
kono
parents:
diff changeset
265 Target_Parent : Cursor;
kono
parents:
diff changeset
266 Before : Cursor;
kono
parents:
diff changeset
267 Source_Parent : Cursor);
kono
parents:
diff changeset
268
kono
parents:
diff changeset
269 function Parent (Position : Cursor) return Cursor;
kono
parents:
diff changeset
270
kono
parents:
diff changeset
271 function First_Child (Parent : Cursor) return Cursor;
kono
parents:
diff changeset
272
kono
parents:
diff changeset
273 function First_Child_Element (Parent : Cursor) return Element_Type;
kono
parents:
diff changeset
274
kono
parents:
diff changeset
275 function Last_Child (Parent : Cursor) return Cursor;
kono
parents:
diff changeset
276
kono
parents:
diff changeset
277 function Last_Child_Element (Parent : Cursor) return Element_Type;
kono
parents:
diff changeset
278
kono
parents:
diff changeset
279 function Next_Sibling (Position : Cursor) return Cursor;
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 function Previous_Sibling (Position : Cursor) return Cursor;
kono
parents:
diff changeset
282
kono
parents:
diff changeset
283 procedure Next_Sibling (Position : in out Cursor);
kono
parents:
diff changeset
284
kono
parents:
diff changeset
285 procedure Previous_Sibling (Position : in out Cursor);
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 -- This version of the AI:
kono
parents:
diff changeset
288 -- 10-06-02 AI05-0136-1/07
kono
parents:
diff changeset
289 -- declares Iterate_Children this way:
kono
parents:
diff changeset
290 --
kono
parents:
diff changeset
291 -- procedure Iterate_Children
kono
parents:
diff changeset
292 -- (Container : Tree;
kono
parents:
diff changeset
293 -- Parent : Cursor;
kono
parents:
diff changeset
294 -- Process : not null access procedure (Position : Cursor));
kono
parents:
diff changeset
295 --
kono
parents:
diff changeset
296 -- It seems that the Container parameter is there by mistake, but we need
kono
parents:
diff changeset
297 -- an official ruling from the ARG. ???
kono
parents:
diff changeset
298
kono
parents:
diff changeset
299 procedure Iterate_Children
kono
parents:
diff changeset
300 (Parent : Cursor;
kono
parents:
diff changeset
301 Process : not null access procedure (Position : Cursor));
kono
parents:
diff changeset
302
kono
parents:
diff changeset
303 procedure Reverse_Iterate_Children
kono
parents:
diff changeset
304 (Parent : Cursor;
kono
parents:
diff changeset
305 Process : not null access procedure (Position : Cursor));
kono
parents:
diff changeset
306
kono
parents:
diff changeset
307 private
kono
parents:
diff changeset
308
kono
parents:
diff changeset
309 use Ada.Containers.Helpers;
kono
parents:
diff changeset
310 package Implementation is new Generic_Implementation;
kono
parents:
diff changeset
311 use Implementation;
kono
parents:
diff changeset
312
kono
parents:
diff changeset
313 type Tree_Node_Type;
kono
parents:
diff changeset
314 type Tree_Node_Access is access all Tree_Node_Type;
kono
parents:
diff changeset
315
kono
parents:
diff changeset
316 type Children_Type is record
kono
parents:
diff changeset
317 First : Tree_Node_Access;
kono
parents:
diff changeset
318 Last : Tree_Node_Access;
kono
parents:
diff changeset
319 end record;
kono
parents:
diff changeset
320
kono
parents:
diff changeset
321 type Element_Access is access all Element_Type;
kono
parents:
diff changeset
322
kono
parents:
diff changeset
323 type Tree_Node_Type is record
kono
parents:
diff changeset
324 Parent : Tree_Node_Access;
kono
parents:
diff changeset
325 Prev : Tree_Node_Access;
kono
parents:
diff changeset
326 Next : Tree_Node_Access;
kono
parents:
diff changeset
327 Children : Children_Type;
kono
parents:
diff changeset
328 Element : Element_Access;
kono
parents:
diff changeset
329 end record;
kono
parents:
diff changeset
330
kono
parents:
diff changeset
331 use Ada.Finalization;
kono
parents:
diff changeset
332
kono
parents:
diff changeset
333 -- The Count component of type Tree represents the number of nodes that
kono
parents:
diff changeset
334 -- have been (dynamically) allocated. It does not include the root node
kono
parents:
diff changeset
335 -- itself. As implementors, we decide to cache this value, so that the
kono
parents:
diff changeset
336 -- selector function Node_Count can execute in O(1) time, in order to be
kono
parents:
diff changeset
337 -- consistent with the behavior of the Length selector function for other
kono
parents:
diff changeset
338 -- standard container library units. This does mean, however, that the
kono
parents:
diff changeset
339 -- two-container forms for Splice_XXX (that move subtrees across tree
kono
parents:
diff changeset
340 -- containers) will execute in O(n) time, because we must count the number
kono
parents:
diff changeset
341 -- of nodes in the subtree(s) that get moved. (We resolve the tension
kono
parents:
diff changeset
342 -- between Node_Count and Splice_XXX in favor of Node_Count, under the
kono
parents:
diff changeset
343 -- assumption that Node_Count is the more common operation).
kono
parents:
diff changeset
344
kono
parents:
diff changeset
345 type Tree is new Controlled with record
kono
parents:
diff changeset
346 Root : aliased Tree_Node_Type;
kono
parents:
diff changeset
347 TC : aliased Tamper_Counts;
kono
parents:
diff changeset
348 Count : Count_Type := 0;
kono
parents:
diff changeset
349 end record;
kono
parents:
diff changeset
350
kono
parents:
diff changeset
351 overriding procedure Adjust (Container : in out Tree);
kono
parents:
diff changeset
352
kono
parents:
diff changeset
353 overriding procedure Finalize (Container : in out Tree) renames Clear;
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 use Ada.Streams;
kono
parents:
diff changeset
356
kono
parents:
diff changeset
357 procedure Write
kono
parents:
diff changeset
358 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
359 Container : Tree);
kono
parents:
diff changeset
360
kono
parents:
diff changeset
361 for Tree'Write use Write;
kono
parents:
diff changeset
362
kono
parents:
diff changeset
363 procedure Read
kono
parents:
diff changeset
364 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
365 Container : out Tree);
kono
parents:
diff changeset
366
kono
parents:
diff changeset
367 for Tree'Read use Read;
kono
parents:
diff changeset
368
kono
parents:
diff changeset
369 type Tree_Access is access all Tree;
kono
parents:
diff changeset
370 for Tree_Access'Storage_Size use 0;
kono
parents:
diff changeset
371
kono
parents:
diff changeset
372 type Cursor is record
kono
parents:
diff changeset
373 Container : Tree_Access;
kono
parents:
diff changeset
374 Node : Tree_Node_Access;
kono
parents:
diff changeset
375 end record;
kono
parents:
diff changeset
376
kono
parents:
diff changeset
377 procedure Write
kono
parents:
diff changeset
378 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
379 Position : Cursor);
kono
parents:
diff changeset
380
kono
parents:
diff changeset
381 for Cursor'Write use Write;
kono
parents:
diff changeset
382
kono
parents:
diff changeset
383 procedure Read
kono
parents:
diff changeset
384 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
385 Position : out Cursor);
kono
parents:
diff changeset
386
kono
parents:
diff changeset
387 for Cursor'Read use Read;
kono
parents:
diff changeset
388
kono
parents:
diff changeset
389 subtype Reference_Control_Type is Implementation.Reference_Control_Type;
kono
parents:
diff changeset
390 -- It is necessary to rename this here, so that the compiler can find it
kono
parents:
diff changeset
391
kono
parents:
diff changeset
392 type Constant_Reference_Type
kono
parents:
diff changeset
393 (Element : not null access constant Element_Type) is
kono
parents:
diff changeset
394 record
kono
parents:
diff changeset
395 Control : Reference_Control_Type :=
kono
parents:
diff changeset
396 raise Program_Error with "uninitialized reference";
kono
parents:
diff changeset
397 -- The RM says, "The default initialization of an object of
kono
parents:
diff changeset
398 -- type Constant_Reference_Type or Reference_Type propagates
kono
parents:
diff changeset
399 -- Program_Error."
kono
parents:
diff changeset
400 end record;
kono
parents:
diff changeset
401
kono
parents:
diff changeset
402 procedure Read
kono
parents:
diff changeset
403 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
404 Item : out Constant_Reference_Type);
kono
parents:
diff changeset
405
kono
parents:
diff changeset
406 for Constant_Reference_Type'Read use Read;
kono
parents:
diff changeset
407
kono
parents:
diff changeset
408 procedure Write
kono
parents:
diff changeset
409 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
410 Item : Constant_Reference_Type);
kono
parents:
diff changeset
411
kono
parents:
diff changeset
412 for Constant_Reference_Type'Write use Write;
kono
parents:
diff changeset
413
kono
parents:
diff changeset
414 type Reference_Type
kono
parents:
diff changeset
415 (Element : not null access Element_Type) is
kono
parents:
diff changeset
416 record
kono
parents:
diff changeset
417 Control : Reference_Control_Type :=
kono
parents:
diff changeset
418 raise Program_Error with "uninitialized reference";
kono
parents:
diff changeset
419 -- The RM says, "The default initialization of an object of
kono
parents:
diff changeset
420 -- type Constant_Reference_Type or Reference_Type propagates
kono
parents:
diff changeset
421 -- Program_Error."
kono
parents:
diff changeset
422 end record;
kono
parents:
diff changeset
423
kono
parents:
diff changeset
424 procedure Read
kono
parents:
diff changeset
425 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
426 Item : out Reference_Type);
kono
parents:
diff changeset
427
kono
parents:
diff changeset
428 for Reference_Type'Read use Read;
kono
parents:
diff changeset
429
kono
parents:
diff changeset
430 procedure Write
kono
parents:
diff changeset
431 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
432 Item : Reference_Type);
kono
parents:
diff changeset
433
kono
parents:
diff changeset
434 for Reference_Type'Write use Write;
kono
parents:
diff changeset
435
kono
parents:
diff changeset
436 -- Three operations are used to optimize in the expansion of "for ... of"
kono
parents:
diff changeset
437 -- loops: the Next(Cursor) procedure in the visible part, and the following
kono
parents:
diff changeset
438 -- Pseudo_Reference and Get_Element_Access functions. See Exp_Ch5 for
kono
parents:
diff changeset
439 -- details.
kono
parents:
diff changeset
440
kono
parents:
diff changeset
441 function Pseudo_Reference
kono
parents:
diff changeset
442 (Container : aliased Tree'Class) return Reference_Control_Type;
kono
parents:
diff changeset
443 pragma Inline (Pseudo_Reference);
kono
parents:
diff changeset
444 -- Creates an object of type Reference_Control_Type pointing to the
kono
parents:
diff changeset
445 -- container, and increments the Lock. Finalization of this object will
kono
parents:
diff changeset
446 -- decrement the Lock.
kono
parents:
diff changeset
447
kono
parents:
diff changeset
448 function Get_Element_Access
kono
parents:
diff changeset
449 (Position : Cursor) return not null Element_Access;
kono
parents:
diff changeset
450 -- Returns a pointer to the element designated by Position.
kono
parents:
diff changeset
451
kono
parents:
diff changeset
452 Empty_Tree : constant Tree := (Controlled with others => <>);
kono
parents:
diff changeset
453
kono
parents:
diff changeset
454 No_Element : constant Cursor := (others => <>);
kono
parents:
diff changeset
455
kono
parents:
diff changeset
456 end Ada.Containers.Indefinite_Multiway_Trees;