OSDN Git Service

2005-11-21 Joel Sherrill <joel.sherrill@oarcorp.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / elists.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                               E 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 ------------------------------------------------------------------------------
33
34 --  This package provides facilities for manipulating lists of nodes (see
35 --  package Atree for format and implementation of tree nodes). Separate list
36 --  elements are allocated to represent elements of these lists, so it is
37 --  possible for a given node to be on more than one element list at a time.
38 --  See also package Nlists, which provides another form that is threaded
39 --  through the nodes themselves (using the Link field), which is more time
40 --  and space efficient, but a node can be only one such list.
41
42 with Types;  use Types;
43 with System;
44
45 package Elists is
46
47    --  An element list is represented by a header that is allocated in the
48    --  Elist header table. This header contains pointers to the first and
49    --  last elements in the list, or to No_Elmt if the list is empty.
50
51    --  The elements in the list each contain a pointer to the next element
52    --  and a pointer to the referenced node. Putting a node into an element
53    --  list causes no change at all to the node itself, so a node may be
54    --  included in multiple element lists, and the nodes thus included may
55    --  or may not be elements of node lists (see package Nlists).
56
57    procedure Initialize;
58    --  Initialize allocation of element list tables. Called at the start of
59    --  compiling each new main source file. Note that Initialize must not be
60    --  called if Tree_Read is used.
61
62    procedure Lock;
63    --  Lock tables used for element lists before calling backend
64
65    procedure Tree_Read;
66    --  Initializes internal tables from current tree file using the relevant
67    --  Table.Tree_Read routines. Note that Initialize should not be called if
68    --  Tree_Read is used. Tree_Read includes all necessary initialization.
69
70    procedure Tree_Write;
71    --  Writes out internal tables to current tree file using the relevant
72    --  Table.Tree_Write routines.
73
74    function Last_Elist_Id return Elist_Id;
75    --  Returns Id of last allocated element list header
76
77    function Elists_Address return System.Address;
78    --  Return address of Elists table (used in Back_End for Gigi call)
79
80    function Num_Elists return Nat;
81    --  Number of currently allocated element lists
82
83    function Last_Elmt_Id return Elmt_Id;
84    --  Returns Id of last allocated list element
85
86    function Elmts_Address return System.Address;
87    --  Return address of Elmts table (used in Back_End for Gigi call)
88
89    function Node (Elmt : Elmt_Id) return Node_Id;
90    pragma Inline (Node);
91    --  Returns the value of a given list element. Returns Empty if Elmt
92    --  is set to No_Elmt.
93
94    function New_Elmt_List return Elist_Id;
95    --  Creates a new empty element list. Typically this is used to initialize
96    --  a field in some other node which points to an element list where the
97    --  list is then subsequently filled in using Append calls.
98
99    function First_Elmt (List : Elist_Id) return Elmt_Id;
100    pragma Inline (First_Elmt);
101    --  Obtains the first element of the given element list or, if the
102    --  list has no items, then No_Elmt is returned.
103
104    function Last_Elmt (List : Elist_Id) return Elmt_Id;
105    pragma Inline (Last_Elmt);
106    --  Obtains the last element of the given element list or, if the
107    --  list has no items, then No_Elmt is returned.
108
109    function Next_Elmt (Elmt : Elmt_Id) return Elmt_Id;
110    pragma Inline (Next_Elmt);
111    --  This function returns the next element on an element list. The argument
112    --  must be a list element other than No_Elmt. Returns No_Elmt if the given
113    --  element is the last element of the list.
114
115    procedure Next_Elmt (Elmt : in out Elmt_Id);
116    pragma Inline (Next_Elmt);
117    --  Next_Elmt (Elmt) is equivalent to Elmt := Next_Elmt (Elmt)
118
119    function Is_Empty_Elmt_List (List : Elist_Id) return Boolean;
120    pragma Inline (Is_Empty_Elmt_List);
121    --  This function determines if a given tree id references an element list
122    --  that contains no items.
123
124    procedure Append_Elmt (Node : Node_Id; To : Elist_Id);
125    --  Appends Node at the end of To, allocating a new element
126
127    procedure Prepend_Elmt (Node : Node_Id; To : Elist_Id);
128    --  Appends Node at the beginning of To, allocating a new element
129
130    procedure Insert_Elmt_After (Node : Node_Id; Elmt : Elmt_Id);
131    --  Add a new element (Node) right after the pre-existing element Elmt
132    --  It is invalid to call this subprogram with Elmt = No_Elmt.
133
134    procedure Replace_Elmt (Elmt : Elmt_Id; New_Node : Node_Id);
135    pragma Inline (Replace_Elmt);
136    --  Causes the given element of the list to refer to New_Node, the node
137    --  which was previously referred to by Elmt is effectively removed from
138    --  the list and replaced by New_Node.
139
140    procedure Remove_Elmt (List : Elist_Id; Elmt : Elmt_Id);
141    --  Removes Elmt from the given list. The node itself is not affected,
142    --  but the space used by the list element may be (but is not required
143    --  to be) freed for reuse in a subsequent Append_Elmt call.
144
145    procedure Remove_Last_Elmt (List : Elist_Id);
146    --  Removes the last element of the given list. The node itself is not
147    --  affected, but the space used by the list element may be (but is not
148    --  required to be) freed for reuse in a subsequent Append_Elmt call.
149
150    function No (List : Elist_Id) return Boolean;
151    pragma Inline (No);
152    --  Tests given Id for equality with No_Elist. This allows notations like
153    --  "if No (Statements)" as opposed to "if Statements = No_Elist".
154
155    function Present (List : Elist_Id) return Boolean;
156    pragma Inline (Present);
157    --  Tests given Id for inequality with No_Elist. This allows notations like
158    --  "if Present (Statements)" as opposed to "if Statements /= No_Elist".
159
160    function No (Elmt : Elmt_Id) return Boolean;
161    pragma Inline (No);
162    --  Tests given Id for equality with No_Elmt. This allows notations like
163    --  "if No (Operation)" as opposed to "if Operation = No_Elmt".
164
165    function Present (Elmt : Elmt_Id) return Boolean;
166    pragma Inline (Present);
167    --  Tests given Id for inequality with No_Elmt. This allows notations like
168    --  "if Present (Operation)" as opposed to "if Operation /= No_Elmt".
169
170 end Elists;