annotate gcc/ada/elists.ads @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
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 COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- E L I S T S --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 1992-2019, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -- This package provides facilities for manipulating lists of nodes (see
kono
parents:
diff changeset
33 -- package Atree for format and implementation of tree nodes). Separate list
kono
parents:
diff changeset
34 -- elements are allocated to represent elements of these lists, so it is
kono
parents:
diff changeset
35 -- possible for a given node to be on more than one element list at a time.
kono
parents:
diff changeset
36 -- See also package Nlists, which provides another form that is threaded
kono
parents:
diff changeset
37 -- through the nodes themselves (using the Link field), which is more time
kono
parents:
diff changeset
38 -- and space efficient, but a node can be only one such list.
kono
parents:
diff changeset
39
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
40 -- WARNING: There is a C version of this package. Any changes to this
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
41 -- source file must be properly reflected in the C header file elists.h
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
42
111
kono
parents:
diff changeset
43 with Types; use Types;
kono
parents:
diff changeset
44 with System;
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 package Elists is
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 -- An element list is represented by a header that is allocated in the
kono
parents:
diff changeset
49 -- Elist header table. This header contains pointers to the first and
kono
parents:
diff changeset
50 -- last elements in the list, or to No_Elmt if the list is empty.
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 -- The elements in the list each contain a pointer to the next element
kono
parents:
diff changeset
53 -- and a pointer to the referenced node. Putting a node into an element
kono
parents:
diff changeset
54 -- list causes no change at all to the node itself, so a node may be
kono
parents:
diff changeset
55 -- included in multiple element lists, and the nodes thus included may
kono
parents:
diff changeset
56 -- or may not be elements of node lists (see package Nlists).
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 procedure Initialize;
kono
parents:
diff changeset
59 -- Initialize allocation of element list tables. Called at the start of
kono
parents:
diff changeset
60 -- compiling each new main source file. Note that Initialize must not be
kono
parents:
diff changeset
61 -- called if Tree_Read is used.
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 procedure Lock;
kono
parents:
diff changeset
64 -- Lock tables used for element lists before calling backend
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 procedure Unlock;
kono
parents:
diff changeset
67 -- Unlock list tables, in cases where the back end needs to modify them
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 procedure Tree_Read;
kono
parents:
diff changeset
70 -- Initializes internal tables from current tree file using the relevant
kono
parents:
diff changeset
71 -- Table.Tree_Read routines. Note that Initialize should not be called if
kono
parents:
diff changeset
72 -- Tree_Read is used. Tree_Read includes all necessary initialization.
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 procedure Tree_Write;
kono
parents:
diff changeset
75 -- Writes out internal tables to current tree file using the relevant
kono
parents:
diff changeset
76 -- Table.Tree_Write routines.
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 function Last_Elist_Id return Elist_Id;
kono
parents:
diff changeset
79 -- Returns Id of last allocated element list header
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 function Elists_Address return System.Address;
kono
parents:
diff changeset
82 -- Return address of Elists table (used in Back_End for Gigi call)
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 function Num_Elists return Nat;
kono
parents:
diff changeset
85 -- Number of currently allocated element lists
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 function Last_Elmt_Id return Elmt_Id;
kono
parents:
diff changeset
88 -- Returns Id of last allocated list element
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 function Elmts_Address return System.Address;
kono
parents:
diff changeset
91 -- Return address of Elmts table (used in Back_End for Gigi call)
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 function Node (Elmt : Elmt_Id) return Node_Or_Entity_Id;
kono
parents:
diff changeset
94 pragma Inline (Node);
kono
parents:
diff changeset
95 -- Returns the value of a given list element. Returns Empty if Elmt
kono
parents:
diff changeset
96 -- is set to No_Elmt.
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 function New_Elmt_List return Elist_Id;
kono
parents:
diff changeset
99 -- Creates a new empty element list. Typically this is used to initialize
kono
parents:
diff changeset
100 -- a field in some other node which points to an element list where the
kono
parents:
diff changeset
101 -- list is then subsequently filled in using Append calls.
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 function First_Elmt (List : Elist_Id) return Elmt_Id;
kono
parents:
diff changeset
104 pragma Inline (First_Elmt);
kono
parents:
diff changeset
105 -- Obtains the first element of the given element list or, if the list has
kono
parents:
diff changeset
106 -- no items, then No_Elmt is returned.
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 function Last_Elmt (List : Elist_Id) return Elmt_Id;
kono
parents:
diff changeset
109 pragma Inline (Last_Elmt);
kono
parents:
diff changeset
110 -- Obtains the last element of the given element list or, if the list has
kono
parents:
diff changeset
111 -- no items, then No_Elmt is returned.
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 function List_Length (List : Elist_Id) return Nat;
kono
parents:
diff changeset
114 -- Returns number of elements in given List (zero if List = No_Elist)
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 function Next_Elmt (Elmt : Elmt_Id) return Elmt_Id;
kono
parents:
diff changeset
117 pragma Inline (Next_Elmt);
kono
parents:
diff changeset
118 -- This function returns the next element on an element list. The argument
kono
parents:
diff changeset
119 -- must be a list element other than No_Elmt. Returns No_Elmt if the given
kono
parents:
diff changeset
120 -- element is the last element of the list.
kono
parents:
diff changeset
121
kono
parents:
diff changeset
122 procedure Next_Elmt (Elmt : in out Elmt_Id);
kono
parents:
diff changeset
123 pragma Inline (Next_Elmt);
kono
parents:
diff changeset
124 -- Next_Elmt (Elmt) is equivalent to Elmt := Next_Elmt (Elmt)
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 function Is_Empty_Elmt_List (List : Elist_Id) return Boolean;
kono
parents:
diff changeset
127 pragma Inline (Is_Empty_Elmt_List);
kono
parents:
diff changeset
128 -- This function determines if a given tree id references an element list
kono
parents:
diff changeset
129 -- that contains no items.
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 procedure Append_Elmt (N : Node_Or_Entity_Id; To : Elist_Id);
kono
parents:
diff changeset
132 -- Appends N at the end of To, allocating a new element. N must be a
kono
parents:
diff changeset
133 -- non-empty node or entity Id, and To must be an Elist (not No_Elist).
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 procedure Append_New_Elmt (N : Node_Or_Entity_Id; To : in out Elist_Id);
kono
parents:
diff changeset
136 pragma Inline (Append_New_Elmt);
kono
parents:
diff changeset
137 -- Like Append_Elmt if Elist_Id is not No_List, but if Elist_Id is No_List,
kono
parents:
diff changeset
138 -- then first assigns it an empty element list and then does the append.
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 procedure Append_Unique_Elmt (N : Node_Or_Entity_Id; To : Elist_Id);
kono
parents:
diff changeset
141 -- Like Append_Elmt, except that a check is made to see if To already
kono
parents:
diff changeset
142 -- contains N and if so the call has no effect.
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 procedure Prepend_Elmt (N : Node_Or_Entity_Id; To : Elist_Id);
kono
parents:
diff changeset
145 -- Appends N at the beginning of To, allocating a new element
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 procedure Prepend_Unique_Elmt (N : Node_Or_Entity_Id; To : Elist_Id);
kono
parents:
diff changeset
148 -- Like Prepend_Elmt, except that a check is made to see if To already
kono
parents:
diff changeset
149 -- contains N and if so the call has no effect.
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 procedure Insert_Elmt_After (N : Node_Or_Entity_Id; Elmt : Elmt_Id);
kono
parents:
diff changeset
152 -- Add a new element (N) right after the pre-existing element Elmt
kono
parents:
diff changeset
153 -- It is invalid to call this subprogram with Elmt = No_Elmt.
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 function New_Copy_Elist (List : Elist_Id) return Elist_Id;
kono
parents:
diff changeset
156 -- Replicate the contents of a list. Internal list nodes are not shared and
kono
parents:
diff changeset
157 -- order of elements is preserved.
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 procedure Replace_Elmt (Elmt : Elmt_Id; New_Node : Node_Or_Entity_Id);
kono
parents:
diff changeset
160 pragma Inline (Replace_Elmt);
kono
parents:
diff changeset
161 -- Causes the given element of the list to refer to New_Node, the node
kono
parents:
diff changeset
162 -- which was previously referred to by Elmt is effectively removed from
kono
parents:
diff changeset
163 -- the list and replaced by New_Node.
kono
parents:
diff changeset
164
kono
parents:
diff changeset
165 procedure Remove (List : Elist_Id; N : Node_Or_Entity_Id);
kono
parents:
diff changeset
166 -- Remove a node or an entity from a list. If the list does not contain the
kono
parents:
diff changeset
167 -- item in question, the routine has no effect.
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 procedure Remove_Elmt (List : Elist_Id; Elmt : Elmt_Id);
kono
parents:
diff changeset
170 -- Removes Elmt from the given list. The node itself is not affected,
kono
parents:
diff changeset
171 -- but the space used by the list element may be (but is not required
kono
parents:
diff changeset
172 -- to be) freed for reuse in a subsequent Append_Elmt call.
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 procedure Remove_Last_Elmt (List : Elist_Id);
kono
parents:
diff changeset
175 -- Removes the last element of the given list. The node itself is not
kono
parents:
diff changeset
176 -- affected, but the space used by the list element may be (but is not
kono
parents:
diff changeset
177 -- required to be) freed for reuse in a subsequent Append_Elmt call.
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 function Contains (List : Elist_Id; N : Node_Or_Entity_Id) return Boolean;
kono
parents:
diff changeset
180 -- Perform a sequential search to determine whether the given list contains
kono
parents:
diff changeset
181 -- a node or an entity.
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 function No (List : Elist_Id) return Boolean;
kono
parents:
diff changeset
184 pragma Inline (No);
kono
parents:
diff changeset
185 -- Tests given Id for equality with No_Elist. This allows notations like
kono
parents:
diff changeset
186 -- "if No (Statements)" as opposed to "if Statements = No_Elist".
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 function Present (List : Elist_Id) return Boolean;
kono
parents:
diff changeset
189 pragma Inline (Present);
kono
parents:
diff changeset
190 -- Tests given Id for inequality with No_Elist. This allows notations like
kono
parents:
diff changeset
191 -- "if Present (Statements)" as opposed to "if Statements /= No_Elist".
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 function No (Elmt : Elmt_Id) return Boolean;
kono
parents:
diff changeset
194 pragma Inline (No);
kono
parents:
diff changeset
195 -- Tests given Id for equality with No_Elmt. This allows notations like
kono
parents:
diff changeset
196 -- "if No (Operation)" as opposed to "if Operation = No_Elmt".
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 function Present (Elmt : Elmt_Id) return Boolean;
kono
parents:
diff changeset
199 pragma Inline (Present);
kono
parents:
diff changeset
200 -- Tests given Id for inequality with No_Elmt. This allows notations like
kono
parents:
diff changeset
201 -- "if Present (Operation)" as opposed to "if Operation /= No_Elmt".
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 end Elists;