mips.h (set_volatile): Delete.
[official-gcc.git] / gcc / ada / sem_maps.ads
blob713999f92cc0306581a2d07d748666342b17b0d4
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ M A P S --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1996-2007, 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 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 -- This package contains the operations on the renaming maps used for
27 -- generic analysis and instantiation. Renaming maps are created when
28 -- a generic unit is analyzed, in order to capture all references to
29 -- global variables within the unit. The renaming map of a generic unit
30 -- copied prior to each instantiation, and then updated by mapping the
31 -- formals into the actuals and the local entities into entities local to
32 -- the instance. When the generic tree is copied to produce the instance,
33 -- all references are updated by means of the renaming map.
35 -- Map composition of renaming maps takes place for nested instantiations,
36 -- for generic child units, and for formal packages.
38 -- For additional details, see the documentation in sem_ch12
40 with Table;
41 with Types; use Types;
43 package Sem_Maps is
45 type Map is new Int;
47 type Assoc is private;
49 type Scope_Kind is (S_Global, S_Formal, S_Local);
51 function New_Map (Num_Assoc : Int) return Map;
52 -- Build empty map with the given number of associations, and a
53 -- headers table of the appropriate size.
55 function Compose (Orig_Map : Map; New_Map : Map) return Map;
56 -- Update the associations in Orig_Map, so that if Orig_Map (e1) = e2
57 -- and New_Map (e2) = e3, then the image of e1 under the result is e3.
59 function Copy (M : Map) return Map;
60 -- Full copy of contents and headers
62 function Lookup (M : Map; E : Entity_Id) return Entity_Id;
63 -- Retrieve image of E under M, Empty if undefined
65 procedure Add_Association
66 (M : Map;
67 O_Id : Entity_Id;
68 N_Id : Entity_Id;
69 Kind : Scope_Kind := S_Local);
70 -- Update M in place. On entry M (O_Id) must not be defined
72 procedure Update_Association
73 (M : Map;
74 O_Id : Entity_Id;
75 N_Id : Entity_Id;
76 Kind : Scope_Kind := S_Local);
77 -- Update the entry in M for O_Id
79 function Build_Instance_Map (M : Map) return Map;
80 -- Copy renaming map of generic, and create new entities for all the
81 -- local entities within.
83 private
85 -- New maps are created when a generic is analyzed, and for each of
86 -- its instantiations. Maps are also updated for nested generics, for
87 -- child units, and for formal packages. As a result we need to allocate
88 -- maps dynamically.
90 -- When analyzing a generic, we do not know how many references are
91 -- in it. We build an initial map after generic analysis, using a static
92 -- structure that relies on the compiler's extensible table mechanism.
93 -- After constructing this initial map, all subsequent uses and updates
94 -- of this map do not modify its domain, so that dynamically allocated
95 -- maps have a fixed size and never need to be reallocated. Furthermore,
96 -- the headers of the hash table of a dynamically allocated map can be
97 -- chosen according to the total number of entries in the map, to
98 -- accommodate efficiently generic units of different sizes (Unchecked_
99 -- Conversion vs. Generic_Elementary_Functions, for example). So in
100 -- fact both components of a map have fixed size, and can be allocated
101 -- using the standard table mechanism. A Maps_Table holds records that
102 -- contain indices into the global Headers table and the Associations
103 -- table, and a Map is an index into the Maps_Table.
105 -- Maps_Table Headers_Table Associations_Table
107 -- |_____| |___________ |
108 -- |_____| | | | |
109 -- ------>|Map |------------------------------>|Associations|
110 -- |Info |------------->| |=========>| for one |
111 -- |_____| | |====| | unit |
112 -- | | | | |====>| |
113 -- |_____| |____________|
114 -- | | | |
115 type Header_Index is new Int;
116 type Assoc_Index is new Int;
117 No_Assoc : constant Assoc_Index := -1;
119 type Map_Info is record
120 Header_Offset : Header_Index;
121 Header_Num : Header_Index;
122 Assoc_Offset : Assoc_Index;
123 Assoc_Num : Assoc_Index;
124 Assoc_Next : Assoc_Index;
125 end record;
127 type Assoc is record
128 Old_Id : Entity_Id := Empty;
129 New_Id : Entity_Id := Empty;
130 Kind : Scope_Kind := S_Local;
131 Next : Assoc_Index := No_Assoc;
132 end record;
134 -- All maps are accessed through the following table. The map attribute
135 -- of a generic unit or an instance is an index into this table.
137 package Maps_Table is new Table.Table (
138 Table_Component_Type => Map_Info,
139 Table_Index_Type => Map,
140 Table_Low_Bound => 0,
141 Table_Initial => 100,
142 Table_Increment => 100,
143 Table_Name => "Maps_Table");
145 -- All headers for hash tables are allocated in one global table. Each
146 -- map stores the offset into this table at which its own headers start.
148 package Headers_Table is new Table.Table (
149 Table_Component_Type => Assoc_Index,
150 Table_Index_Type => Header_Index,
151 Table_Low_Bound => 0,
152 Table_Initial => 1000,
153 Table_Increment => 100,
154 Table_Name => "Headers_Table");
156 -- All associations are allocated in one global table. Each map stores
157 -- the offset into this table at which its own associations start.
159 package Associations_Table is new Table.Table (
160 Table_Component_Type => Assoc,
161 Table_Index_Type => Assoc_Index,
162 Table_Low_Bound => 1,
163 Table_Initial => 1000,
164 Table_Increment => 100,
165 Table_Name => "Associations_Table");
167 end Sem_Maps;