PR tree-optimization/85699
[official-gcc.git] / gcc / ada / rtsfind.adb
blob63d8a00ea0d356ed900ea65c3aae4d6071c70039
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-2018, 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 Elists; use Elists;
32 with Errout; use Errout;
33 with Exp_Dist;
34 with Fname; use Fname;
35 with Fname.UF; use Fname.UF;
36 with Ghost; use Ghost;
37 with Lib; use Lib;
38 with Lib.Load; use Lib.Load;
39 with Namet; use Namet;
40 with Nlists; use Nlists;
41 with Nmake; use Nmake;
42 with Output; use Output;
43 with Opt; use Opt;
44 with Restrict; use Restrict;
45 with Sem; use Sem;
46 with Sem_Aux; use Sem_Aux;
47 with Sem_Ch7; use Sem_Ch7;
48 with Sem_Dist; use Sem_Dist;
49 with Sem_Util; use Sem_Util;
50 with Sinfo; use Sinfo;
51 with Stand; use Stand;
52 with Snames; use Snames;
53 with Tbuild; use Tbuild;
54 with Uname; use Uname;
56 package body Rtsfind is
58 RTE_Available_Call : Boolean := False;
59 -- Set True during call to RTE from RTE_Available (or from call to
60 -- RTE_Record_Component from RTE_Record_Component_Available). Tells
61 -- the called subprogram to set RTE_Is_Available to False rather than
62 -- generating an error message.
64 RTE_Is_Available : Boolean;
65 -- Set True by RTE_Available on entry. When RTE_Available_Call is set
66 -- True, set False if RTE would otherwise generate an error message.
68 ----------------
69 -- Unit table --
70 ----------------
72 -- The unit table has one entry for each unit included in the definition
73 -- of the type RTU_Id in the spec. The table entries are initialized in
74 -- Initialize to set the Entity field to Empty, indicating that the
75 -- corresponding unit has not yet been loaded. The fields are set when
76 -- a unit is loaded to contain the defining entity for the unit, the
77 -- unit name, and the unit number.
79 -- Note that a unit can be loaded either by a call to find an entity
80 -- within the unit (e.g. RTE), or by an explicit with of the unit. In
81 -- the latter case it is critical to make a call to Set_RTU_Loaded to
82 -- ensure that the entry in this table reflects the load.
84 -- A unit retrieved through rtsfind may end up in the context of several
85 -- other units, in addition to the main unit. These additional with_clauses
86 -- are needed to generate a proper traversal order for CodePeer. To
87 -- minimize somewhat the redundancy created by numerous calls to rtsfind
88 -- from different units, we keep track of the list of implicit with_clauses
89 -- already created for the current loaded unit.
91 type RT_Unit_Table_Record is record
92 Entity : Entity_Id;
93 Uname : Unit_Name_Type;
94 First_Implicit_With : Node_Id;
95 Unum : Unit_Number_Type;
96 end record;
98 RT_Unit_Table : array (RTU_Id) of RT_Unit_Table_Record;
100 --------------------------
101 -- Runtime Entity Table --
102 --------------------------
104 -- There is one entry in the runtime entity table for each entity that is
105 -- included in the definition of the RE_Id type in the spec. The entries
106 -- are set by Initialize_Rtsfind to contain Empty, indicating that the
107 -- entity has not yet been located. Once the entity is located for the
108 -- first time, its ID is stored in this array, so that subsequent calls
109 -- for the same entity can be satisfied immediately.
111 -- NOTE: In order to avoid conflicts between record components and subprgs
112 -- that have the same name (i.e. subprogram External_Tag and
113 -- component External_Tag of package Ada.Tags) this table is not used
114 -- with Record_Components.
116 RE_Table : array (RE_Id) of Entity_Id;
118 --------------------------------
119 -- Generation of with_clauses --
120 --------------------------------
122 -- When a unit is implicitly loaded as a result of a call to RTE, it is
123 -- necessary to create one or two implicit with_clauses. We add such
124 -- with_clauses to the extended main unit if needed, and also to whatever
125 -- unit needs them, which is not necessarily the main unit. The former
126 -- ensures that the object is correctly loaded by the binder. The latter
127 -- is necessary for CodePeer.
129 -- The field First_Implicit_With in the unit table record are used to
130 -- avoid creating duplicate with_clauses.
132 ----------------------------------------------
133 -- Table of Predefined RE_Id Error Messages --
134 ----------------------------------------------
136 -- If an attempt is made to load an entity, given an RE_Id value, and the
137 -- entity is not available in the current configuration, an error message
138 -- is given (see Entity_Not_Defined below). The general form of such an
139 -- error message is for example:
141 -- entity "System.Pack_43.Bits_43" not defined
143 -- The following table defines a set of RE_Id image values for which this
144 -- error message is specialized and replaced by specific text indicating
145 -- the exact message to be output. For example, in the case above, for the
146 -- RE_Id value RE_Bits_43, we do indeed specialize the message, and the
147 -- above generic message is replaced by:
149 -- packed component size of 43 is not supported
151 type CString_Ptr is access constant String;
153 type PRE_Id_Entry is record
154 Str : CString_Ptr;
155 -- Pointer to string with the RE_Id image. The sequence ?? may appear
156 -- in which case it will match any characters in the RE_Id image value.
157 -- This is used to avoid the need for dozens of entries for RE_Bits_??.
159 Msg : CString_Ptr;
160 -- Pointer to string with the corresponding error text. The sequence
161 -- ?? may appear, in which case, it is replaced by the corresponding
162 -- sequence ?? in the Str value (if the first ? is zero, then it is
163 -- omitted from the message).
164 end record;
166 Str1 : aliased constant String := "RE_BITS_??";
167 Str2 : aliased constant String := "RE_GET_??";
168 Str3 : aliased constant String := "RE_SET_??";
169 Str4 : aliased constant String := "RE_CALL_SIMPLE";
171 MsgPack : aliased constant String :=
172 "packed component size of ?? is not supported";
173 MsgRV : aliased constant String :=
174 "task rendezvous is not supported";
176 PRE_Id_Table : constant array (Natural range <>) of PRE_Id_Entry :=
177 (1 => (Str1'Access, MsgPack'Access),
178 2 => (Str2'Access, MsgPack'Access),
179 3 => (Str3'Access, MsgPack'Access),
180 4 => (Str4'Access, MsgRV'Access));
181 -- We will add entries to this table as we find cases where it is a good
182 -- idea to do so. By no means all the RE_Id values need entries, because
183 -- the expander often gives clear messages before it makes the Rtsfind
184 -- call expecting to find the entity.
186 -----------------------
187 -- Local Subprograms --
188 -----------------------
190 function Check_CRT (E : RE_Id; Eid : Entity_Id) return Entity_Id;
191 -- Check entity Eid to ensure that configurable run-time restrictions are
192 -- met. May generate an error message (if RTE_Available_Call is false) and
193 -- raise RE_Not_Available if entity E does not exist (e.g. Eid is Empty).
194 -- Also check that entity is not overloaded.
196 procedure Entity_Not_Defined (Id : RE_Id);
197 -- Outputs error messages for an entity that is not defined in the run-time
198 -- library (the form of the error message is tailored for no run time or
199 -- configurable run time mode as required). See also table of pre-defined
200 -- messages for entities above (RE_Id_Messages).
202 function Get_Unit_Name (U_Id : RTU_Id) return Unit_Name_Type;
203 -- Retrieves the Unit Name given a unit id represented by its enumeration
204 -- value in RTU_Id.
206 procedure Load_Fail (S : String; U_Id : RTU_Id; Id : RE_Id);
207 pragma No_Return (Load_Fail);
208 -- Internal procedure called if we can't successfully locate or process a
209 -- run-time unit. The parameters give information about the error message
210 -- to be given. S is a reason for failing to compile the file and U_Id is
211 -- the unit id. RE_Id is the RE_Id originally passed to RTE. The message in
212 -- S is one of the following:
214 -- "not found"
215 -- "had parser errors"
216 -- "had semantic errors"
218 -- The "not found" case is treated specially in that it is considered
219 -- a normal situation in configurable run-time mode, and generates
220 -- a warning, but is otherwise ignored.
222 procedure Load_RTU
223 (U_Id : RTU_Id;
224 Id : RE_Id := RE_Null;
225 Use_Setting : Boolean := False);
226 -- Load the unit whose Id is given if not already loaded. The unit is
227 -- loaded and analyzed, and the entry in RT_Unit_Table is updated to
228 -- reflect the load. Use_Setting is used to indicate the initial setting
229 -- for the Is_Potentially_Use_Visible flag of the entity for the loaded
230 -- unit (if it is indeed loaded). A value of False means nothing special
231 -- need be done. A value of True indicates that this flag must be set to
232 -- True. It is needed only in the Check_Text_IO_Special_Unit procedure,
233 -- which may materialize an entity of Text_IO (or [Wide_]Wide_Text_IO) that
234 -- was previously unknown. Id is the RE_Id value of the entity which was
235 -- originally requested. Id is used only for error message detail, and if
236 -- it is RE_Null, then the attempt to output the entity name is ignored.
238 function Make_Unit_Name
239 (U : RT_Unit_Table_Record;
240 N : Node_Id) return Node_Id;
241 -- If the unit is a child unit, build fully qualified name for use in
242 -- With_Clause.
244 procedure Maybe_Add_With (U : in out RT_Unit_Table_Record);
245 -- If necessary, add an implicit with_clause from the current unit to the
246 -- one represented by U.
248 procedure Output_Entity_Name (Id : RE_Id; Msg : String);
249 -- Output continuation error message giving qualified name of entity
250 -- corresponding to Id, appending the string given by Msg.
252 function RE_Chars (E : RE_Id) return Name_Id;
253 -- Given a RE_Id value returns the Chars of the corresponding entity
255 procedure RTE_Error_Msg (Msg : String);
256 -- Generates a message by calling Error_Msg_N specifying Current_Error_Node
257 -- as the node location using the given Msg text. Special processing in the
258 -- case where RTE_Available_Call is set. In this case, no message is output
259 -- and instead RTE_Is_Available is set to False. Note that this can only be
260 -- used if you are sure that the message comes directly or indirectly from
261 -- a call to the RTE function.
263 ---------------
264 -- Check_CRT --
265 ---------------
267 function Check_CRT (E : RE_Id; Eid : Entity_Id) return Entity_Id is
268 U_Id : constant RTU_Id := RE_Unit_Table (E);
270 begin
271 if No (Eid) then
272 if RTE_Available_Call then
273 RTE_Is_Available := False;
274 else
275 Entity_Not_Defined (E);
276 end if;
278 raise RE_Not_Available;
280 -- Entity is available
282 else
283 -- If in No_Run_Time mode and entity is neither in the current unit
284 -- nor in one of the specially permitted units, raise the exception.
286 if No_Run_Time_Mode
287 and then not OK_No_Run_Time_Unit (U_Id)
289 -- If the entity being referenced is defined in the current scope,
290 -- using it is always fine as such usage can never introduce any
291 -- dependency on an additional unit. The presence of this test
292 -- helps generating meaningful error messages for CRT violations.
294 and then Scope (Eid) /= Current_Scope
295 then
296 Entity_Not_Defined (E);
297 raise RE_Not_Available;
298 end if;
300 -- Check entity is not overloaded, checking for special exceptions
302 if Has_Homonym (Eid)
303 and then E /= RE_Save_Occurrence
304 then
305 Set_Standard_Error;
306 Write_Str ("Run-time configuration error (");
307 Write_Str ("rtsfind entity """);
308 Get_Decoded_Name_String (Chars (Eid));
309 Set_Casing (Mixed_Case);
310 Write_Str (Name_Buffer (1 .. Name_Len));
311 Write_Str (""" is overloaded)");
312 Write_Eol;
313 raise Unrecoverable_Error;
314 end if;
316 -- Otherwise entity is accessible
318 return Eid;
319 end if;
320 end Check_CRT;
322 --------------------------------
323 -- Check_Text_IO_Special_Unit --
324 --------------------------------
326 procedure Check_Text_IO_Special_Unit (Nam : Node_Id) is
327 Chrs : Name_Id;
329 type Name_Map_Type is array (Text_IO_Package_Name) of RTU_Id;
331 Name_Map : constant Name_Map_Type := Name_Map_Type'(
332 Name_Decimal_IO => Ada_Text_IO_Decimal_IO,
333 Name_Enumeration_IO => Ada_Text_IO_Enumeration_IO,
334 Name_Fixed_IO => Ada_Text_IO_Fixed_IO,
335 Name_Float_IO => Ada_Text_IO_Float_IO,
336 Name_Integer_IO => Ada_Text_IO_Integer_IO,
337 Name_Modular_IO => Ada_Text_IO_Modular_IO);
339 Wide_Name_Map : constant Name_Map_Type := Name_Map_Type'(
340 Name_Decimal_IO => Ada_Wide_Text_IO_Decimal_IO,
341 Name_Enumeration_IO => Ada_Wide_Text_IO_Enumeration_IO,
342 Name_Fixed_IO => Ada_Wide_Text_IO_Fixed_IO,
343 Name_Float_IO => Ada_Wide_Text_IO_Float_IO,
344 Name_Integer_IO => Ada_Wide_Text_IO_Integer_IO,
345 Name_Modular_IO => Ada_Wide_Text_IO_Modular_IO);
347 Wide_Wide_Name_Map : constant Name_Map_Type := Name_Map_Type'(
348 Name_Decimal_IO => Ada_Wide_Wide_Text_IO_Decimal_IO,
349 Name_Enumeration_IO => Ada_Wide_Wide_Text_IO_Enumeration_IO,
350 Name_Fixed_IO => Ada_Wide_Wide_Text_IO_Fixed_IO,
351 Name_Float_IO => Ada_Wide_Wide_Text_IO_Float_IO,
352 Name_Integer_IO => Ada_Wide_Wide_Text_IO_Integer_IO,
353 Name_Modular_IO => Ada_Wide_Wide_Text_IO_Modular_IO);
355 To_Load : RTU_Id;
356 -- Unit to be loaded, from one of the above maps
358 begin
359 -- Nothing to do if name is not an identifier or a selected component
360 -- whose selector_name is an identifier.
362 if Nkind (Nam) = N_Identifier then
363 Chrs := Chars (Nam);
365 elsif Nkind (Nam) = N_Selected_Component
366 and then Nkind (Selector_Name (Nam)) = N_Identifier
367 then
368 Chrs := Chars (Selector_Name (Nam));
370 else
371 return;
372 end if;
374 -- Nothing to do if name is not one of the Text_IO subpackages
375 -- Otherwise look through loaded units, and if we find Text_IO
376 -- or [Wide_]Wide_Text_IO already loaded, then load the proper child.
378 if Chrs in Text_IO_Package_Name then
379 for U in Main_Unit .. Last_Unit loop
380 Get_Name_String (Unit_File_Name (U));
382 if Name_Len = 12 then
384 -- Here is where we do the loads if we find one of the units
385 -- Ada.Text_IO or Ada.[Wide_]Wide_Text_IO. An interesting
386 -- detail is that these units may already be used (i.e. their
387 -- In_Use flags may be set). Normally when the In_Use flag is
388 -- set, the Is_Potentially_Use_Visible flag of all entities in
389 -- the package is set, but the new entity we are mysteriously
390 -- adding was not there to have its flag set at the time. So
391 -- that's why we pass the extra parameter to RTU_Find, to make
392 -- sure the flag does get set now. Given that those generic
393 -- packages are in fact child units, we must indicate that
394 -- they are visible.
396 if Name_Buffer (1 .. 12) = "a-textio.ads" then
397 To_Load := Name_Map (Chrs);
399 elsif Name_Buffer (1 .. 12) = "a-witeio.ads" then
400 To_Load := Wide_Name_Map (Chrs);
402 elsif Name_Buffer (1 .. 12) = "a-ztexio.ads" then
403 To_Load := Wide_Wide_Name_Map (Chrs);
405 else
406 goto Continue;
407 end if;
409 Load_RTU (To_Load, Use_Setting => In_Use (Cunit_Entity (U)));
410 Set_Is_Visible_Lib_Unit (RT_Unit_Table (To_Load).Entity);
412 -- Prevent creation of an implicit 'with' from (for example)
413 -- Ada.Wide_Text_IO.Integer_IO to Ada.Text_IO.Integer_IO,
414 -- because these could create cycles. First check whether the
415 -- simple names match ("integer_io" = "integer_io"), and then
416 -- check whether the parent is indeed one of the
417 -- [[Wide_]Wide_]Text_IO packages.
419 if Chrs = Chars (Cunit_Entity (Current_Sem_Unit)) then
420 declare
421 Parent_Name : constant Unit_Name_Type :=
422 Get_Parent_Spec_Name
423 (Unit_Name (Current_Sem_Unit));
425 begin
426 if Parent_Name /= No_Unit_Name then
427 Get_Name_String (Parent_Name);
429 declare
430 P : String renames Name_Buffer (1 .. Name_Len);
431 begin
432 if P = "ada.text_io%s" or else
433 P = "ada.wide_text_io%s" or else
434 P = "ada.wide_wide_text_io%s"
435 then
436 goto Continue;
437 end if;
438 end;
439 end if;
440 end;
441 end if;
443 -- Add an implicit with clause from the current unit to the
444 -- [[Wide_]Wide_]Text_IO child (if necessary).
446 Maybe_Add_With (RT_Unit_Table (To_Load));
447 end if;
449 <<Continue>> null;
450 end loop;
451 end if;
453 exception
454 -- Generate error message if run-time unit not available
456 when RE_Not_Available =>
457 Error_Msg_N ("& not available", Nam);
458 end Check_Text_IO_Special_Unit;
460 ------------------------
461 -- Entity_Not_Defined --
462 ------------------------
464 procedure Entity_Not_Defined (Id : RE_Id) is
465 begin
466 if No_Run_Time_Mode then
468 -- If the error occurs when compiling the body of a predefined
469 -- unit for inlining purposes, the body must be illegal in this
470 -- mode, and there is no point in continuing.
472 if In_Predefined_Unit (Current_Error_Node) then
473 Error_Msg_N
474 ("construct not allowed in no run time mode!",
475 Current_Error_Node);
476 raise Unrecoverable_Error;
478 else
479 RTE_Error_Msg ("|construct not allowed in no run time mode");
480 end if;
482 elsif Configurable_Run_Time_Mode then
483 RTE_Error_Msg ("|construct not allowed in this configuration>");
484 else
485 RTE_Error_Msg ("run-time configuration error");
486 end if;
488 -- See if this entry is to be found in the PRE_Id table that provides
489 -- specialized messages for some RE_Id values.
491 for J in PRE_Id_Table'Range loop
492 declare
493 TStr : constant String := PRE_Id_Table (J).Str.all;
494 RStr : constant String := RE_Id'Image (Id);
495 TMsg : String := PRE_Id_Table (J).Msg.all;
496 LMsg : Natural := TMsg'Length;
498 begin
499 if TStr'Length = RStr'Length then
500 for J in TStr'Range loop
501 if TStr (J) /= RStr (J) and then TStr (J) /= '?' then
502 goto Continue;
503 end if;
504 end loop;
506 for J in TMsg'First .. TMsg'Last - 1 loop
507 if TMsg (J) = '?' then
508 for K in 1 .. TStr'Last loop
509 if TStr (K) = '?' then
510 if RStr (K) = '0' then
511 TMsg (J) := RStr (K + 1);
512 TMsg (J + 1 .. LMsg - 1) := TMsg (J + 2 .. LMsg);
513 LMsg := LMsg - 1;
514 else
515 TMsg (J .. J + 1) := RStr (K .. K + 1);
516 end if;
518 exit;
519 end if;
520 end loop;
521 end if;
522 end loop;
524 RTE_Error_Msg (TMsg (1 .. LMsg));
525 return;
526 end if;
527 end;
529 <<Continue>> null;
530 end loop;
532 -- We did not find an entry in the table, so output the generic entity
533 -- not found message, where the name of the entity corresponds to the
534 -- given RE_Id value.
536 Output_Entity_Name (Id, "not defined");
537 end Entity_Not_Defined;
539 -------------------
540 -- Get_Unit_Name --
541 -------------------
543 function Get_Unit_Name (U_Id : RTU_Id) return Unit_Name_Type is
544 Uname_Chars : constant String := RTU_Id'Image (U_Id);
546 begin
547 Name_Len := Uname_Chars'Length;
548 Name_Buffer (1 .. Name_Len) := Uname_Chars;
549 Set_Casing (All_Lower_Case);
551 if U_Id in Ada_Child then
552 Name_Buffer (4) := '.';
554 if U_Id in Ada_Calendar_Child then
555 Name_Buffer (13) := '.';
557 elsif U_Id in Ada_Dispatching_Child then
558 Name_Buffer (16) := '.';
560 elsif U_Id in Ada_Interrupts_Child then
561 Name_Buffer (15) := '.';
563 elsif U_Id in Ada_Numerics_Child then
564 Name_Buffer (13) := '.';
566 elsif U_Id in Ada_Real_Time_Child then
567 Name_Buffer (14) := '.';
569 elsif U_Id in Ada_Streams_Child then
570 Name_Buffer (12) := '.';
572 elsif U_Id in Ada_Strings_Child then
573 Name_Buffer (12) := '.';
575 elsif U_Id in Ada_Text_IO_Child then
576 Name_Buffer (12) := '.';
578 elsif U_Id in Ada_Wide_Text_IO_Child then
579 Name_Buffer (17) := '.';
581 elsif U_Id in Ada_Wide_Wide_Text_IO_Child then
582 Name_Buffer (22) := '.';
583 end if;
585 elsif U_Id in Interfaces_Child then
586 Name_Buffer (11) := '.';
588 elsif U_Id in System_Child then
589 Name_Buffer (7) := '.';
591 if U_Id in System_Dim_Child then
592 Name_Buffer (11) := '.';
593 end if;
595 if U_Id in System_Multiprocessors_Child then
596 Name_Buffer (23) := '.';
597 end if;
599 if U_Id in System_Storage_Pools_Child then
600 Name_Buffer (21) := '.';
601 end if;
603 if U_Id in System_Strings_Child then
604 Name_Buffer (15) := '.';
605 end if;
607 if U_Id in System_Tasking_Child then
608 Name_Buffer (15) := '.';
609 end if;
611 if U_Id in System_Tasking_Restricted_Child then
612 Name_Buffer (26) := '.';
613 end if;
615 if U_Id in System_Tasking_Protected_Objects_Child then
616 Name_Buffer (33) := '.';
617 end if;
619 if U_Id in System_Tasking_Async_Delays_Child then
620 Name_Buffer (28) := '.';
621 end if;
622 end if;
624 -- Add %s at end for spec
626 Name_Buffer (Name_Len + 1) := '%';
627 Name_Buffer (Name_Len + 2) := 's';
628 Name_Len := Name_Len + 2;
630 return Name_Find;
631 end Get_Unit_Name;
633 ----------------
634 -- Initialize --
635 ----------------
637 procedure Initialize is
638 begin
639 -- Initialize the unit table
641 for J in RTU_Id loop
642 RT_Unit_Table (J).Entity := Empty;
643 RT_Unit_Table (J).First_Implicit_With := Empty;
644 end loop;
646 for J in RE_Id loop
647 RE_Table (J) := Empty;
648 end loop;
650 RTE_Is_Available := False;
651 end Initialize;
653 ------------
654 -- Is_RTE --
655 ------------
657 function Is_RTE (Ent : Entity_Id; E : RE_Id) return Boolean is
658 E_Unit_Name : Unit_Name_Type;
659 Ent_Unit_Name : Unit_Name_Type;
661 S : Entity_Id;
662 E1 : Entity_Id;
663 E2 : Entity_Id;
665 begin
666 if No (Ent) then
667 return False;
669 -- If E has already a corresponding entity, check it directly,
670 -- going to full views if they exist to deal with the incomplete
671 -- and private type cases properly.
673 elsif Present (RE_Table (E)) then
674 E1 := Ent;
676 if Is_Type (E1) and then Present (Full_View (E1)) then
677 E1 := Full_View (E1);
678 end if;
680 E2 := RE_Table (E);
682 if Is_Type (E2) and then Present (Full_View (E2)) then
683 E2 := Full_View (E2);
684 end if;
686 return E1 = E2;
687 end if;
689 -- If the unit containing E is not loaded, we already know that the
690 -- entity we have cannot have come from this unit.
692 E_Unit_Name := Get_Unit_Name (RE_Unit_Table (E));
694 if not Is_Loaded (E_Unit_Name) then
695 return False;
696 end if;
698 -- Here the unit containing the entity is loaded. We have not made
699 -- an explicit call to RTE to get the entity in question, but we may
700 -- have obtained a reference to it indirectly from some other entity
701 -- in the same unit, or some other unit that references it.
703 -- Get the defining unit of the entity
705 S := Scope (Ent);
707 if No (S) or else Ekind (S) /= E_Package then
708 return False;
709 end if;
711 Ent_Unit_Name := Get_Unit_Name (Unit_Declaration_Node (S));
713 -- If the defining unit of the entity we are testing is not the
714 -- unit containing E, then they cannot possibly match.
716 if Ent_Unit_Name /= E_Unit_Name then
717 return False;
718 end if;
720 -- If the units match, then compare the names (remember that no
721 -- overloading is permitted in entities fetched using Rtsfind).
723 if RE_Chars (E) = Chars (Ent) then
724 RE_Table (E) := Ent;
726 -- If front-end inlining is enabled, we may be within a body that
727 -- contains inlined functions, which has not been retrieved through
728 -- rtsfind, and therefore is not yet recorded in the RT_Unit_Table.
729 -- Add the unit information now, it must be fully available.
731 declare
732 U : RT_Unit_Table_Record
733 renames RT_Unit_Table (RE_Unit_Table (E));
734 begin
735 if No (U.Entity) then
736 U.Entity := S;
737 U.Uname := E_Unit_Name;
738 U.Unum := Get_Source_Unit (S);
739 end if;
740 end;
742 return True;
743 else
744 return False;
745 end if;
746 end Is_RTE;
748 ------------
749 -- Is_RTU --
750 ------------
752 function Is_RTU (Ent : Entity_Id; U : RTU_Id) return Boolean is
753 E : constant Entity_Id := RT_Unit_Table (U).Entity;
754 begin
755 return Present (E) and then E = Ent;
756 end Is_RTU;
758 -----------------------------
759 -- Is_Text_IO_Special_Unit --
760 -----------------------------
762 function Is_Text_IO_Special_Unit (Nam : Node_Id) return Boolean is
763 Prf : Node_Id;
764 Sel : Node_Id;
766 begin
767 if Nkind (Nam) /= N_Expanded_Name then
768 return False;
769 end if;
771 Prf := Prefix (Nam);
772 Sel := Selector_Name (Nam);
774 if Nkind (Sel) /= N_Expanded_Name
775 or else Nkind (Prf) /= N_Identifier
776 or else Chars (Prf) /= Name_Ada
777 then
778 return False;
779 end if;
781 Prf := Prefix (Sel);
782 Sel := Selector_Name (Sel);
784 return
785 Nkind (Prf) = N_Identifier
786 and then
787 Nam_In (Chars (Prf), Name_Text_IO,
788 Name_Wide_Text_IO,
789 Name_Wide_Wide_Text_IO)
790 and then Nkind (Sel) = N_Identifier
791 and then Chars (Sel) in Text_IO_Package_Name;
792 end Is_Text_IO_Special_Unit;
794 ---------------
795 -- Load_Fail --
796 ---------------
798 procedure Load_Fail (S : String; U_Id : RTU_Id; Id : RE_Id) is
799 M : String (1 .. 100);
800 P : Natural := 0;
802 begin
803 -- Output header message
805 if Configurable_Run_Time_Mode then
806 RTE_Error_Msg ("construct not allowed in configurable run-time mode");
807 else
808 RTE_Error_Msg ("run-time library configuration error");
809 end if;
811 -- Output file name and reason string
813 M (1 .. 6) := "\file ";
814 P := 6;
816 Get_Name_String
817 (Get_File_Name (RT_Unit_Table (U_Id).Uname, Subunit => False));
818 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
819 P := P + Name_Len;
821 M (P + 1) := ' ';
822 P := P + 1;
824 M (P + 1 .. P + S'Length) := S;
825 P := P + S'Length;
827 RTE_Error_Msg (M (1 .. P));
829 -- Output entity name
831 Output_Entity_Name (Id, "not available");
833 -- In configurable run time mode, we raise RE_Not_Available, and the
834 -- caller is expected to deal gracefully with this. In the case of a
835 -- call to RTE_Available, this exception will be caught in Rtsfind,
836 -- and result in a returned value of False for the call.
838 if Configurable_Run_Time_Mode then
839 raise RE_Not_Available;
841 -- Here we have a load failure in normal full run time mode. See if we
842 -- are in the context of an RTE_Available call. If so, we just raise
843 -- RE_Not_Available. This can happen if a unit is unavailable, which
844 -- happens for example in the VM case, where the run-time is not
845 -- complete, but we do not regard it as a configurable run-time.
846 -- If the caller has done an explicit call to RTE_Available, then
847 -- clearly the caller is prepared to deal with a result of False.
849 elsif RTE_Available_Call then
850 RTE_Is_Available := False;
851 raise RE_Not_Available;
853 -- If we are not in the context of an RTE_Available call, we are really
854 -- trying to load an entity that is not there, and that should never
855 -- happen, so in this case we signal a fatal error.
857 else
858 raise Unrecoverable_Error;
859 end if;
860 end Load_Fail;
862 --------------
863 -- Load_RTU --
864 --------------
866 -- WARNING: This routine manages Ghost and SPARK regions. Return statements
867 -- must be replaced by gotos which jump to the end of the routine in order
868 -- to restore the Ghost and SPARK modes.
870 procedure Load_RTU
871 (U_Id : RTU_Id;
872 Id : RE_Id := RE_Null;
873 Use_Setting : Boolean := False)
875 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
876 Priv_Par : constant Elist_Id := New_Elmt_List;
877 Lib_Unit : Node_Id;
879 procedure Save_Private_Visibility;
880 -- If the current unit is the body of child unit or the spec of a
881 -- private child unit, the private declarations of the parent(s) are
882 -- visible. If the unit to be loaded is another public sibling, its
883 -- compilation will affect the visibility of the common ancestors.
884 -- Indicate those that must be restored.
886 procedure Restore_Private_Visibility;
887 -- Restore the visibility of ancestors after compiling RTU
889 --------------------------------
890 -- Restore_Private_Visibility --
891 --------------------------------
893 procedure Restore_Private_Visibility is
894 E_Par : Elmt_Id;
896 begin
897 E_Par := First_Elmt (Priv_Par);
898 while Present (E_Par) loop
899 if not In_Private_Part (Node (E_Par)) then
900 Install_Private_Declarations (Node (E_Par));
901 end if;
903 Next_Elmt (E_Par);
904 end loop;
905 end Restore_Private_Visibility;
907 -----------------------------
908 -- Save_Private_Visibility --
909 -----------------------------
911 procedure Save_Private_Visibility is
912 Par : Entity_Id;
914 begin
915 Par := Scope (Current_Scope);
916 while Present (Par)
917 and then Par /= Standard_Standard
918 loop
919 if Ekind (Par) = E_Package
920 and then Is_Compilation_Unit (Par)
921 and then In_Private_Part (Par)
922 then
923 Append_Elmt (Par, Priv_Par);
924 end if;
926 Par := Scope (Par);
927 end loop;
928 end Save_Private_Visibility;
930 -- Local variables
932 Save_GM : constant Ghost_Mode_Type := Ghost_Mode;
933 Save_SM : constant SPARK_Mode_Type := SPARK_Mode;
934 Save_SMP : constant Node_Id := SPARK_Mode_Pragma;
935 -- Save Ghost and SPARK mode-related data to restore on exit
937 -- Start of processing for Load_RTU
939 begin
940 -- Nothing to do if unit is already loaded
942 if Present (U.Entity) then
943 return;
944 end if;
946 -- Provide a clean environment for the unit
948 Install_Ghost_Mode (None);
949 Install_SPARK_Mode (None, Empty);
951 -- Note if secondary stack is used
953 if U_Id = System_Secondary_Stack then
954 Opt.Sec_Stack_Used := True;
955 end if;
957 -- Otherwise we need to load the unit, First build unit name
958 -- from the enumeration literal name in type RTU_Id.
960 U.Uname := Get_Unit_Name (U_Id);
961 U.First_Implicit_With := Empty;
963 -- Now do the load call, note that setting Error_Node to Empty is
964 -- a signal to Load_Unit that we will regard a failure to find the
965 -- file as a fatal error, and that it should not output any kind
966 -- of diagnostics, since we will take care of it here.
968 -- We save style checking switches and turn off style checking for
969 -- loading the unit, since we don't want any style checking.
971 declare
972 Save_Style_Check : constant Boolean := Style_Check;
973 begin
974 Style_Check := False;
975 U.Unum :=
976 Load_Unit
977 (Load_Name => U.Uname,
978 Required => False,
979 Subunit => False,
980 Error_Node => Empty);
981 Style_Check := Save_Style_Check;
982 end;
984 -- Check for bad unit load
986 if U.Unum = No_Unit then
987 Load_Fail ("not found", U_Id, Id);
988 elsif Fatal_Error (U.Unum) = Error_Detected then
989 Load_Fail ("had parser errors", U_Id, Id);
990 end if;
992 -- Make sure that the unit is analyzed
994 declare
995 Was_Analyzed : constant Boolean :=
996 Analyzed (Cunit (Current_Sem_Unit));
998 begin
999 -- Pretend that the current unit is analyzed, in case it is System
1000 -- or some such. This allows us to put some declarations, such as
1001 -- exceptions and packed arrays of Boolean, into System even though
1002 -- expanding them requires System...
1004 -- This is a bit odd but works fine. If the RTS unit does not depend
1005 -- in any way on the current unit, then it never gets back into the
1006 -- current unit's tree, and the change we make to the current unit
1007 -- tree is never noticed by anyone (it is undone in a moment). That
1008 -- is the normal situation.
1010 -- If the RTS Unit *does* depend on the current unit, for instance,
1011 -- when you are compiling System, then you had better have finished
1012 -- analyzing the part of System that is depended on before you try to
1013 -- load the RTS Unit. This means having the code in System ordered in
1014 -- an appropriate manner.
1016 Set_Analyzed (Cunit (Current_Sem_Unit), True);
1018 if not Analyzed (Cunit (U.Unum)) then
1020 -- If the unit is already loaded through a limited_with_clause,
1021 -- the relevant entities must already be available. We do not
1022 -- want to load and analyze the unit because this would create
1023 -- a real semantic dependence when the purpose of the limited_with
1024 -- is precisely to avoid such.
1026 if From_Limited_With (Cunit_Entity (U.Unum)) then
1027 null;
1029 else
1030 Save_Private_Visibility;
1031 Semantics (Cunit (U.Unum));
1032 Restore_Private_Visibility;
1034 if Fatal_Error (U.Unum) = Error_Detected then
1035 Load_Fail ("had semantic errors", U_Id, Id);
1036 end if;
1037 end if;
1038 end if;
1040 -- Undo the pretence
1042 Set_Analyzed (Cunit (Current_Sem_Unit), Was_Analyzed);
1043 end;
1045 Lib_Unit := Unit (Cunit (U.Unum));
1046 U.Entity := Defining_Entity (Lib_Unit);
1048 if Use_Setting then
1049 Set_Is_Potentially_Use_Visible (U.Entity, True);
1050 end if;
1052 Restore_Ghost_Mode (Save_GM);
1053 Restore_SPARK_Mode (Save_SM, Save_SMP);
1054 end Load_RTU;
1056 --------------------
1057 -- Make_Unit_Name --
1058 --------------------
1060 function Make_Unit_Name
1061 (U : RT_Unit_Table_Record;
1062 N : Node_Id) return Node_Id is
1064 Nam : Node_Id;
1065 Scop : Entity_Id;
1067 begin
1068 Nam := New_Occurrence_Of (U.Entity, Standard_Location);
1069 Scop := Scope (U.Entity);
1071 if Nkind (N) = N_Defining_Program_Unit_Name then
1072 while Scop /= Standard_Standard loop
1073 Nam :=
1074 Make_Expanded_Name (Standard_Location,
1075 Chars => Chars (U.Entity),
1076 Prefix => New_Occurrence_Of (Scop, Standard_Location),
1077 Selector_Name => Nam);
1078 Set_Entity (Nam, U.Entity);
1080 Scop := Scope (Scop);
1081 end loop;
1082 end if;
1084 return Nam;
1085 end Make_Unit_Name;
1087 --------------------
1088 -- Maybe_Add_With --
1089 --------------------
1091 procedure Maybe_Add_With (U : in out RT_Unit_Table_Record) is
1092 begin
1093 -- We do not need to generate a with_clause for a call issued from
1094 -- RTE_Component_Available. However, for CodePeer, we need these
1095 -- additional with's, because for a sequence like "if RTE_Available (X)
1096 -- then ... RTE (X)" the RTE call fails to create some necessary with's.
1098 if RTE_Available_Call and not Generate_SCIL then
1099 return;
1100 end if;
1102 -- Avoid creating directly self-referential with clauses
1104 if Current_Sem_Unit = U.Unum then
1105 return;
1106 end if;
1108 -- Add the with_clause, if we have not already added an implicit with
1109 -- for this unit to the current compilation unit.
1111 declare
1112 LibUnit : constant Node_Id := Unit (Cunit (U.Unum));
1113 Clause : Node_Id;
1114 Withn : Node_Id;
1116 begin
1117 Clause := U.First_Implicit_With;
1118 while Present (Clause) loop
1119 if Parent (Clause) = Cunit (Current_Sem_Unit) then
1120 return;
1121 end if;
1123 Clause := Next_Implicit_With (Clause);
1124 end loop;
1126 Withn :=
1127 Make_With_Clause (Standard_Location,
1128 Name =>
1129 Make_Unit_Name
1130 (U, Defining_Unit_Name (Specification (LibUnit))));
1132 Set_Corresponding_Spec (Withn, U.Entity);
1133 Set_First_Name (Withn);
1134 Set_Implicit_With (Withn);
1135 Set_Library_Unit (Withn, Cunit (U.Unum));
1136 Set_Next_Implicit_With (Withn, U.First_Implicit_With);
1138 U.First_Implicit_With := Withn;
1140 Mark_Rewrite_Insertion (Withn);
1141 Append (Withn, Context_Items (Cunit (Current_Sem_Unit)));
1142 Check_Restriction_No_Dependence (Name (Withn), Current_Error_Node);
1143 end;
1144 end Maybe_Add_With;
1146 ------------------------
1147 -- Output_Entity_Name --
1148 ------------------------
1150 procedure Output_Entity_Name (Id : RE_Id; Msg : String) is
1151 M : String (1 .. 2048);
1152 P : Natural := 0;
1153 -- M (1 .. P) is current message to be output
1155 RE_Image : constant String := RE_Id'Image (Id);
1156 S : Natural;
1157 -- RE_Image (S .. RE_Image'Last) is the name of the entity without the
1158 -- "RE_" or "RO_XX_" prefix.
1160 begin
1161 if Id = RE_Null then
1162 return;
1163 end if;
1165 M (1 .. 9) := "\entity """;
1166 P := 9;
1168 -- Add unit name to message, excluding %s or %b at end
1170 Get_Name_String (Get_Unit_Name (RE_Unit_Table (Id)));
1171 Name_Len := Name_Len - 2;
1172 Set_Casing (Mixed_Case);
1173 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
1174 P := P + Name_Len;
1176 -- Add a qualifying period
1178 M (P + 1) := '.';
1179 P := P + 1;
1181 -- Strip "RE"
1183 if RE_Image (2) = 'E' then
1184 S := 4;
1186 -- Strip "RO_XX"
1188 else
1189 S := 7;
1190 end if;
1192 -- Add entity name and closing quote to message
1194 Name_Len := RE_Image'Length - S + 1;
1195 Name_Buffer (1 .. Name_Len) := RE_Image (S .. RE_Image'Last);
1196 Set_Casing (Mixed_Case);
1197 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
1198 P := P + Name_Len;
1199 M (P + 1) := '"';
1200 P := P + 1;
1202 -- Add message
1204 M (P + 1) := ' ';
1205 P := P + 1;
1206 M (P + 1 .. P + Msg'Length) := Msg;
1207 P := P + Msg'Length;
1209 -- Output message at current error node location
1211 RTE_Error_Msg (M (1 .. P));
1212 end Output_Entity_Name;
1214 --------------
1215 -- RE_Chars --
1216 --------------
1218 function RE_Chars (E : RE_Id) return Name_Id is
1219 RE_Name_Chars : constant String := RE_Id'Image (E);
1221 begin
1222 -- Copy name skipping initial RE_ or RO_XX characters
1224 if RE_Name_Chars (1 .. 2) = "RE" then
1225 for J in 4 .. RE_Name_Chars'Last loop
1226 Name_Buffer (J - 3) := Fold_Lower (RE_Name_Chars (J));
1227 end loop;
1229 Name_Len := RE_Name_Chars'Length - 3;
1231 else
1232 for J in 7 .. RE_Name_Chars'Last loop
1233 Name_Buffer (J - 6) := Fold_Lower (RE_Name_Chars (J));
1234 end loop;
1236 Name_Len := RE_Name_Chars'Length - 6;
1237 end if;
1239 return Name_Find;
1240 end RE_Chars;
1242 ---------
1243 -- RTE --
1244 ---------
1246 function RTE (E : RE_Id) return Entity_Id is
1247 U_Id : constant RTU_Id := RE_Unit_Table (E);
1248 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
1250 Lib_Unit : Node_Id;
1251 Pkg_Ent : Entity_Id;
1252 Ename : Name_Id;
1254 -- The following flag is used to disable front-end inlining when RTE
1255 -- is invoked. This prevents the analysis of other runtime bodies when
1256 -- a particular spec is loaded through Rtsfind. This is both efficient,
1257 -- and it prevents spurious visibility conflicts between use-visible
1258 -- user entities, and entities in run-time packages.
1260 Save_Front_End_Inlining : Boolean;
1262 procedure Check_RPC;
1263 -- Reject programs that make use of distribution features not supported
1264 -- on the current target. Also check that the PCS is compatible with the
1265 -- code generator version. On such targets (Vxworks, others?) we provide
1266 -- a minimal body for System.Rpc that only supplies an implementation of
1267 -- Partition_Id.
1269 function Find_Local_Entity (E : RE_Id) return Entity_Id;
1270 -- This function is used when entity E is in this compilation's main
1271 -- unit. It gets the value from the already compiled declaration.
1273 ---------------
1274 -- Check_RPC --
1275 ---------------
1277 procedure Check_RPC is
1278 begin
1279 -- Bypass this check if debug flag -gnatdR set
1281 if Debug_Flag_RR then
1282 return;
1283 end if;
1285 -- Otherwise we need the check if we are going after one of the
1286 -- critical entities in System.RPC / System.Partition_Interface.
1288 if E = RE_Do_Rpc
1289 or else
1290 E = RE_Do_Apc
1291 or else
1292 E = RE_Params_Stream_Type
1293 or else
1294 E = RE_Request_Access
1295 then
1296 -- If generating RCI stubs, check that we have a real PCS
1298 if (Distribution_Stub_Mode = Generate_Receiver_Stub_Body
1299 or else
1300 Distribution_Stub_Mode = Generate_Caller_Stub_Body)
1301 and then Get_PCS_Name = Name_No_DSA
1302 then
1303 Set_Standard_Error;
1304 Write_Str ("distribution feature not supported");
1305 Write_Eol;
1306 raise Unrecoverable_Error;
1308 -- In all cases, check Exp_Dist and System.Partition_Interface
1309 -- consistency.
1311 elsif Get_PCS_Version /=
1312 Exp_Dist.PCS_Version_Number (Get_PCS_Name)
1313 then
1314 Set_Standard_Error;
1315 Write_Str ("PCS version mismatch: expander ");
1316 Write_Int (Exp_Dist.PCS_Version_Number (Get_PCS_Name));
1317 Write_Str (", PCS (");
1318 Write_Name (Get_PCS_Name);
1319 Write_Str (") ");
1320 Write_Int (Get_PCS_Version);
1321 Write_Eol;
1322 raise Unrecoverable_Error;
1323 end if;
1324 end if;
1325 end Check_RPC;
1327 -----------------------
1328 -- Find_Local_Entity --
1329 -----------------------
1331 function Find_Local_Entity (E : RE_Id) return Entity_Id is
1332 RE_Str : constant String := RE_Id'Image (E);
1333 Nam : Name_Id;
1334 Ent : Entity_Id;
1336 Save_Nam : constant String := Name_Buffer (1 .. Name_Len);
1337 -- Save name buffer and length over call
1339 begin
1340 Name_Len := Natural'Max (0, RE_Str'Length - 3);
1341 Name_Buffer (1 .. Name_Len) :=
1342 RE_Str (RE_Str'First + 3 .. RE_Str'Last);
1344 Nam := Name_Find;
1345 Ent := Entity_Id (Get_Name_Table_Int (Nam));
1347 Name_Len := Save_Nam'Length;
1348 Name_Buffer (1 .. Name_Len) := Save_Nam;
1350 return Ent;
1351 end Find_Local_Entity;
1353 -- Start of processing for RTE
1355 begin
1356 -- Doing a rtsfind in system.ads is special, as we cannot do this
1357 -- when compiling System itself. So if we are compiling system then
1358 -- we should already have acquired and processed the declaration
1359 -- of the entity. The test is to see if this compilation's main unit
1360 -- is System. If so, return the value from the already compiled
1361 -- declaration and otherwise do a regular find.
1363 -- Not pleasant, but these kinds of annoying recursion scenarios when
1364 -- writing an Ada compiler in Ada have to be broken somewhere.
1366 if Present (Main_Unit_Entity)
1367 and then Chars (Main_Unit_Entity) = Name_System
1368 and then Analyzed (Main_Unit_Entity)
1369 and then not Is_Child_Unit (Main_Unit_Entity)
1370 then
1371 return Check_CRT (E, Find_Local_Entity (E));
1372 end if;
1374 Save_Front_End_Inlining := Front_End_Inlining;
1375 Front_End_Inlining := False;
1377 -- Load unit if unit not previously loaded
1379 if No (RE_Table (E)) then
1380 Load_RTU (U_Id, Id => E);
1381 Lib_Unit := Unit (Cunit (U.Unum));
1383 -- In the subprogram case, we are all done, the entity we want
1384 -- is the entity for the subprogram itself. Note that we do not
1385 -- bother to check that it is the entity that was requested.
1386 -- the only way that could fail to be the case is if runtime is
1387 -- hopelessly misconfigured, and it isn't worth testing for this.
1389 if Nkind (Lib_Unit) = N_Subprogram_Declaration then
1390 RE_Table (E) := U.Entity;
1392 -- Otherwise we must have the package case. First check package
1393 -- entity itself (e.g. RTE_Name for System.Interrupts.Name)
1395 else
1396 pragma Assert (Nkind (Lib_Unit) = N_Package_Declaration);
1397 Ename := RE_Chars (E);
1399 -- First we search the package entity chain. If the package
1400 -- only has a limited view, scan the corresponding list of
1401 -- incomplete types.
1403 if From_Limited_With (U.Entity) then
1404 Pkg_Ent := First_Entity (Limited_View (U.Entity));
1405 else
1406 Pkg_Ent := First_Entity (U.Entity);
1407 end if;
1409 while Present (Pkg_Ent) loop
1410 if Ename = Chars (Pkg_Ent) then
1411 RE_Table (E) := Pkg_Ent;
1412 Check_RPC;
1413 goto Found;
1414 end if;
1416 Next_Entity (Pkg_Ent);
1417 end loop;
1419 -- If we did not find the entity in the package entity chain,
1420 -- then check if the package entity itself matches. Note that
1421 -- we do this check after searching the entity chain, since
1422 -- the rule is that in case of ambiguity, we prefer the entity
1423 -- defined within the package, rather than the package itself.
1425 if Ename = Chars (U.Entity) then
1426 RE_Table (E) := U.Entity;
1427 end if;
1429 -- If we didn't find the entity we want, something is wrong.
1430 -- We just leave RE_Table (E) set to Empty and the appropriate
1431 -- action will be taken by Check_CRT when we exit.
1433 end if;
1434 end if;
1436 <<Found>>
1437 Maybe_Add_With (U);
1439 Front_End_Inlining := Save_Front_End_Inlining;
1440 return Check_CRT (E, RE_Table (E));
1441 end RTE;
1443 -------------------
1444 -- RTE_Available --
1445 -------------------
1447 function RTE_Available (E : RE_Id) return Boolean is
1448 Dummy : Entity_Id;
1449 pragma Warnings (Off, Dummy);
1451 Result : Boolean;
1453 Save_RTE_Available_Call : constant Boolean := RTE_Available_Call;
1454 Save_RTE_Is_Available : constant Boolean := RTE_Is_Available;
1455 -- These are saved recursively because the call to load a unit
1456 -- caused by an upper level call may perform a recursive call
1457 -- to this routine during analysis of the corresponding unit.
1459 begin
1460 RTE_Available_Call := True;
1461 RTE_Is_Available := True;
1462 Dummy := RTE (E);
1463 Result := RTE_Is_Available;
1464 RTE_Available_Call := Save_RTE_Available_Call;
1465 RTE_Is_Available := Save_RTE_Is_Available;
1466 return Result;
1468 exception
1469 when RE_Not_Available =>
1470 RTE_Available_Call := Save_RTE_Available_Call;
1471 RTE_Is_Available := Save_RTE_Is_Available;
1472 return False;
1473 end RTE_Available;
1475 --------------------------
1476 -- RTE_Record_Component --
1477 --------------------------
1479 function RTE_Record_Component (E : RE_Id) return Entity_Id is
1480 U_Id : constant RTU_Id := RE_Unit_Table (E);
1481 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
1482 E1 : Entity_Id;
1483 Ename : Name_Id;
1484 Found_E : Entity_Id;
1485 Lib_Unit : Node_Id;
1486 Pkg_Ent : Entity_Id;
1488 -- The following flag is used to disable front-end inlining when
1489 -- RTE_Record_Component is invoked. This prevents the analysis of other
1490 -- runtime bodies when a particular spec is loaded through Rtsfind. This
1491 -- is both efficient, and it prevents spurious visibility conflicts
1492 -- between use-visible user entities, and entities in run-time packages.
1494 Save_Front_End_Inlining : Boolean;
1496 begin
1497 -- Note: Contrary to subprogram RTE, there is no need to do any special
1498 -- management with package system.ads because it has no record type
1499 -- declarations.
1501 Save_Front_End_Inlining := Front_End_Inlining;
1502 Front_End_Inlining := False;
1504 -- Load unit if unit not previously loaded
1506 if not Present (U.Entity) then
1507 Load_RTU (U_Id, Id => E);
1508 end if;
1510 Lib_Unit := Unit (Cunit (U.Unum));
1512 pragma Assert (Nkind (Lib_Unit) = N_Package_Declaration);
1513 Ename := RE_Chars (E);
1515 -- Search the entity in the components of record type declarations
1516 -- found in the package entity chain.
1518 Found_E := Empty;
1519 Pkg_Ent := First_Entity (U.Entity);
1520 Search : while Present (Pkg_Ent) loop
1521 if Is_Record_Type (Pkg_Ent) then
1522 E1 := First_Entity (Pkg_Ent);
1523 while Present (E1) loop
1524 if Ename = Chars (E1) then
1525 pragma Assert (not Present (Found_E));
1526 Found_E := E1;
1527 end if;
1529 Next_Entity (E1);
1530 end loop;
1531 end if;
1533 Next_Entity (Pkg_Ent);
1534 end loop Search;
1536 -- If we didn't find the entity we want, something is wrong. The
1537 -- appropriate action will be taken by Check_CRT when we exit.
1539 Maybe_Add_With (U);
1541 Front_End_Inlining := Save_Front_End_Inlining;
1542 return Check_CRT (E, Found_E);
1543 end RTE_Record_Component;
1545 ------------------------------------
1546 -- RTE_Record_Component_Available --
1547 ------------------------------------
1549 function RTE_Record_Component_Available (E : RE_Id) return Boolean is
1550 Dummy : Entity_Id;
1551 pragma Warnings (Off, Dummy);
1553 Result : Boolean;
1555 Save_RTE_Available_Call : constant Boolean := RTE_Available_Call;
1556 Save_RTE_Is_Available : constant Boolean := RTE_Is_Available;
1557 -- These are saved recursively because the call to load a unit
1558 -- caused by an upper level call may perform a recursive call
1559 -- to this routine during analysis of the corresponding unit.
1561 begin
1562 RTE_Available_Call := True;
1563 RTE_Is_Available := True;
1564 Dummy := RTE_Record_Component (E);
1565 Result := RTE_Is_Available;
1566 RTE_Available_Call := Save_RTE_Available_Call;
1567 RTE_Is_Available := Save_RTE_Is_Available;
1568 return Result;
1570 exception
1571 when RE_Not_Available =>
1572 RTE_Available_Call := Save_RTE_Available_Call;
1573 RTE_Is_Available := Save_RTE_Is_Available;
1574 return False;
1575 end RTE_Record_Component_Available;
1577 -------------------
1578 -- RTE_Error_Msg --
1579 -------------------
1581 procedure RTE_Error_Msg (Msg : String) is
1582 begin
1583 if RTE_Available_Call then
1584 RTE_Is_Available := False;
1585 else
1586 Error_Msg_N (Msg, Current_Error_Node);
1588 -- Bump count of violations if we are in configurable run-time
1589 -- mode and this is not a continuation message.
1591 if Configurable_Run_Time_Mode and then Msg (Msg'First) /= '\' then
1592 Configurable_Run_Time_Violations :=
1593 Configurable_Run_Time_Violations + 1;
1594 end if;
1595 end if;
1596 end RTE_Error_Msg;
1598 ----------------
1599 -- RTU_Entity --
1600 ----------------
1602 function RTU_Entity (U : RTU_Id) return Entity_Id is
1603 begin
1604 return RT_Unit_Table (U).Entity;
1605 end RTU_Entity;
1607 ----------------
1608 -- RTU_Loaded --
1609 ----------------
1611 function RTU_Loaded (U : RTU_Id) return Boolean is
1612 begin
1613 return Present (RT_Unit_Table (U).Entity);
1614 end RTU_Loaded;
1616 --------------------
1617 -- Set_RTU_Loaded --
1618 --------------------
1620 procedure Set_RTU_Loaded (N : Node_Id) is
1621 Loc : constant Source_Ptr := Sloc (N);
1622 Unum : constant Unit_Number_Type := Get_Source_Unit (Loc);
1623 Uname : constant Unit_Name_Type := Unit_Name (Unum);
1624 E : constant Entity_Id :=
1625 Defining_Entity (Unit (Cunit (Unum)));
1626 begin
1627 pragma Assert (Is_Predefined_Unit (Unum));
1629 -- Loop through entries in RTU table looking for matching entry
1631 for U_Id in RTU_Id'Range loop
1633 -- Here we have a match
1635 if Get_Unit_Name (U_Id) = Uname then
1636 declare
1637 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
1638 -- The RT_Unit_Table entry that may need updating
1640 begin
1641 -- If entry is not set, set it now, and indicate that it was
1642 -- loaded through an explicit context clause.
1644 if No (U.Entity) then
1645 U := (Entity => E,
1646 Uname => Get_Unit_Name (U_Id),
1647 Unum => Unum,
1648 First_Implicit_With => Empty);
1649 end if;
1651 return;
1652 end;
1653 end if;
1654 end loop;
1655 end Set_RTU_Loaded;
1657 -------------------------
1658 -- SPARK_Implicit_Load --
1659 -------------------------
1661 procedure SPARK_Implicit_Load (E : RE_Id) is
1662 Unused : Entity_Id;
1664 begin
1665 pragma Assert (GNATprove_Mode);
1667 -- Force loading of a predefined unit
1669 Unused := RTE (E);
1670 end SPARK_Implicit_Load;
1672 end Rtsfind;