OSDN Git Service

* 1aexcept.adb, 1aexcept.ads, 1ic.ads, 1ssecsta.adb,
[pf3gnuchains/gcc-fork.git] / gcc / ada / nlists.ads
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-2000 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,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, 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 ------------------------------------------------------------------------------
33
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).
39
40 with System;
41 with Types; use Types;
42
43 package Nlists is
44
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.
50
51    --  Note: node lists can contain either nodes or entities (extended nodes)
52    --  or a mixture of nodes and extended nodes.
53
54    function Last_List_Id return List_Id;
55    pragma Inline (Last_List_Id);
56    --  Returns Id of last allocated list header
57
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)
61
62    function Num_Lists return Nat;
63    pragma Inline (Num_Lists);
64    --  Number of currently allocated lists
65
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.
70
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.
74
75    function New_List (Node : Node_Id) return List_Id;
76    --  Build a new list initially containing the given node
77
78    function New_List (Node1, Node2 : Node_Id) return List_Id;
79    --  Build a new list initially containing the two given nodes
80
81    function New_List (Node1, Node2, Node3 : Node_Id) return List_Id;
82    --  Build a new list initially containing the three given nodes
83
84    function New_List (Node1, Node2, Node3, Node4 : Node_Id) return List_Id;
85    --  Build a new list initially containing the four given nodes
86
87    function New_List
88      (Node1 : Node_Id;
89       Node2 : Node_Id;
90       Node3 : Node_Id;
91       Node4 : Node_Id;
92       Node5 : Node_Id)
93       return  List_Id;
94    --  Build a new list initially containing the five given nodes
95
96    function New_List
97      (Node1 : Node_Id;
98       Node2 : Node_Id;
99       Node3 : Node_Id;
100       Node4 : Node_Id;
101       Node5 : Node_Id;
102       Node6 : Node_Id)
103       return  List_Id;
104    --  Build a new list initially containing the five given nodes
105
106    function New_Copy_List (List : List_Id) return List_Id;
107    --  Creates a new list containing copies (made with Atree.New_Copy) of every
108    --  node in the original list. If the argument is No_List, then the returned
109    --  result is No_List. If the argument is an empty list, then the returned
110    --  result is a new empty list.
111
112    function New_Copy_List_Original (List : List_Id) return List_Id;
113    --  Same as New_Copy_List but copies only nodes coming from source
114
115    function New_Copy_List_Tree (List : List_Id) return List_Id;
116    --  Similar to New_Copy_List, except that the copies are done using the
117    --  Atree.New_Copy_Tree function, which means that a full recursive copy
118    --  of the subtrees in the list is performed, setting proper parents. As
119    --  for New_Copy_Tree, it is illegal to attempt to copy extended nodes
120    --  (entities) either directly or indirectly using this function.
121
122    function First (List : List_Id) return Node_Id;
123    pragma Inline (First);
124    --  Obtains the first element of the given node list or, if the node list
125    --  has no items or is equal to No_List, then Empty is returned.
126
127    function First_Non_Pragma (List : List_Id) return Node_Id;
128    --  Used when dealing with a list that can contain pragmas to skip past
129    --  any initial pragmas and return the first element that is not a pragma.
130    --  If the list is empty, or if it contains only pragmas, then Empty is
131    --  returned. It is an error to call First_Non_Pragma with a Node_Id value
132    --  or No_List (No_List is not considered to be the same as an empty list).
133    --  This function also skips N_Null nodes which can result from rewriting
134    --  unrecognized or incorrrect pragmas.
135
136    function Last (List : List_Id) return Node_Id;
137    pragma Inline (Last);
138    --  Obtains the last element of the given node list or, if the node list
139    --  has no items, then Empty is returned. It is an error to call Last with
140    --  a Node_Id or No_List. (No_List is not considered to be the same as an
141    --  empty node list).
142
143    function Last_Non_Pragma (List : List_Id) return Node_Id;
144    --  Obtains the last element of a given node list that is not a pragma.
145    --  If the list is empty, or if it contains only pragmas, then Empty is
146    --  returned. It is an error to call Last_Non_Pragma with a Node_Id or
147    --  No_List. (No_List is not considered to be the same as an empty list).
148
149    function List_Length (List : List_Id) return Nat;
150    pragma Inline (List_Length);
151    --  Returns number of items in the given list. It is an error to call
152    --  this function with No_List (No_List is not considered to be the same
153    --  as an empty list).
154
155    function Next (Node : Node_Id) return Node_Id;
156    pragma Inline (Next);
157    --  This function returns the next node on a node list, or Empty if Node is
158    --  the last element of the node list. The argument must be a member of a
159    --  node list.
160
161    procedure Next (Node : in out Node_Id);
162    pragma Inline (Next);
163    --  Equivalent to Node := Next (Node);
164
165    function Next_Non_Pragma (Node : Node_Id) return Node_Id;
166    --  This function returns the next node on a node list, skipping past any
167    --  pragmas, or Empty if there is no non-pragma entry left. The argument
168    --  must be a member of a node list. This function also skips N_Null nodes
169    --  which can result from rewriting unrecognized or incorrect pragmas.
170
171    procedure Next_Non_Pragma (Node : in out Node_Id);
172    pragma Inline (Next_Non_Pragma);
173    --  Equivalent to Node := Next_Non_Pragma (Node);
174
175    function Prev (Node : Node_Id) return Node_Id;
176    pragma Inline (Prev);
177    --  This function returns the previous node on a node list list, or Empty if
178    --  Node is the first element of the node list. The argument must be a
179    --  member of a node list. Note that the implementation does not maintain
180    --  back pointers, so this function potentially requires traversal of the
181    --  entire list, or more accurately of the part of the list preceding Node.
182
183    function Pick (List : List_Id; Index : Pos) return Node_Id;
184    --  Given a list, picks out the Index'th entry (1 = first entry). The
185    --  caller must ensure that Index is in range.
186
187    procedure Prev (Node : in out Node_Id);
188    pragma Inline (Prev);
189    --  Equivalent to Node := Prev (Node);
190
191    function Prev_Non_Pragma (Node : Node_Id) return Node_Id;
192    pragma Inline (Prev_Non_Pragma);
193    --  This function returns the previous node on a node list, skipping any
194    --  pragmas. If Node is the first element of the list, or if the only
195    --  elements preceding it are pragmas, then Empty is returned. The
196    --  argument must be a member of a node list. Like Prev, this function
197    --  may require expensive traversal of the head section of the list.
198
199    procedure Prev_Non_Pragma (Node : in out Node_Id);
200    pragma Inline (Prev_Non_Pragma);
201    --  Equivalent to Node := Prev_Non_Pragma (Node);
202
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 is a not a legitimate argument.
207
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.
212
213    function Is_List_Member (Node : Node_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.
217
218    function List_Containing (Node : Node_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.
222
223    procedure Append (Node : Node_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
226    --  node list. An attempt to append an error node is ignored without
227    --  complaint and the list is unchanged.
228
229    procedure Append_To (To : List_Id; Node : Node_Id);
230    pragma Inline (Append_To);
231    --  Like Append, but arguments are the other way round
232
233    procedure Append_List (List : List_Id; To : List_Id);
234    --  Appends node list List to the end of node list To. On return,
235    --  List is reset to be empty.
236
237    procedure Append_List_To (To : List_Id; List : List_Id);
238    pragma Inline (Append_List_To);
239    --  Like Append_List, but arguments are the other way round
240
241    procedure Insert_After (After : Node_Id; Node : Node_Id);
242    --  Insert Node, which must be a non-empty node that is not already a
243    --  member of a node list, immediately past node After, which must be a
244    --  node that is currently a member of a node list. An attempt to insert
245    --  an error node is ignored without complaint (and the list is unchanged).
246
247    procedure Insert_List_After (After : Node_Id; List : List_Id);
248    --  Inserts the entire contents of node list List immediately after node
249    --  After, which must be a member of a node list. On return, the node list
250    --  List is reset to be the empty node list.
251
252    procedure Insert_Before (Before : Node_Id; Node : Node_Id);
253    --  Insert Node, which must be a non-empty node that is not already a
254    --  member of a node list, immediately before Before, which must be a node
255    --  that is currently a member of a node list. An attempt to insert an
256    --  error node is ignored without complaint (and the list is unchanged).
257
258    procedure Insert_List_Before (Before : Node_Id; List : List_Id);
259    --  Inserts the entire contents of node list List immediately before node
260    --  Before, which must be a member of a node list. On return, the node list
261    --  List is reset to be the empty node list.
262
263    procedure Prepend (Node : Node_Id; To : List_Id);
264    pragma Inline (Prepend);
265    --  Prepends Node at the start of node list To. Node must be a non-empty
266    --  node that is not already a member of a node list, and To must be a
267    --  node list. An attempt to prepend an error node is ignored without
268    --  complaint and the list is unchanged.
269
270    procedure Prepend_To (To : List_Id; Node : Node_Id);
271    pragma Inline (Prepend_To);
272    --  Like Prepend, but arguments are the other way round
273
274    procedure Remove (Node : Node_Id);
275    --  Removes Node, which must be a node that is a member of a node list,
276    --  from this node list. The contents of Node are not otherwise affected.
277
278    function Remove_Head (List : List_Id) return Node_Id;
279    --  Removes the head element of a node list, and returns the node (whose
280    --  contents are not otherwise affected) as the result. If the node list
281    --  is empty, then Empty is returned.
282
283    function Remove_Next (Node : Node_Id) return Node_Id;
284    pragma Inline (Remove_Next);
285    --  Removes the item immediately following the given node, and returns it
286    --  as the result. If Node is the last element of the list, then Empty is
287    --  returned. Node must be a member of a list. Unlike Remove, Remove_Next
288    --  is fast and does not involve any list traversal.
289
290    procedure Initialize;
291    --  Called at the start of compilation of each new main source file to
292    --  initialize the allocation of the list table. Note that Initialize
293    --  must not be called if Tree_Read is used.
294
295    procedure Lock;
296    --  Called to lock tables before back end is called
297
298    procedure Tree_Read;
299    --  Initializes internal tables from current tree file using Tree_Read.
300    --  Note that Initialize should not be called if Tree_Read is used.
301    --  Tree_Read includes all necessary initialization.
302
303    procedure Tree_Write;
304    --  Writes out internal tables to current tree file using Tree_Write
305
306    function Parent (List : List_Id) return Node_Id;
307    pragma Inline (Parent);
308    --  Node lists may have a parent in the same way as a node. The function
309    --  accesses the Parent value, which is either Empty when a list header
310    --  is first created, or the value that has been set by Set_Parent.
311
312    procedure Set_Parent (List : List_Id; Node : Node_Id);
313    pragma Inline (Set_Parent);
314    --  Sets the parent field of the given list to reference the given node
315
316    function No (List : List_Id) return Boolean;
317    pragma Inline (No);
318    --  Tests given Id for equality with No_List. This allows notations like
319    --  "if No (Statements)" as opposed to "if Statements = No_List".
320
321    function Present (List : List_Id) return Boolean;
322    pragma Inline (Present);
323    --  Tests given Id for inequality with No_List. This allows notations like
324    --  "if Present (Statements)" as opposed to "if Statements /= No_List".
325
326    procedure Allocate_List_Tables (N : Node_Id);
327    --  Called when nodes table is expanded to include node N. This call
328    --  makes sure that list structures internal to Nlists are adjusted
329    --  appropriately to reflect this increase in the size of the nodes table.
330
331    function Next_Node_Address return System.Address;
332    function Prev_Node_Address return System.Address;
333    --  These functions return the addresses of the Next_Node and Prev_Node
334    --  tables (used in Back_End for Gigi).
335
336    procedure Delete_List (L : List_Id);
337    --  Removes all elements of the given list, and calls Delete_Tree on each
338
339    function p (U : Union_Id) return Node_Id;
340    --  This function is intended for use from the debugger, it determines
341    --  whether U is a Node_Id or List_Id, and calls the appropriate Parent
342    --  function and returns the parent Node in either case. This is shorter
343    --  to type, and avoids the overloading problem of using Parent. It
344    --  should NEVER be used except from the debugger. If p is called with
345    --  other than a node or list id value, it returns 99_999_999.
346
347 end Nlists;