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