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