]>
Commit | Line | Data |
---|---|---|
38cbfe40 RK |
1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3 | -- GNAT COMPILER COMPONENTS -- | |
4 | -- -- | |
5 | -- N A M E T -- | |
6 | -- -- | |
7 | -- S p e c -- | |
8 | -- -- | |
8d0d46f4 | 9 | -- Copyright (C) 1992-2021, Free Software Foundation, Inc. -- |
38cbfe40 RK |
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- -- | |
748086b7 | 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- |
38cbfe40 RK |
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 -- | |
b740cf28 AC |
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. -- | |
38cbfe40 RK |
20 | -- -- |
21 | -- GNAT was originally developed by the GNAT team at New York University. -- | |
71ff80dc | 22 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- |
38cbfe40 RK |
23 | -- -- |
24 | ------------------------------------------------------------------------------ | |
25 | ||
26 | with Alloc; | |
d9049849 | 27 | with Hostparm; use Hostparm; |
38cbfe40 | 28 | with Table; |
38cbfe40 RK |
29 | with Types; use Types; |
30 | ||
31 | package Namet is | |
32 | ||
33 | -- WARNING: There is a C version of this package. Any changes to this | |
34 | -- source file must be properly reflected in the C header file namet.h | |
38cbfe40 RK |
35 | |
36 | -- This package contains routines for handling the names table. The table | |
37 | -- is used to store character strings for identifiers and operator symbols, | |
38 | -- as well as other string values such as unit names and file names. | |
39 | ||
40 | -- The forms of the entries are as follows: | |
41 | ||
0ea55619 AC |
42 | -- Identifiers Stored with upper case letters folded to lower case. |
43 | -- Upper half (16#80# bit set) and wide characters are | |
44 | -- stored in an encoded form (Uhh for upper half char, | |
45 | -- Whhhh for wide characters, WWhhhhhhhh as provided by | |
3e20cb68 | 46 | -- the routine Append_Encoded, where hh are hex |
82c80734 RD |
47 | -- digits for the character code using lower case a-f). |
48 | -- Normally the use of U or W in other internal names is | |
49 | -- avoided, but these letters may be used in internal | |
50 | -- names (without this special meaning), if they appear | |
51 | -- as the last character of the name, or they are | |
52 | -- followed by an upper case letter (other than the WW | |
53 | -- sequence), or an underscore. | |
fbf5a39b | 54 | |
38cbfe40 RK |
55 | -- Operator symbols Stored with an initial letter O, and the remainder |
56 | -- of the name is the lower case characters XXX where | |
57 | -- the name is Name_Op_XXX, see Snames spec for a full | |
fbf5a39b AC |
58 | -- list of the operator names. Normally the use of O |
59 | -- in other internal names is avoided, but it may be | |
60 | -- used in internal names (without this special meaning) | |
61 | -- if it is the last character of the name, or if it is | |
62 | -- followed by an upper case letter or an underscore. | |
38cbfe40 RK |
63 | |
64 | -- Character literals Character literals have names that are used only for | |
1c1289e7 | 65 | -- debugging and error message purposes. The form is an |
fbf5a39b | 66 | -- upper case Q followed by a single lower case letter, |
82c80734 | 67 | -- or by a Uxx/Wxxxx/WWxxxxxxx encoding as described for |
fbf5a39b AC |
68 | -- identifiers. The Set_Character_Literal_Name procedure |
69 | -- should be used to construct these encodings. Normally | |
70 | -- the use of O in other internal names is avoided, but | |
71 | -- it may be used in internal names (without this special | |
72 | -- meaning) if it is the last character of the name, or | |
73 | -- if it is followed by an upper case letter or an | |
74 | -- underscore. | |
38cbfe40 RK |
75 | |
76 | -- Unit names Stored with upper case letters folded to lower case, | |
82c80734 RD |
77 | -- using Uhh/Whhhh/WWhhhhhhhh encoding as described for |
78 | -- identifiers, and a %s or %b suffix for specs/bodies. | |
79 | -- See package Uname for further details. | |
38cbfe40 RK |
80 | |
81 | -- File names Are stored in the form provided by Osint. Typically | |
82 | -- they may include wide character escape sequences and | |
83 | -- upper case characters (in non-encoded form). Casing | |
84 | -- is also derived from the external environment. Note | |
85 | -- that file names provided by Osint must generally be | |
86 | -- consistent with the names from Fname.Get_File_Name. | |
87 | ||
88 | -- Other strings The names table is also used as a convenient storage | |
89 | -- location for other variable length strings such as | |
90 | -- error messages etc. There are no restrictions on what | |
91 | -- characters may appear for such entries. | |
92 | ||
93 | -- Note: the encodings Uhh (upper half characters), Whhhh (wide characters), | |
82c80734 RD |
94 | -- WWhhhhhhhh (wide wide characters) and Qx (character literal names) are |
95 | -- described in the spec, since they are visible throughout the system (e.g. | |
96 | -- in debugging output). However, no code should depend on these particular | |
97 | -- encodings, so it should be possible to change the encodings by making | |
98 | -- changes only to the Namet specification (to change these comments) and the | |
99 | -- body (which actually implements the encodings). | |
38cbfe40 RK |
100 | |
101 | -- The names are hashed so that a given name appears only once in the table, | |
102 | -- except that names entered with Name_Enter as opposed to Name_Find are | |
103 | -- omitted from the hash table. | |
104 | ||
105 | -- The first 26 entries in the names table (with Name_Id values in the range | |
106 | -- First_Name_Id .. First_Name_Id + 25) represent names which are the one | |
107 | -- character lower case letters in the range a-z, and these names are created | |
108 | -- and initialized by the Initialize procedure. | |
109 | ||
a921e83c | 110 | -- Five values, one of type Int, one of type Byte, and three of type Boolean, |
572f38e4 AC |
111 | -- are stored with each names table entry and subprograms are provided for |
112 | -- setting and retrieving these associated values. The usage of these values | |
113 | -- is up to the client: | |
114 | ||
115 | -- In the compiler we have the following uses: | |
116 | ||
117 | -- The Int field is used to point to a chain of potentially visible | |
118 | -- entities (see Sem.Ch8 for details). | |
119 | ||
120 | -- The Byte field is used to hold the Token_Type value for reserved words | |
121 | -- (see Sem for details). | |
122 | ||
a921e83c | 123 | -- The Boolean1 field is used to mark address clauses to optimize the |
572f38e4 AC |
124 | -- performance of the Exp_Util.Following_Address_Clause function. |
125 | ||
db761fee AC |
126 | -- The Boolean2 field is used to mark simple names that appear in |
127 | -- Restriction[_Warning]s pragmas for No_Use_Of_Entity. This avoids most | |
128 | -- unnecessary searches of the No_Use_Of_Entity table. | |
129 | ||
47346923 AC |
130 | -- The Boolean3 field is set for names of pragmas that are to be ignored |
131 | -- because of the occurrence of a corresponding pragma Ignore_Pragma. | |
a921e83c | 132 | |
572f38e4 AC |
133 | -- In the binder, we have the following uses: |
134 | ||
135 | -- The Int field is used in various ways depending on the name involved, | |
136 | -- see binder documentation for details. | |
137 | ||
138 | -- The Byte and Boolean fields are unused. | |
139 | ||
140 | -- Note that the value of the Int and Byte fields are initialized to zero, | |
141 | -- and the Boolean field is initialized to False, when a new Name table entry | |
142 | -- is created. | |
38cbfe40 | 143 | |
a77152ca AC |
144 | type Bounded_String (Max_Length : Natural := 2**12) is limited |
145 | -- It's unlikely to have names longer than this. But we don't want to make | |
146 | -- it too big, because we declare these on the stack in recursive routines. | |
87feba05 AC |
147 | record |
148 | Length : Natural := 0; | |
149 | Chars : String (1 .. Max_Length); | |
150 | end record; | |
3e20cb68 AC |
151 | |
152 | -- To create a Name_Id, you can declare a Bounded_String as a local | |
153 | -- variable, and Append things onto it, and finally call Name_Find. | |
154 | -- You can also use a String, as in: | |
155 | -- X := Name_Find (Some_String & "_some_suffix"); | |
156 | ||
157 | -- For historical reasons, we also have the Global_Name_Buffer below, | |
158 | -- which is used by most of the code via the renamings. New code ought | |
159 | -- to avoid the global. | |
160 | ||
d9049849 | 161 | Global_Name_Buffer : Bounded_String (Max_Length => 4 * Max_Line_Length); |
87feba05 AC |
162 | Name_Buffer : String renames Global_Name_Buffer.Chars; |
163 | Name_Len : Natural renames Global_Name_Buffer.Length; | |
3e20cb68 AC |
164 | |
165 | -- Note that there is some circuitry (e.g. Osint.Write_Program_Name) that | |
166 | -- does a save/restore on Name_Len and Name_Buffer (1 .. Name_Len). This | |
167 | -- works in part because Name_Len is default-initialized to 0. | |
38cbfe40 | 168 | |
1c28fe3a RD |
169 | ----------------------------- |
170 | -- Types for Namet Package -- | |
171 | ----------------------------- | |
172 | ||
173 | -- Name_Id values are used to identify entries in the names table. Except | |
1c1289e7 AC |
174 | -- for the special values No_Name and Error_Name, they are subscript values |
175 | -- for the Names table defined in this package. | |
1c28fe3a RD |
176 | |
177 | -- Note that with only a few exceptions, which are clearly documented, the | |
178 | -- type Name_Id should be regarded as a private type. In particular it is | |
179 | -- never appropriate to perform arithmetic operations using this type. | |
180 | ||
181 | type Name_Id is range Names_Low_Bound .. Names_High_Bound; | |
182 | for Name_Id'Size use 32; | |
183 | -- Type used to identify entries in the names table | |
184 | ||
185 | No_Name : constant Name_Id := Names_Low_Bound; | |
186 | -- The special Name_Id value No_Name is used in the parser to indicate | |
187 | -- a situation where no name is present (e.g. on a loop or block). | |
188 | ||
1ceee6a1 | 189 | Error_Name : constant Name_Id := Names_Low_Bound + 1; |
1c28fe3a RD |
190 | -- The special Name_Id value Error_Name is used in the parser to |
191 | -- indicate that some kind of error was encountered in scanning out | |
192 | -- the relevant name, so it does not have a representable label. | |
193 | ||
1c28fe3a RD |
194 | First_Name_Id : constant Name_Id := Names_Low_Bound + 2; |
195 | -- Subscript of first entry in names table | |
196 | ||
c312b9f2 PMR |
197 | subtype Valid_Name_Id is Name_Id range First_Name_Id .. Name_Id'Last; |
198 | -- All but No_Name and Error_Name | |
199 | ||
69e6ee2f HK |
200 | function Present (Nam : Name_Id) return Boolean; |
201 | pragma Inline (Present); | |
202 | -- Determine whether name Nam exists | |
203 | ||
38cbfe40 RK |
204 | ----------------- |
205 | -- Subprograms -- | |
206 | ----------------- | |
207 | ||
b269f477 BD |
208 | function To_String (Buf : Bounded_String) return String; |
209 | pragma Inline (To_String); | |
210 | function "+" (Buf : Bounded_String) return String renames To_String; | |
3e20cb68 AC |
211 | |
212 | function Name_Find | |
c312b9f2 PMR |
213 | (Buf : Bounded_String := Global_Name_Buffer) return Valid_Name_Id; |
214 | function Name_Find (S : String) return Valid_Name_Id; | |
3e20cb68 AC |
215 | -- Name_Find searches the names table to see if the string has already been |
216 | -- stored. If so, the Id of the existing entry is returned. Otherwise a new | |
217 | -- entry is created with its Name_Table_Int fields set to zero/false. Note | |
218 | -- that it is permissible for Buf.Length to be zero to lookup the empty | |
219 | -- name string. | |
220 | ||
221 | function Name_Enter | |
c312b9f2 PMR |
222 | (Buf : Bounded_String := Global_Name_Buffer) return Valid_Name_Id; |
223 | function Name_Enter (S : String) return Valid_Name_Id; | |
3e20cb68 AC |
224 | -- Name_Enter is similar to Name_Find. The difference is that it does not |
225 | -- search the table for an existing match, and also subsequent Name_Find | |
226 | -- calls using the same name will not locate the entry created by this | |
227 | -- call. Thus multiple calls to Name_Enter with the same name will create | |
228 | -- multiple entries in the name table with different Name_Id values. This | |
229 | -- is useful in the case of created names, which are never expected to be | |
230 | -- looked up. Note: Name_Enter should never be used for one character | |
231 | -- names, since these are efficiently located without hashing by Name_Find | |
232 | -- in any case. | |
cd8d6792 | 233 | |
d63199d8 PMR |
234 | function Name_Equals |
235 | (N1 : Valid_Name_Id; | |
236 | N2 : Valid_Name_Id) return Boolean; | |
3e20cb68 | 237 | -- Return whether N1 and N2 denote the same character sequence |
cd8d6792 | 238 | |
c312b9f2 | 239 | function Get_Name_String (Id : Valid_Name_Id) return String; |
3e20cb68 AC |
240 | -- Returns the characters of Id as a String. The lower bound is 1. |
241 | ||
242 | -- The following Append procedures ignore any characters that don't fit in | |
243 | -- Buf. | |
244 | ||
245 | procedure Append (Buf : in out Bounded_String; C : Character); | |
246 | -- Append C onto Buf | |
247 | pragma Inline (Append); | |
248 | ||
249 | procedure Append (Buf : in out Bounded_String; V : Nat); | |
250 | -- Append decimal representation of V onto Buf | |
251 | ||
252 | procedure Append (Buf : in out Bounded_String; S : String); | |
253 | -- Append S onto Buf | |
254 | ||
b269f477 BD |
255 | procedure Append (Buf : in out Bounded_String; Buf2 : Bounded_String); |
256 | -- Append Buf2 onto Buf | |
257 | ||
c312b9f2 | 258 | procedure Append (Buf : in out Bounded_String; Id : Valid_Name_Id); |
3e20cb68 AC |
259 | -- Append the characters of Id onto Buf. It is an error to call this with |
260 | -- one of the special name Id values (No_Name or Error_Name). | |
261 | ||
c312b9f2 | 262 | procedure Append_Decoded (Buf : in out Bounded_String; Id : Valid_Name_Id); |
3e20cb68 AC |
263 | -- Same as Append, except that the result is decoded, so that upper half |
264 | -- characters and wide characters appear as originally found in the source | |
265 | -- program text, operators have their source forms (special characters and | |
266 | -- enclosed in quotes), and character literals appear surrounded by | |
267 | -- apostrophes. | |
268 | ||
269 | procedure Append_Decoded_With_Brackets | |
87feba05 | 270 | (Buf : in out Bounded_String; |
c312b9f2 | 271 | Id : Valid_Name_Id); |
3e20cb68 AC |
272 | -- Same as Append_Decoded, except that the brackets notation (Uhh |
273 | -- replaced by ["hh"], Whhhh replaced by ["hhhh"], WWhhhhhhhh replaced by | |
274 | -- ["hhhhhhhh"]) is used for all non-lower half characters, regardless of | |
275 | -- how Opt.Wide_Character_Encoding_Method is set, and also in that | |
276 | -- characters in the range 16#80# .. 16#FF# are converted to brackets | |
277 | -- notation in all cases. This routine can be used when there is a | |
278 | -- requirement for a canonical representation not affected by the | |
279 | -- character set options (e.g. in the binder generation of symbols). | |
280 | ||
c312b9f2 PMR |
281 | procedure Append_Unqualified |
282 | (Buf : in out Bounded_String; Id : Valid_Name_Id); | |
3e20cb68 AC |
283 | -- Same as Append, except that qualification (as defined in unit |
284 | -- Exp_Dbug) is removed (including both preceding __ delimited names, and | |
285 | -- also the suffixes used to indicate package body entities and to | |
286 | -- distinguish between overloaded entities). Note that names are not | |
287 | -- qualified until just before the call to gigi, so this routine is only | |
65f1ca2e | 288 | -- needed by processing that occurs after gigi has been called. |
cd8d6792 | 289 | |
3e20cb68 | 290 | procedure Append_Unqualified_Decoded |
87feba05 | 291 | (Buf : in out Bounded_String; |
c312b9f2 | 292 | Id : Valid_Name_Id); |
3e20cb68 AC |
293 | -- Same as Append_Unqualified, but decoded as for Append_Decoded |
294 | ||
295 | procedure Append_Encoded (Buf : in out Bounded_String; C : Char_Code); | |
296 | -- Appends given character code at the end of Buf. Lower case letters and | |
297 | -- digits are stored unchanged. Other 8-bit characters are stored using the | |
298 | -- Uhh encoding (hh = hex code), other 16-bit wide character values are | |
299 | -- stored using the Whhhh (hhhh = hex code) encoding, and other 32-bit wide | |
300 | -- wide character values are stored using the WWhhhhhhhh (hhhhhhhh = hex | |
64ac53f4 | 301 | -- code). Note that this procedure does not fold upper case letters (they |
3e20cb68 AC |
302 | -- are stored using the Uhh encoding). |
303 | ||
304 | procedure Set_Character_Literal_Name | |
87feba05 AC |
305 | (Buf : in out Bounded_String; |
306 | C : Char_Code); | |
3e20cb68 AC |
307 | -- This procedure sets the proper encoded name for the character literal |
308 | -- for the given character code. | |
38cbfe40 | 309 | |
3e20cb68 | 310 | procedure Insert_Str |
87feba05 AC |
311 | (Buf : in out Bounded_String; |
312 | S : String; | |
313 | Index : Positive); | |
3e20cb68 AC |
314 | -- Inserts S in Buf, starting at Index. Any existing characters at or past |
315 | -- this location get moved beyond the inserted string. | |
38cbfe40 | 316 | |
3e20cb68 | 317 | function Is_Internal_Name (Buf : Bounded_String) return Boolean; |
38cbfe40 | 318 | |
cd8d6792 | 319 | procedure Get_Last_Two_Chars |
c312b9f2 | 320 | (N : Valid_Name_Id; |
cd8d6792 HK |
321 | C1 : out Character; |
322 | C2 : out Character); | |
323 | -- Obtains last two characters of a name. C1 is last but one character and | |
324 | -- C2 is last character. If name is less than two characters long then both | |
325 | -- C1 and C2 are set to ASCII.NUL on return. | |
326 | ||
c312b9f2 PMR |
327 | function Get_Name_Table_Boolean1 (Id : Valid_Name_Id) return Boolean; |
328 | function Get_Name_Table_Boolean2 (Id : Valid_Name_Id) return Boolean; | |
329 | function Get_Name_Table_Boolean3 (Id : Valid_Name_Id) return Boolean; | |
cd8d6792 HK |
330 | -- Fetches the Boolean values associated with the given name |
331 | ||
c312b9f2 | 332 | function Get_Name_Table_Byte (Id : Valid_Name_Id) return Byte; |
38cbfe40 RK |
333 | pragma Inline (Get_Name_Table_Byte); |
334 | -- Fetches the Byte value associated with the given name | |
335 | ||
c312b9f2 | 336 | function Get_Name_Table_Int (Id : Valid_Name_Id) return Int; |
ac16e74c | 337 | pragma Inline (Get_Name_Table_Int); |
38cbfe40 RK |
338 | -- Fetches the Int value associated with the given name |
339 | ||
c312b9f2 PMR |
340 | procedure Set_Name_Table_Boolean1 (Id : Valid_Name_Id; Val : Boolean); |
341 | procedure Set_Name_Table_Boolean2 (Id : Valid_Name_Id; Val : Boolean); | |
342 | procedure Set_Name_Table_Boolean3 (Id : Valid_Name_Id; Val : Boolean); | |
3e20cb68 | 343 | -- Sets the Boolean value associated with the given name |
38cbfe40 | 344 | |
c312b9f2 | 345 | procedure Set_Name_Table_Byte (Id : Valid_Name_Id; Val : Byte); |
3e20cb68 AC |
346 | pragma Inline (Set_Name_Table_Byte); |
347 | -- Sets the Byte value associated with the given name | |
38cbfe40 | 348 | |
c312b9f2 | 349 | procedure Set_Name_Table_Int (Id : Valid_Name_Id; Val : Int); |
3e20cb68 AC |
350 | pragma Inline (Set_Name_Table_Int); |
351 | -- Sets the Int value associated with the given name | |
498d1b80 | 352 | |
c312b9f2 | 353 | function Is_Internal_Name (Id : Valid_Name_Id) return Boolean; |
5168a9b3 | 354 | -- Returns True if the name is an internal name, i.e. contains a character |
cd8d6792 | 355 | -- for which Is_OK_Internal_Letter is true, or if the name starts or ends |
3e20cb68 | 356 | -- with an underscore. |
cd8d6792 HK |
357 | -- |
358 | -- Note: if the name is qualified (has a double underscore), then only the | |
359 | -- final entity name is considered, not the qualifying names. Consider for | |
360 | -- example that the name: | |
361 | -- | |
362 | -- pkg__B_1__xyz | |
363 | -- | |
364 | -- is not an internal name, because the B comes from the internal name of | |
365 | -- a qualifying block, but the xyz means that this was indeed a declared | |
366 | -- identifier called "xyz" within this block and there is nothing internal | |
367 | -- about that name. | |
368 | ||
369 | function Is_OK_Internal_Letter (C : Character) return Boolean; | |
370 | pragma Inline (Is_OK_Internal_Letter); | |
371 | -- Returns true if C is a suitable character for using as a prefix or a | |
372 | -- suffix of an internally generated name, i.e. it is an upper case letter | |
373 | -- other than one of the ones used for encoding source names (currently the | |
374 | -- set of reserved letters is O, Q, U, W) and also returns False for the | |
375 | -- letter X, which is reserved for debug output (see Exp_Dbug). | |
376 | ||
c312b9f2 | 377 | function Is_Operator_Name (Id : Valid_Name_Id) return Boolean; |
cd8d6792 HK |
378 | -- Returns True if name given is of the form of an operator (that is, it |
379 | -- starts with an upper case O). | |
380 | ||
381 | function Is_Valid_Name (Id : Name_Id) return Boolean; | |
382 | -- True if Id is a valid name - points to a valid entry in the Name_Entries | |
383 | -- table. | |
38cbfe40 | 384 | |
c312b9f2 | 385 | function Length_Of_Name (Id : Valid_Name_Id) return Nat; |
38cbfe40 RK |
386 | pragma Inline (Length_Of_Name); |
387 | -- Returns length of given name in characters. This is the length of the | |
3e20cb68 | 388 | -- encoded name, as stored in the names table. |
38cbfe40 | 389 | |
3e20cb68 AC |
390 | procedure Initialize; |
391 | -- This is a dummy procedure. It is retained for easy compatibility with | |
392 | -- clients who used to call Initialize when this call was required. Now | |
393 | -- initialization is performed automatically during package elaboration. | |
394 | -- Note that this change fixes problems which existed prior to the change | |
395 | -- of Initialize being called more than once. See also Reinitialize which | |
396 | -- allows reinitialization of the tables. | |
38cbfe40 | 397 | |
cd8d6792 HK |
398 | procedure Reinitialize; |
399 | -- Clears the name tables and removes all existing entries from the table. | |
3726d5d9 | 400 | |
38cbfe40 | 401 | procedure Reset_Name_Table; |
cd8d6792 HK |
402 | -- This procedure is used when there are multiple source files to reset the |
403 | -- name table info entries associated with current entries in the names | |
404 | -- table. There is no harm in keeping the names entries themselves from one | |
405 | -- compilation to another, but we can't keep the entity info, since this | |
406 | -- refers to tree nodes, which are destroyed between each main source file. | |
beacce02 | 407 | |
3e20cb68 AC |
408 | procedure Finalize; |
409 | -- Called at the end of a use of the Namet package (before a subsequent | |
410 | -- call to Initialize). Currently this routine is only used to generate | |
411 | -- debugging output. | |
cd8d6792 | 412 | |
3e20cb68 AC |
413 | procedure Lock; |
414 | -- Lock name tables before calling back end. We reserve some extra space | |
415 | -- before locking to avoid unnecessary inefficiencies when we unlock. | |
572f38e4 | 416 | |
3e20cb68 AC |
417 | procedure Unlock; |
418 | -- Unlocks the name table to allow use of the extra space reserved by the | |
419 | -- call to Lock. See gnat1drv for details of the need for this. | |
38cbfe40 | 420 | |
c312b9f2 | 421 | procedure Write_Name (Id : Valid_Name_Id); |
38cbfe40 | 422 | -- Write_Name writes the characters of the specified name using the |
3e20cb68 | 423 | -- standard output procedures in package Output. The name is written |
38cbfe40 RK |
424 | -- in encoded form (i.e. including Uhh, Whhh, Qx, _op as they appear in |
425 | -- the name table). If Id is Error_Name, or No_Name, no text is output. | |
426 | ||
c312b9f2 | 427 | procedure Write_Name_Decoded (Id : Valid_Name_Id); |
38cbfe40 | 428 | -- Like Write_Name, except that the name written is the decoded name, as |
3e20cb68 AC |
429 | -- described for Append_Decoded. |
430 | ||
3e20cb68 AC |
431 | function Name_Entries_Count return Nat; |
432 | -- Return current number of entries in the names table | |
433 | ||
83dcc2bd BD |
434 | function Last_Name_Id return Name_Id; |
435 | -- Return the last Name_Id in the table. This information is valid until | |
436 | -- new names have been added. | |
437 | ||
3e20cb68 AC |
438 | -------------------------- |
439 | -- Obsolete Subprograms -- | |
440 | -------------------------- | |
441 | ||
442 | -- The following routines operate on Global_Name_Buffer. New code should | |
443 | -- use the routines above, and declare Bounded_Strings as local | |
444 | -- variables. Existing code can be improved incrementally by removing calls | |
0964be07 | 445 | -- to the following. If we eliminate all of these, we can remove |
3e20cb68 AC |
446 | -- Global_Name_Buffer. But be sure to look at namet.h first. |
447 | ||
448 | -- To see what these do, look at the bodies. They are all trivially defined | |
449 | -- in terms of routines above. | |
450 | ||
451 | procedure Add_Char_To_Name_Buffer (C : Character); | |
452 | pragma Inline (Add_Char_To_Name_Buffer); | |
453 | ||
454 | procedure Add_Nat_To_Name_Buffer (V : Nat); | |
455 | ||
456 | procedure Add_Str_To_Name_Buffer (S : String); | |
457 | ||
c312b9f2 | 458 | procedure Get_Decoded_Name_String (Id : Valid_Name_Id); |
3e20cb68 | 459 | |
c312b9f2 | 460 | procedure Get_Decoded_Name_String_With_Brackets (Id : Valid_Name_Id); |
3e20cb68 | 461 | |
c312b9f2 | 462 | procedure Get_Name_String (Id : Valid_Name_Id); |
3e20cb68 | 463 | |
c312b9f2 | 464 | procedure Get_Name_String_And_Append (Id : Valid_Name_Id); |
3e20cb68 | 465 | |
c312b9f2 | 466 | procedure Get_Unqualified_Decoded_Name_String (Id : Valid_Name_Id); |
3e20cb68 | 467 | |
c312b9f2 | 468 | procedure Get_Unqualified_Name_String (Id : Valid_Name_Id); |
3e20cb68 AC |
469 | |
470 | procedure Insert_Str_In_Name_Buffer (S : String; Index : Positive); | |
471 | ||
472 | function Is_Internal_Name return Boolean; | |
473 | ||
474 | procedure Set_Character_Literal_Name (C : Char_Code); | |
475 | ||
476 | procedure Store_Encoded_Character (C : Char_Code); | |
38cbfe40 | 477 | |
1c28fe3a RD |
478 | ------------------------------ |
479 | -- File and Unit Name Types -- | |
480 | ------------------------------ | |
481 | ||
482 | -- These are defined here in Namet rather than Fname and Uname to avoid | |
483 | -- problems with dependencies, and to avoid dragging in Fname and Uname | |
484 | -- into many more files, but it would be cleaner to move to Fname/Uname. | |
485 | ||
486 | type File_Name_Type is new Name_Id; | |
487 | -- File names are stored in the names table and this type is used to | |
488 | -- indicate that a Name_Id value is being used to hold a simple file name | |
489 | -- (which does not include any directory information). | |
490 | ||
491 | No_File : constant File_Name_Type := File_Name_Type (No_Name); | |
492 | -- Constant used to indicate no file is present (this is used for example | |
493 | -- when a search for a file indicates that no file of the name exists). | |
494 | ||
69e6ee2f HK |
495 | function Present (Nam : File_Name_Type) return Boolean; |
496 | pragma Inline (Present); | |
497 | -- Determine whether file name Nam exists | |
498 | ||
1c28fe3a RD |
499 | Error_File_Name : constant File_Name_Type := File_Name_Type (Error_Name); |
500 | -- The special File_Name_Type value Error_File_Name is used to indicate | |
501 | -- a unit name where some previous processing has found an error. | |
502 | ||
503 | subtype Error_File_Name_Or_No_File is | |
504 | File_Name_Type range No_File .. Error_File_Name; | |
505 | -- Used to test for either error file name or no file | |
506 | ||
507 | type Path_Name_Type is new Name_Id; | |
508 | -- Path names are stored in the names table and this type is used to | |
509 | -- indicate that a Name_Id value is being used to hold a path name (that | |
510 | -- may contain directory information). | |
511 | ||
512 | No_Path : constant Path_Name_Type := Path_Name_Type (No_Name); | |
513 | -- Constant used to indicate no path name is present | |
514 | ||
515 | type Unit_Name_Type is new Name_Id; | |
516 | -- Unit names are stored in the names table and this type is used to | |
517 | -- indicate that a Name_Id value is being used to hold a unit name, which | |
518 | -- terminates in %b for a body or %s for a spec. | |
519 | ||
520 | No_Unit_Name : constant Unit_Name_Type := Unit_Name_Type (No_Name); | |
521 | -- Constant used to indicate no file name present | |
522 | ||
76b4158b HK |
523 | function Present (Nam : Unit_Name_Type) return Boolean; |
524 | pragma Inline (Present); | |
525 | -- Determine whether unit name Nam exists | |
526 | ||
1c28fe3a RD |
527 | Error_Unit_Name : constant Unit_Name_Type := Unit_Name_Type (Error_Name); |
528 | -- The special Unit_Name_Type value Error_Unit_Name is used to indicate | |
529 | -- a unit name where some previous processing has found an error. | |
530 | ||
531 | subtype Error_Unit_Name_Or_No_Unit_Name is | |
532 | Unit_Name_Type range No_Unit_Name .. Error_Unit_Name; | |
533 | ||
534 | ------------------------ | |
535 | -- Debugging Routines -- | |
536 | ------------------------ | |
537 | ||
3726d5d9 RD |
538 | procedure wn (Id : Name_Id); |
539 | pragma Export (Ada, wn); | |
540 | -- This routine is intended for debugging use only (i.e. it is intended to | |
541 | -- be called from the debugger). It writes the characters of the specified | |
542 | -- name using the standard output procedures in package Output, followed by | |
543 | -- a new line. The name is written in encoded form (i.e. including Uhh, | |
544 | -- Whhh, Qx, _op as they appear in the name table). If Id is Error_Name, | |
545 | -- No_Name, or invalid an appropriate string is written (<Error_Name>, | |
546 | -- <No_Name>, <invalid name>). Unlike Write_Name, this call does not affect | |
547 | -- the contents of Name_Buffer or Name_Len. | |
548 | ||
3e20cb68 AC |
549 | private |
550 | ||
38cbfe40 RK |
551 | --------------------------- |
552 | -- Table Data Structures -- | |
553 | --------------------------- | |
554 | ||
555 | -- The following declarations define the data structures used to store | |
556 | -- names. The definitions are in the private part of the package spec, | |
557 | -- rather than the body, since they are referenced directly by gigi. | |
558 | ||
87b3f81f AC |
559 | -- This table stores the actual string names. Although logically there is |
560 | -- no need for a terminating character (since the length is stored in the | |
561 | -- name entry table), we still store a NUL character at the end of every | |
562 | -- name (for convenience in interfacing to the C world). | |
38cbfe40 RK |
563 | |
564 | package Name_Chars is new Table.Table ( | |
565 | Table_Component_Type => Character, | |
566 | Table_Index_Type => Int, | |
567 | Table_Low_Bound => 0, | |
568 | Table_Initial => Alloc.Name_Chars_Initial, | |
569 | Table_Increment => Alloc.Name_Chars_Increment, | |
570 | Table_Name => "Name_Chars"); | |
571 | ||
572 | type Name_Entry is record | |
a6d3b499 | 573 | Name_Chars_Index : aliased Int; |
87b3f81f AC |
574 | -- Starting location of characters in the Name_Chars table minus one |
575 | -- (i.e. pointer to character just before first character). The reason | |
576 | -- for the bias of one is that indexes in Name_Buffer are one's origin, | |
577 | -- so this avoids unnecessary adds and subtracts of 1. | |
38cbfe40 | 578 | |
a6d3b499 | 579 | Name_Len : aliased Short; |
38cbfe40 RK |
580 | -- Length of this name in characters |
581 | ||
a6d3b499 | 582 | Byte_Info : aliased Byte; |
38cbfe40 RK |
583 | -- Byte value associated with this name |
584 | ||
3726d5d9 RD |
585 | Name_Has_No_Encodings : Boolean; |
586 | -- This flag is set True if the name entry is known not to contain any | |
587 | -- special character encodings. This is used to speed up repeated calls | |
3e20cb68 AC |
588 | -- to Append_Decoded. A value of False means that it is not known |
589 | -- whether the name contains any such encodings. | |
3726d5d9 | 590 | |
a6d3b499 EB |
591 | Boolean1_Info : Boolean; |
592 | Boolean2_Info : Boolean; | |
593 | Boolean3_Info : Boolean; | |
594 | -- Boolean values associated with the name | |
595 | ||
596 | Spare : Boolean; | |
597 | -- Four remaining bits in the current byte | |
598 | ||
599 | Hash_Link : aliased Name_Id; | |
38cbfe40 RK |
600 | -- Link to next entry in names table for same hash code |
601 | ||
a6d3b499 | 602 | Int_Info : aliased Int; |
38cbfe40 | 603 | -- Int Value associated with this name |
572f38e4 | 604 | |
38cbfe40 RK |
605 | end record; |
606 | ||
1c28fe3a RD |
607 | for Name_Entry use record |
608 | Name_Chars_Index at 0 range 0 .. 31; | |
609 | Name_Len at 4 range 0 .. 15; | |
610 | Byte_Info at 6 range 0 .. 7; | |
a6d3b499 EB |
611 | Name_Has_No_Encodings at 7 range 0 .. 0; |
612 | Boolean1_Info at 7 range 1 .. 1; | |
613 | Boolean2_Info at 7 range 2 .. 2; | |
614 | Boolean3_Info at 7 range 3 .. 3; | |
615 | Spare at 7 range 4 .. 7; | |
1c28fe3a RD |
616 | Hash_Link at 8 range 0 .. 31; |
617 | Int_Info at 12 range 0 .. 31; | |
618 | end record; | |
619 | ||
620 | for Name_Entry'Size use 16 * 8; | |
621 | -- This ensures that we did not leave out any fields | |
622 | ||
c312b9f2 | 623 | -- This is the table that is referenced by Valid_Name_Id entries. |
38cbfe40 RK |
624 | -- It contains one entry for each unique name in the table. |
625 | ||
626 | package Name_Entries is new Table.Table ( | |
627 | Table_Component_Type => Name_Entry, | |
c312b9f2 | 628 | Table_Index_Type => Valid_Name_Id'Base, |
38cbfe40 RK |
629 | Table_Low_Bound => First_Name_Id, |
630 | Table_Initial => Alloc.Names_Initial, | |
631 | Table_Increment => Alloc.Names_Increment, | |
632 | Table_Name => "Name_Entries"); | |
633 | ||
634 | end Namet; |