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