OSDN Git Service

* configure.in (all_headers, all_lib2funcs): Remove.
[pf3gnuchains/gcc-fork.git] / gcc / ada / g-table.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT RUNTIME COMPONENTS                          --
4 --                                                                          --
5 --                            G N A T . T A B L E                           --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --                            $Revision: 1.1 $
10 --                                                                          --
11 --            Copyright (C) 1998-2001 Ada Core Technologies, Inc.           --
12 --                                                                          --
13 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
14 -- terms of the  GNU General Public License as published  by the Free Soft- --
15 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
16 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
19 -- for  more details.  You should have  received  a copy of the GNU General --
20 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
21 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
22 -- MA 02111-1307, USA.                                                      --
23 --                                                                          --
24 -- As a special exception,  if other files  instantiate  generics from this --
25 -- unit, or you link  this unit with other files  to produce an executable, --
26 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
27 -- covered  by the  GNU  General  Public  License.  This exception does not --
28 -- however invalidate  any other reasons why  the executable file  might be --
29 -- covered by the  GNU Public License.                                      --
30 --                                                                          --
31 -- GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com).   --
32 --                                                                          --
33 ------------------------------------------------------------------------------
34
35 --  Resizable one dimensional array support
36
37 --  This package provides an implementation of dynamically resizable one
38 --  dimensional arrays. The idea is to mimic the normal Ada semantics for
39 --  arrays as closely as possible with the one additional capability of
40 --  dynamically modifying the value of the Last attribute.
41
42 --  This package provides a facility similar to that of GNAT.Dynamic_Tables,
43 --  except that this package declares a single instance of the table type,
44 --  while an instantiation of GNAT.Dynamic_Tables creates a type that can be
45 --  used to define dynamic instances of the table.
46
47 --  Note that this interface should remain synchronized with those in
48 --  GNAT.Dynamic_Tables and the GNAT compiler source unit Table to keep
49 --  as much coherency as possible between these three related units.
50
51 generic
52    type Table_Component_Type is private;
53    type Table_Index_Type     is range <>;
54
55    Table_Low_Bound : Table_Index_Type;
56    Table_Initial   : Positive;
57    Table_Increment : Natural;
58
59 package GNAT.Table is
60 pragma Elaborate_Body (Table);
61
62    --  Table_Component_Type and Table_Index_Type specify the type of the
63    --  array, Table_Low_Bound is the lower bound. Index_type must be an
64    --  integer type. The effect is roughly to declare:
65
66    --    Table : array (Table_Index_Type range Table_Low_Bound .. <>)
67    --                       of Table_Component_Type;
68
69    --    Note: since the upper bound can be one less than the lower
70    --    bound for an empty array, the table index type must be able
71    --    to cover this range, e.g. if the lower bound is 1, then the
72    --    Table_Index_Type should be Natural rather than Positive.
73
74    --  Table_Component_Type may be any Ada type, except that controlled
75    --  types are not supported. Note however that default initialization
76    --  will NOT occur for array components.
77
78    --  The Table_Initial values controls the allocation of the table when
79    --  it is first allocated, either by default, or by an explicit Init call.
80
81    --  The Table_Increment value controls the amount of increase, if the
82    --  table has to be increased in size. The value given is a percentage
83    --  value (e.g. 100 = increase table size by 100%, i.e. double it).
84
85    --  The Last and Set_Last subprograms provide control over the current
86    --  logical allocation. They are quite efficient, so they can be used
87    --  freely (expensive reallocation occurs only at major granularity
88    --  chunks controlled by the allocation parameters).
89
90    --  Note: we do not make the table components aliased, since this would
91    --  restrict the use of table for discriminated types. If it is necessary
92    --  to take the access of a table element, use Unrestricted_Access.
93
94    type Table_Type is
95      array (Table_Index_Type range <>) of Table_Component_Type;
96
97    subtype Big_Table_Type is
98      Table_Type (Table_Low_Bound .. Table_Index_Type'Last);
99    --  We work with pointers to a bogus array type that is constrained
100    --  with the maximum possible range bound. This means that the pointer
101    --  is a thin pointer, which is more efficient. Since subscript checks
102    --  in any case must be on the logical, rather than physical bounds,
103    --  safety is not compromised by this approach.
104
105    type Table_Ptr is access all Big_Table_Type;
106    --  The table is actually represented as a pointer to allow reallocation
107
108    Table : aliased Table_Ptr := null;
109    --  The table itself. The lower bound is the value of Low_Bound.
110    --  Logically the upper bound is the current value of Last (although
111    --  the actual size of the allocated table may be larger than this).
112    --  The program may only access and modify Table entries in the range
113    --  First .. Last.
114
115    Locked : Boolean := False;
116    --  Table expansion is permitted only if this switch is set to False. A
117    --  client may set Locked to True, in which case any attempt to expand
118    --  the table will cause an assertion failure. Note that while a table
119    --  is locked, its address in memory remains fixed and unchanging.
120
121    procedure Init;
122    --  This procedure allocates a new table of size Initial (freeing any
123    --  previously allocated larger table). It is not necessary to call
124    --  Init when a table is first instantiated (since the instantiation does
125    --  the same initialization steps). However, it is harmless to do so, and
126    --  Init is convenient in reestablishing a table for new use.
127
128    function Last return Table_Index_Type;
129    pragma Inline (Last);
130    --  Returns the current value of the last used entry in the table, which
131    --  can then be used as a subscript for Table. Note that the only way to
132    --  modify Last is to call the Set_Last procedure. Last must always be
133    --  used to determine the logically last entry.
134
135    procedure Release;
136    --  Storage is allocated in chunks according to the values given in the
137    --  Initial and Increment parameters. A call to Release releases all
138    --  storage that is allocated, but is not logically part of the current
139    --  array value. Current array values are not affected by this call.
140
141    procedure Free;
142    --  Free all allocated memory for the table. A call to init is required
143    --  before any use of this table after calling Free.
144
145    First : constant Table_Index_Type := Table_Low_Bound;
146    --  Export First as synonym for Low_Bound (parallel with use of Last)
147
148    procedure Set_Last (New_Val : Table_Index_Type);
149    pragma Inline (Set_Last);
150    --  This procedure sets Last to the indicated value. If necessary the
151    --  table is reallocated to accommodate the new value (i.e. on return
152    --  the allocated table has an upper bound of at least Last). If Set_Last
153    --  reduces the size of the table, then logically entries are removed
154    --  from the table. If Set_Last increases the size of the table, then
155    --  new entries are logically added to the table.
156
157    procedure Increment_Last;
158    pragma Inline (Increment_Last);
159    --  Adds 1 to Last (same as Set_Last (Last + 1).
160
161    procedure Decrement_Last;
162    pragma Inline (Decrement_Last);
163    --  Subtracts 1 from Last (same as Set_Last (Last - 1).
164
165    procedure Append (New_Val : Table_Component_Type);
166    pragma Inline (Append);
167    --  Equivalent to:
168    --    x.Increment_Last;
169    --    x.Table (x.Last) := New_Val;
170    --  i.e. the table size is increased by one, and the given new item
171    --  stored in the newly created table element.
172
173    procedure Set_Item
174      (Index : Table_Index_Type;
175       Item  : Table_Component_Type);
176    pragma Inline (Set_Item);
177    --  Put Item in the table at position Index. The table is expanded if the
178    --  current table length is less than Index and in that case Last is set to
179    --  Index. Item will replace any value already present in the table at this
180    --  position.
181
182    function Allocate (Num : Integer := 1) return Table_Index_Type;
183    pragma Inline (Allocate);
184    --  Adds Num to Last, and returns the old value of Last + 1. Note that
185    --  this function has the possible side effect of reallocating the table.
186    --  This means that a reference X.Table (X.Allocate) is incorrect, since
187    --  the call to X.Allocate may modify the results of calling X.Table.
188
189 end GNAT.Table;