Debian Codegraph @

gcc/ada/rtsfind.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- R T S F I N D --
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 Atree; use Atree;
27 with Casing; use Casing;
28 with Csets; use Csets;
29 with Debug; use Debug;
30 with Einfo; use Einfo;
31 with Einfo.Entities; use Einfo.Entities;
32 with Einfo.Utils; use Einfo.Utils;
33 with Elists; use Elists;
34 with Errout; use Errout;
35 with Exp_Dist;
36 with Fname; use Fname;
37 with Fname.UF; use Fname.UF;
38 with Ghost; use Ghost;
39 with Lib; use Lib;
40 with Lib.Load; use Lib.Load;
41 with Namet; use Namet;
42 with Nlists; use Nlists;
43 with Nmake; use Nmake;
44 with Output; use Output;
45 with Opt; use Opt;
46 with Restrict; use Restrict;
47 with Sem; use Sem;
48 with Sem_Aux; use Sem_Aux;
49 with Sem_Ch7; use Sem_Ch7;
50 with Sem_Ch12; use Sem_Ch12;
51 with Sem_Dist; use Sem_Dist;
52 with Sem_Util; use Sem_Util;
53 with Sinfo; use Sinfo;
54 with Sinfo.Nodes; use Sinfo.Nodes;
55 with Sinfo.Utils; use Sinfo.Utils;
56 with Stand; use Stand;
57 with Snames; use Snames;
58 with Tbuild; use Tbuild;
59 with Uname; use Uname;
60
61 package body Rtsfind is
62
63 RTE_Available_Call : Boolean := False;
64 -- Set True during call to RTE from RTE_Available (or from call to
65 -- RTE_Record_Component from RTE_Record_Component_Available). Tells
66 -- the called subprogram to set RTE_Is_Available to False rather than
67 -- generating an error message.
68
69 RTE_Is_Available : Boolean;
70 -- Set True by RTE_Available on entry. When RTE_Available_Call is set
71 -- True, set False if RTE would otherwise generate an error message.
72
73 ----------------
74 -- Unit table --
75 ----------------
76
77 -- The unit table has one entry for each unit included in the definition
78 -- of the type RTU_Id in the spec. The table entries are initialized in
79 -- Initialize to set the Entity field to Empty, indicating that the
80 -- corresponding unit has not yet been loaded. The fields are set when
81 -- a unit is loaded to contain the defining entity for the unit, the
82 -- unit name, and the unit number.
83
84 -- Note that a unit can be loaded either by a call to find an entity
85 -- within the unit (e.g. RTE), or by an explicit with of the unit. In
86 -- the latter case it is critical to make a call to Set_RTU_Loaded to
87 -- ensure that the entry in this table reflects the load.
88
89 -- A unit retrieved through rtsfind may end up in the context of several
90 -- other units, in addition to the main unit. These additional with_clauses
91 -- are needed to generate a proper traversal order for CodePeer. To
92 -- minimize somewhat the redundancy created by numerous calls to rtsfind
93 -- from different units, we keep track of the list of implicit with_clauses
94 -- already created for the current loaded unit.
95
96 type RT_Unit_Table_Record is record
97 Entity : Entity_Id;
98 Uname : Unit_Name_Type;
99 First_Implicit_With : Node_Id;
100 Unum : Unit_Number_Type;
101 end record;
102
103 RT_Unit_Table : array (RTU_Id) of RT_Unit_Table_Record;
104
105 --------------------------
106 -- Runtime Entity Table --
107 --------------------------
108
109 -- There is one entry in the runtime entity table for each entity that is
110 -- included in the definition of the RE_Id type in the spec. The entries
111 -- are set by Initialize_Rtsfind to contain Empty, indicating that the
112 -- entity has not yet been located. Once the entity is located for the
113 -- first time, its ID is stored in this array, so that subsequent calls
114 -- for the same entity can be satisfied immediately.
115
116 -- NOTE: In order to avoid conflicts between record components and subprgs
117 -- that have the same name (i.e. subprogram External_Tag and
118 -- component External_Tag of package Ada.Tags) this table is not used
119 -- with Record_Components.
120
121 RE_Table : array (RE_Id) of Entity_Id;
122
123 --------------------------------
124 -- Generation of with_clauses --
125 --------------------------------
126
127 -- When a unit is implicitly loaded as a result of a call to RTE, it is
128 -- necessary to create one or two implicit with_clauses. We add such
129 -- with_clauses to the extended main unit if needed, and also to whatever
130 -- unit needs them, which is not necessarily the main unit. The former
131 -- ensures that the object is correctly loaded by the binder. The latter
132 -- is necessary for CodePeer.
133
134 -- The field First_Implicit_With in the unit table record are used to
135 -- avoid creating duplicate with_clauses.
136
137 ----------------------------------------------
138 -- Table of Predefined RE_Id Error Messages --
139 ----------------------------------------------
140
141 -- If an attempt is made to load an entity, given an RE_Id value, and the
142 -- entity is not available in the current configuration, an error message
143 -- is given (see Entity_Not_Defined below). The general form of such an
144 -- error message is for example:
145
146 -- entity "System.Pack_43.Bits_43" not defined
147
148 -- The following table defines a set of RE_Id image values for which this
149 -- error message is specialized and replaced by specific text indicating
150 -- the exact message to be output. For example, in the case above, for the
151 -- RE_Id value RE_Bits_43, we do indeed specialize the message, and the
152 -- above generic message is replaced by:
153
154 -- packed component size of 43 is not supported
155
156 type CString_Ptr is not null access constant String;
157
158 type PRE_Id_Entry is record
159 Str : CString_Ptr;
160 -- Pointer to string with the RE_Id image. The sequence ?? may appear
161 -- in which case it will match any characters in the RE_Id image value.
162 -- This is used to avoid the need for dozens of entries for RE_Bits_??.
163
164 Msg : CString_Ptr;
165 -- Pointer to string with the corresponding error text. The sequence
166 -- ?? may appear, in which case, it is replaced by the corresponding
167 -- sequence ?? in the Str value (if the first ? is zero, then it is
168 -- omitted from the message).
169 end record;
170
171 Str1 : aliased constant String := "RE_BITS_??";
172 Str2 : aliased constant String := "RE_GET_??";
173 Str3 : aliased constant String := "RE_SET_??";
174 Str4 : aliased constant String := "RE_CALL_SIMPLE";
175
176 MsgPack : aliased constant String :=
177 "packed component size of ?? is not supported";
178 MsgRV : aliased constant String :=
179 "task rendezvous is not supported";
180
181 PRE_Id_Table : constant array (Natural range <>) of PRE_Id_Entry :=
182 (1 => (Str1'Access, MsgPack'Access),
183 2 => (Str2'Access, MsgPack'Access),
184 3 => (Str3'Access, MsgPack'Access),
185 4 => (Str4'Access, MsgRV'Access));
186 -- We will add entries to this table as we find cases where it is a good
187 -- idea to do so. By no means all the RE_Id values need entries, because
188 -- the expander often gives clear messages before it makes the Rtsfind
189 -- call expecting to find the entity.
190
191 -----------------------
192 -- Local Subprograms --
193 -----------------------
194
195 function Check_CRT (E : RE_Id; Eid : Entity_Id) return Entity_Id;
196 -- Check entity Eid to ensure that configurable run-time restrictions are
197 -- met. May generate an error message (if RTE_Available_Call is false) and
198 -- raise RE_Not_Available if entity E does not exist (e.g. Eid is Empty).
199 -- Also check that entity is not overloaded.
200
201 procedure Entity_Not_Defined (Id : RE_Id);
202 -- Outputs error messages for an entity that is not defined in the run-time
203 -- library (the form of the error message is tailored for no run time or
204 -- configurable run time mode as required). See also table of pre-defined
205 -- messages for entities above (RE_Id_Messages).
206
207 function Get_Unit_Name (U_Id : RTU_Id) return Unit_Name_Type;
208 -- Retrieves the Unit Name given a unit id represented by its enumeration
209 -- value in RTU_Id.
210
211 procedure Load_Fail (S : String; U_Id : RTU_Id; Id : RE_Id);
212 pragma No_Return (Load_Fail);
213 -- Internal procedure called if we can't successfully locate or process a
214 -- run-time unit. The parameters give information about the error message
215 -- to be given. S is a reason for failing to compile the file and U_Id is
216 -- the unit id. RE_Id is the RE_Id originally passed to RTE. The message in
217 -- S is one of the following:
218 --
219 -- "not found"
220 -- "had parser errors"
221 -- "had semantic errors"
222 --
223 -- The "not found" case is treated specially in that it is considered
224 -- a normal situation in configurable run-time mode, and generates
225 -- a warning, but is otherwise ignored.
226
227 procedure Load_RTU
228 (U_Id : RTU_Id;
229 Id : RE_Id := RE_Null;
230 Use_Setting : Boolean := False);
231 -- Load the unit whose Id is given if not already loaded. The unit is
232 -- loaded and analyzed, and the entry in RT_Unit_Table is updated to
233 -- reflect the load. Use_Setting is used to indicate the initial setting
234 -- for the Is_Potentially_Use_Visible flag of the entity for the loaded
235 -- unit (if it is indeed loaded). A value of False means nothing special
236 -- need be done. A value of True indicates that this flag must be set to
237 -- True. It is needed only in the Check_Text_IO_Special_Unit procedure,
238 -- which may materialize an entity of Text_IO (or [Wide_]Wide_Text_IO) that
239 -- was previously unknown. Id is the RE_Id value of the entity which was
240 -- originally requested. Id is used only for error message detail, and if
241 -- it is RE_Null, then the attempt to output the entity name is ignored.
242
243 function Make_Unit_Name
244 (U : RT_Unit_Table_Record;
245 N : Node_Id) return Node_Id;
246 -- If the unit is a child unit, build fully qualified name for use in
247 -- With_Clause.
248
249 procedure Maybe_Add_With (U : in out RT_Unit_Table_Record);
250 -- If necessary, add an implicit with_clause from the current unit to the
251 -- one represented by U.
252
253 procedure Output_Entity_Name (Id : RE_Id; Msg : String);
254 -- Output continuation error message giving qualified name of entity
255 -- corresponding to Id, appending the string given by Msg.
256
257 function RE_Chars (E : RE_Id) return Name_Id;
258 -- Given a RE_Id value returns the Chars of the corresponding entity
259
260 procedure RTE_Error_Msg (Msg : String);
261 -- Generates a message by calling Error_Msg_N specifying Current_Error_Node
262 -- as the node location using the given Msg text. Special processing in the
263 -- case where RTE_Available_Call is set. In this case, no message is output
264 -- and instead RTE_Is_Available is set to False. Note that this can only be
265 -- used if you are sure that the message comes directly or indirectly from
266 -- a call to the RTE function.
267
268 ---------------
269 -- Check_CRT --
270 ---------------
271
272 function Check_CRT (E : RE_Id; Eid : Entity_Id) return Entity_Id is
273 U_Id : constant RTU_Id := RE_Unit_Table (E);
274
275 begin
276 if No (Eid) then
277 if RTE_Available_Call then
278 RTE_Is_Available := False;
279 else
280 Entity_Not_Defined (E);
281 end if;
282
283 raise RE_Not_Available;
284
285 -- Entity is available
286
287 else
288 -- If in No_Run_Time mode and entity is neither in the current unit
289 -- nor in one of the specially permitted units, raise the exception.
290
291 if No_Run_Time_Mode
292 and then not OK_No_Run_Time_Unit (U_Id)
293
294 -- If the entity being referenced is defined in the current scope,
295 -- using it is always fine as such usage can never introduce any
296 -- dependency on an additional unit. The presence of this test
297 -- helps generating meaningful error messages for CRT violations.
298
299 and then Scope (Eid) /= Current_Scope
300 then
301 Entity_Not_Defined (E);
302 raise RE_Not_Available;
303 end if;
304
305 -- Check entity is not overloaded, checking for special exceptions
306
307 if Has_Homonym (Eid)
308 and then E /= RE_Save_Occurrence
309 then
310 Set_Standard_Error;
311 Write_Str ("Run-time configuration error (");
312 Write_Str ("rtsfind entity """);
313 Get_Decoded_Name_String (Chars (Eid));
314 Set_Casing (Mixed_Case);
315 Write_Str (Name_Buffer (1 .. Name_Len));
316 Write_Str (""" is overloaded)");
317 Write_Eol;
318 raise Unrecoverable_Error;
319 end if;
320
321 -- Otherwise entity is accessible
322
323 return Eid;
324 end if;
325 end Check_CRT;
326
327 --------------------------------
328 -- Check_Text_IO_Special_Unit --
329 --------------------------------
330
331 procedure Check_Text_IO_Special_Unit (Nam : Node_Id) is
332 Chrs : Name_Id;
333
334 type Name_Map_Type is array (Text_IO_Package_Name) of RTU_Id;
335
336 Name_Map : constant Name_Map_Type := Name_Map_Type'(
337 Name_Decimal_IO => Ada_Text_IO_Decimal_IO,
338 Name_Enumeration_IO => Ada_Text_IO_Enumeration_IO,
339 Name_Fixed_IO => Ada_Text_IO_Fixed_IO,
340 Name_Float_IO => Ada_Text_IO_Float_IO,
341 Name_Integer_IO => Ada_Text_IO_Integer_IO,
342 Name_Modular_IO => Ada_Text_IO_Modular_IO);
343
344 Wide_Name_Map : constant Name_Map_Type := Name_Map_Type'(
345 Name_Decimal_IO => Ada_Wide_Text_IO_Decimal_IO,
346 Name_Enumeration_IO => Ada_Wide_Text_IO_Enumeration_IO,
347 Name_Fixed_IO => Ada_Wide_Text_IO_Fixed_IO,
348 Name_Float_IO => Ada_Wide_Text_IO_Float_IO,
349 Name_Integer_IO => Ada_Wide_Text_IO_Integer_IO,
350 Name_Modular_IO => Ada_Wide_Text_IO_Modular_IO);
351
352 Wide_Wide_Name_Map : constant Name_Map_Type := Name_Map_Type'(
353 Name_Decimal_IO => Ada_Wide_Wide_Text_IO_Decimal_IO,
354 Name_Enumeration_IO => Ada_Wide_Wide_Text_IO_Enumeration_IO,
355 Name_Fixed_IO => Ada_Wide_Wide_Text_IO_Fixed_IO,
356 Name_Float_IO => Ada_Wide_Wide_Text_IO_Float_IO,
357 Name_Integer_IO => Ada_Wide_Wide_Text_IO_Integer_IO,
358 Name_Modular_IO => Ada_Wide_Wide_Text_IO_Modular_IO);
359
360 To_Load : RTU_Id;
361 -- Unit to be loaded, from one of the above maps
362
363 begin
364 -- Nothing to do if name is not an identifier or a selected component
365 -- whose selector_name is an identifier.
366
367 if Nkind (Nam) = N_Identifier then
368 Chrs := Chars (Nam);
369
370 elsif Nkind (Nam) = N_Selected_Component
371 and then Nkind (Selector_Name (Nam)) = N_Identifier
372 then
373 Chrs := Chars (Selector_Name (Nam));
374
375 else
376 return;
377 end if;
378
379 -- Nothing to do if name is not one of the Text_IO subpackages
380 -- Otherwise look through loaded units, and if we find Text_IO
381 -- or [Wide_]Wide_Text_IO already loaded, then load the proper child.
382
383 if Chrs in Text_IO_Package_Name then
384 for U in Main_Unit .. Last_Unit loop
385 Get_Name_String (Unit_File_Name (U));
386
387 if Name_Len = 12 then
388
389 -- Here is where we do the loads if we find one of the units
390 -- Ada.Text_IO or Ada.[Wide_]Wide_Text_IO. An interesting
391 -- detail is that these units may already be used (i.e. their
392 -- In_Use flags may be set). Normally when the In_Use flag is
393 -- set, the Is_Potentially_Use_Visible flag of all entities in
394 -- the package is set, but the new entity we are mysteriously
395 -- adding was not there to have its flag set at the time. So
396 -- that's why we pass the extra parameter to RTU_Find, to make
397 -- sure the flag does get set now. Given that those generic
398 -- packages are in fact child units, we must indicate that
399 -- they are visible.
400
401 if Name_Buffer (1 .. 12) = "a-textio.ads" then
402 To_Load := Name_Map (Chrs);
403
404 elsif Name_Buffer (1 .. 12) = "a-witeio.ads" then
405 To_Load := Wide_Name_Map (Chrs);
406
407 elsif Name_Buffer (1 .. 12) = "a-ztexio.ads" then
408 To_Load := Wide_Wide_Name_Map (Chrs);
409
410 else
411 goto Continue;
412 end if;
413
414 Load_RTU (To_Load, Use_Setting => In_Use (Cunit_Entity (U)));
415 Set_Is_Visible_Lib_Unit (RT_Unit_Table (To_Load).Entity);
416
417 -- Prevent creation of an implicit 'with' from (for example)
418 -- Ada.Wide_Text_IO.Integer_IO to Ada.Text_IO.Integer_IO,
419 -- because these could create cycles. First check whether the
420 -- simple names match ("integer_io" = "integer_io"), and then
421 -- check whether the parent is indeed one of the
422 -- [[Wide_]Wide_]Text_IO packages.
423
424 if Chrs = Chars (Cunit_Entity (Current_Sem_Unit)) then
425 declare
426 Parent_Name : constant Unit_Name_Type :=
427 Get_Parent_Spec_Name
428 (Unit_Name (Current_Sem_Unit));
429
430 begin
431 if Present (Parent_Name) then
432 Get_Name_String (Parent_Name);
433
434 declare
435 P : String renames Name_Buffer (1 .. Name_Len);
436 begin
437 if P = "ada.text_io%s" or else
438 P = "ada.wide_text_io%s" or else
439 P = "ada.wide_wide_text_io%s"
440 then
441 goto Continue;
442 end if;
443 end;
444 end if;
445 end;
446 end if;
447
448 -- Add an implicit with clause from the current unit to the
449 -- [[Wide_]Wide_]Text_IO child (if necessary).
450
451 Maybe_Add_With (RT_Unit_Table (To_Load));
452 end if;
453
454 <<Continue>> null;
455 end loop;
456 end if;
457
458 exception
459 -- Generate error message if run-time unit not available
460
461 when RE_Not_Available =>
462 Error_Msg_N ("& not available", Nam);
463 end Check_Text_IO_Special_Unit;
464
465 ------------------------
466 -- Entity_Not_Defined --
467 ------------------------
468
469 procedure Entity_Not_Defined (Id : RE_Id) is
470 begin
471 if No_Run_Time_Mode then
472
473 -- If the error occurs when compiling the body of a predefined
474 -- unit for inlining purposes, the body must be illegal in this
475 -- mode, and there is no point in continuing.
476
477 if In_Predefined_Unit (Current_Error_Node) then
478 Error_Msg_N
479 ("construct not allowed in no run time mode!",
480 Current_Error_Node);
481 raise Unrecoverable_Error;
482
483 else
484 RTE_Error_Msg ("|construct not allowed in no run time mode");
485 end if;
486
487 elsif Configurable_Run_Time_Mode then
488 RTE_Error_Msg ("|construct not allowed in this configuration>");
489 else
490 RTE_Error_Msg ("run-time configuration error");
491 end if;
492
493 -- See if this entry is to be found in the PRE_Id table that provides
494 -- specialized messages for some RE_Id values.
495
496 for J in PRE_Id_Table'Range loop
497 declare
498 TStr : constant String := PRE_Id_Table (J).Str.all;
499 RStr : constant String := RE_Id'Image (Id);
500 TMsg : String := PRE_Id_Table (J).Msg.all;
501 LMsg : Natural := TMsg'Length;
502
503 begin
504 if TStr'Length = RStr'Length then
505 for J in TStr'Range loop
506 if TStr (J) /= RStr (J) and then TStr (J) /= '?' then
507 goto Continue;
508 end if;
509 end loop;
510
511 for J in TMsg'First .. TMsg'Last - 1 loop
512 if TMsg (J) = '?' then
513 for K in 1 .. TStr'Last loop
514 if TStr (K) = '?' then
515 if RStr (K) = '0' then
516 TMsg (J) := RStr (K + 1);
517 TMsg (J + 1 .. LMsg - 1) := TMsg (J + 2 .. LMsg);
518 LMsg := LMsg - 1;
519 else
520 TMsg (J .. J + 1) := RStr (K .. K + 1);
521 end if;
522
523 exit;
524 end if;
525 end loop;
526 end if;
527 end loop;
528
529 RTE_Error_Msg (TMsg (1 .. LMsg));
530 return;
531 end if;
532 end;
533
534 <<Continue>> null;
535 end loop;
536
537 -- We did not find an entry in the table, so output the generic entity
538 -- not found message, where the name of the entity corresponds to the
539 -- given RE_Id value.
540
541 Output_Entity_Name (Id, "not defined");
542 end Entity_Not_Defined;
543
544 -------------------
545 -- Get_Unit_Name --
546 -------------------
547
548 -- The following subtypes include all the proper descendants of each unit
549 -- that has such descendants. For example, Ada_Calendar_Descendant includes
550 -- all the descendents of Ada.Calendar (except Ada.Calendar itself). These
551 -- are used by Get_Unit_Name to know where to change "_" to ".", and by
552 -- Is_Text_IO_Special_Package to detect the special generic pseudo-children
553 -- of [[Wide_]Wide_]Text_IO.
554
555 subtype Ada_Descendant is RTU_Id
556 range Ada_Calendar .. Ada_Wide_Wide_Text_IO_Modular_IO;
557
558 subtype Ada_Calendar_Descendant is Ada_Descendant
559 range Ada_Calendar_Delays .. Ada_Calendar_Delays;
560
561 subtype Ada_Dispatching_Descendant is Ada_Descendant
562 range Ada_Dispatching_EDF .. Ada_Dispatching_EDF;
563
564 subtype Ada_Interrupts_Descendant is Ada_Descendant range
565 Ada_Interrupts_Names .. Ada_Interrupts_Names;
566
567 subtype Ada_Numerics_Descendant is Ada_Descendant
568 range Ada_Numerics_Big_Numbers ..
569 Ada_Numerics_Big_Numbers_Big_Integers_Ghost;
570
571 subtype Ada_Numerics_Big_Numbers_Descendant is Ada_Descendant
572 range Ada_Numerics_Big_Numbers_Big_Integers ..
573 Ada_Numerics_Big_Numbers_Big_Integers_Ghost;
574
575 subtype Ada_Real_Time_Descendant is Ada_Descendant
576 range Ada_Real_Time_Delays .. Ada_Real_Time_Timing_Events;
577
578 subtype Ada_Streams_Descendant is Ada_Descendant
579 range Ada_Streams_Stream_IO .. Ada_Streams_Stream_IO;
580
581 subtype Ada_Strings_Descendant is Ada_Descendant
582 range Ada_Strings_Superbounded .. Ada_Strings_Text_Buffers_Unbounded;
583
584 subtype Ada_Strings_Text_Buffers_Descendant is Ada_Strings_Descendant
585 range Ada_Strings_Text_Buffers_Unbounded ..
586 Ada_Strings_Text_Buffers_Unbounded;
587
588 subtype Ada_Text_IO_Descendant is Ada_Descendant
589 range Ada_Text_IO_Decimal_IO .. Ada_Text_IO_Modular_IO;
590
591 subtype Ada_Wide_Text_IO_Descendant is Ada_Descendant
592 range Ada_Wide_Text_IO_Decimal_IO .. Ada_Wide_Text_IO_Modular_IO;
593
594 subtype Ada_Wide_Wide_Text_IO_Descendant is Ada_Descendant
595 range Ada_Wide_Wide_Text_IO_Decimal_IO ..
596 Ada_Wide_Wide_Text_IO_Modular_IO;
597
598 subtype CUDA_Descendant is RTU_Id
599 range CUDA_Driver_Types .. CUDA_Vector_Types;
600
601 subtype Interfaces_Descendant is RTU_Id
602 range Interfaces_C .. Interfaces_C_Strings;
603
604 subtype Interfaces_C_Descendant is Interfaces_Descendant
605 range Interfaces_C_Strings .. Interfaces_C_Strings;
606
607 subtype SPARK_Descendant is RTU_Id
608 range SPARK_Big_Integers .. SPARK_Big_Integers;
609
610 subtype System_Descendant is RTU_Id
611 range System_Address_To_Access_Conversions .. System_Tasking_Stages;
612
613 subtype System_Atomic_Operations_Descendant is System_Descendant
614 range System_Atomic_Operations_Test_And_Set ..
615 System_Atomic_Operations_Test_And_Set;
616
617 subtype System_Dim_Descendant is System_Descendant
618 range System_Dim_Float_IO .. System_Dim_Integer_IO;
619
620 subtype System_Multiprocessors_Descendant is System_Descendant
621 range System_Multiprocessors_Dispatching_Domains ..
622 System_Multiprocessors_Dispatching_Domains;
623
624 subtype System_Storage_Pools_Descendant is System_Descendant
625 range System_Storage_Pools_Subpools .. System_Storage_Pools_Subpools;
626
627 subtype System_Strings_Descendant is System_Descendant
628 range System_Strings_Stream_Ops .. System_Strings_Stream_Ops;
629
630 subtype System_Tasking_Descendant is System_Descendant
631 range System_Tasking_Async_Delays .. System_Tasking_Stages;
632
633 subtype System_Tasking_Protected_Objects_Descendant is
634 System_Tasking_Descendant
635 range System_Tasking_Protected_Objects_Entries ..
636 System_Tasking_Protected_Objects_Single_Entry;
637
638 subtype System_Tasking_Restricted_Descendant is System_Tasking_Descendant
639 range System_Tasking_Restricted_Stages ..
640 System_Tasking_Restricted_Stages;
641
642 subtype System_Tasking_Async_Delays_Descendant is System_Tasking_Descendant
643 range System_Tasking_Async_Delays_Enqueue_Calendar ..
644 System_Tasking_Async_Delays_Enqueue_RT;
645
646 function Get_Unit_Name (U_Id : RTU_Id) return Unit_Name_Type is
647 Uname_Chars : constant String := RTU_Id'Image (U_Id);
648 begin
649 Name_Len := Uname_Chars'Length;
650 Name_Buffer (1 .. Name_Len) := Uname_Chars;
651 Set_Casing (All_Lower_Case);
652
653 if U_Id in Ada_Descendant then
654 Name_Buffer (4) := '.';
655
656 if U_Id in Ada_Calendar_Descendant then
657 Name_Buffer (13) := '.';
658
659 elsif U_Id in Ada_Dispatching_Descendant then
660 Name_Buffer (16) := '.';
661
662 elsif U_Id in Ada_Interrupts_Descendant then
663 Name_Buffer (15) := '.';
664
665 elsif U_Id in Ada_Numerics_Descendant then
666 Name_Buffer (13) := '.';
667
668 if U_Id in Ada_Numerics_Big_Numbers_Descendant then
669 Name_Buffer (25) := '.';
670 end if;
671
672 elsif U_Id in Ada_Real_Time_Descendant then
673 Name_Buffer (14) := '.';
674
675 elsif U_Id in Ada_Streams_Descendant then
676 Name_Buffer (12) := '.';
677
678 elsif U_Id in Ada_Strings_Descendant then
679 Name_Buffer (12) := '.';
680
681 if U_Id in Ada_Strings_Text_Buffers_Descendant then
682 Name_Buffer (25) := '.';
683 end if;
684
685 elsif U_Id in Ada_Text_IO_Descendant then
686 Name_Buffer (12) := '.';
687
688 elsif U_Id in Ada_Wide_Text_IO_Descendant then
689 Name_Buffer (17) := '.';
690
691 elsif U_Id in Ada_Wide_Wide_Text_IO_Descendant then
692 Name_Buffer (22) := '.';
693 end if;
694
695 elsif U_Id in CUDA_Descendant then
696 Name_Buffer (5) := '.';
697
698 elsif U_Id in Interfaces_Descendant then
699 Name_Buffer (11) := '.';
700
701 if U_Id in Interfaces_C_Descendant then
702 Name_Buffer (13) := '.';
703 end if;
704
705 elsif U_Id in SPARK_Descendant then
706 Name_Buffer (6) := '.';
707
708 elsif U_Id in System_Descendant then
709 Name_Buffer (7) := '.';
710
711 if U_Id in System_Atomic_Operations_Descendant then
712 Name_Buffer (25) := '.';
713 end if;
714
715 if U_Id in System_Dim_Descendant then
716 Name_Buffer (11) := '.';
717 end if;
718
719 if U_Id in System_Multiprocessors_Descendant then
720 Name_Buffer (23) := '.';
721 end if;
722
723 if U_Id in System_Storage_Pools_Descendant then
724 Name_Buffer (21) := '.';
725 end if;
726
727 if U_Id in System_Strings_Descendant then
728 Name_Buffer (15) := '.';
729 end if;
730
731 if U_Id in System_Tasking_Descendant then
732 Name_Buffer (15) := '.';
733 end if;
734
735 if U_Id in System_Tasking_Restricted_Descendant then
736 Name_Buffer (26) := '.';
737 end if;
738
739 if U_Id in System_Tasking_Protected_Objects_Descendant then
740 Name_Buffer (33) := '.';
741 end if;
742
743 if U_Id in System_Tasking_Async_Delays_Descendant then
744 Name_Buffer (28) := '.';
745 end if;
746 end if;
747
748 -- Add %s at end for spec
749
750 Name_Buffer (Name_Len + 1) := '%';
751 Name_Buffer (Name_Len + 2) := 's';
752 Name_Len := Name_Len + 2;
753
754 return Name_Find;
755 end Get_Unit_Name;
756
757 ----------------
758 -- Initialize --
759 ----------------
760
761 procedure Initialize is
762 begin
763 -- Initialize the unit table
764
765 for J in RTU_Id loop
766 RT_Unit_Table (J).Entity := Empty;
767 RT_Unit_Table (J).First_Implicit_With := Empty;
768 end loop;
769
770 for J in RE_Id loop
771 RE_Table (J) := Empty;
772 end loop;
773
774 RTE_Is_Available := False;
775 end Initialize;
776
777 ------------
778 -- Is_RTE --
779 ------------
780
781 function Is_RTE (Ent : Entity_Id; E : RE_Id) return Boolean is
782 E_Unit_Name : Unit_Name_Type;
783 Ent_Unit_Name : Unit_Name_Type;
784
785 S : Entity_Id;
786 E1 : Entity_Id;
787 E2 : Entity_Id;
788
789 begin
790 if No (Ent) then
791 return False;
792
793 -- If E has already a corresponding entity, check it directly,
794 -- going to full views if they exist to deal with the incomplete
795 -- and private type cases properly.
796
797 elsif Present (RE_Table (E)) then
798 E1 := Ent;
799
800 if Is_Type (E1) and then Present (Full_View (E1)) then
801 E1 := Full_View (E1);
802 end if;
803
804 E2 := RE_Table (E);
805
806 if Is_Type (E2) and then Present (Full_View (E2)) then
807 E2 := Full_View (E2);
808 end if;
809
810 return E1 = E2;
811 end if;
812
813 -- If the unit containing E is not loaded, we already know that the
814 -- entity we have cannot have come from this unit.
815
816 E_Unit_Name := Get_Unit_Name (RE_Unit_Table (E));
817
818 if not Is_Loaded (E_Unit_Name) then
819 return False;
820 end if;
821
822 -- Here the unit containing the entity is loaded. We have not made
823 -- an explicit call to RTE to get the entity in question, but we may
824 -- have obtained a reference to it indirectly from some other entity
825 -- in the same unit, or some other unit that references it.
826
827 -- Get the defining unit of the entity
828
829 S := Scope (Ent);
830
831 if No (S) or else Ekind (S) /= E_Package then
832 return False;
833 end if;
834
835 Ent_Unit_Name := Get_Unit_Name (Unit_Declaration_Node (S));
836
837 -- If the defining unit of the entity we are testing is not the
838 -- unit containing E, then they cannot possibly match.
839
840 if Ent_Unit_Name /= E_Unit_Name then
841 return False;
842 end if;
843
844 -- If the units match, then compare the names (remember that no
845 -- overloading is permitted in entities fetched using Rtsfind).
846
847 if RE_Chars (E) = Chars (Ent) then
848 RE_Table (E) := Ent;
849
850 -- If front-end inlining is enabled, we may be within a body that
851 -- contains inlined functions, which has not been retrieved through
852 -- rtsfind, and therefore is not yet recorded in the RT_Unit_Table.
853 -- Add the unit information now, it must be fully available.
854
855 declare
856 U : RT_Unit_Table_Record
857 renames RT_Unit_Table (RE_Unit_Table (E));
858 begin
859 if No (U.Entity) then
860 U.Entity := S;
861 U.Uname := E_Unit_Name;
862 U.Unum := Get_Source_Unit (S);
863 end if;
864 end;
865
866 return True;
867 else
868 return False;
869 end if;
870 end Is_RTE;
871
872 ------------
873 -- Is_RTU --
874 ------------
875
876 function Is_RTU (Ent : Entity_Id; U : RTU_Id) return Boolean is
877 E : constant Entity_Id := RT_Unit_Table (U).Entity;
878 begin
879 return Present (E) and then E = Ent;
880 end Is_RTU;
881
882 --------------------------------
883 -- Is_Text_IO_Special_Package --
884 --------------------------------
885
886 function Is_Text_IO_Special_Package (E : Entity_Id) return Boolean is
887 begin
888 pragma Assert (Is_Package_Or_Generic_Package (E));
889
890 -- ??? detection with a scope climbing might be more efficient
891
892 for U in Ada_Text_IO_Descendant loop
893 if Is_RTU (E, U) then
894 return True;
895 end if;
896 end loop;
897
898 for U in Ada_Wide_Text_IO_Descendant loop
899 if Is_RTU (E, U) then
900 return True;
901 end if;
902 end loop;
903
904 for U in Ada_Wide_Wide_Text_IO_Descendant loop
905 if Is_RTU (E, U) then
906 return True;
907 end if;
908 end loop;
909
910 return False;
911 end Is_Text_IO_Special_Package;
912
913 -----------------------------
914 -- Is_Text_IO_Special_Unit --
915 -----------------------------
916
917 function Is_Text_IO_Special_Unit (Nam : Node_Id) return Boolean is
918 Prf : Node_Id;
919 Sel : Node_Id;
920
921 begin
922 if Nkind (Nam) /= N_Expanded_Name then
923 return False;
924 end if;
925
926 Prf := Prefix (Nam);
927 Sel := Selector_Name (Nam);
928
929 if Nkind (Sel) /= N_Expanded_Name
930 or else Nkind (Prf) /= N_Identifier
931 or else Chars (Prf) /= Name_Ada
932 then
933 return False;
934 end if;
935
936 Prf := Prefix (Sel);
937 Sel := Selector_Name (Sel);
938
939 return
940 Nkind (Prf) = N_Identifier
941 and then
942 Chars (Prf) in Name_Text_IO
943 | Name_Wide_Text_IO
944 | Name_Wide_Wide_Text_IO
945 and then Nkind (Sel) = N_Identifier
946 and then Chars (Sel) in Text_IO_Package_Name;
947 end Is_Text_IO_Special_Unit;
948
949 ---------------
950 -- Load_Fail --
951 ---------------
952
953 procedure Load_Fail (S : String; U_Id : RTU_Id; Id : RE_Id) is
954 M : String (1 .. 100);
955 P : Natural := 0;
956
957 begin
958 -- Output header message
959
960 if Configurable_Run_Time_Mode then
961 RTE_Error_Msg ("construct not allowed in configurable run-time mode");
962 else
963 RTE_Error_Msg ("run-time library configuration error");
964 end if;
965
966 -- Output file name and reason string
967
968 M (1 .. 6) := "\file ";
969 P := 6;
970
971 Get_Name_String
972 (Get_File_Name (RT_Unit_Table (U_Id).Uname, Subunit => False));
973 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
974 P := P + Name_Len;
975
976 M (P + 1) := ' ';
977 P := P + 1;
978
979 M (P + 1 .. P + S'Length) := S;
980 P := P + S'Length;
981
982 RTE_Error_Msg (M (1 .. P));
983
984 -- Output entity name
985
986 Output_Entity_Name (Id, "not available");
987
988 -- In configurable run time mode, we raise RE_Not_Available, and the
989 -- caller is expected to deal gracefully with this. In the case of a
990 -- call to RTE_Available, this exception will be caught in Rtsfind,
991 -- and result in a returned value of False for the call.
992
993 if Configurable_Run_Time_Mode then
994 raise RE_Not_Available;
995
996 -- Here we have a load failure in normal full run time mode. See if we
997 -- are in the context of an RTE_Available call. If so, we just raise
998 -- RE_Not_Available. This can happen if a unit is unavailable, which
999 -- happens for example in the VM case, where the run-time is not
1000 -- complete, but we do not regard it as a configurable run-time.
1001 -- If the caller has done an explicit call to RTE_Available, then
1002 -- clearly the caller is prepared to deal with a result of False.
1003
1004 elsif RTE_Available_Call then
1005 RTE_Is_Available := False;
1006 raise RE_Not_Available;
1007
1008 -- If we are not in the context of an RTE_Available call, we are really
1009 -- trying to load an entity that is not there, and that should never
1010 -- happen, so in this case we signal a fatal error.
1011
1012 else
1013 raise Unrecoverable_Error;
1014 end if;
1015 end Load_Fail;
1016
1017 --------------
1018 -- Load_RTU --
1019 --------------
1020
1021 -- WARNING: This routine manages Ghost and SPARK regions. Return statements
1022 -- must be replaced by gotos which jump to the end of the routine in order
1023 -- to restore the Ghost and SPARK modes.
1024
1025 procedure Load_RTU
1026 (U_Id : RTU_Id;
1027 Id : RE_Id := RE_Null;
1028 Use_Setting : Boolean := False)
1029 is
1030 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
1031 Priv_Par : constant Elist_Id := New_Elmt_List;
1032 Lib_Unit : Node_Id;
1033 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
1034 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
1035 Saved_ISMP : constant Boolean :=
1036 Ignore_SPARK_Mode_Pragmas_In_Instance;
1037 Saved_SM : constant SPARK_Mode_Type := SPARK_Mode;
1038 Saved_SMP : constant Node_Id := SPARK_Mode_Pragma;
1039 -- Save Ghost and SPARK mode-related data to restore on exit
1040
1041 procedure Save_Private_Visibility;
1042 -- If the current unit is the body of child unit or the spec of a
1043 -- private child unit, the private declarations of the parent(s) are
1044 -- visible. If the unit to be loaded is another public sibling, its
1045 -- compilation will affect the visibility of the common ancestors.
1046 -- Indicate those that must be restored.
1047
1048 procedure Restore_Private_Visibility;
1049 -- Restore the visibility of ancestors after compiling RTU
1050
1051 procedure Restore_SPARK_Context;
1052 -- Restore Ghost and SPARK mode-related data saved on procedure entry
1053
1054 --------------------------------
1055 -- Restore_Private_Visibility --
1056 --------------------------------
1057
1058 procedure Restore_Private_Visibility is
1059 E_Par : Elmt_Id;
1060
1061 begin
1062 E_Par := First_Elmt (Priv_Par);
1063 while Present (E_Par) loop
1064 if not In_Private_Part (Node (E_Par)) then
1065 Install_Private_Declarations (Node (E_Par));
1066 end if;
1067
1068 Next_Elmt (E_Par);
1069 end loop;
1070 end Restore_Private_Visibility;
1071
1072 -----------------------------
1073 -- Save_Private_Visibility --
1074 -----------------------------
1075
1076 procedure Save_Private_Visibility is
1077 Par : Entity_Id;
1078
1079 begin
1080 Par := Scope (Current_Scope);
1081 while Present (Par)
1082 and then Par /= Standard_Standard
1083 loop
1084 if Ekind (Par) = E_Package
1085 and then Is_Compilation_Unit (Par)
1086 and then In_Private_Part (Par)
1087 then
1088 Append_Elmt (Par, Priv_Par);
1089 end if;
1090
1091 Par := Scope (Par);
1092 end loop;
1093 end Save_Private_Visibility;
1094
1095 ---------------------------
1096 -- Restore_SPARK_Context --
1097 ---------------------------
1098
1099 procedure Restore_SPARK_Context is
1100 begin
1101 Ignore_SPARK_Mode_Pragmas_In_Instance := Saved_ISMP;
1102 Restore_Ghost_Region (Saved_GM, Saved_IGR);
1103 Restore_SPARK_Mode (Saved_SM, Saved_SMP);
1104 end Restore_SPARK_Context;
1105
1106 -- Start of processing for Load_RTU
1107
1108 begin
1109 -- Nothing to do if unit is already loaded
1110
1111 if Present (U.Entity) then
1112 return;
1113 end if;
1114
1115 -- Provide a clean environment for the unit
1116
1117 Ignore_SPARK_Mode_Pragmas_In_Instance := False;
1118 Install_Ghost_Region (None, Empty);
1119 Install_SPARK_Mode (None, Empty);
1120
1121 -- Otherwise we need to load the unit, First build unit name from the
1122 -- enumeration literal name in type RTU_Id.
1123
1124 U.Uname := Get_Unit_Name (U_Id);
1125 U.First_Implicit_With := Empty;
1126
1127 -- Now do the load call, note that setting Error_Node to Empty is a
1128 -- signal to Load_Unit that we will regard a failure to find the file as
1129 -- a fatal error, and that it should not output any kind of diagnostics,
1130 -- since we will take care of it here.
1131
1132 -- We save style checking switches and turn off style checking for
1133 -- loading the unit, since we don't want any style checking.
1134
1135 declare
1136 Save_Style_Check : constant Boolean := Style_Check;
1137 begin
1138 Style_Check := False;
1139 U.Unum :=
1140 Load_Unit
1141 (Load_Name => U.Uname,
1142 Required => False,
1143 Subunit => False,
1144 Error_Node => Empty);
1145 Style_Check := Save_Style_Check;
1146 end;
1147
1148 -- Check for bad unit load
1149
1150 if U.Unum = No_Unit then
1151 Load_Fail ("not found", U_Id, Id);
1152 elsif Fatal_Error (U.Unum) = Error_Detected then
1153 Load_Fail ("had parser errors", U_Id, Id);
1154 end if;
1155
1156 -- Make sure that the unit is analyzed
1157
1158 declare
1159 Was_Analyzed : constant Boolean :=
1160 Analyzed (Cunit (Current_Sem_Unit));
1161
1162 begin
1163 -- Pretend that the current unit is analyzed, in case it is System
1164 -- or some such. This allows us to put some declarations, such as
1165 -- exceptions and packed arrays of Boolean, into System even though
1166 -- expanding them requires System...
1167
1168 -- This is a bit odd but works fine. If the RTS unit does not depend
1169 -- in any way on the current unit, then it never gets back into the
1170 -- current unit's tree, and the change we make to the current unit
1171 -- tree is never noticed by anyone (it is undone in a moment). That
1172 -- is the normal situation.
1173
1174 -- If the RTS Unit *does* depend on the current unit, for instance,
1175 -- when you are compiling System, then you had better have finished
1176 -- analyzing the part of System that is depended on before you try to
1177 -- load the RTS Unit. This means having the code in System ordered in
1178 -- an appropriate manner.
1179
1180 Set_Analyzed (Cunit (Current_Sem_Unit), True);
1181
1182 if not Analyzed (Cunit (U.Unum)) then
1183
1184 -- If the unit is already loaded through a limited_with_clause,
1185 -- the relevant entities must already be available. We do not
1186 -- want to load and analyze the unit because this would create
1187 -- a real semantic dependence when the purpose of the limited_with
1188 -- is precisely to avoid such.
1189
1190 if From_Limited_With (Cunit_Entity (U.Unum)) then
1191 null;
1192
1193 else
1194 Save_Private_Visibility;
1195 declare
1196 Saved_Instance_Context : constant Instance_Context.Context :=
1197 Instance_Context.Save_And_Reset;
1198 begin
1199 Semantics (Cunit (U.Unum));
1200 Instance_Context.Restore (Saved_Instance_Context);
1201 end;
1202 Restore_Private_Visibility;
1203
1204 if Fatal_Error (U.Unum) = Error_Detected then
1205 Load_Fail ("had semantic errors", U_Id, Id);
1206 end if;
1207 end if;
1208 end if;
1209
1210 -- Undo the pretence
1211
1212 Set_Analyzed (Cunit (Current_Sem_Unit), Was_Analyzed);
1213 end;
1214
1215 Lib_Unit := Unit (Cunit (U.Unum));
1216 U.Entity := Defining_Entity (Lib_Unit);
1217
1218 if Use_Setting then
1219 Set_Is_Potentially_Use_Visible (U.Entity, True);
1220 end if;
1221
1222 Restore_SPARK_Context;
1223
1224 exception
1225 -- The Load_Fail procedure that is called when the result of Load_Unit
1226 -- is not satisfactory raises an exception. As the compiler is able to
1227 -- recover in some cases (i.e. when RE_Not_Available is raised), we need
1228 -- to restore the SPARK/Ghost context correctly.
1229
1230 when others =>
1231 Restore_SPARK_Context;
1232 raise;
1233 end Load_RTU;
1234
1235 --------------------
1236 -- Make_Unit_Name --
1237 --------------------
1238
1239 function Make_Unit_Name
1240 (U : RT_Unit_Table_Record;
1241 N : Node_Id) return Node_Id is
1242
1243 Nam : Node_Id;
1244 Scop : Entity_Id;
1245
1246 begin
1247 Nam := New_Occurrence_Of (U.Entity, Standard_Location);
1248 Scop := Scope (U.Entity);
1249
1250 if Nkind (N) = N_Defining_Program_Unit_Name then
1251 while Scop /= Standard_Standard loop
1252 Nam :=
1253 Make_Expanded_Name (Standard_Location,
1254 Chars => Chars (U.Entity),
1255 Prefix => New_Occurrence_Of (Scop, Standard_Location),
1256 Selector_Name => Nam);
1257 Set_Entity (Nam, U.Entity);
1258
1259 Scop := Scope (Scop);
1260 end loop;
1261 end if;
1262
1263 return Nam;
1264 end Make_Unit_Name;
1265
1266 --------------------
1267 -- Maybe_Add_With --
1268 --------------------
1269
1270 procedure Maybe_Add_With (U : in out RT_Unit_Table_Record) is
1271 begin
1272 -- We do not need to generate a with_clause for a call issued from
1273 -- RTE_Component_Available. However, for CodePeer, we need these
1274 -- additional with's, because for a sequence like "if RTE_Available (X)
1275 -- then ... RTE (X)" the RTE call fails to create some necessary with's.
1276
1277 if RTE_Available_Call and not Generate_SCIL then
1278 return;
1279 end if;
1280
1281 -- Avoid creating directly self-referential with clauses
1282
1283 if Current_Sem_Unit = U.Unum then
1284 return;
1285 end if;
1286
1287 -- Add the with_clause, if we have not already added an implicit with
1288 -- for this unit to the current compilation unit.
1289
1290 declare
1291 LibUnit : constant Node_Id := Unit (Cunit (U.Unum));
1292 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
1293 Clause : Node_Id;
1294 Withn : Node_Id;
1295
1296 begin
1297 Clause := U.First_Implicit_With;
1298 while Present (Clause) loop
1299 if Parent (Clause) = Cunit (Current_Sem_Unit) then
1300 return;
1301 end if;
1302
1303 Clause := Next_Implicit_With (Clause);
1304 end loop;
1305
1306 -- We want to make sure that the "with" we create below isn't
1307 -- marked as ignored ghost code because this list may be walked
1308 -- later, after ignored ghost code is converted to a null
1309 -- statement.
1310
1311 Ghost_Mode := None;
1312 Withn :=
1313 Make_With_Clause (Standard_Location,
1314 Name =>
1315 Make_Unit_Name
1316 (U, Defining_Unit_Name (Specification (LibUnit))));
1317 Ghost_Mode := Saved_GM;
1318
1319 Set_Corresponding_Spec (Withn, U.Entity);
1320 Set_First_Name (Withn);
1321 Set_Is_Implicit_With (Withn);
1322 Set_Withed_Lib_Unit (Withn, Cunit (U.Unum));
1323 Set_Next_Implicit_With (Withn, U.First_Implicit_With);
1324
1325 U.First_Implicit_With := Withn;
1326
1327 Mark_Rewrite_Insertion (Withn);
1328 Append (Withn, Context_Items (Cunit (Current_Sem_Unit)));
1329 Check_Restriction_No_Dependence (Name (Withn), Current_Error_Node);
1330 end;
1331 end Maybe_Add_With;
1332
1333 ------------------------
1334 -- Output_Entity_Name --
1335 ------------------------
1336
1337 procedure Output_Entity_Name (Id : RE_Id; Msg : String) is
1338 M : String (1 .. 2048);
1339 P : Natural := 0;
1340 -- M (1 .. P) is current message to be output
1341
1342 RE_Image : constant String := RE_Id'Image (Id);
1343 S : Natural;
1344 -- RE_Image (S .. RE_Image'Last) is the name of the entity without the
1345 -- "RE_" or "RO_XX_" prefix.
1346
1347 begin
1348 if Id = RE_Null then
1349 return;
1350 end if;
1351
1352 M (1 .. 9) := "\entity """;
1353 P := 9;
1354
1355 -- Add unit name to message, excluding %s or %b at end
1356
1357 Get_Name_String (Get_Unit_Name (RE_Unit_Table (Id)));
1358 Name_Len := Name_Len - 2;
1359 Set_Casing (Mixed_Case);
1360 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
1361 P := P + Name_Len;
1362
1363 -- Add a qualifying period
1364
1365 M (P + 1) := '.';
1366 P := P + 1;
1367
1368 -- Strip "RE"
1369
1370 if RE_Image (2) = 'E' then
1371 S := 4;
1372
1373 -- Strip "RO_XX"
1374
1375 else
1376 S := 7;
1377 end if;
1378
1379 -- Add entity name and closing quote to message
1380
1381 Name_Len := RE_Image'Length - S + 1;
1382 Name_Buffer (1 .. Name_Len) := RE_Image (S .. RE_Image'Last);
1383 Set_Casing (Mixed_Case);
1384 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
1385 P := P + Name_Len;
1386 M (P + 1) := '"';
1387 P := P + 1;
1388
1389 -- Add message
1390
1391 M (P + 1) := ' ';
1392 P := P + 1;
1393 M (P + 1 .. P + Msg'Length) := Msg;
1394 P := P + Msg'Length;
1395
1396 -- Output message at current error node location
1397
1398 RTE_Error_Msg (M (1 .. P));
1399 end Output_Entity_Name;
1400
1401 --------------
1402 -- RE_Chars --
1403 --------------
1404
1405 function RE_Chars (E : RE_Id) return Name_Id is
1406 RE_Name_Chars : constant String := RE_Id'Image (E);
1407
1408 begin
1409 -- Copy name skipping initial RE_ or RO_XX characters
1410
1411 if RE_Name_Chars (1 .. 2) = "RE" then
1412 for J in 4 .. RE_Name_Chars'Last loop
1413 Name_Buffer (J - 3) := Fold_Lower (RE_Name_Chars (J));
1414 end loop;
1415
1416 Name_Len := RE_Name_Chars'Length - 3;
1417
1418 else
1419 for J in 7 .. RE_Name_Chars'Last loop
1420 Name_Buffer (J - 6) := Fold_Lower (RE_Name_Chars (J));
1421 end loop;
1422
1423 Name_Len := RE_Name_Chars'Length - 6;
1424 end if;
1425
1426 return Name_Find;
1427 end RE_Chars;
1428
1429 ---------
1430 -- RTE --
1431 ---------
1432
1433 function RTE (E : RE_Id) return Entity_Id is
1434 procedure Check_RPC;
1435 -- Reject programs that make use of distribution features not supported
1436 -- on the current target. Also check that the PCS is compatible with the
1437 -- code generator version. On such targets (Vxworks, others?) we provide
1438 -- a minimal body for System.Rpc that only supplies an implementation of
1439 -- Partition_Id.
1440
1441 function Find_Local_Entity (E : RE_Id) return Entity_Id;
1442 -- This function is used when entity E is in this compilation's main
1443 -- unit. It gets the value from the already compiled declaration.
1444
1445 ---------------
1446 -- Check_RPC --
1447 ---------------
1448
1449 procedure Check_RPC is
1450 begin
1451 -- Bypass this check if debug flag -gnatdR set
1452
1453 if Debug_Flag_RR then
1454 return;
1455 end if;
1456
1457 -- Otherwise we need the check if we are going after one of the
1458 -- critical entities in System.RPC / System.Partition_Interface.
1459
1460 if E = RE_Do_Rpc
1461 or else
1462 E = RE_Do_Apc
1463 or else
1464 E = RE_Params_Stream_Type
1465 or else
1466 E = RE_Request_Access
1467 then
1468 -- If generating RCI stubs, check that we have a real PCS
1469
1470 if (Distribution_Stub_Mode = Generate_Receiver_Stub_Body
1471 or else
1472 Distribution_Stub_Mode = Generate_Caller_Stub_Body)
1473 and then Get_PCS_Name = Name_No_DSA
1474 then
1475 Set_Standard_Error;
1476 Write_Str ("distribution feature not supported");
1477 Write_Eol;
1478 raise Unrecoverable_Error;
1479
1480 -- In all cases, check Exp_Dist and System.Partition_Interface
1481 -- consistency.
1482
1483 elsif Get_PCS_Version /=
1484 Exp_Dist.PCS_Version_Number (Get_PCS_Name)
1485 then
1486 Set_Standard_Error;
1487 Write_Str ("PCS version mismatch: expander ");
1488 Write_Int (Exp_Dist.PCS_Version_Number (Get_PCS_Name));
1489 Write_Str (", PCS (");
1490 Write_Name (Get_PCS_Name);
1491 Write_Str (") ");
1492 Write_Int (Get_PCS_Version);
1493 Write_Eol;
1494 raise Unrecoverable_Error;
1495 end if;
1496 end if;
1497 end Check_RPC;
1498
1499 -----------------------
1500 -- Find_Local_Entity --
1501 -----------------------
1502
1503 function Find_Local_Entity (E : RE_Id) return Entity_Id is
1504 RE_Str : constant String := RE_Id'Image (E);
1505 Nam : Name_Id;
1506 Ent : Entity_Id;
1507
1508 Save_Nam : constant String := Name_Buffer (1 .. Name_Len);
1509 -- Save name buffer and length over call
1510
1511 begin
1512 Name_Len := Natural'Max (0, RE_Str'Length - 3);
1513 Name_Buffer (1 .. Name_Len) :=
1514 RE_Str (RE_Str'First + 3 .. RE_Str'Last);
1515
1516 Nam := Name_Find;
1517 Ent := Entity_Id (Get_Name_Table_Int (Nam));
1518
1519 Name_Len := Save_Nam'Length;
1520 Name_Buffer (1 .. Name_Len) := Save_Nam;
1521
1522 return Ent;
1523 end Find_Local_Entity;
1524
1525 -- Local variables
1526
1527 U_Id : constant RTU_Id := RE_Unit_Table (E);
1528 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
1529
1530 Ename : Name_Id;
1531 Lib_Unit : Node_Id;
1532 Pkg_Ent : Entity_Id;
1533
1534 Save_Front_End_Inlining : constant Boolean := Front_End_Inlining;
1535 -- This flag is used to disable front-end inlining when RTE is invoked.
1536 -- This prevents the analysis of other runtime bodies when a particular
1537 -- spec is loaded through Rtsfind. This is both efficient, and prevents
1538 -- spurious visibility conflicts between use-visible user entities, and
1539 -- entities in run-time packages.
1540
1541 -- Start of processing for RTE
1542
1543 begin
1544 -- Doing a rtsfind in system.ads is special, as we cannot do this
1545 -- when compiling System itself. So if we are compiling system then
1546 -- we should already have acquired and processed the declaration
1547 -- of the entity. The test is to see if this compilation's main unit
1548 -- is System. If so, return the value from the already compiled
1549 -- declaration and otherwise do a regular find.
1550
1551 -- Not pleasant, but these kinds of annoying recursion scenarios when
1552 -- writing an Ada compiler in Ada have to be broken somewhere.
1553
1554 if Present (Main_Unit_Entity)
1555 and then Chars (Main_Unit_Entity) = Name_System
1556 and then Analyzed (Main_Unit_Entity)
1557 and then not Is_Child_Unit (Main_Unit_Entity)
1558 then
1559 return Check_CRT (E, Find_Local_Entity (E));
1560 end if;
1561
1562 Front_End_Inlining := False;
1563
1564 -- Load unit if unit not previously loaded
1565
1566 if No (RE_Table (E)) then
1567 Load_RTU (U_Id, Id => E);
1568 Lib_Unit := Unit (Cunit (U.Unum));
1569
1570 -- In the subprogram case, we are all done, the entity we want
1571 -- is the entity for the subprogram itself. Note that we do not
1572 -- bother to check that it is the entity that was requested.
1573 -- the only way that could fail to be the case is if runtime is
1574 -- hopelessly misconfigured, and it isn't worth testing for this.
1575
1576 if Nkind (Lib_Unit) = N_Subprogram_Declaration then
1577 RE_Table (E) := U.Entity;
1578
1579 -- Otherwise we must have the package case. First check package
1580 -- entity itself (e.g. RTE_Name for System.Interrupts.Name)
1581
1582 else
1583 pragma Assert (Nkind (Lib_Unit) = N_Package_Declaration);
1584 Ename := RE_Chars (E);
1585
1586 -- First we search the package entity chain. If the package
1587 -- only has a limited view, scan the corresponding list of
1588 -- incomplete types.
1589
1590 if From_Limited_With (U.Entity) then
1591 Pkg_Ent := First_Entity (Limited_View (U.Entity));
1592 else
1593 Pkg_Ent := First_Entity (U.Entity);
1594 end if;
1595
1596 while Present (Pkg_Ent) loop
1597 if Ename = Chars (Pkg_Ent) then
1598 RE_Table (E) := Pkg_Ent;
1599 Check_RPC;
1600 goto Found;
1601 end if;
1602
1603 Next_Entity (Pkg_Ent);
1604 end loop;
1605
1606 -- If we did not find the entity in the package entity chain,
1607 -- then check if the package entity itself matches. Note that
1608 -- we do this check after searching the entity chain, since
1609 -- the rule is that in case of ambiguity, we prefer the entity
1610 -- defined within the package, rather than the package itself.
1611
1612 if Ename = Chars (U.Entity) then
1613 RE_Table (E) := U.Entity;
1614 end if;
1615
1616 -- If we didn't find the entity we want, something is wrong.
1617 -- We just leave RE_Table (E) set to Empty and the appropriate
1618 -- action will be taken by Check_CRT when we exit.
1619
1620 end if;
1621 end if;
1622
1623 <<Found>>
1624
1625 -- Record whether the secondary stack is in use in order to generate
1626 -- the proper binder code. No action is taken when the secondary stack
1627 -- is pulled within an ignored Ghost context because all this code will
1628 -- disappear.
1629
1630 if U_Id = System_Secondary_Stack and then Ghost_Mode /= Ignore then
1631 Sec_Stack_Used := True;
1632 end if;
1633
1634 Maybe_Add_With (U);
1635 Front_End_Inlining := Save_Front_End_Inlining;
1636
1637 return Check_CRT (E, RE_Table (E));
1638 end RTE;
1639
1640 -------------------
1641 -- RTE_Available --
1642 -------------------
1643
1644 function RTE_Available (E : RE_Id) return Boolean is
1645 Dummy : Entity_Id;
1646 pragma Warnings (Off, Dummy);
1647
1648 Result : Boolean;
1649
1650 Save_RTE_Available_Call : constant Boolean := RTE_Available_Call;
1651 Save_RTE_Is_Available : constant Boolean := RTE_Is_Available;
1652 -- These are saved recursively because the call to load a unit
1653 -- caused by an upper level call may perform a recursive call
1654 -- to this routine during analysis of the corresponding unit.
1655
1656 begin
1657 RTE_Available_Call := True;
1658 RTE_Is_Available := True;
1659 Dummy := RTE (E);
1660 Result := RTE_Is_Available;
1661 RTE_Available_Call := Save_RTE_Available_Call;
1662 RTE_Is_Available := Save_RTE_Is_Available;
1663 return Result;
1664
1665 exception
1666 when RE_Not_Available =>
1667 RTE_Available_Call := Save_RTE_Available_Call;
1668 RTE_Is_Available := Save_RTE_Is_Available;
1669 return False;
1670 end RTE_Available;
1671
1672 --------------------------
1673 -- RTE_Record_Component --
1674 --------------------------
1675
1676 function RTE_Record_Component (E : RE_Id) return Entity_Id is
1677 U_Id : constant RTU_Id := RE_Unit_Table (E);
1678 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
1679 E1 : Entity_Id;
1680 Ename : Name_Id;
1681 Found_E : Entity_Id;
1682 Lib_Unit : Node_Id;
1683 Pkg_Ent : Entity_Id;
1684
1685 -- The following flag is used to disable front-end inlining when
1686 -- RTE_Record_Component is invoked. This prevents the analysis of other
1687 -- runtime bodies when a particular spec is loaded through Rtsfind. This
1688 -- is both efficient, and it prevents spurious visibility conflicts
1689 -- between use-visible user entities, and entities in run-time packages.
1690
1691 Save_Front_End_Inlining : Boolean;
1692
1693 begin
1694 -- Note: Contrary to subprogram RTE, there is no need to do any special
1695 -- management with package system.ads because it has no record type
1696 -- declarations.
1697
1698 Save_Front_End_Inlining := Front_End_Inlining;
1699 Front_End_Inlining := False;
1700
1701 -- Load unit if unit not previously loaded
1702
1703 if No (U.Entity) then
1704 Load_RTU (U_Id, Id => E);
1705 end if;
1706
1707 Lib_Unit := Unit (Cunit (U.Unum));
1708
1709 pragma Assert (Nkind (Lib_Unit) = N_Package_Declaration);
1710 Ename := RE_Chars (E);
1711
1712 -- Search the entity in the components of record type declarations
1713 -- found in the package entity chain.
1714
1715 Found_E := Empty;
1716 Pkg_Ent := First_Entity (U.Entity);
1717 Search : while Present (Pkg_Ent) loop
1718 if Is_Record_Type (Pkg_Ent) then
1719 E1 := First_Entity (Pkg_Ent);
1720 while Present (E1) loop
1721 if Ename = Chars (E1) then
1722 pragma Assert (No (Found_E));
1723 Found_E := E1;
1724 end if;
1725
1726 Next_Entity (E1);
1727 end loop;
1728 end if;
1729
1730 Next_Entity (Pkg_Ent);
1731 end loop Search;
1732
1733 -- If we didn't find the entity we want, something is wrong. The
1734 -- appropriate action will be taken by Check_CRT when we exit.
1735
1736 Maybe_Add_With (U);
1737
1738 Front_End_Inlining := Save_Front_End_Inlining;
1739 return Check_CRT (E, Found_E);
1740 end RTE_Record_Component;
1741
1742 ------------------------------------
1743 -- RTE_Record_Component_Available --
1744 ------------------------------------
1745
1746 function RTE_Record_Component_Available (E : RE_Id) return Boolean is
1747 Dummy : Entity_Id;
1748 pragma Warnings (Off, Dummy);
1749
1750 Result : Boolean;
1751
1752 Save_RTE_Available_Call : constant Boolean := RTE_Available_Call;
1753 Save_RTE_Is_Available : constant Boolean := RTE_Is_Available;
1754 -- These are saved recursively because the call to load a unit
1755 -- caused by an upper level call may perform a recursive call
1756 -- to this routine during analysis of the corresponding unit.
1757
1758 begin
1759 RTE_Available_Call := True;
1760 RTE_Is_Available := True;
1761 Dummy := RTE_Record_Component (E);
1762 Result := RTE_Is_Available;
1763 RTE_Available_Call := Save_RTE_Available_Call;
1764 RTE_Is_Available := Save_RTE_Is_Available;
1765 return Result;
1766
1767 exception
1768 when RE_Not_Available =>
1769 RTE_Available_Call := Save_RTE_Available_Call;
1770 RTE_Is_Available := Save_RTE_Is_Available;
1771 return False;
1772 end RTE_Record_Component_Available;
1773
1774 -------------------
1775 -- RTE_Error_Msg --
1776 -------------------
1777
1778 procedure RTE_Error_Msg (Msg : String) is
1779 begin
1780 if RTE_Available_Call then
1781 RTE_Is_Available := False;
1782 else
1783 Error_Msg_N (Msg, Current_Error_Node);
1784
1785 -- Bump count of violations if we are in configurable run-time
1786 -- mode and this is not a continuation message.
1787
1788 if Configurable_Run_Time_Mode and then Msg (Msg'First) /= '\' then
1789 Configurable_Run_Time_Violations :=
1790 Configurable_Run_Time_Violations + 1;
1791 end if;
1792 end if;
1793 end RTE_Error_Msg;
1794
1795 ----------------
1796 -- RTU_Entity --
1797 ----------------
1798
1799 function RTU_Entity (U : RTU_Id) return Entity_Id is
1800 begin
1801 return RT_Unit_Table (U).Entity;
1802 end RTU_Entity;
1803
1804 ----------------
1805 -- RTU_Loaded --
1806 ----------------
1807
1808 function RTU_Loaded (U : RTU_Id) return Boolean is
1809 begin
1810 return Present (RT_Unit_Table (U).Entity);
1811 end RTU_Loaded;
1812
1813 --------------------
1814 -- Set_RTU_Loaded --
1815 --------------------
1816
1817 procedure Set_RTU_Loaded (N : Node_Id) is
1818 Loc : constant Source_Ptr := Sloc (N);
1819 Unum : constant Unit_Number_Type := Get_Source_Unit (Loc);
1820 Uname : constant Unit_Name_Type := Unit_Name (Unum);
1821 E : constant Entity_Id :=
1822 Defining_Entity (Unit (Cunit (Unum)));
1823 begin
1824 pragma Assert (Is_Predefined_Unit (Unum));
1825
1826 -- Loop through entries in RTU table looking for matching entry
1827
1828 for U_Id in RTU_Id'Range loop
1829
1830 -- Here we have a match
1831
1832 if Get_Unit_Name (U_Id) = Uname then
1833 declare
1834 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
1835 -- The RT_Unit_Table entry that may need updating
1836
1837 begin
1838 -- If entry is not set, set it now, and indicate that it was
1839 -- loaded through an explicit context clause.
1840
1841 if No (U.Entity) then
1842 U := (Entity => E,
1843 Uname => Get_Unit_Name (U_Id),
1844 Unum => Unum,
1845 First_Implicit_With => Empty);
1846 end if;
1847
1848 return;
1849 end;
1850 end if;
1851 end loop;
1852 end Set_RTU_Loaded;
1853
1854 -------------------------
1855 -- SPARK_Implicit_Load --
1856 -------------------------
1857
1858 procedure SPARK_Implicit_Load (E : RE_Id) is
1859 begin
1860 pragma Assert (GNATprove_Mode);
1861
1862 -- Force loading of a predefined unit
1863
1864 Discard_Node (RTE (E));
1865 end SPARK_Implicit_Load;
1866
1867 end Rtsfind;