Add x prefix to v850e case for handling --with-cpu=v850e.
[official-gcc.git] / gcc / ada / sem_maps.ads
blob2aeb88afe2103150cab8daa0353ae1a69b684efc
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ M A P S --
6 -- --
7 -- S p e c --
8 -- --
9 -- --
10 -- Copyright (C) 1996-2001 Free Software Foundation, Inc. --
11 -- --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
22 -- --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
25 -- --
26 ------------------------------------------------------------------------------
28 -- This package contains the operations on the renaming maps used for
29 -- generic analysis and instantiation. Renaming maps are created when
30 -- a generic unit is analyzed, in order to capture all references to
31 -- global variables within the unit. The renaming map of a generic unit
32 -- copied prior to each instantiation, and then updated by mapping the
33 -- formals into the actuals and the local entities into entities local to
34 -- the instance. When the generic tree is copied to produce the instance,
35 -- all references are updated by means of the renaming map.
37 -- Map composition of renaming maps takes place for nested instantiations,
38 -- for generic child units, and for formal packages.
40 -- For additional details, see the documentation in sem_ch12.
42 with Table;
43 with Types; use Types;
45 package Sem_Maps is
47 type Map is new Int;
49 type Assoc is private;
51 type Scope_Kind is (S_Global, S_Formal, S_Local);
53 function New_Map (Num_Assoc : Int) return Map;
54 -- Build empty map with the given number of associations, and a
55 -- headers table of the appropriate size.
57 function Compose (Orig_Map : Map; New_Map : Map) return Map;
58 -- Update the associations in Orig_Map, so that if Orig_Map (e1) = e2
59 -- and New_Map (e2) = e3, then the image of e1 under the result is e3.
61 function Copy (M : Map) return Map;
62 -- Full copy of contents and headers.
64 function Lookup (M : Map; E : Entity_Id) return Entity_Id;
65 -- Retrieve image of E under M, Empty if undefined.
67 procedure Add_Association
68 (M : in out Map;
69 O_Id : Entity_Id;
70 N_Id : Entity_Id;
71 Kind : Scope_Kind := S_Local);
72 -- Update M in place. On entry M (O_Id) must not be defined.
74 procedure Update_Association
75 (M : in out Map;
76 O_Id : Entity_Id;
77 N_Id : Entity_Id;
78 Kind : Scope_Kind := S_Local);
79 -- Update the entry in M for O_Id.
81 function Build_Instance_Map (M : Map) return Map;
82 -- Copy renaming map of generic, and create new entities for all the
83 -- local entities within.
85 private
87 -- New maps are created when a generic is analyzed, and for each of
88 -- its instantiations. Maps are also updated for nested generics, for
89 -- child units, and for formal packages. As a result we need to allocate
90 -- maps dynamically.
92 -- When analyzing a generic, we do not know how many references are
93 -- in it. We build an initial map after generic analysis, using a static
94 -- structure that relies on the compiler's extensible table mechanism.
95 -- After constructing this initial map, all subsequent uses and updates
96 -- of this map do not modify its domain, so that dynamically allocated
97 -- maps have a fixed size and never need to be reallocated. Furthermore,
98 -- the headers of the hash table of a dynamically allocated map can be
99 -- chosen according to the total number of entries in the map, to
100 -- accommodate efficiently generic units of different sizes (Unchecked_
101 -- Conversion vs. Generic_Elementary_Functions, for example). So in
102 -- fact both components of a map have fixed size, and can be allocated
103 -- using the standard table mechanism. A Maps_Table holds records that
104 -- contain indices into the global Headers table and the Associations
105 -- table, and a Map is an index into the Maps_Table.
107 -- Maps_Table Headers_Table Associations_Table
109 -- |_____| |___________ |
110 -- |_____| | | | |
111 -- ------>|Map |------------------------------>|Associations|
112 -- |Info |------------->| |=========>| for one |
113 -- |_____| | |====| | unit |
114 -- | | | | |====>| |
115 -- |_____| |____________|
116 -- | | | |
117 type Header_Index is new Int;
118 type Assoc_Index is new Int;
119 No_Assoc : constant Assoc_Index := -1;
121 type Map_Info is record
122 Header_Offset : Header_Index;
123 Header_Num : Header_Index;
124 Assoc_Offset : Assoc_Index;
125 Assoc_Num : Assoc_Index;
126 Assoc_Next : Assoc_Index;
127 end record;
129 type Assoc is record
130 Old_Id : Entity_Id := Empty;
131 New_Id : Entity_Id := Empty;
132 Kind : Scope_Kind := S_Local;
133 Next : Assoc_Index := No_Assoc;
134 end record;
136 -- All maps are accessed through the following table. The map attribute
137 -- of a generic unit or an instance is an index into this table.
139 package Maps_Table is new Table.Table (
140 Table_Component_Type => Map_Info,
141 Table_Index_Type => Map,
142 Table_Low_Bound => 0,
143 Table_Initial => 100,
144 Table_Increment => 10,
145 Table_Name => "Maps_Table");
147 -- All headers for hash tables are allocated in one global table. Each
148 -- map stores the offset into this table at which its own headers start.
150 package Headers_Table is new Table.Table (
151 Table_Component_Type => Assoc_Index,
152 Table_Index_Type => Header_Index,
153 Table_Low_Bound => 0,
154 Table_Initial => 1000,
155 Table_Increment => 10,
156 Table_Name => "Headers_Table");
158 -- All associations are allocated in one global table. Each map stores
159 -- the offset into this table at which its own associations start.
161 package Associations_Table is new Table.Table (
162 Table_Component_Type => Assoc,
163 Table_Index_Type => Assoc_Index,
164 Table_Low_Bound => 1,
165 Table_Initial => 1000,
166 Table_Increment => 10,
167 Table_Name => "Associations_Table");
169 end Sem_Maps;