Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / gcc / ada / nlists.ads
blob533b5a8be8ccdad30568a8ba3de99c81db2ea9ae
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-2005, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
21 -- --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
28 -- --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 ------------------------------------------------------------------------------
34 -- This package provides facilities for manipulating lists of nodes (see
35 -- package Atree for format and implementation of tree nodes). The Link field
36 -- of the nodes is used as the forward pointer for these lists. See also
37 -- package Elists which provides another form of lists that are not threaded
38 -- through the nodes (and therefore allow nodes to be on multiple lists).
40 with System;
41 with Types; use Types;
43 package Nlists is
45 -- A node list is a list of nodes in a special format that means that
46 -- nodes can be on at most one such list. For each node list, a list
47 -- header is allocated in the lists table, and a List_Id value references
48 -- this header, which may be used to access the nodes in the list using
49 -- the set of routines that define this interface.
51 -- Note: node lists can contain either nodes or entities (extended nodes)
52 -- or a mixture of nodes and extended nodes.
54 function Last_List_Id return List_Id;
55 pragma Inline (Last_List_Id);
56 -- Returns Id of last allocated list header
58 function Lists_Address return System.Address;
59 pragma Inline (Lists_Address);
60 -- Return address of Lists table (used in Back_End for Gigi call)
62 function Num_Lists return Nat;
63 pragma Inline (Num_Lists);
64 -- Number of currently allocated lists
66 function New_List return List_Id;
67 -- Creates a new empty node list. Typically this is used to initialize
68 -- a field in some other node which points to a node list where the list
69 -- is then subsequently filled in using Append calls.
71 function Empty_List return List_Id renames New_List;
72 -- Used in contexts where an empty list (as opposed to an initially empty
73 -- list to be filled in) is required.
75 function New_List (Node : Node_Id) return List_Id;
76 -- Build a new list initially containing the given node
78 function New_List (Node1, Node2 : Node_Id) return List_Id;
79 -- Build a new list initially containing the two given nodes
81 function New_List (Node1, Node2, Node3 : Node_Id) return List_Id;
82 -- Build a new list initially containing the three given nodes
84 function New_List (Node1, Node2, Node3, Node4 : Node_Id) return List_Id;
85 -- Build a new list initially containing the four given nodes
87 function New_List
88 (Node1 : Node_Id;
89 Node2 : Node_Id;
90 Node3 : Node_Id;
91 Node4 : Node_Id;
92 Node5 : Node_Id) return List_Id;
93 -- Build a new list initially containing the five given nodes
95 function New_List
96 (Node1 : Node_Id;
97 Node2 : Node_Id;
98 Node3 : Node_Id;
99 Node4 : Node_Id;
100 Node5 : Node_Id;
101 Node6 : Node_Id) return List_Id;
102 -- Build a new list initially containing the six given nodes
104 function New_Copy_List (List : List_Id) return List_Id;
105 -- Creates a new list containing copies (made with Atree.New_Copy) of every
106 -- node in the original list. If the argument is No_List, then the returned
107 -- result is No_List. If the argument is an empty list, then the returned
108 -- result is a new empty list.
110 function New_Copy_List_Original (List : List_Id) return List_Id;
111 -- Same as New_Copy_List but copies only nodes coming from source
113 function New_Copy_List_Tree (List : List_Id) return List_Id;
114 -- Similar to New_Copy_List, except that the copies are done using the
115 -- Atree.New_Copy_Tree function, which means that a full recursive copy
116 -- of the subtrees in the list is performed, setting proper parents. As
117 -- for New_Copy_Tree, it is illegal to attempt to copy extended nodes
118 -- (entities) either directly or indirectly using this function.
120 function First (List : List_Id) return Node_Id;
121 pragma Inline (First);
122 -- Obtains the first element of the given node list or, if the node list
123 -- has no items or is equal to No_List, then Empty is returned.
125 function First_Non_Pragma (List : List_Id) return Node_Id;
126 -- Used when dealing with a list that can contain pragmas to skip past
127 -- any initial pragmas and return the first element that is not a pragma.
128 -- If the list is empty, or if it contains only pragmas, then Empty is
129 -- returned. It is an error to call First_Non_Pragma with a Node_Id value
130 -- or No_List (No_List is not considered to be the same as an empty list).
131 -- This function also skips N_Null nodes which can result from rewriting
132 -- unrecognized or incorrrect pragmas.
134 function Last (List : List_Id) return Node_Id;
135 pragma Inline (Last);
136 -- Obtains the last element of the given node list or, if the node list
137 -- has no items, then Empty is returned. It is an error to call Last with
138 -- a Node_Id or No_List. (No_List is not considered to be the same as an
139 -- empty node list).
141 function Last_Non_Pragma (List : List_Id) return Node_Id;
142 -- Obtains the last element of a given node list that is not a pragma.
143 -- If the list is empty, or if it contains only pragmas, then Empty is
144 -- returned. It is an error to call Last_Non_Pragma with a Node_Id or
145 -- No_List. (No_List is not considered to be the same as an empty list).
147 function List_Length (List : List_Id) return Nat;
148 pragma Inline (List_Length);
149 -- Returns number of items in the given list. It is an error to call
150 -- this function with No_List (No_List is not considered to be the same
151 -- as an empty list).
153 function Next (Node : Node_Id) return Node_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_Id);
160 pragma Inline (Next);
161 -- Equivalent to Node := Next (Node);
163 function Next_Non_Pragma (Node : Node_Id) return Node_Id;
164 -- This function returns the next node on a node list, skipping past any
165 -- pragmas, or Empty if there is no non-pragma entry left. The argument
166 -- must be a member of a node list. This function also skips N_Null nodes
167 -- which can result from rewriting unrecognized or incorrect pragmas.
169 procedure Next_Non_Pragma (Node : in out Node_Id);
170 pragma Inline (Next_Non_Pragma);
171 -- Equivalent to Node := Next_Non_Pragma (Node);
173 function Prev (Node : Node_Id) return Node_Id;
174 pragma Inline (Prev);
175 -- This function returns the previous node on a node list list, or Empty
176 -- if Node is the first element of the node list. The argument must be
177 -- a member of a node list. Note: the implementation does maintain back
178 -- pointers, so this function executes quickly in constant time.
180 function Pick (List : List_Id; Index : Pos) return Node_Id;
181 -- Given a list, picks out the Index'th entry (1 = first entry). The
182 -- caller must ensure that Index is in range.
184 procedure Prev (Node : in out Node_Id);
185 pragma Inline (Prev);
186 -- Equivalent to Node := Prev (Node);
188 function Prev_Non_Pragma (Node : Node_Id) return Node_Id;
189 pragma Inline (Prev_Non_Pragma);
190 -- This function returns the previous node on a node list, skipping any
191 -- pragmas. If Node is the first element of the list, or if the only
192 -- elements preceding it are pragmas, then Empty is returned. The
193 -- argument must be a member of a node list. Note: the implementation
194 -- does maintain back pointers, so this function executes quickly in
195 -- constant time.
197 procedure Prev_Non_Pragma (Node : in out Node_Id);
198 pragma Inline (Prev_Non_Pragma);
199 -- Equivalent to Node := Prev_Non_Pragma (Node);
201 function Is_Empty_List (List : List_Id) return Boolean;
202 pragma Inline (Is_Empty_List);
203 -- This function determines if a given list id references a node list that
204 -- contains no items. No_List is a not a legitimate argument.
206 function Is_Non_Empty_List (List : List_Id) return Boolean;
207 pragma Inline (Is_Non_Empty_List);
208 -- This function determines if a given list id references a node list that
209 -- contains at least one item. No_List as an argument returns False.
211 function Is_List_Member (Node : Node_Id) return Boolean;
212 pragma Inline (Is_List_Member);
213 -- This function determines if a given node is a member of a node list.
214 -- It is an error for Node to be Empty, or to be a node list.
216 function List_Containing (Node : Node_Id) return List_Id;
217 pragma Inline (List_Containing);
218 -- This function provides a pointer to the node list containing Node.
219 -- Node must be a member of a node list.
221 procedure Append (Node : Node_Id; To : List_Id);
222 -- Appends Node at the end of node list To. Node must be a non-empty node
223 -- that is not already a member of a node list, and To must be a
224 -- node list. An attempt to append an error node is ignored without
225 -- complaint and the list is unchanged.
227 procedure Append_To (To : List_Id; Node : Node_Id);
228 pragma Inline (Append_To);
229 -- Like Append, but arguments are the other way round
231 procedure Append_List (List : List_Id; To : List_Id);
232 -- Appends node list List to the end of node list To. On return,
233 -- List is reset to be empty.
235 procedure Append_List_To (To : List_Id; List : List_Id);
236 pragma Inline (Append_List_To);
237 -- Like Append_List, but arguments are the other way round
239 procedure Insert_After (After : Node_Id; Node : Node_Id);
240 -- Insert Node, which must be a non-empty node that is not already a
241 -- member of a node list, immediately past node After, which must be a
242 -- node that is currently a member of a node list. An attempt to insert
243 -- an error node is ignored without complaint (and the list is unchanged).
245 procedure Insert_List_After (After : Node_Id; List : List_Id);
246 -- Inserts the entire contents of node list List immediately after node
247 -- After, which must be a member of a node list. On return, the node list
248 -- List is reset to be the empty node list.
250 procedure Insert_Before (Before : Node_Id; Node : Node_Id);
251 -- Insert Node, which must be a non-empty node that is not already a
252 -- member of a node list, immediately before Before, which must be a node
253 -- that is currently a member of a node list. An attempt to insert an
254 -- error node is ignored without complaint (and the list is unchanged).
256 procedure Insert_List_Before (Before : Node_Id; List : List_Id);
257 -- Inserts the entire contents of node list List immediately before node
258 -- Before, which must be a member of a node list. On return, the node list
259 -- List is reset to be the empty node list.
261 procedure Prepend (Node : Node_Id; To : List_Id);
262 -- Prepends Node at the start of node list To. Node must be a non-empty
263 -- node that is not already a member of a node list, and To must be a
264 -- node list. An attempt to prepend an error node is ignored without
265 -- complaint and the list is unchanged.
267 procedure Prepend_To (To : List_Id; Node : Node_Id);
268 pragma Inline (Prepend_To);
269 -- Like Prepend, but arguments are the other way round
271 procedure Remove (Node : Node_Id);
272 -- Removes Node, which must be a node that is a member of a node list,
273 -- from this node list. The contents of Node are not otherwise affected.
275 function Remove_Head (List : List_Id) return Node_Id;
276 -- Removes the head element of a node list, and returns the node (whose
277 -- contents are not otherwise affected) as the result. If the node list
278 -- is empty, then Empty is returned.
280 function Remove_Next (Node : Node_Id) return Node_Id;
281 -- Removes the item immediately following the given node, and returns it
282 -- as the result. If Node is the last element of the list, then Empty is
283 -- returned. Node must be a member of a list. Unlike Remove, Remove_Next
284 -- is fast and does not involve any list traversal.
286 procedure Initialize;
287 -- Called at the start of compilation of each new main source file to
288 -- initialize the allocation of the list table. Note that Initialize
289 -- must not be called if Tree_Read is used.
291 procedure Lock;
292 -- Called to lock tables before back end is called
294 procedure Tree_Read;
295 -- Initializes internal tables from current tree file using the relevant
296 -- Table.Tree_Read routines. Note that Initialize should not be called if
297 -- Tree_Read is used. Tree_Read includes all necessary initialization.
299 procedure Tree_Write;
300 -- Writes out internal tables to current tree file using the relevant
301 -- Table.Tree_Write routines.
303 function Parent (List : List_Id) return Node_Id;
304 pragma Inline (Parent);
305 -- Node lists may have a parent in the same way as a node. The function
306 -- accesses the Parent value, which is either Empty when a list header
307 -- is first created, or the value that has been set by Set_Parent.
309 procedure Set_Parent (List : List_Id; Node : Node_Id);
310 pragma Inline (Set_Parent);
311 -- Sets the parent field of the given list to reference the given node
313 function No (List : List_Id) return Boolean;
314 pragma Inline (No);
315 -- Tests given Id for equality with No_List. This allows notations like
316 -- "if No (Statements)" as opposed to "if Statements = No_List".
318 function Present (List : List_Id) return Boolean;
319 pragma Inline (Present);
320 -- Tests given Id for inequality with No_List. This allows notations like
321 -- "if Present (Statements)" as opposed to "if Statements /= No_List".
323 procedure Allocate_List_Tables (N : Node_Id);
324 -- Called when nodes table is expanded to include node N. This call
325 -- makes sure that list structures internal to Nlists are adjusted
326 -- appropriately to reflect this increase in the size of the nodes table.
328 function Next_Node_Address return System.Address;
329 function Prev_Node_Address return System.Address;
330 -- These functions return the addresses of the Next_Node and Prev_Node
331 -- tables (used in Back_End for Gigi).
333 procedure Delete_List (L : List_Id);
334 -- Removes all elements of the given list, and calls Delete_Tree on each
336 function p (U : Union_Id) return Node_Id;
337 -- This function is intended for use from the debugger, it determines
338 -- whether U is a Node_Id or List_Id, and calls the appropriate Parent
339 -- function and returns the parent Node in either case. This is shorter
340 -- to type, and avoids the overloading problem of using Parent. It
341 -- should NEVER be used except from the debugger. If p is called with
342 -- other than a node or list id value, it returns 99_999_999.
344 end Nlists;