* dwarf2out.c (loc_descriptor_from_tree, case CONSTRUCTOR): New case.
[official-gcc.git] / gcc / ada / g-dyntab.ads
blob6adf4ee5573f8b81044f8992c5c7f2d999aec77a
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- G N A T . D Y N A M I C _ T A B L E S --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2000-2002 Ada Core Technologies, 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 is maintained by Ada Core Technologies Inc (http://www.gnat.com). --
30 -- --
31 ------------------------------------------------------------------------------
33 -- Resizable one dimensional array support
35 -- This package provides an implementation of dynamically resizable one
36 -- dimensional arrays. The idea is to mimic the normal Ada semantics for
37 -- arrays as closely as possible with the one additional capability of
38 -- dynamically modifying the value of the Last attribute.
40 -- This package provides a facility similar to that of GNAT.Table, except
41 -- that this package declares a type that can be used to define dynamic
42 -- instances of the table, while an instantiation of GNAT.Table creates a
43 -- single instance of the table type.
45 -- Note that this interface should remain synchronized with those in
46 -- GNAT.Table and the GNAT compiler source unit Table to keep as much
47 -- coherency as possible between these three related units.
49 generic
50 type Table_Component_Type is private;
51 type Table_Index_Type is range <>;
53 Table_Low_Bound : Table_Index_Type;
54 Table_Initial : Positive;
55 Table_Increment : Natural;
57 package GNAT.Dynamic_Tables is
59 -- Table_Component_Type and Table_Index_Type specify the type of the
60 -- array, Table_Low_Bound is the lower bound. Index_type must be an
61 -- integer type. The effect is roughly to declare:
63 -- Table : array (Table_Low_Bound .. <>) of Table_Component_Type;
65 -- Table_Component_Type may be any Ada type, except that controlled
66 -- types are not supported. Note however that default initialization
67 -- will NOT occur for array components.
69 -- The Table_Initial values controls the allocation of the table when
70 -- it is first allocated, either by default, or by an explicit Init
71 -- call.
73 -- The Table_Increment value controls the amount of increase, if the
74 -- table has to be increased in size. The value given is a percentage
75 -- value (e.g. 100 = increase table size by 100%, i.e. double it).
77 -- The Last and Set_Last subprograms provide control over the current
78 -- logical allocation. They are quite efficient, so they can be used
79 -- freely (expensive reallocation occurs only at major granularity
80 -- chunks controlled by the allocation parameters).
82 -- Note: we do not make the table components aliased, since this would
83 -- restrict the use of table for discriminated types. If it is necessary
84 -- to take the access of a table element, use Unrestricted_Access.
86 type Table_Type is
87 array (Table_Index_Type range <>) of Table_Component_Type;
89 subtype Big_Table_Type is
90 Table_Type (Table_Low_Bound .. Table_Index_Type'Last);
91 -- We work with pointers to a bogus array type that is constrained
92 -- with the maximum possible range bound. This means that the pointer
93 -- is a thin pointer, which is more efficient. Since subscript checks
94 -- in any case must be on the logical, rather than physical bounds,
95 -- safety is not compromised by this approach.
97 type Table_Ptr is access all Big_Table_Type;
98 -- The table is actually represented as a pointer to allow
99 -- reallocation.
101 type Table_Private is private;
102 -- table private data that is not exported in Instance.
104 type Instance is record
105 Table : aliased Table_Ptr := null;
106 -- The table itself. The lower bound is the value of Low_Bound.
107 -- Logically the upper bound is the current value of Last (although
108 -- the actual size of the allocated table may be larger than this).
109 -- The program may only access and modify Table entries in the
110 -- range First .. Last.
112 P : Table_Private;
113 end record;
115 procedure Init (T : in out Instance);
116 -- This procedure allocates a new table of size Initial (freeing any
117 -- previously allocated larger table). Init must be called before using
118 -- the table. Init is convenient in reestablishing a table for new use.
120 function Last (T : in Instance) return Table_Index_Type;
121 pragma Inline (Last);
122 -- Returns the current value of the last used entry in the table,
123 -- which can then be used as a subscript for Table. Note that the
124 -- only way to modify Last is to call the Set_Last procedure. Last
125 -- must always be used to determine the logically last entry.
127 procedure Release (T : in out Instance);
128 -- Storage is allocated in chunks according to the values given in the
129 -- Initial and Increment parameters. A call to Release releases all
130 -- storage that is allocated, but is not logically part of the current
131 -- array value. Current array values are not affected by this call.
133 procedure Free (T : in out Instance);
134 -- Free all allocated memory for the table. A call to init is required
135 -- before any use of this table after calling Free.
137 First : constant Table_Index_Type := Table_Low_Bound;
138 -- Export First as synonym for Low_Bound (parallel with use of Last)
140 procedure Set_Last (T : in out Instance; New_Val : Table_Index_Type);
141 pragma Inline (Set_Last);
142 -- This procedure sets Last to the indicated value. If necessary the
143 -- table is reallocated to accommodate the new value (i.e. on return
144 -- the allocated table has an upper bound of at least Last). If
145 -- Set_Last reduces the size of the table, then logically entries are
146 -- removed from the table. If Set_Last increases the size of the
147 -- table, then new entries are logically added to the table.
149 procedure Increment_Last (T : in out Instance);
150 pragma Inline (Increment_Last);
151 -- Adds 1 to Last (same as Set_Last (Last + 1).
153 procedure Decrement_Last (T : in out Instance);
154 pragma Inline (Decrement_Last);
155 -- Subtracts 1 from Last (same as Set_Last (Last - 1).
157 procedure Append (T : in out Instance; New_Val : Table_Component_Type);
158 pragma Inline (Append);
159 -- Equivalent to:
160 -- Increment_Last (T);
161 -- T.Table (T.Last) := New_Val;
162 -- i.e. the table size is increased by one, and the given new item
163 -- stored in the newly created table element.
165 procedure Set_Item
166 (T : in out Instance;
167 Index : Table_Index_Type;
168 Item : Table_Component_Type);
169 pragma Inline (Set_Item);
170 -- Put Item in the table at position Index. The table is expanded if
171 -- current table length is less than Index and in that case Last is set to
172 -- Index. Item will replace any value already present in the table at this
173 -- position.
175 procedure Allocate (T : in out Instance; Num : Integer := 1);
176 pragma Inline (Allocate);
177 -- Adds Num to Last.
179 private
181 type Table_Private is record
182 Max : Integer;
183 -- Subscript of the maximum entry in the currently allocated table
185 Length : Integer := 0;
186 -- Number of entries in currently allocated table. The value of zero
187 -- ensures that we initially allocate the table.
189 Last_Val : Integer;
190 -- Current value of Last.
191 end record;
193 end GNAT.Dynamic_Tables;