annotate gcc/ada/libgnat/g-spitbo.ads @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
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 LIBRARY COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- G N A T . S P I T B O L --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
kono
parents:
diff changeset
9 -- Copyright (C) 1997-2017, AdaCore --
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 -- SPITBOL-like interface facilities
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 -- This package provides a set of interfaces to semantic operations copied
kono
parents:
diff changeset
35 -- from SPITBOL, including a complete implementation of SPITBOL pattern
kono
parents:
diff changeset
36 -- matching. The code is derived from the original SPITBOL MINIMAL sources,
kono
parents:
diff changeset
37 -- created by Robert Dewar. The translation is not exact, but the
kono
parents:
diff changeset
38 -- algorithmic approaches are similar.
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 with Ada.Finalization; use Ada.Finalization;
kono
parents:
diff changeset
41 with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
kono
parents:
diff changeset
42 with Interfaces; use Interfaces;
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 package GNAT.Spitbol is
kono
parents:
diff changeset
45 pragma Preelaborate;
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 -- The Spitbol package relies heavily on the Unbounded_String package,
kono
parents:
diff changeset
48 -- using the synonym VString for variable length string. The following
kono
parents:
diff changeset
49 -- declarations define this type and other useful abbreviations.
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 subtype VString is Ada.Strings.Unbounded.Unbounded_String;
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 function V (Source : String) return VString
kono
parents:
diff changeset
54 renames Ada.Strings.Unbounded.To_Unbounded_String;
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 function S (Source : VString) return String
kono
parents:
diff changeset
57 renames Ada.Strings.Unbounded.To_String;
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 Nul : VString renames Ada.Strings.Unbounded.Null_Unbounded_String;
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 -------------------------
kono
parents:
diff changeset
62 -- Facilities Provided --
kono
parents:
diff changeset
63 -------------------------
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 -- The SPITBOL support in GNAT consists of this package together with
kono
parents:
diff changeset
66 -- several child packages. In this package, we have first a set of
kono
parents:
diff changeset
67 -- useful string functions, copied exactly from the corresponding
kono
parents:
diff changeset
68 -- SPITBOL functions, except that we had to rename REVERSE because
kono
parents:
diff changeset
69 -- reverse is a reserved word (it is now Reverse_String).
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 -- The second element of the parent package is a generic implementation
kono
parents:
diff changeset
72 -- of a table facility. In SPITBOL, the TABLE function allows general
kono
parents:
diff changeset
73 -- mappings from any datatype to any other datatype, and of course, as
kono
parents:
diff changeset
74 -- always, we can freely mix multiple types in the same table.
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 -- The Ada version of tables is strongly typed, so the indexing type and
kono
parents:
diff changeset
77 -- the range type are always of a consistent type. In this implementation
kono
parents:
diff changeset
78 -- we only provide VString as an indexing type, since this is by far the
kono
parents:
diff changeset
79 -- most common case. The generic instantiation specifies the range type
kono
parents:
diff changeset
80 -- to be used.
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 -- Three child packages provide standard instantiations of this table
kono
parents:
diff changeset
83 -- package for three common datatypes:
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 -- GNAT.Spitbol.Table_Boolean (file g-sptabo.ads)
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 -- The range type is Boolean. The default value is False. This
kono
parents:
diff changeset
88 -- means that this table is essentially a representation of a set.
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 -- GNAT.Spitbol.Table_Integer (file g-sptain.ads)
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 -- The range type is Integer. The default value is Integer'First.
kono
parents:
diff changeset
93 -- This provides a general mapping from strings to integers.
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 -- GNAT.Spitbol.Table_VString (file g-sptavs.ads)
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 -- The range type is VString. The default value is the null string.
kono
parents:
diff changeset
98 -- This provides a general mapping from strings to strings.
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 -- Finally there is another child package:
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 -- GNAT.Spitbol.Patterns (file g-spipat.ads)
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 -- This child package provides a complete implementation of SPITBOL
kono
parents:
diff changeset
105 -- pattern matching. The spec contains a complete tutorial on the
kono
parents:
diff changeset
106 -- use of pattern matching.
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 ---------------------------------
kono
parents:
diff changeset
109 -- Standard String Subprograms --
kono
parents:
diff changeset
110 ---------------------------------
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 -- This section contains some operations on unbounded strings that are
kono
parents:
diff changeset
113 -- closely related to those in the package Unbounded.Strings, but they
kono
parents:
diff changeset
114 -- correspond to the SPITBOL semantics for these operations.
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 function Char (Num : Natural) return Character;
kono
parents:
diff changeset
117 pragma Inline (Char);
kono
parents:
diff changeset
118 -- Equivalent to Character'Val (Num)
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 function Lpad
kono
parents:
diff changeset
121 (Str : VString;
kono
parents:
diff changeset
122 Len : Natural;
kono
parents:
diff changeset
123 Pad : Character := ' ') return VString;
kono
parents:
diff changeset
124 function Lpad
kono
parents:
diff changeset
125 (Str : String;
kono
parents:
diff changeset
126 Len : Natural;
kono
parents:
diff changeset
127 Pad : Character := ' ') return VString;
kono
parents:
diff changeset
128 -- If the length of Str is greater than or equal to Len, then Str is
kono
parents:
diff changeset
129 -- returned unchanged. Otherwise, The value returned is obtained by
kono
parents:
diff changeset
130 -- concatenating Length (Str) - Len instances of the Pad character to
kono
parents:
diff changeset
131 -- the left hand side.
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 procedure Lpad
kono
parents:
diff changeset
134 (Str : in out VString;
kono
parents:
diff changeset
135 Len : Natural;
kono
parents:
diff changeset
136 Pad : Character := ' ');
kono
parents:
diff changeset
137 -- The procedure form is identical to the function form, except that
kono
parents:
diff changeset
138 -- the result overwrites the input argument Str.
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 function Reverse_String (Str : VString) return VString;
kono
parents:
diff changeset
141 function Reverse_String (Str : String) return VString;
kono
parents:
diff changeset
142 -- Returns result of reversing the string Str, i.e. the result returned
kono
parents:
diff changeset
143 -- is a mirror image (end-for-end reversal) of the input string.
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 procedure Reverse_String (Str : in out VString);
kono
parents:
diff changeset
146 -- The procedure form is identical to the function form, except that the
kono
parents:
diff changeset
147 -- result overwrites the input argument Str.
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 function Rpad
kono
parents:
diff changeset
150 (Str : VString;
kono
parents:
diff changeset
151 Len : Natural;
kono
parents:
diff changeset
152 Pad : Character := ' ') return VString;
kono
parents:
diff changeset
153 function Rpad
kono
parents:
diff changeset
154 (Str : String;
kono
parents:
diff changeset
155 Len : Natural;
kono
parents:
diff changeset
156 Pad : Character := ' ') return VString;
kono
parents:
diff changeset
157 -- If the length of Str is greater than or equal to Len, then Str is
kono
parents:
diff changeset
158 -- returned unchanged. Otherwise, The value returned is obtained by
kono
parents:
diff changeset
159 -- concatenating Length (Str) - Len instances of the Pad character to
kono
parents:
diff changeset
160 -- the right hand side.
kono
parents:
diff changeset
161
kono
parents:
diff changeset
162 procedure Rpad
kono
parents:
diff changeset
163 (Str : in out VString;
kono
parents:
diff changeset
164 Len : Natural;
kono
parents:
diff changeset
165 Pad : Character := ' ');
kono
parents:
diff changeset
166 -- The procedure form is identical to the function form, except that the
kono
parents:
diff changeset
167 -- result overwrites the input argument Str.
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 function Size (Source : VString) return Natural
kono
parents:
diff changeset
170 renames Ada.Strings.Unbounded.Length;
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 function Substr
kono
parents:
diff changeset
173 (Str : VString;
kono
parents:
diff changeset
174 Start : Positive;
kono
parents:
diff changeset
175 Len : Natural) return VString;
kono
parents:
diff changeset
176 function Substr
kono
parents:
diff changeset
177 (Str : String;
kono
parents:
diff changeset
178 Start : Positive;
kono
parents:
diff changeset
179 Len : Natural) return VString;
kono
parents:
diff changeset
180 -- Returns the substring starting at the given character position (which
kono
parents:
diff changeset
181 -- is always counted from the start of the string, regardless of bounds,
kono
parents:
diff changeset
182 -- e.g. 2 means starting with the second character of the string), and
kono
parents:
diff changeset
183 -- with the length (Len) given. Index_Error is raised if the starting
kono
parents:
diff changeset
184 -- position is out of range, and Length_Error is raised if Len is too long.
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 function Trim (Str : VString) return VString;
kono
parents:
diff changeset
187 function Trim (Str : String) return VString;
kono
parents:
diff changeset
188 -- Returns the string obtained by removing all spaces from the right
kono
parents:
diff changeset
189 -- hand side of the string Str.
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 procedure Trim (Str : in out VString);
kono
parents:
diff changeset
192 -- The procedure form is identical to the function form, except that the
kono
parents:
diff changeset
193 -- result overwrites the input argument Str.
kono
parents:
diff changeset
194
kono
parents:
diff changeset
195 -----------------------
kono
parents:
diff changeset
196 -- Utility Functions --
kono
parents:
diff changeset
197 -----------------------
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 -- In SPITBOL, integer values can be freely treated as strings. The
kono
parents:
diff changeset
200 -- following definitions help provide some of this capability in
kono
parents:
diff changeset
201 -- some common cases.
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 function "&" (Num : Integer; Str : String) return String;
kono
parents:
diff changeset
204 function "&" (Str : String; Num : Integer) return String;
kono
parents:
diff changeset
205 function "&" (Num : Integer; Str : VString) return VString;
kono
parents:
diff changeset
206 function "&" (Str : VString; Num : Integer) return VString;
kono
parents:
diff changeset
207 -- In all these concatenation operations, the integer is converted to
kono
parents:
diff changeset
208 -- its corresponding decimal string form, with no leading blank.
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 function S (Num : Integer) return String;
kono
parents:
diff changeset
211 function V (Num : Integer) return VString;
kono
parents:
diff changeset
212 -- These operators return the given integer converted to its decimal
kono
parents:
diff changeset
213 -- string form with no leading blank.
kono
parents:
diff changeset
214
kono
parents:
diff changeset
215 function N (Str : VString) return Integer;
kono
parents:
diff changeset
216 -- Converts string to number (same as Integer'Value (S (Str)))
kono
parents:
diff changeset
217
kono
parents:
diff changeset
218 -------------------
kono
parents:
diff changeset
219 -- Table Support --
kono
parents:
diff changeset
220 -------------------
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222 -- So far, we only provide support for tables whose indexing data values
kono
parents:
diff changeset
223 -- are strings (or unbounded strings). The values stored may be of any
kono
parents:
diff changeset
224 -- type, as supplied by the generic formal parameter.
kono
parents:
diff changeset
225
kono
parents:
diff changeset
226 generic
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 type Value_Type is private;
kono
parents:
diff changeset
229 -- Any non-limited type can be used as the value type in the table
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231 Null_Value : Value_Type;
kono
parents:
diff changeset
232 -- Value used to represent a value that is not present in the table
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 with function Img (A : Value_Type) return String;
kono
parents:
diff changeset
235 -- Used to provide image of value in Dump procedure
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 with function "=" (A, B : Value_Type) return Boolean is <>;
kono
parents:
diff changeset
238 -- This allows a user-defined equality function to override the
kono
parents:
diff changeset
239 -- predefined equality function.
kono
parents:
diff changeset
240
kono
parents:
diff changeset
241 package Table is
kono
parents:
diff changeset
242
kono
parents:
diff changeset
243 ------------------------
kono
parents:
diff changeset
244 -- Table Declarations --
kono
parents:
diff changeset
245 ------------------------
kono
parents:
diff changeset
246
kono
parents:
diff changeset
247 type Table (N : Unsigned_32) is private;
kono
parents:
diff changeset
248 -- This is the table type itself. A table is a mapping from string
kono
parents:
diff changeset
249 -- values to values of Value_Type. The discriminant is an estimate of
kono
parents:
diff changeset
250 -- the number of values in the table. If the estimate is much too
kono
parents:
diff changeset
251 -- high, some space is wasted, if the estimate is too low, access to
kono
parents:
diff changeset
252 -- table elements is slowed down. The type Table has copy semantics,
kono
parents:
diff changeset
253 -- not reference semantics. This means that if a table is copied
kono
parents:
diff changeset
254 -- using simple assignment, then the two copies refer to entirely
kono
parents:
diff changeset
255 -- separate tables.
kono
parents:
diff changeset
256
kono
parents:
diff changeset
257 -----------------------------
kono
parents:
diff changeset
258 -- Table Access Operations --
kono
parents:
diff changeset
259 -----------------------------
kono
parents:
diff changeset
260
kono
parents:
diff changeset
261 function Get (T : Table; Name : VString) return Value_Type;
kono
parents:
diff changeset
262 function Get (T : Table; Name : Character) return Value_Type;
kono
parents:
diff changeset
263 pragma Inline (Get);
kono
parents:
diff changeset
264 function Get (T : Table; Name : String) return Value_Type;
kono
parents:
diff changeset
265
kono
parents:
diff changeset
266 -- If an entry with the given name exists in the table, then the
kono
parents:
diff changeset
267 -- corresponding Value_Type value is returned. Otherwise Null_Value
kono
parents:
diff changeset
268 -- is returned.
kono
parents:
diff changeset
269
kono
parents:
diff changeset
270 function Present (T : Table; Name : VString) return Boolean;
kono
parents:
diff changeset
271 function Present (T : Table; Name : Character) return Boolean;
kono
parents:
diff changeset
272 pragma Inline (Present);
kono
parents:
diff changeset
273 function Present (T : Table; Name : String) return Boolean;
kono
parents:
diff changeset
274 -- Determines if an entry with the given name is present in the table.
kono
parents:
diff changeset
275 -- A returned value of True means that it is in the table, otherwise
kono
parents:
diff changeset
276 -- False indicates that it is not in the table.
kono
parents:
diff changeset
277
kono
parents:
diff changeset
278 procedure Delete (T : in out Table; Name : VString);
kono
parents:
diff changeset
279 procedure Delete (T : in out Table; Name : Character);
kono
parents:
diff changeset
280 pragma Inline (Delete);
kono
parents:
diff changeset
281 procedure Delete (T : in out Table; Name : String);
kono
parents:
diff changeset
282 -- Deletes the table element with the given name from the table. If
kono
parents:
diff changeset
283 -- no element in the table has this name, then the call has no effect.
kono
parents:
diff changeset
284
kono
parents:
diff changeset
285 procedure Set (T : in out Table; Name : VString; Value : Value_Type);
kono
parents:
diff changeset
286 procedure Set (T : in out Table; Name : Character; Value : Value_Type);
kono
parents:
diff changeset
287 pragma Inline (Set);
kono
parents:
diff changeset
288 procedure Set (T : in out Table; Name : String; Value : Value_Type);
kono
parents:
diff changeset
289 -- Sets the value of the element with the given name to the given
kono
parents:
diff changeset
290 -- value. If Value is equal to Null_Value, the effect is to remove
kono
parents:
diff changeset
291 -- the entry from the table. If no element with the given name is
kono
parents:
diff changeset
292 -- currently in the table, then a new element with the given value
kono
parents:
diff changeset
293 -- is created.
kono
parents:
diff changeset
294
kono
parents:
diff changeset
295 ----------------------------
kono
parents:
diff changeset
296 -- Allocation and Copying --
kono
parents:
diff changeset
297 ----------------------------
kono
parents:
diff changeset
298
kono
parents:
diff changeset
299 -- Table is a controlled type, so that all storage associated with
kono
parents:
diff changeset
300 -- tables is properly reclaimed when a Table value is abandoned.
kono
parents:
diff changeset
301 -- Tables have value semantics rather than reference semantics as
kono
parents:
diff changeset
302 -- in Spitbol, i.e. when you assign a copy you end up with two
kono
parents:
diff changeset
303 -- distinct copies of the table, as though COPY had been used in
kono
parents:
diff changeset
304 -- Spitbol. It seems clearly more appropriate in Ada to require
kono
parents:
diff changeset
305 -- the use of explicit pointers for reference semantics.
kono
parents:
diff changeset
306
kono
parents:
diff changeset
307 procedure Clear (T : in out Table);
kono
parents:
diff changeset
308 -- Clears all the elements of the given table, freeing associated
kono
parents:
diff changeset
309 -- storage. On return T is an empty table with no elements.
kono
parents:
diff changeset
310
kono
parents:
diff changeset
311 procedure Copy (From : Table; To : in out Table);
kono
parents:
diff changeset
312 -- First all the elements of table To are cleared (as described for
kono
parents:
diff changeset
313 -- the Clear procedure above), then all the elements of table From
kono
parents:
diff changeset
314 -- are copied into To. In the case where the tables From and To have
kono
parents:
diff changeset
315 -- the same declared size (i.e. the same discriminant), the call to
kono
parents:
diff changeset
316 -- Copy has the same effect as the assignment of From to To. The
kono
parents:
diff changeset
317 -- difference is that, unlike the assignment statement, which will
kono
parents:
diff changeset
318 -- cause a Constraint_Error if the source and target are of different
kono
parents:
diff changeset
319 -- sizes, Copy works fine with different sized tables.
kono
parents:
diff changeset
320
kono
parents:
diff changeset
321 ----------------
kono
parents:
diff changeset
322 -- Conversion --
kono
parents:
diff changeset
323 ----------------
kono
parents:
diff changeset
324
kono
parents:
diff changeset
325 type Table_Entry is record
kono
parents:
diff changeset
326 Name : VString;
kono
parents:
diff changeset
327 Value : Value_Type;
kono
parents:
diff changeset
328 end record;
kono
parents:
diff changeset
329
kono
parents:
diff changeset
330 type Table_Array is array (Positive range <>) of Table_Entry;
kono
parents:
diff changeset
331
kono
parents:
diff changeset
332 function Convert_To_Array (T : Table) return Table_Array;
kono
parents:
diff changeset
333 -- Returns a Table_Array value with a low bound of 1, and a length
kono
parents:
diff changeset
334 -- corresponding to the number of elements in the table. The elements
kono
parents:
diff changeset
335 -- of the array give the elements of the table in unsorted order.
kono
parents:
diff changeset
336
kono
parents:
diff changeset
337 ---------------
kono
parents:
diff changeset
338 -- Debugging --
kono
parents:
diff changeset
339 ---------------
kono
parents:
diff changeset
340
kono
parents:
diff changeset
341 procedure Dump (T : Table; Str : String := "Table");
kono
parents:
diff changeset
342 -- Dump contents of given table to the standard output file. The
kono
parents:
diff changeset
343 -- string value Str is used as the name of the table in the dump.
kono
parents:
diff changeset
344
kono
parents:
diff changeset
345 procedure Dump (T : Table_Array; Str : String := "Table_Array");
kono
parents:
diff changeset
346 -- Dump contents of given table array to the current output file. The
kono
parents:
diff changeset
347 -- string value Str is used as the name of the table array in the dump.
kono
parents:
diff changeset
348
kono
parents:
diff changeset
349 private
kono
parents:
diff changeset
350
kono
parents:
diff changeset
351 ------------------
kono
parents:
diff changeset
352 -- Private Part --
kono
parents:
diff changeset
353 ------------------
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 -- A Table is a pointer to a hash table which contains the indicated
kono
parents:
diff changeset
356 -- number of hash elements (the number is forced to the next odd value
kono
parents:
diff changeset
357 -- if it is even to improve hashing performance). If more than one
kono
parents:
diff changeset
358 -- of the entries in a table hashes to the same slot, the Next field
kono
parents:
diff changeset
359 -- is used to chain entries from the header. The chains are not kept
kono
parents:
diff changeset
360 -- ordered. A chain is terminated by a null pointer in Next. An unused
kono
parents:
diff changeset
361 -- chain is marked by an element whose Name is null and whose value
kono
parents:
diff changeset
362 -- is Null_Value.
kono
parents:
diff changeset
363
kono
parents:
diff changeset
364 type Hash_Element;
kono
parents:
diff changeset
365 type Hash_Element_Ptr is access all Hash_Element;
kono
parents:
diff changeset
366
kono
parents:
diff changeset
367 type Hash_Element is record
kono
parents:
diff changeset
368 Name : String_Access := null;
kono
parents:
diff changeset
369 Value : Value_Type := Null_Value;
kono
parents:
diff changeset
370 Next : Hash_Element_Ptr := null;
kono
parents:
diff changeset
371 end record;
kono
parents:
diff changeset
372
kono
parents:
diff changeset
373 type Hash_Table is
kono
parents:
diff changeset
374 array (Unsigned_32 range <>) of aliased Hash_Element;
kono
parents:
diff changeset
375
kono
parents:
diff changeset
376 type Table (N : Unsigned_32) is new Controlled with record
kono
parents:
diff changeset
377 Elmts : Hash_Table (1 .. N);
kono
parents:
diff changeset
378 end record;
kono
parents:
diff changeset
379
kono
parents:
diff changeset
380 pragma Finalize_Storage_Only (Table);
kono
parents:
diff changeset
381
kono
parents:
diff changeset
382 overriding procedure Adjust (Object : in out Table);
kono
parents:
diff changeset
383 -- The Adjust procedure does a deep copy of the table structure
kono
parents:
diff changeset
384 -- so that the effect of assignment is, like other assignments
kono
parents:
diff changeset
385 -- in Ada, value-oriented.
kono
parents:
diff changeset
386
kono
parents:
diff changeset
387 overriding procedure Finalize (Object : in out Table);
kono
parents:
diff changeset
388 -- This is the finalization routine that ensures that all storage
kono
parents:
diff changeset
389 -- associated with a table is properly released when a table object
kono
parents:
diff changeset
390 -- is abandoned and finalized.
kono
parents:
diff changeset
391
kono
parents:
diff changeset
392 end Table;
kono
parents:
diff changeset
393
kono
parents:
diff changeset
394 end GNAT.Spitbol;