c++: remove some xfails
[official-gcc.git] / gcc / ada / nlists.ads
blob3c3d6004ea54ec9b8c12f85db3356ab6487ad9c9
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- N L I S T S --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2022, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 -- This package provides facilities for manipulating lists of nodes (see
27 -- package Atree for format and implementation of tree nodes). The Link field
28 -- of the nodes is used as the forward pointer for these lists. See also
29 -- package Elists which provides another form of lists that are not threaded
30 -- through the nodes (and therefore allow nodes to be on multiple lists).
32 -- WARNING: There is a C version of this package. Any changes to this
33 -- source file must be properly reflected in the C header file nlists.h
35 with System;
36 with Types; use Types;
38 package Nlists is
40 -- A node list is a list of nodes in a special format that means that
41 -- nodes can be on at most one such list. For each node list, a list
42 -- header is allocated in the lists table, and a List_Id value references
43 -- this header, which may be used to access the nodes in the list using
44 -- the set of routines that define this interface.
46 -- Note: node lists can contain either nodes or entities (extended nodes)
47 -- or a mixture of nodes and extended nodes.
49 function In_Same_List (N1, N2 : Node_Or_Entity_Id) return Boolean;
50 pragma Inline (In_Same_List);
51 -- Equivalent to List_Containing (N1) = List_Containing (N2)
53 function Last_List_Id return List_Id;
54 pragma Inline (Last_List_Id);
55 -- Returns Id of last allocated list header
57 function Lists_Address return System.Address;
58 pragma Inline (Lists_Address);
59 -- Return address of Lists table (used in Back_End for Gigi call)
61 function Num_Lists return Nat;
62 pragma Inline (Num_Lists);
63 -- Number of currently allocated lists
65 function New_List return List_Id;
66 -- Creates a new empty node list. Typically this is used to initialize
67 -- a field in some other node which points to a node list where the list
68 -- is then subsequently filled in using Append calls.
70 function Empty_List return List_Id renames New_List;
71 -- Used in contexts where an empty list (as opposed to an initially empty
72 -- list to be filled in) is required.
74 function New_List
75 (Node : Node_Or_Entity_Id) return List_Id;
76 -- Build a new list initially containing the given node
78 function New_List
79 (Node1 : Node_Or_Entity_Id;
80 Node2 : Node_Or_Entity_Id) return List_Id;
81 -- Build a new list initially containing the two given nodes
83 function New_List
84 (Node1 : Node_Or_Entity_Id;
85 Node2 : Node_Or_Entity_Id;
86 Node3 : Node_Or_Entity_Id) return List_Id;
87 -- Build a new list initially containing the three given nodes
89 function New_List
90 (Node1 : Node_Or_Entity_Id;
91 Node2 : Node_Or_Entity_Id;
92 Node3 : Node_Or_Entity_Id;
93 Node4 : Node_Or_Entity_Id) return List_Id;
95 function New_List
96 (Node1 : Node_Or_Entity_Id;
97 Node2 : Node_Or_Entity_Id;
98 Node3 : Node_Or_Entity_Id;
99 Node4 : Node_Or_Entity_Id;
100 Node5 : Node_Or_Entity_Id) return List_Id;
101 -- Build a new list initially containing the five given nodes
103 function New_List
104 (Node1 : Node_Or_Entity_Id;
105 Node2 : Node_Or_Entity_Id;
106 Node3 : Node_Or_Entity_Id;
107 Node4 : Node_Or_Entity_Id;
108 Node5 : Node_Or_Entity_Id;
109 Node6 : Node_Or_Entity_Id) return List_Id;
110 -- Build a new list initially containing the six given nodes
112 function New_Copy_List (List : List_Id) return List_Id;
113 -- Creates a new list containing copies (made with Atree.New_Copy) of every
114 -- node in the original list. If the argument is No_List, then the returned
115 -- result is No_List. If the argument is an empty list, then the returned
116 -- result is a new empty list.
118 function New_Copy_List_Original (List : List_Id) return List_Id;
119 -- Same as New_Copy_List but copies only nodes coming from source
121 function First (List : List_Id) return Node_Or_Entity_Id;
122 pragma Inline (First);
123 -- Obtains the first element of the given node list or, if the node list
124 -- has no items or is equal to No_List, then Empty is returned.
126 function First_Non_Pragma (List : List_Id) return Node_Or_Entity_Id;
127 -- Used when dealing with a list that can contain pragmas to skip past
128 -- any initial pragmas and return the first element that is not a pragma.
129 -- If the list is empty, or if it contains only pragmas, then Empty is
130 -- returned. It is an error to call First_Non_Pragma with a Node_Id value
131 -- or No_List (No_List is not considered to be the same as an empty list).
132 -- This function also skips N_Null nodes which can result from rewriting
133 -- unrecognized or incorrect pragmas.
135 function Last (List : List_Id) return Node_Or_Entity_Id;
136 pragma Inline (Last);
137 -- Obtains the last element of the given node list or, if the node list
138 -- has no items, then Empty is returned. It is an error to call Last with
139 -- a Node_Id or No_List. (No_List is not considered to be the same as an
140 -- empty node list).
142 function Last_Non_Pragma (List : List_Id) return Node_Or_Entity_Id;
143 -- Obtains the last element of a given node list that is not a pragma.
144 -- If the list is empty, or if it contains only pragmas, then Empty is
145 -- returned. It is an error to call Last_Non_Pragma with a Node_Id or
146 -- No_List. (No_List is not considered to be the same as an empty list).
148 function List_Length (List : List_Id) return Nat;
149 -- Returns number of items in the given list. If called on No_List it
150 -- returns 0, even though No_List is not considered to be the same as an
151 -- empty list.
153 function Next (Node : Node_Or_Entity_Id) return Node_Or_Entity_Id;
154 pragma Inline (Next);
155 -- This function returns the next node on a node list, or Empty if Node is
156 -- the last element of the node list. The argument must be a member of a
157 -- node list.
159 procedure Next (Node : in out Node_Or_Entity_Id);
160 pragma Inline (Next);
161 -- Equivalent to Node := Next (Node);
163 function Next_Non_Pragma
164 (Node : Node_Or_Entity_Id) return Node_Or_Entity_Id;
165 -- This function returns the next node on a node list, skipping past any
166 -- pragmas, or Empty if there is no non-pragma entry left. The argument
167 -- must be a member of a node list. This function also skips N_Null nodes
168 -- which can result from rewriting unrecognized or incorrect pragmas.
170 procedure Next_Non_Pragma (Node : in out Node_Or_Entity_Id);
171 pragma Inline (Next_Non_Pragma);
172 -- Equivalent to Node := Next_Non_Pragma (Node);
174 function Prev (Node : Node_Or_Entity_Id) return Node_Or_Entity_Id;
175 pragma Inline (Prev);
176 -- This function returns the previous node on a node list, or Empty
177 -- if Node is the first element of the node list. The argument must be
178 -- a member of a node list. Note: the implementation does maintain back
179 -- pointers, so this function executes quickly in constant time.
181 function Pick (List : List_Id; Index : Pos) return Node_Or_Entity_Id;
182 -- Given a list, picks out the Index'th entry (1 = first entry). The
183 -- caller must ensure that Index is in range.
185 procedure Prev (Node : in out Node_Or_Entity_Id);
186 pragma Inline (Prev);
187 -- Equivalent to Node := Prev (Node);
189 function Prev_Non_Pragma
190 (Node : Node_Or_Entity_Id) return Node_Or_Entity_Id;
191 pragma Inline (Prev_Non_Pragma);
192 -- This function returns the previous node on a node list, skipping any
193 -- pragmas. If Node is the first element of the list, or if the only
194 -- elements preceding it are pragmas, then Empty is returned. The
195 -- argument must be a member of a node list. Note: the implementation
196 -- does maintain back pointers, so this function executes quickly in
197 -- constant time.
199 procedure Prev_Non_Pragma (Node : in out Node_Or_Entity_Id);
200 pragma Inline (Prev_Non_Pragma);
201 -- Equivalent to Node := Prev_Non_Pragma (Node);
203 function Is_Empty_List (List : List_Id) return Boolean;
204 pragma Inline (Is_Empty_List);
205 -- This function determines if a given list id references a node list that
206 -- contains no items. No_List as an argument returns True.
208 function Is_Non_Empty_List (List : List_Id) return Boolean;
209 pragma Inline (Is_Non_Empty_List);
210 -- This function determines if a given list id references a node list that
211 -- contains at least one item. No_List as an argument returns False.
213 function Is_List_Member (Node : Node_Or_Entity_Id) return Boolean;
214 pragma Inline (Is_List_Member);
215 -- This function determines if a given node is a member of a node list.
216 -- It is an error for Node to be Empty, or to be a node list.
218 function List_Containing (Node : Node_Or_Entity_Id) return List_Id;
219 pragma Inline (List_Containing);
220 -- This function provides a pointer to the node list containing Node.
221 -- Node must be a member of a node list.
223 procedure Append (Node : Node_Or_Entity_Id; To : List_Id);
224 -- Appends Node at the end of node list To. Node must be a non-empty node
225 -- that is not already a member of a node list, and To must be a node list.
226 -- An attempt to append an error node is ignored without complaint and the
227 -- list is unchanged.
229 procedure Append_New (Node : Node_Or_Entity_Id; To : in out List_Id);
230 pragma Inline (Append_New);
231 -- Appends Node at the end of node list To. If To is non-existent list, a
232 -- list is created. Node must be a non-empty node that is not already a
233 -- member of a node list, and To must be a node list.
235 procedure Append_New_To (To : in out List_Id; Node : Node_Or_Entity_Id);
236 pragma Inline (Append_New_To);
237 -- Like Append_New, but the arguments are in reverse order
239 procedure Append_To (To : List_Id; Node : Node_Or_Entity_Id);
240 pragma Inline (Append_To);
241 -- Like Append, but arguments are the other way round
243 procedure Append_List (List : List_Id; To : List_Id);
244 -- Appends node list List to the end of node list To. On return,
245 -- List is reset to be empty.
247 procedure Append_List_To (To : List_Id; List : List_Id);
248 pragma Inline (Append_List_To);
249 -- Like Append_List, but arguments are the other way round
251 procedure Insert_After
252 (After : Node_Or_Entity_Id;
253 Node : Node_Or_Entity_Id);
254 -- Insert Node, which must be a non-empty node that is not already a
255 -- member of a node list, immediately past node After, which must be a
256 -- node that is currently a member of a node list. An attempt to insert
257 -- an error node is ignored without complaint (and the list is unchanged).
259 procedure Insert_List_After
260 (After : Node_Or_Entity_Id;
261 List : List_Id);
262 -- Inserts the entire contents of node list List immediately after node
263 -- After, which must be a member of a node list. On return, the node list
264 -- List is reset to be the empty node list.
266 procedure Insert_Before
267 (Before : Node_Or_Entity_Id;
268 Node : Node_Or_Entity_Id);
269 -- Insert Node, which must be a non-empty node that is not already a
270 -- member of a node list, immediately before Before, which must be a node
271 -- that is currently a member of a node list. An attempt to insert an
272 -- error node is ignored without complaint (and the list is unchanged).
274 procedure Insert_List_Before
275 (Before : Node_Or_Entity_Id;
276 List : List_Id);
277 -- Inserts the entire contents of node list List immediately before node
278 -- Before, which must be a member of a node list. On return, the node list
279 -- List is reset to be the empty node list.
281 procedure Prepend
282 (Node : Node_Or_Entity_Id;
283 To : List_Id);
284 -- Prepends Node at the start of node list To. Node must be a non-empty
285 -- node that is not already a member of a node list, and To must be a
286 -- node list. An attempt to prepend an error node is ignored without
287 -- complaint and the list is unchanged.
289 procedure Prepend_List
290 (List : List_Id;
291 To : List_Id);
292 -- Prepends node list List to the start of node list To. On return,
293 -- List is reset to be empty.
295 procedure Prepend_List_To
296 (To : List_Id;
297 List : List_Id);
298 pragma Inline (Prepend_List_To);
299 -- Like Prepend_List, but arguments are the other way round
301 procedure Prepend_New (Node : Node_Or_Entity_Id; To : in out List_Id);
302 pragma Inline (Prepend_New);
303 -- Prepends Node at the end of node list To. If To is non-existent list, a
304 -- list is created. Node must be a non-empty node that is not already a
305 -- member of a node list, and To must be a node list.
307 procedure Prepend_New_To (To : in out List_Id; Node : Node_Or_Entity_Id);
308 pragma Inline (Prepend_New_To);
309 -- Like Prepend_New, but the arguments are in reverse order
311 procedure Prepend_To
312 (To : List_Id;
313 Node : Node_Or_Entity_Id);
314 pragma Inline (Prepend_To);
315 -- Like Prepend, but arguments are the other way round
317 procedure Remove (Node : Node_Or_Entity_Id);
318 -- Removes Node, which must be a node that is a member of a node list,
319 -- from this node list. The contents of Node are not otherwise affected.
321 function Remove_Head (List : List_Id) return Node_Or_Entity_Id;
322 -- Removes the head element of a node list, and returns the node (whose
323 -- contents are not otherwise affected) as the result. If the node list
324 -- is empty, then Empty is returned.
326 function Remove_Next (Node : Node_Or_Entity_Id) return Node_Or_Entity_Id;
327 -- Removes the item immediately following the given node, and returns it
328 -- as the result. If Node is the last element of the list, then Empty is
329 -- returned. Node must be a member of a list. Unlike Remove, Remove_Next
330 -- is fast and does not involve any list traversal.
332 procedure Initialize;
333 -- Called at the start of compilation of each new main source file to
334 -- initialize the allocation of the list table.
336 procedure Lock;
337 -- Called to lock tables before back end is called
339 procedure Lock_Lists;
340 -- Called to lock list contents when assertions are enabled. Without
341 -- assertions calling this subprogram has no effect. The initial state
342 -- of the lock is unlocked.
344 procedure Unlock;
345 -- Unlock tables, in cases where the back end needs to modify them
347 procedure Unlock_Lists;
348 -- Called to unlock list contents when assertions are enabled; if
349 -- assertions are not enabled calling this subprogram has no effect.
351 function List_Parent (List : List_Id) return Node_Or_Entity_Id;
352 pragma Inline (List_Parent);
353 function Parent (List : List_Id) return Node_Or_Entity_Id
354 renames List_Parent;
355 pragma Inline (Parent);
356 -- Node lists may have a parent in the same way as a node. The function
357 -- accesses the Parent value, which is either Empty when a list header
358 -- is first created, or the value that has been set by Set_Parent.
359 -- Parent has the same name as the one in Atree; List_Parent can be used
360 -- more easily in the debugger.
362 procedure Set_List_Parent (List : List_Id; Node : Node_Or_Entity_Id);
363 pragma Inline (Set_List_Parent);
364 procedure Set_Parent (List : List_Id; Node : Node_Or_Entity_Id)
365 renames Set_List_Parent;
366 pragma Inline (Set_Parent);
367 -- Sets the parent field of the given list to reference the given node
369 function No (List : List_Id) return Boolean;
370 pragma Inline (No);
371 -- Tests given Id for equality with No_List. This allows notations like
372 -- "if No (Statements)" as opposed to "if Statements = No_List". Note that
373 -- an empty list gives False for this test, as opposed to Is_Empty_List
374 -- which gives True either for No_List or for an empty list.
376 function Present (List : List_Id) return Boolean;
377 pragma Inline (Present);
378 -- Tests given Id for inequality with No_List. This allows notations like
379 -- "if Present (Statements)" as opposed to "if Statements /= No_List".
381 procedure Allocate_List_Tables (N : Node_Or_Entity_Id);
382 pragma Inline (Allocate_List_Tables);
383 -- Called when nodes table is expanded to include node N. This call
384 -- makes sure that list structures internal to Nlists are adjusted
385 -- appropriately to reflect this increase in the size of the nodes table.
387 function Next_Node_Address return System.Address;
388 function Prev_Node_Address return System.Address;
389 -- These functions return the addresses of the Next_Node and Prev_Node
390 -- tables (used in Back_End for Gigi).
392 end Nlists;