Debian Codegraph @

gcc/ada/snames.adb-tmpl

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S N A M E S --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2025, 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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
25
26 with Debug; use Debug;
27 with Opt; use Opt;
28 with Table;
29 with Types; use Types;
30
31 package body Snames is
32
33 -- Table used to record convention identifiers
34
35 type Convention_Id_Entry is record
36 Name : Name_Id;
37 Convention : Convention_Id;
38 end record;
39
40 package Convention_Identifiers is new Table.Table (
41 Table_Component_Type => Convention_Id_Entry,
42 Table_Index_Type => Int,
43 Table_Low_Bound => 1,
44 Table_Initial => 50,
45 Table_Increment => 200,
46 Table_Name => "Name_Convention_Identifiers");
47
48 -- Table of names to be set by Initialize. Each name is terminated by a
49 -- single #, and the end of the list is marked by a null entry, i.e. by
50 -- two # marks in succession. Note that the table does not include the
51 -- entries for a-z, since these are initialized by Namet itself.
52
53 Preset_Names : constant String :=
54 !! TEMPLATE INSERTION POINT
55 "#";
56
57 ---------------------
58 -- Generated Names --
59 ---------------------
60
61 -- This section lists the various cases of generated names which are
62 -- built from existing names by adding unique leading and/or trailing
63 -- upper case letters. In some cases these names are built recursively,
64 -- in particular names built from types may be built from types which
65 -- themselves have generated names. In this list, xxx represents an
66 -- existing name to which identifying letters are prepended or appended,
67 -- and a trailing n represents a serial number in an external name that
68 -- has some semantic significance (e.g. the n'th index type of an array).
69
70 -- xxxA access type for formal xxx in entry param record (Exp_Ch9)
71 -- xxxB tag table for tagged type xxx (Exp_Ch3)
72 -- xxxB task body procedure for task xxx (Exp_Ch9)
73 -- xxxD dispatch table for tagged type xxx (Exp_Ch3)
74 -- xxxD discriminal for discriminant xxx (Sem_Ch3)
75 -- xxxDn n'th discr check function for rec type xxx (Exp_Ch3)
76 -- xxxE elaboration boolean flag for task xxx (Exp_Ch9)
77 -- xxxE dispatch table pointer type for tagged type xxx (Exp_Ch3)
78 -- xxxE parameters for accept body for entry xxx (Exp_Ch9)
79 -- xxxFn n'th primitive of a tagged type (named xxx) (Exp_Ch3)
80 -- xxxJ tag table type index for tagged type xxx (Exp_Ch3)
81 -- xxxM master Id value for access type xxx (Exp_Ch3)
82 -- xxxP tag table pointer type for tagged type xxx (Exp_Ch3)
83 -- xxxP parameter record type for entry xxx (Exp_Ch9)
84 -- xxxPA access to parameter record type for entry xxx (Exp_Ch9)
85 -- xxxPn pointer type for n'th primitive of tagged type xxx (Exp_Ch3)
86 -- xxxR dispatch table pointer for tagged type xxx (Exp_Ch3)
87 -- xxxT tag table type for tagged type xxx (Exp_Ch3)
88 -- xxxT literal table for enumeration type xxx (Sem_Ch3)
89 -- xxxV type for task value record for task xxx (Exp_Ch9)
90 -- xxxX entry index constant (Exp_Ch9)
91 -- xxxY dispatch table type for tagged type xxx (Exp_Ch3)
92 -- xxxZ size variable for task xxx (Exp_Ch9)
93
94 -- TSS names
95
96 -- xxxDA deep adjust routine for type xxx (Exp_TSS)
97 -- xxxDF deep finalize routine for type xxx (Exp_TSS)
98 -- xxxDI deep initialize routine for type xxx (Exp_TSS)
99 -- xxxEQ composite equality routine for record type xxx (Exp_TSS)
100 -- xxxFD finalize address routine for type xxx (Exp_TSS)
101 -- xxxFA PolyORB/DSA From_Any converter for type xxx (Exp_TSS)
102 -- xxxIP initialization procedure for type xxx (Exp_TSS)
103 -- xxxIC init C++ dispatch tables procedure for type xxx (Exp_TSS)
104 -- xxxRA RAS type access routine for type xxx (Exp_TSS)
105 -- xxxRD RAS type dereference routine for type xxx (Exp_TSS)
106 -- xxxRP Rep to Pos conversion for enumeration type xxx (Exp_TSS)
107 -- xxxSA array/slice assignment for controlled comp. arrays (Exp_TSS)
108 -- xxxSI stream input attribute subprogram for type xxx (Exp_TSS)
109 -- xxxSO stream output attribute subprogram for type xxx (Exp_TSS)
110 -- xxxSR stream read attribute subprogram for type xxx (Exp_TSS)
111 -- xxxSW stream write attribute subprogram for type xxx (Exp_TSS)
112 -- xxxPI Put_Image attribute subprogram for type xxx (Exp_TSS)
113 -- xxxTA PolyORB/DSA To_Any converter for type xxx (Exp_TSS)
114 -- xxxTC PolyORB/DSA Typecode for type xxx (Exp_TSS)
115
116 -- Implicit type names
117
118 -- TxxxT type of literal table for enumeration type xxx (Sem_Ch3)
119
120 -- (Note: this list is not complete or accurate ???)
121
122 ----------------------
123 -- Get_Attribute_Id --
124 ----------------------
125
126 function Get_Attribute_Id (N : Name_Id) return Attribute_Id is
127 begin
128 case N is
129 when Name_Constant_Indexing =>
130 return Attribute_Constant_Indexing;
131 when Name_CPU =>
132 return Attribute_CPU;
133 when Name_Default_Iterator =>
134 return Attribute_Default_Iterator;
135 when Name_Dispatching_Domain =>
136 return Attribute_Dispatching_Domain;
137 when Name_Implicit_Dereference =>
138 return Attribute_Implicit_Dereference;
139 when Name_Interrupt_Priority =>
140 return Attribute_Interrupt_Priority;
141 when Name_Iterable =>
142 return Attribute_Iterable;
143 when Name_Iterator_Element =>
144 return Attribute_Iterator_Element;
145 when Name_Variable_Indexing =>
146 return Attribute_Variable_Indexing;
147 when First_Attribute_Name .. Last_Attribute_Name =>
148 return Attribute_Id'Val (N - First_Attribute_Name);
149 when others =>
150 raise Program_Error;
151 end case;
152 end Get_Attribute_Id;
153
154 -----------------------
155 -- Get_Convention_Id --
156 -----------------------
157
158 function Get_Convention_Id (N : Name_Id) return Convention_Id is
159 begin
160 case N is
161 when Name_Ada => return Convention_Ada;
162 when Name_Ada_Pass_By_Copy => return Convention_Ada_Pass_By_Copy;
163 when Name_Ada_Pass_By_Reference => return
164 Convention_Ada_Pass_By_Reference;
165 when Name_Assembler => return Convention_Assembler;
166 when Name_C => return Convention_C;
167 when Name_C_Variadic_0 => return Convention_C_Variadic_0;
168 when Name_C_Variadic_1 => return Convention_C_Variadic_1;
169 when Name_C_Variadic_2 => return Convention_C_Variadic_2;
170 when Name_C_Variadic_3 => return Convention_C_Variadic_3;
171 when Name_C_Variadic_4 => return Convention_C_Variadic_4;
172 when Name_C_Variadic_5 => return Convention_C_Variadic_5;
173 when Name_C_Variadic_6 => return Convention_C_Variadic_6;
174 when Name_C_Variadic_7 => return Convention_C_Variadic_7;
175 when Name_C_Variadic_8 => return Convention_C_Variadic_8;
176 when Name_C_Variadic_9 => return Convention_C_Variadic_9;
177 when Name_C_Variadic_10 => return Convention_C_Variadic_10;
178 when Name_C_Variadic_11 => return Convention_C_Variadic_11;
179 when Name_C_Variadic_12 => return Convention_C_Variadic_12;
180 when Name_C_Variadic_13 => return Convention_C_Variadic_13;
181 when Name_C_Variadic_14 => return Convention_C_Variadic_14;
182 when Name_C_Variadic_15 => return Convention_C_Variadic_15;
183 when Name_C_Variadic_16 => return Convention_C_Variadic_16;
184 when Name_COBOL => return Convention_COBOL;
185 when Name_CPP => return Convention_CPP;
186 when Name_Fortran => return Convention_Fortran;
187 when Name_Intrinsic => return Convention_Intrinsic;
188 when Name_Stdcall => return Convention_Stdcall;
189 when Name_Stubbed => return Convention_Stubbed;
190
191 -- If no direct match, then we must have a convention
192 -- identifier pragma that has specified this name.
193
194 when others =>
195 for J in 1 .. Convention_Identifiers.Last loop
196 if N = Convention_Identifiers.Table (J).Name then
197 return Convention_Identifiers.Table (J).Convention;
198 end if;
199 end loop;
200
201 raise Program_Error;
202 end case;
203 end Get_Convention_Id;
204
205 -------------------------
206 -- Get_Convention_Name --
207 -------------------------
208
209 function Get_Convention_Name (C : Convention_Id) return Name_Id is
210 begin
211 case C is
212 when Convention_Ada => return Name_Ada;
213 when Convention_Ada_Pass_By_Copy => return Name_Ada_Pass_By_Copy;
214 when Convention_Ada_Pass_By_Reference =>
215 return Name_Ada_Pass_By_Reference;
216 when Convention_Assembler => return Name_Assembler;
217 when Convention_C => return Name_C;
218 when Convention_C_Variadic_0 => return Name_C_Variadic_0;
219 when Convention_C_Variadic_1 => return Name_C_Variadic_1;
220 when Convention_C_Variadic_2 => return Name_C_Variadic_2;
221 when Convention_C_Variadic_3 => return Name_C_Variadic_3;
222 when Convention_C_Variadic_4 => return Name_C_Variadic_4;
223 when Convention_C_Variadic_5 => return Name_C_Variadic_5;
224 when Convention_C_Variadic_6 => return Name_C_Variadic_6;
225 when Convention_C_Variadic_7 => return Name_C_Variadic_7;
226 when Convention_C_Variadic_8 => return Name_C_Variadic_8;
227 when Convention_C_Variadic_9 => return Name_C_Variadic_9;
228 when Convention_C_Variadic_10 => return Name_C_Variadic_10;
229 when Convention_C_Variadic_11 => return Name_C_Variadic_11;
230 when Convention_C_Variadic_12 => return Name_C_Variadic_12;
231 when Convention_C_Variadic_13 => return Name_C_Variadic_13;
232 when Convention_C_Variadic_14 => return Name_C_Variadic_14;
233 when Convention_C_Variadic_15 => return Name_C_Variadic_15;
234 when Convention_C_Variadic_16 => return Name_C_Variadic_16;
235 when Convention_COBOL => return Name_COBOL;
236 when Convention_CPP => return Name_CPP;
237 when Convention_Entry => return Name_Entry;
238 when Convention_Fortran => return Name_Fortran;
239 when Convention_Intrinsic => return Name_Intrinsic;
240 when Convention_Protected => return Name_Protected;
241 when Convention_Stdcall => return Name_Stdcall;
242 when Convention_Stubbed => return Name_Stubbed;
243 end case;
244 end Get_Convention_Name;
245
246 ---------------------------
247 -- Get_Locking_Policy_Id --
248 ---------------------------
249
250 function Get_Locking_Policy_Id (N : Name_Id) return Locking_Policy_Id is
251 begin
252 return Locking_Policy_Id'Val (N - First_Locking_Policy_Name);
253 end Get_Locking_Policy_Id;
254
255 -------------------
256 -- Get_Pragma_Id --
257 -------------------
258
259 function Get_Pragma_Id (N : Name_Id) return Pragma_Id is
260 begin
261 case N is
262 when Name_CPU =>
263 return Pragma_CPU;
264 when Name_Default_Scalar_Storage_Order =>
265 return Pragma_Default_Scalar_Storage_Order;
266 when Name_Dispatching_Domain =>
267 return Pragma_Dispatching_Domain;
268 when Name_Fast_Math =>
269 return Pragma_Fast_Math;
270 when Name_Interface =>
271 return Pragma_Interface;
272 when Name_Interrupt_Priority =>
273 return Pragma_Interrupt_Priority;
274 when Name_Preelaborable_Initialization =>
275 return Pragma_Preelaborable_Initialization;
276 when Name_Priority =>
277 return Pragma_Priority;
278 when Name_Secondary_Stack_Size =>
279 return Pragma_Secondary_Stack_Size;
280 when Name_Storage_Size =>
281 return Pragma_Storage_Size;
282 when Name_Storage_Unit =>
283 return Pragma_Storage_Unit;
284 when First_Pragma_Name .. Last_Pragma_Name =>
285 return Pragma_Id'Val (N - First_Pragma_Name);
286 when others =>
287 return Unknown_Pragma;
288 end case;
289 end Get_Pragma_Id;
290
291 ---------------------------
292 -- Get_Queuing_Policy_Id --
293 ---------------------------
294
295 function Get_Queuing_Policy_Id (N : Name_Id) return Queuing_Policy_Id is
296 begin
297 return Queuing_Policy_Id'Val (N - First_Queuing_Policy_Name);
298 end Get_Queuing_Policy_Id;
299
300 ------------------------------------
301 -- Get_Task_Dispatching_Policy_Id --
302 ------------------------------------
303
304 function Get_Task_Dispatching_Policy_Id
305 (N : Name_Id) return Task_Dispatching_Policy_Id
306 is
307 begin
308 return Task_Dispatching_Policy_Id'Val
309 (N - First_Task_Dispatching_Policy_Name);
310 end Get_Task_Dispatching_Policy_Id;
311
312 ----------------
313 -- Initialize --
314 ----------------
315
316 procedure Initialize is
317 P_Index : Natural;
318 Discard_Name : Name_Id;
319
320 begin
321 P_Index := Preset_Names'First;
322 loop
323 Name_Len := 0;
324 while Preset_Names (P_Index) /= '#' loop
325 Name_Len := Name_Len + 1;
326 Name_Buffer (Name_Len) := Preset_Names (P_Index);
327 P_Index := P_Index + 1;
328 end loop;
329
330 -- We do the Name_Find call to enter the name into the table, but
331 -- we don't need to do anything with the result, since we already
332 -- initialized all the preset names to have the right value (we
333 -- are depending on the order of the names and Preset_Names).
334
335 Discard_Name := Name_Find;
336 P_Index := P_Index + 1;
337 exit when Preset_Names (P_Index) = '#';
338 end loop;
339
340 -- Make sure that number of names in standard table is correct. If this
341 -- check fails, run utility program XSNAMES to construct a new properly
342 -- matching version of the body.
343
344 pragma Assert (Discard_Name = Last_Predefined_Name);
345
346 -- Initialize the convention identifiers table with the standard set of
347 -- synonyms that we recognize for conventions.
348
349 Convention_Identifiers.Init;
350
351 Convention_Identifiers.Append ((Name_Asm, Convention_Assembler));
352 Convention_Identifiers.Append ((Name_Assembly, Convention_Assembler));
353
354 Convention_Identifiers.Append ((Name_Default, Convention_C));
355 Convention_Identifiers.Append ((Name_External, Convention_C));
356
357 Convention_Identifiers.Append ((Name_C_Plus_Plus, Convention_CPP));
358
359 Convention_Identifiers.Append ((Name_DLL, Convention_Stdcall));
360 Convention_Identifiers.Append ((Name_Win32, Convention_Stdcall));
361 end Initialize;
362
363 -----------------------
364 -- Is_Attribute_Name --
365 -----------------------
366
367 function Is_Attribute_Name (N : Name_Id) return Boolean is
368 begin
369 -- Don't consider Name_Elab_Subp_Body to be a valid attribute name
370 -- unless we are working in CodePeer mode.
371
372 return N in First_Attribute_Name .. Last_Attribute_Name
373 and then (CodePeer_Mode or else N /= Name_Elab_Subp_Body);
374 end Is_Attribute_Name;
375
376 ----------------------------------
377 -- Is_Configuration_Pragma_Name --
378 ----------------------------------
379
380 function Is_Configuration_Pragma_Name (N : Name_Id) return Boolean is
381 begin
382 return N in Configuration_Pragma_Names
383 or else N = Name_Default_Scalar_Storage_Order
384 or else N = Name_Fast_Math;
385 end Is_Configuration_Pragma_Name;
386
387 ------------------------
388 -- Is_Convention_Name --
389 ------------------------
390
391 function Is_Convention_Name (N : Name_Id) return Boolean is
392 begin
393 -- Check if this is one of the standard conventions
394
395 if N in First_Convention_Name .. Last_Convention_Name
396 or else N = Name_C
397 then
398 return True;
399
400 -- Otherwise check if it is in convention identifier table
401
402 else
403 for J in 1 .. Convention_Identifiers.Last loop
404 if N = Convention_Identifiers.Table (J).Name then
405 return True;
406 end if;
407 end loop;
408
409 return False;
410 end if;
411 end Is_Convention_Name;
412
413 ------------------------------
414 -- Is_Entity_Attribute_Name --
415 ------------------------------
416
417 function Is_Entity_Attribute_Name (N : Name_Id) return Boolean is
418 begin
419 return N in First_Entity_Attribute_Name .. Last_Entity_Attribute_Name;
420 end Is_Entity_Attribute_Name;
421
422 --------------------------------
423 -- Is_Function_Attribute_Name --
424 --------------------------------
425
426 function Is_Function_Attribute_Name (N : Name_Id) return Boolean is
427 begin
428 return N in
429 First_Renamable_Function_Attribute ..
430 Last_Renamable_Function_Attribute;
431 end Is_Function_Attribute_Name;
432
433 ---------------------
434 -- Is_Keyword_Name --
435 ---------------------
436
437 function Is_Keyword_Name (N : Name_Id) return Boolean is
438 begin
439 return Get_Name_Table_Byte (N) /= 0
440 and then (Ada_Version >= Ada_95
441 or else N not in Ada_95_Reserved_Words)
442 and then (Ada_Version >= Ada_2005
443 or else N not in Ada_2005_Reserved_Words
444 or else (Debug_Flag_Dot_DD and then N = Name_Overriding))
445 -- Accept 'overriding' keywords if -gnatd.D is used,
446 -- for compatibility with Ada 95 compilers implementing
447 -- only this Ada 2005 extension.
448 and then (Ada_Version >= Ada_2012
449 or else N not in Ada_2012_Reserved_Words)
450 and then (Ada_Version >= Ada_With_All_Extensions
451 or else N not in GNAT_Extensions_Reserved_Words);
452 end Is_Keyword_Name;
453
454 --------------------------------
455 -- Is_Internal_Attribute_Name --
456 --------------------------------
457
458 function Is_Internal_Attribute_Name (N : Name_Id) return Boolean is
459 begin
460 return
461 N in First_Internal_Attribute_Name .. Last_Internal_Attribute_Name;
462 end Is_Internal_Attribute_Name;
463
464 ----------------------------
465 -- Is_Locking_Policy_Name --
466 ----------------------------
467
468 function Is_Locking_Policy_Name (N : Name_Id) return Boolean is
469 begin
470 return N in First_Locking_Policy_Name .. Last_Locking_Policy_Name;
471 end Is_Locking_Policy_Name;
472
473 ------------------------------------------
474 -- Is_Partition_Elaboration_Policy_Name --
475 ------------------------------------------
476
477 function Is_Partition_Elaboration_Policy_Name
478 (N : Name_Id) return Boolean
479 is
480 begin
481 return N in First_Partition_Elaboration_Policy_Name ..
482 Last_Partition_Elaboration_Policy_Name;
483 end Is_Partition_Elaboration_Policy_Name;
484
485 -----------------------------
486 -- Is_Operator_Symbol_Name --
487 -----------------------------
488
489 function Is_Operator_Symbol_Name (N : Name_Id) return Boolean is
490 begin
491 return N in First_Operator_Name .. Last_Operator_Name;
492 end Is_Operator_Symbol_Name;
493
494 --------------------
495 -- Is_Pragma_Name --
496 --------------------
497
498 function Is_Pragma_Name (N : Name_Id) return Boolean is
499 begin
500 return N in First_Pragma_Name .. Last_Pragma_Name
501 or else N = Name_CPU
502 or else N = Name_Default_Scalar_Storage_Order
503 or else N = Name_Dispatching_Domain
504 or else N = Name_Fast_Math
505 or else N = Name_Interface
506 or else N = Name_Interrupt_Priority
507 or else N = Name_Preelaborable_Initialization
508 or else N = Name_Priority
509 or else N = Name_Secondary_Stack_Size
510 or else N = Name_Storage_Size
511 or else N = Name_Storage_Unit;
512 end Is_Pragma_Name;
513
514 ---------------------------------
515 -- Is_Procedure_Attribute_Name --
516 ---------------------------------
517
518 function Is_Procedure_Attribute_Name (N : Name_Id) return Boolean is
519 begin
520 return N in First_Procedure_Attribute .. Last_Procedure_Attribute;
521 end Is_Procedure_Attribute_Name;
522
523 ----------------------------
524 -- Is_Queuing_Policy_Name --
525 ----------------------------
526
527 function Is_Queuing_Policy_Name (N : Name_Id) return Boolean is
528 begin
529 return N in First_Queuing_Policy_Name .. Last_Queuing_Policy_Name;
530 end Is_Queuing_Policy_Name;
531
532 -------------------------------------
533 -- Is_Task_Dispatching_Policy_Name --
534 -------------------------------------
535
536 function Is_Task_Dispatching_Policy_Name (N : Name_Id) return Boolean is
537 begin
538 return N in First_Task_Dispatching_Policy_Name ..
539 Last_Task_Dispatching_Policy_Name;
540 end Is_Task_Dispatching_Policy_Name;
541
542 ----------------------------
543 -- Is_Type_Attribute_Name --
544 ----------------------------
545
546 function Is_Type_Attribute_Name (N : Name_Id) return Boolean is
547 begin
548 return N in First_Type_Attribute_Name .. Last_Type_Attribute_Name;
549 end Is_Type_Attribute_Name;
550
551 ----------------------------------
552 -- Record_Convention_Identifier --
553 ----------------------------------
554
555 procedure Record_Convention_Identifier
556 (Id : Name_Id;
557 Convention : Convention_Id)
558 is
559 begin
560 Convention_Identifiers.Append ((Id, Convention));
561 end Record_Convention_Identifier;
562
563 end Snames;