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