1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2024, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
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
;
36 with Fname
; use Fname
;
37 with Fname
.UF
; use Fname
.UF
;
38 with Ghost
; use Ghost
;
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
;
46 with Restrict
; use Restrict
;
48 with Sem_Aux
; use Sem_Aux
;
49 with Sem_Ch7
; use Sem_Ch7
;
50 with Sem_Ch12
; use Sem_Ch12
;
51 with Sem_Dist
; use Sem_Dist
;
52 with Sem_Util
; use Sem_Util
;
53 with Sinfo
; use Sinfo
;
54 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
55 with Sinfo
.Utils
; use Sinfo
.Utils
;
56 with Stand
; use Stand
;
57 with Snames
; use Snames
;
58 with Tbuild
; use Tbuild
;
59 with Uname
; use Uname
;
61 package body Rtsfind
is
63 RTE_Available_Call
: Boolean := False;
64 -- Set True during call to RTE from RTE_Available (or from call to
65 -- RTE_Record_Component from RTE_Record_Component_Available). Tells
66 -- the called subprogram to set RTE_Is_Available to False rather than
67 -- generating an error message.
69 RTE_Is_Available
: Boolean;
70 -- Set True by RTE_Available on entry. When RTE_Available_Call is set
71 -- True, set False if RTE would otherwise generate an error message.
77 -- The unit table has one entry for each unit included in the definition
78 -- of the type RTU_Id in the spec. The table entries are initialized in
79 -- Initialize to set the Entity field to Empty, indicating that the
80 -- corresponding unit has not yet been loaded. The fields are set when
81 -- a unit is loaded to contain the defining entity for the unit, the
82 -- unit name, and the unit number.
84 -- Note that a unit can be loaded either by a call to find an entity
85 -- within the unit (e.g. RTE), or by an explicit with of the unit. In
86 -- the latter case it is critical to make a call to Set_RTU_Loaded to
87 -- ensure that the entry in this table reflects the load.
89 -- A unit retrieved through rtsfind may end up in the context of several
90 -- other units, in addition to the main unit. These additional with_clauses
91 -- are needed to generate a proper traversal order for CodePeer. To
92 -- minimize somewhat the redundancy created by numerous calls to rtsfind
93 -- from different units, we keep track of the list of implicit with_clauses
94 -- already created for the current loaded unit.
96 type RT_Unit_Table_Record
is record
98 Uname
: Unit_Name_Type
;
99 First_Implicit_With
: Node_Id
;
100 Unum
: Unit_Number_Type
;
103 RT_Unit_Table
: array (RTU_Id
) of RT_Unit_Table_Record
;
105 --------------------------
106 -- Runtime Entity Table --
107 --------------------------
109 -- There is one entry in the runtime entity table for each entity that is
110 -- included in the definition of the RE_Id type in the spec. The entries
111 -- are set by Initialize_Rtsfind to contain Empty, indicating that the
112 -- entity has not yet been located. Once the entity is located for the
113 -- first time, its ID is stored in this array, so that subsequent calls
114 -- for the same entity can be satisfied immediately.
116 -- NOTE: In order to avoid conflicts between record components and subprgs
117 -- that have the same name (i.e. subprogram External_Tag and
118 -- component External_Tag of package Ada.Tags) this table is not used
119 -- with Record_Components.
121 RE_Table
: array (RE_Id
) of Entity_Id
;
123 --------------------------------
124 -- Generation of with_clauses --
125 --------------------------------
127 -- When a unit is implicitly loaded as a result of a call to RTE, it is
128 -- necessary to create one or two implicit with_clauses. We add such
129 -- with_clauses to the extended main unit if needed, and also to whatever
130 -- unit needs them, which is not necessarily the main unit. The former
131 -- ensures that the object is correctly loaded by the binder. The latter
132 -- is necessary for CodePeer.
134 -- The field First_Implicit_With in the unit table record are used to
135 -- avoid creating duplicate with_clauses.
137 ----------------------------------------------
138 -- Table of Predefined RE_Id Error Messages --
139 ----------------------------------------------
141 -- If an attempt is made to load an entity, given an RE_Id value, and the
142 -- entity is not available in the current configuration, an error message
143 -- is given (see Entity_Not_Defined below). The general form of such an
144 -- error message is for example:
146 -- entity "System.Pack_43.Bits_43" not defined
148 -- The following table defines a set of RE_Id image values for which this
149 -- error message is specialized and replaced by specific text indicating
150 -- the exact message to be output. For example, in the case above, for the
151 -- RE_Id value RE_Bits_43, we do indeed specialize the message, and the
152 -- above generic message is replaced by:
154 -- packed component size of 43 is not supported
156 type CString_Ptr
is access constant String;
158 type PRE_Id_Entry
is record
160 -- Pointer to string with the RE_Id image. The sequence ?? may appear
161 -- in which case it will match any characters in the RE_Id image value.
162 -- This is used to avoid the need for dozens of entries for RE_Bits_??.
165 -- Pointer to string with the corresponding error text. The sequence
166 -- ?? may appear, in which case, it is replaced by the corresponding
167 -- sequence ?? in the Str value (if the first ? is zero, then it is
168 -- omitted from the message).
171 Str1
: aliased constant String := "RE_BITS_??";
172 Str2
: aliased constant String := "RE_GET_??";
173 Str3
: aliased constant String := "RE_SET_??";
174 Str4
: aliased constant String := "RE_CALL_SIMPLE";
176 MsgPack
: aliased constant String :=
177 "packed component size of ?? is not supported";
178 MsgRV
: aliased constant String :=
179 "task rendezvous is not supported";
181 PRE_Id_Table
: constant array (Natural range <>) of PRE_Id_Entry
:=
182 (1 => (Str1
'Access, MsgPack
'Access),
183 2 => (Str2
'Access, MsgPack
'Access),
184 3 => (Str3
'Access, MsgPack
'Access),
185 4 => (Str4
'Access, MsgRV
'Access));
186 -- We will add entries to this table as we find cases where it is a good
187 -- idea to do so. By no means all the RE_Id values need entries, because
188 -- the expander often gives clear messages before it makes the Rtsfind
189 -- call expecting to find the entity.
191 -----------------------
192 -- Local Subprograms --
193 -----------------------
195 function Check_CRT
(E
: RE_Id
; Eid
: Entity_Id
) return Entity_Id
;
196 -- Check entity Eid to ensure that configurable run-time restrictions are
197 -- met. May generate an error message (if RTE_Available_Call is false) and
198 -- raise RE_Not_Available if entity E does not exist (e.g. Eid is Empty).
199 -- Also check that entity is not overloaded.
201 procedure Entity_Not_Defined
(Id
: RE_Id
);
202 -- Outputs error messages for an entity that is not defined in the run-time
203 -- library (the form of the error message is tailored for no run time or
204 -- configurable run time mode as required). See also table of pre-defined
205 -- messages for entities above (RE_Id_Messages).
207 function Get_Unit_Name
(U_Id
: RTU_Id
) return Unit_Name_Type
;
208 -- Retrieves the Unit Name given a unit id represented by its enumeration
211 procedure Load_Fail
(S
: String; U_Id
: RTU_Id
; Id
: RE_Id
);
212 pragma No_Return
(Load_Fail
);
213 -- Internal procedure called if we can't successfully locate or process a
214 -- run-time unit. The parameters give information about the error message
215 -- to be given. S is a reason for failing to compile the file and U_Id is
216 -- the unit id. RE_Id is the RE_Id originally passed to RTE. The message in
217 -- S is one of the following:
220 -- "had parser errors"
221 -- "had semantic errors"
223 -- The "not found" case is treated specially in that it is considered
224 -- a normal situation in configurable run-time mode, and generates
225 -- a warning, but is otherwise ignored.
229 Id
: RE_Id
:= RE_Null
;
230 Use_Setting
: Boolean := False);
231 -- Load the unit whose Id is given if not already loaded. The unit is
232 -- loaded and analyzed, and the entry in RT_Unit_Table is updated to
233 -- reflect the load. Use_Setting is used to indicate the initial setting
234 -- for the Is_Potentially_Use_Visible flag of the entity for the loaded
235 -- unit (if it is indeed loaded). A value of False means nothing special
236 -- need be done. A value of True indicates that this flag must be set to
237 -- True. It is needed only in the Check_Text_IO_Special_Unit procedure,
238 -- which may materialize an entity of Text_IO (or [Wide_]Wide_Text_IO) that
239 -- was previously unknown. Id is the RE_Id value of the entity which was
240 -- originally requested. Id is used only for error message detail, and if
241 -- it is RE_Null, then the attempt to output the entity name is ignored.
243 function Make_Unit_Name
244 (U
: RT_Unit_Table_Record
;
245 N
: Node_Id
) return Node_Id
;
246 -- If the unit is a child unit, build fully qualified name for use in
249 procedure Maybe_Add_With
(U
: in out RT_Unit_Table_Record
);
250 -- If necessary, add an implicit with_clause from the current unit to the
251 -- one represented by U.
253 procedure Output_Entity_Name
(Id
: RE_Id
; Msg
: String);
254 -- Output continuation error message giving qualified name of entity
255 -- corresponding to Id, appending the string given by Msg.
257 function RE_Chars
(E
: RE_Id
) return Name_Id
;
258 -- Given a RE_Id value returns the Chars of the corresponding entity
260 procedure RTE_Error_Msg
(Msg
: String);
261 -- Generates a message by calling Error_Msg_N specifying Current_Error_Node
262 -- as the node location using the given Msg text. Special processing in the
263 -- case where RTE_Available_Call is set. In this case, no message is output
264 -- and instead RTE_Is_Available is set to False. Note that this can only be
265 -- used if you are sure that the message comes directly or indirectly from
266 -- a call to the RTE function.
272 function Check_CRT
(E
: RE_Id
; Eid
: Entity_Id
) return Entity_Id
is
273 U_Id
: constant RTU_Id
:= RE_Unit_Table
(E
);
277 if RTE_Available_Call
then
278 RTE_Is_Available
:= False;
280 Entity_Not_Defined
(E
);
283 raise RE_Not_Available
;
285 -- Entity is available
288 -- If in No_Run_Time mode and entity is neither in the current unit
289 -- nor in one of the specially permitted units, raise the exception.
292 and then not OK_No_Run_Time_Unit
(U_Id
)
294 -- If the entity being referenced is defined in the current scope,
295 -- using it is always fine as such usage can never introduce any
296 -- dependency on an additional unit. The presence of this test
297 -- helps generating meaningful error messages for CRT violations.
299 and then Scope
(Eid
) /= Current_Scope
301 Entity_Not_Defined
(E
);
302 raise RE_Not_Available
;
305 -- Check entity is not overloaded, checking for special exceptions
308 and then E
/= RE_Save_Occurrence
311 Write_Str
("Run-time configuration error (");
312 Write_Str
("rtsfind entity """);
313 Get_Decoded_Name_String
(Chars
(Eid
));
314 Set_Casing
(Mixed_Case
);
315 Write_Str
(Name_Buffer
(1 .. Name_Len
));
316 Write_Str
(""" is overloaded)");
318 raise Unrecoverable_Error
;
321 -- Otherwise entity is accessible
327 --------------------------------
328 -- Check_Text_IO_Special_Unit --
329 --------------------------------
331 procedure Check_Text_IO_Special_Unit
(Nam
: Node_Id
) is
334 type Name_Map_Type
is array (Text_IO_Package_Name
) of RTU_Id
;
336 Name_Map
: constant Name_Map_Type
:= Name_Map_Type
'(
337 Name_Decimal_IO => Ada_Text_IO_Decimal_IO,
338 Name_Enumeration_IO => Ada_Text_IO_Enumeration_IO,
339 Name_Fixed_IO => Ada_Text_IO_Fixed_IO,
340 Name_Float_IO => Ada_Text_IO_Float_IO,
341 Name_Integer_IO => Ada_Text_IO_Integer_IO,
342 Name_Modular_IO => Ada_Text_IO_Modular_IO);
344 Wide_Name_Map : constant Name_Map_Type := Name_Map_Type'(
345 Name_Decimal_IO
=> Ada_Wide_Text_IO_Decimal_IO
,
346 Name_Enumeration_IO
=> Ada_Wide_Text_IO_Enumeration_IO
,
347 Name_Fixed_IO
=> Ada_Wide_Text_IO_Fixed_IO
,
348 Name_Float_IO
=> Ada_Wide_Text_IO_Float_IO
,
349 Name_Integer_IO
=> Ada_Wide_Text_IO_Integer_IO
,
350 Name_Modular_IO
=> Ada_Wide_Text_IO_Modular_IO
);
352 Wide_Wide_Name_Map
: constant Name_Map_Type
:= Name_Map_Type
'(
353 Name_Decimal_IO => Ada_Wide_Wide_Text_IO_Decimal_IO,
354 Name_Enumeration_IO => Ada_Wide_Wide_Text_IO_Enumeration_IO,
355 Name_Fixed_IO => Ada_Wide_Wide_Text_IO_Fixed_IO,
356 Name_Float_IO => Ada_Wide_Wide_Text_IO_Float_IO,
357 Name_Integer_IO => Ada_Wide_Wide_Text_IO_Integer_IO,
358 Name_Modular_IO => Ada_Wide_Wide_Text_IO_Modular_IO);
361 -- Unit to be loaded, from one of the above maps
364 -- Nothing to do if name is not an identifier or a selected component
365 -- whose selector_name is an identifier.
367 if Nkind (Nam) = N_Identifier then
370 elsif Nkind (Nam) = N_Selected_Component
371 and then Nkind (Selector_Name (Nam)) = N_Identifier
373 Chrs := Chars (Selector_Name (Nam));
379 -- Nothing to do if name is not one of the Text_IO subpackages
380 -- Otherwise look through loaded units, and if we find Text_IO
381 -- or [Wide_]Wide_Text_IO already loaded, then load the proper child.
383 if Chrs in Text_IO_Package_Name then
384 for U in Main_Unit .. Last_Unit loop
385 Get_Name_String (Unit_File_Name (U));
387 if Name_Len = 12 then
389 -- Here is where we do the loads if we find one of the units
390 -- Ada.Text_IO or Ada.[Wide_]Wide_Text_IO. An interesting
391 -- detail is that these units may already be used (i.e. their
392 -- In_Use flags may be set). Normally when the In_Use flag is
393 -- set, the Is_Potentially_Use_Visible flag of all entities in
394 -- the package is set, but the new entity we are mysteriously
395 -- adding was not there to have its flag set at the time. So
396 -- that's why we pass the extra parameter to RTU_Find, to make
397 -- sure the flag does get set now. Given that those generic
398 -- packages are in fact child units, we must indicate that
401 if Name_Buffer (1 .. 12) = "a-textio.ads" then
402 To_Load := Name_Map (Chrs);
404 elsif Name_Buffer (1 .. 12) = "a-witeio.ads" then
405 To_Load := Wide_Name_Map (Chrs);
407 elsif Name_Buffer (1 .. 12) = "a-ztexio.ads" then
408 To_Load := Wide_Wide_Name_Map (Chrs);
414 Load_RTU (To_Load, Use_Setting => In_Use (Cunit_Entity (U)));
415 Set_Is_Visible_Lib_Unit (RT_Unit_Table (To_Load).Entity);
417 -- Prevent creation of an implicit 'with' from (for example)
418 -- Ada.Wide_Text_IO.Integer_IO to Ada.Text_IO.Integer_IO,
419 -- because these could create cycles. First check whether the
420 -- simple names match ("integer_io" = "integer_io"), and then
421 -- check whether the parent is indeed one of the
422 -- [[Wide_]Wide_]Text_IO packages.
424 if Chrs = Chars (Cunit_Entity (Current_Sem_Unit)) then
426 Parent_Name : constant Unit_Name_Type :=
428 (Unit_Name (Current_Sem_Unit));
431 if Present (Parent_Name) then
432 Get_Name_String (Parent_Name);
435 P : String renames Name_Buffer (1 .. Name_Len);
437 if P = "ada.text_io%s" or else
438 P = "ada.wide_text_io%s" or else
439 P = "ada.wide_wide_text_io%s"
448 -- Add an implicit with clause from the current unit to the
449 -- [[Wide_]Wide_]Text_IO child (if necessary).
451 Maybe_Add_With (RT_Unit_Table (To_Load));
459 -- Generate error message if run-time unit not available
461 when RE_Not_Available =>
462 Error_Msg_N ("& not available", Nam);
463 end Check_Text_IO_Special_Unit;
465 ------------------------
466 -- Entity_Not_Defined --
467 ------------------------
469 procedure Entity_Not_Defined (Id : RE_Id) is
471 if No_Run_Time_Mode then
473 -- If the error occurs when compiling the body of a predefined
474 -- unit for inlining purposes, the body must be illegal in this
475 -- mode, and there is no point in continuing.
477 if In_Predefined_Unit (Current_Error_Node) then
479 ("construct not allowed in no run time mode!",
481 raise Unrecoverable_Error;
484 RTE_Error_Msg ("|construct not allowed in no run time mode");
487 elsif Configurable_Run_Time_Mode then
488 RTE_Error_Msg ("|construct not allowed in this configuration>");
490 RTE_Error_Msg ("run-time configuration error");
493 -- See if this entry is to be found in the PRE_Id table that provides
494 -- specialized messages for some RE_Id values.
496 for J in PRE_Id_Table'Range loop
498 TStr : constant String := PRE_Id_Table (J).Str.all;
499 RStr : constant String := RE_Id'Image (Id);
500 TMsg : String := PRE_Id_Table (J).Msg.all;
501 LMsg : Natural := TMsg'Length;
504 if TStr'Length = RStr'Length then
505 for J in TStr'Range loop
506 if TStr (J) /= RStr (J) and then TStr (J) /= '?
' then
511 for J in TMsg'First .. TMsg'Last - 1 loop
512 if TMsg (J) = '?
' then
513 for K in 1 .. TStr'Last loop
514 if TStr (K) = '?
' then
515 if RStr (K) = '0' then
516 TMsg (J) := RStr (K + 1);
517 TMsg (J + 1 .. LMsg - 1) := TMsg (J + 2 .. LMsg);
520 TMsg (J .. J + 1) := RStr (K .. K + 1);
529 RTE_Error_Msg (TMsg (1 .. LMsg));
537 -- We did not find an entry in the table, so output the generic entity
538 -- not found message, where the name of the entity corresponds to the
539 -- given RE_Id value.
541 Output_Entity_Name (Id, "not defined");
542 end Entity_Not_Defined;
548 -- The following subtypes include all the proper descendants of each unit
549 -- that has such descendants. For example, Ada_Calendar_Descendant includes
550 -- all the descendents of Ada.Calendar (except Ada.Calendar itself). These
551 -- are used by Get_Unit_Name to know where to change "_" to ".", and by
552 -- Is_Text_IO_Special_Package to detect the special generic pseudo-children
553 -- of [[Wide_]Wide_]Text_IO.
555 subtype Ada_Descendant is RTU_Id
556 range Ada_Calendar .. Ada_Wide_Wide_Text_IO_Modular_IO;
558 subtype Ada_Calendar_Descendant is Ada_Descendant
559 range Ada_Calendar_Delays .. Ada_Calendar_Delays;
561 subtype Ada_Dispatching_Descendant is Ada_Descendant
562 range Ada_Dispatching_EDF .. Ada_Dispatching_EDF;
564 subtype Ada_Interrupts_Descendant is Ada_Descendant range
565 Ada_Interrupts_Names .. Ada_Interrupts_Names;
567 subtype Ada_Numerics_Descendant is Ada_Descendant
568 range Ada_Numerics_Big_Numbers ..
569 Ada_Numerics_Big_Numbers_Big_Integers_Ghost;
571 subtype Ada_Numerics_Big_Numbers_Descendant is Ada_Descendant
572 range Ada_Numerics_Big_Numbers_Big_Integers ..
573 Ada_Numerics_Big_Numbers_Big_Integers_Ghost;
575 subtype Ada_Real_Time_Descendant is Ada_Descendant
576 range Ada_Real_Time_Delays .. Ada_Real_Time_Timing_Events;
578 subtype Ada_Streams_Descendant is Ada_Descendant
579 range Ada_Streams_Stream_IO .. Ada_Streams_Stream_IO;
581 subtype Ada_Strings_Descendant is Ada_Descendant
582 range Ada_Strings_Superbounded .. Ada_Strings_Text_Buffers_Unbounded;
584 subtype Ada_Strings_Text_Buffers_Descendant is Ada_Strings_Descendant
585 range Ada_Strings_Text_Buffers_Unbounded ..
586 Ada_Strings_Text_Buffers_Unbounded;
588 subtype Ada_Text_IO_Descendant is Ada_Descendant
589 range Ada_Text_IO_Decimal_IO .. Ada_Text_IO_Modular_IO;
591 subtype Ada_Wide_Text_IO_Descendant is Ada_Descendant
592 range Ada_Wide_Text_IO_Decimal_IO .. Ada_Wide_Text_IO_Modular_IO;
594 subtype Ada_Wide_Wide_Text_IO_Descendant is Ada_Descendant
595 range Ada_Wide_Wide_Text_IO_Decimal_IO ..
596 Ada_Wide_Wide_Text_IO_Modular_IO;
598 subtype CUDA_Descendant is RTU_Id
599 range CUDA_Driver_Types .. CUDA_Vector_Types;
601 subtype Interfaces_Descendant is RTU_Id
602 range Interfaces_C .. Interfaces_C_Strings;
604 subtype Interfaces_C_Descendant is Interfaces_Descendant
605 range Interfaces_C_Strings .. Interfaces_C_Strings;
607 subtype System_Descendant is RTU_Id
608 range System_Address_To_Access_Conversions .. System_Tasking_Stages;
610 subtype System_Atomic_Operations_Descendant is System_Descendant
611 range System_Atomic_Operations_Test_And_Set ..
612 System_Atomic_Operations_Test_And_Set;
614 subtype System_Dim_Descendant is System_Descendant
615 range System_Dim_Float_IO .. System_Dim_Integer_IO;
617 subtype System_Multiprocessors_Descendant is System_Descendant
618 range System_Multiprocessors_Dispatching_Domains ..
619 System_Multiprocessors_Dispatching_Domains;
621 subtype System_Storage_Pools_Descendant is System_Descendant
622 range System_Storage_Pools_Subpools .. System_Storage_Pools_Subpools;
624 subtype System_Strings_Descendant is System_Descendant
625 range System_Strings_Stream_Ops .. System_Strings_Stream_Ops;
627 subtype System_Tasking_Descendant is System_Descendant
628 range System_Tasking_Async_Delays .. System_Tasking_Stages;
630 subtype System_Tasking_Protected_Objects_Descendant is
631 System_Tasking_Descendant
632 range System_Tasking_Protected_Objects_Entries ..
633 System_Tasking_Protected_Objects_Single_Entry;
635 subtype System_Tasking_Restricted_Descendant is System_Tasking_Descendant
636 range System_Tasking_Restricted_Stages ..
637 System_Tasking_Restricted_Stages;
639 subtype System_Tasking_Async_Delays_Descendant is System_Tasking_Descendant
640 range System_Tasking_Async_Delays_Enqueue_Calendar ..
641 System_Tasking_Async_Delays_Enqueue_RT;
643 function Get_Unit_Name (U_Id : RTU_Id) return Unit_Name_Type is
644 Uname_Chars : constant String := RTU_Id'Image (U_Id);
646 Name_Len := Uname_Chars'Length;
647 Name_Buffer (1 .. Name_Len) := Uname_Chars;
648 Set_Casing (All_Lower_Case);
650 if U_Id in Ada_Descendant then
651 Name_Buffer (4) := '.';
653 if U_Id in Ada_Calendar_Descendant then
654 Name_Buffer (13) := '.';
656 elsif U_Id in Ada_Dispatching_Descendant then
657 Name_Buffer (16) := '.';
659 elsif U_Id in Ada_Interrupts_Descendant then
660 Name_Buffer (15) := '.';
662 elsif U_Id in Ada_Numerics_Descendant then
663 Name_Buffer (13) := '.';
665 if U_Id in Ada_Numerics_Big_Numbers_Descendant then
666 Name_Buffer (25) := '.';
669 elsif U_Id in Ada_Real_Time_Descendant then
670 Name_Buffer (14) := '.';
672 elsif U_Id in Ada_Streams_Descendant then
673 Name_Buffer (12) := '.';
675 elsif U_Id in Ada_Strings_Descendant then
676 Name_Buffer (12) := '.';
678 if U_Id in Ada_Strings_Text_Buffers_Descendant then
679 Name_Buffer (25) := '.';
682 elsif U_Id in Ada_Text_IO_Descendant then
683 Name_Buffer (12) := '.';
685 elsif U_Id in Ada_Wide_Text_IO_Descendant then
686 Name_Buffer (17) := '.';
688 elsif U_Id in Ada_Wide_Wide_Text_IO_Descendant then
689 Name_Buffer (22) := '.';
692 elsif U_Id in CUDA_Descendant then
693 Name_Buffer (5) := '.';
695 elsif U_Id in Interfaces_Descendant then
696 Name_Buffer (11) := '.';
698 if U_Id in Interfaces_C_Descendant then
699 Name_Buffer (13) := '.';
702 elsif U_Id in System_Descendant then
703 Name_Buffer (7) := '.';
705 if U_Id in System_Atomic_Operations_Descendant then
706 Name_Buffer (25) := '.';
709 if U_Id in System_Dim_Descendant then
710 Name_Buffer (11) := '.';
713 if U_Id in System_Multiprocessors_Descendant then
714 Name_Buffer (23) := '.';
717 if U_Id in System_Storage_Pools_Descendant then
718 Name_Buffer (21) := '.';
721 if U_Id in System_Strings_Descendant then
722 Name_Buffer (15) := '.';
725 if U_Id in System_Tasking_Descendant then
726 Name_Buffer (15) := '.';
729 if U_Id in System_Tasking_Restricted_Descendant then
730 Name_Buffer (26) := '.';
733 if U_Id in System_Tasking_Protected_Objects_Descendant then
734 Name_Buffer (33) := '.';
737 if U_Id in System_Tasking_Async_Delays_Descendant then
738 Name_Buffer (28) := '.';
742 -- Add %s at end for spec
744 Name_Buffer (Name_Len + 1) := '%';
745 Name_Buffer (Name_Len + 2) := 's
';
746 Name_Len := Name_Len + 2;
755 procedure Initialize is
757 -- Initialize the unit table
760 RT_Unit_Table (J).Entity := Empty;
761 RT_Unit_Table (J).First_Implicit_With := Empty;
765 RE_Table (J) := Empty;
768 RTE_Is_Available := False;
775 function Is_RTE (Ent : Entity_Id; E : RE_Id) return Boolean is
776 E_Unit_Name : Unit_Name_Type;
777 Ent_Unit_Name : Unit_Name_Type;
787 -- If E has already a corresponding entity, check it directly,
788 -- going to full views if they exist to deal with the incomplete
789 -- and private type cases properly.
791 elsif Present (RE_Table (E)) then
794 if Is_Type (E1) and then Present (Full_View (E1)) then
795 E1 := Full_View (E1);
800 if Is_Type (E2) and then Present (Full_View (E2)) then
801 E2 := Full_View (E2);
807 -- If the unit containing E is not loaded, we already know that the
808 -- entity we have cannot have come from this unit.
810 E_Unit_Name := Get_Unit_Name (RE_Unit_Table (E));
812 if not Is_Loaded (E_Unit_Name) then
816 -- Here the unit containing the entity is loaded. We have not made
817 -- an explicit call to RTE to get the entity in question, but we may
818 -- have obtained a reference to it indirectly from some other entity
819 -- in the same unit, or some other unit that references it.
821 -- Get the defining unit of the entity
825 if No (S) or else Ekind (S) /= E_Package then
829 Ent_Unit_Name := Get_Unit_Name (Unit_Declaration_Node (S));
831 -- If the defining unit of the entity we are testing is not the
832 -- unit containing E, then they cannot possibly match.
834 if Ent_Unit_Name /= E_Unit_Name then
838 -- If the units match, then compare the names (remember that no
839 -- overloading is permitted in entities fetched using Rtsfind).
841 if RE_Chars (E) = Chars (Ent) then
844 -- If front-end inlining is enabled, we may be within a body that
845 -- contains inlined functions, which has not been retrieved through
846 -- rtsfind, and therefore is not yet recorded in the RT_Unit_Table.
847 -- Add the unit information now, it must be fully available.
850 U : RT_Unit_Table_Record
851 renames RT_Unit_Table (RE_Unit_Table (E));
853 if No (U.Entity) then
855 U.Uname := E_Unit_Name;
856 U.Unum := Get_Source_Unit (S);
870 function Is_RTU (Ent : Entity_Id; U : RTU_Id) return Boolean is
871 E : constant Entity_Id := RT_Unit_Table (U).Entity;
873 return Present (E) and then E = Ent;
876 --------------------------------
877 -- Is_Text_IO_Special_Package --
878 --------------------------------
880 function Is_Text_IO_Special_Package (E : Entity_Id) return Boolean is
882 pragma Assert (Is_Package_Or_Generic_Package (E));
884 -- ??? detection with a scope climbing might be more efficient
886 for U in Ada_Text_IO_Descendant loop
887 if Is_RTU (E, U) then
892 for U in Ada_Wide_Text_IO_Descendant loop
893 if Is_RTU (E, U) then
898 for U in Ada_Wide_Wide_Text_IO_Descendant loop
899 if Is_RTU (E, U) then
905 end Is_Text_IO_Special_Package;
907 -----------------------------
908 -- Is_Text_IO_Special_Unit --
909 -----------------------------
911 function Is_Text_IO_Special_Unit (Nam : Node_Id) return Boolean is
916 if Nkind (Nam) /= N_Expanded_Name then
921 Sel := Selector_Name (Nam);
923 if Nkind (Sel) /= N_Expanded_Name
924 or else Nkind (Prf) /= N_Identifier
925 or else Chars (Prf) /= Name_Ada
931 Sel := Selector_Name (Sel);
934 Nkind (Prf) = N_Identifier
936 Chars (Prf) in Name_Text_IO
938 | Name_Wide_Wide_Text_IO
939 and then Nkind (Sel) = N_Identifier
940 and then Chars (Sel) in Text_IO_Package_Name;
941 end Is_Text_IO_Special_Unit;
947 procedure Load_Fail (S : String; U_Id : RTU_Id; Id : RE_Id) is
948 M : String (1 .. 100);
952 -- Output header message
954 if Configurable_Run_Time_Mode then
955 RTE_Error_Msg ("construct not allowed in configurable run-time mode");
957 RTE_Error_Msg ("run-time library configuration error");
960 -- Output file name and reason string
962 M (1 .. 6) := "\file ";
966 (Get_File_Name (RT_Unit_Table (U_Id).Uname, Subunit => False));
967 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
973 M (P + 1 .. P + S'Length) := S;
976 RTE_Error_Msg (M (1 .. P));
978 -- Output entity name
980 Output_Entity_Name (Id, "not available");
982 -- In configurable run time mode, we raise RE_Not_Available, and the
983 -- caller is expected to deal gracefully with this. In the case of a
984 -- call to RTE_Available, this exception will be caught in Rtsfind,
985 -- and result in a returned value of False for the call.
987 if Configurable_Run_Time_Mode then
988 raise RE_Not_Available;
990 -- Here we have a load failure in normal full run time mode. See if we
991 -- are in the context of an RTE_Available call. If so, we just raise
992 -- RE_Not_Available. This can happen if a unit is unavailable, which
993 -- happens for example in the VM case, where the run-time is not
994 -- complete, but we do not regard it as a configurable run-time.
995 -- If the caller has done an explicit call to RTE_Available, then
996 -- clearly the caller is prepared to deal with a result of False.
998 elsif RTE_Available_Call then
999 RTE_Is_Available := False;
1000 raise RE_Not_Available;
1002 -- If we are not in the context of an RTE_Available call, we are really
1003 -- trying to load an entity that is not there, and that should never
1004 -- happen, so in this case we signal a fatal error.
1007 raise Unrecoverable_Error;
1015 -- WARNING: This routine manages Ghost and SPARK regions. Return statements
1016 -- must be replaced by gotos which jump to the end of the routine in order
1017 -- to restore the Ghost and SPARK modes.
1021 Id : RE_Id := RE_Null;
1022 Use_Setting : Boolean := False)
1024 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
1025 Priv_Par : constant Elist_Id := New_Elmt_List;
1027 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
1028 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
1029 Saved_ISMP : constant Boolean :=
1030 Ignore_SPARK_Mode_Pragmas_In_Instance;
1031 Saved_SM : constant SPARK_Mode_Type := SPARK_Mode;
1032 Saved_SMP : constant Node_Id := SPARK_Mode_Pragma;
1033 -- Save Ghost and SPARK mode-related data to restore on exit
1035 procedure Save_Private_Visibility;
1036 -- If the current unit is the body of child unit or the spec of a
1037 -- private child unit, the private declarations of the parent(s) are
1038 -- visible. If the unit to be loaded is another public sibling, its
1039 -- compilation will affect the visibility of the common ancestors.
1040 -- Indicate those that must be restored.
1042 procedure Restore_Private_Visibility;
1043 -- Restore the visibility of ancestors after compiling RTU
1045 procedure Restore_SPARK_Context;
1046 -- Restore Ghost and SPARK mode-related data saved on procedure entry
1048 --------------------------------
1049 -- Restore_Private_Visibility --
1050 --------------------------------
1052 procedure Restore_Private_Visibility is
1056 E_Par := First_Elmt (Priv_Par);
1057 while Present (E_Par) loop
1058 if not In_Private_Part (Node (E_Par)) then
1059 Install_Private_Declarations (Node (E_Par));
1064 end Restore_Private_Visibility;
1066 -----------------------------
1067 -- Save_Private_Visibility --
1068 -----------------------------
1070 procedure Save_Private_Visibility is
1074 Par := Scope (Current_Scope);
1076 and then Par /= Standard_Standard
1078 if Ekind (Par) = E_Package
1079 and then Is_Compilation_Unit (Par)
1080 and then In_Private_Part (Par)
1082 Append_Elmt (Par, Priv_Par);
1087 end Save_Private_Visibility;
1089 ---------------------------
1090 -- Restore_SPARK_Context --
1091 ---------------------------
1093 procedure Restore_SPARK_Context is
1095 Ignore_SPARK_Mode_Pragmas_In_Instance := Saved_ISMP;
1096 Restore_Ghost_Region (Saved_GM, Saved_IGR);
1097 Restore_SPARK_Mode (Saved_SM, Saved_SMP);
1098 end Restore_SPARK_Context;
1100 -- Start of processing for Load_RTU
1103 -- Nothing to do if unit is already loaded
1105 if Present (U.Entity) then
1109 -- Provide a clean environment for the unit
1111 Ignore_SPARK_Mode_Pragmas_In_Instance := False;
1112 Install_Ghost_Region (None, Empty);
1113 Install_SPARK_Mode (None, Empty);
1115 -- Otherwise we need to load the unit, First build unit name from the
1116 -- enumeration literal name in type RTU_Id.
1118 U.Uname := Get_Unit_Name (U_Id);
1119 U.First_Implicit_With := Empty;
1121 -- Now do the load call, note that setting Error_Node to Empty is a
1122 -- signal to Load_Unit that we will regard a failure to find the file as
1123 -- a fatal error, and that it should not output any kind of diagnostics,
1124 -- since we will take care of it here.
1126 -- We save style checking switches and turn off style checking for
1127 -- loading the unit, since we don't want any style checking.
1130 Save_Style_Check : constant Boolean := Style_Check;
1132 Style_Check := False;
1135 (Load_Name => U.Uname,
1138 Error_Node => Empty);
1139 Style_Check := Save_Style_Check;
1142 -- Check for bad unit load
1144 if U.Unum = No_Unit then
1145 Load_Fail ("not found", U_Id, Id);
1146 elsif Fatal_Error (U.Unum) = Error_Detected then
1147 Load_Fail ("had parser errors", U_Id, Id);
1150 -- Make sure that the unit is analyzed
1153 Was_Analyzed : constant Boolean :=
1154 Analyzed (Cunit (Current_Sem_Unit));
1157 -- Pretend that the current unit is analyzed, in case it is System
1158 -- or some such. This allows us to put some declarations, such as
1159 -- exceptions and packed arrays of Boolean, into System even though
1160 -- expanding them requires System...
1162 -- This is a bit odd but works fine. If the RTS unit does not depend
1163 -- in any way on the current unit, then it never gets back into the
1164 -- current unit's tree, and the change we make to the current unit
1165 -- tree is never noticed by anyone (it is undone in a moment). That
1166 -- is the normal situation.
1168 -- If the RTS Unit *does* depend on the current unit, for instance,
1169 -- when you are compiling System, then you had better have finished
1170 -- analyzing the part of System that is depended on before you try to
1171 -- load the RTS Unit. This means having the code in System ordered in
1172 -- an appropriate manner.
1174 Set_Analyzed (Cunit (Current_Sem_Unit), True);
1176 if not Analyzed (Cunit (U.Unum)) then
1178 -- If the unit is already loaded through a limited_with_clause,
1179 -- the relevant entities must already be available. We do not
1180 -- want to load and analyze the unit because this would create
1181 -- a real semantic dependence when the purpose of the limited_with
1182 -- is precisely to avoid such.
1184 if From_Limited_With (Cunit_Entity (U.Unum)) then
1188 Save_Private_Visibility;
1190 Saved_Instance_Context : constant Instance_Context.Context :=
1191 Instance_Context.Save_And_Reset;
1193 Semantics (Cunit (U.Unum));
1194 Instance_Context.Restore (Saved_Instance_Context);
1196 Restore_Private_Visibility;
1198 if Fatal_Error (U.Unum) = Error_Detected then
1199 Load_Fail ("had semantic errors", U_Id, Id);
1204 -- Undo the pretence
1206 Set_Analyzed (Cunit (Current_Sem_Unit), Was_Analyzed);
1209 Lib_Unit := Unit (Cunit (U.Unum));
1210 U.Entity := Defining_Entity (Lib_Unit);
1213 Set_Is_Potentially_Use_Visible (U.Entity, True);
1216 Restore_SPARK_Context;
1219 -- The Load_Fail procedure that is called when the result of Load_Unit
1220 -- is not satisfactory raises an exception. As the compiler is able to
1221 -- recover in some cases (i.e. when RE_Not_Available is raised), we need
1222 -- to restore the SPARK/Ghost context correctly.
1225 Restore_SPARK_Context;
1229 --------------------
1230 -- Make_Unit_Name --
1231 --------------------
1233 function Make_Unit_Name
1234 (U : RT_Unit_Table_Record;
1235 N : Node_Id) return Node_Id is
1241 Nam := New_Occurrence_Of (U.Entity, Standard_Location);
1242 Scop := Scope (U.Entity);
1244 if Nkind (N) = N_Defining_Program_Unit_Name then
1245 while Scop /= Standard_Standard loop
1247 Make_Expanded_Name (Standard_Location,
1248 Chars => Chars (U.Entity),
1249 Prefix => New_Occurrence_Of (Scop, Standard_Location),
1250 Selector_Name => Nam);
1251 Set_Entity (Nam, U.Entity);
1253 Scop := Scope (Scop);
1260 --------------------
1261 -- Maybe_Add_With --
1262 --------------------
1264 procedure Maybe_Add_With (U : in out RT_Unit_Table_Record) is
1266 -- We do not need to generate a with_clause for a call issued from
1267 -- RTE_Component_Available. However, for CodePeer, we need these
1268 -- additional with's, because for a sequence like "if RTE_Available (X)
1269 -- then ... RTE (X)" the RTE call fails to create some necessary with's.
1271 if RTE_Available_Call and not Generate_SCIL then
1275 -- Avoid creating directly self-referential with clauses
1277 if Current_Sem_Unit = U.Unum then
1281 -- Add the with_clause, if we have not already added an implicit with
1282 -- for this unit to the current compilation unit.
1285 LibUnit : constant Node_Id := Unit (Cunit (U.Unum));
1286 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
1291 Clause := U.First_Implicit_With;
1292 while Present (Clause) loop
1293 if Parent (Clause) = Cunit (Current_Sem_Unit) then
1297 Clause := Next_Implicit_With (Clause);
1300 -- We want to make sure that the "with" we create below isn't
1301 -- marked as ignored ghost code because this list may be walked
1302 -- later, after ignored ghost code is converted to a null
1307 Make_With_Clause (Standard_Location,
1310 (U, Defining_Unit_Name (Specification (LibUnit))));
1311 Ghost_Mode := Saved_GM;
1313 Set_Corresponding_Spec (Withn, U.Entity);
1314 Set_First_Name (Withn);
1315 Set_Implicit_With (Withn);
1316 Set_Library_Unit (Withn, Cunit (U.Unum));
1317 Set_Next_Implicit_With (Withn, U.First_Implicit_With);
1319 U.First_Implicit_With := Withn;
1321 Mark_Rewrite_Insertion (Withn);
1322 Append (Withn, Context_Items (Cunit (Current_Sem_Unit)));
1323 Check_Restriction_No_Dependence (Name (Withn), Current_Error_Node);
1327 ------------------------
1328 -- Output_Entity_Name --
1329 ------------------------
1331 procedure Output_Entity_Name (Id : RE_Id; Msg : String) is
1332 M : String (1 .. 2048);
1334 -- M (1 .. P) is current message to be output
1336 RE_Image : constant String := RE_Id'Image (Id);
1338 -- RE_Image (S .. RE_Image'Last) is the name of the entity without the
1339 -- "RE_" or "RO_XX_" prefix.
1342 if Id = RE_Null then
1346 M (1 .. 9) := "\entity """;
1349 -- Add unit name to message, excluding %s or %b at end
1351 Get_Name_String (Get_Unit_Name (RE_Unit_Table (Id)));
1352 Name_Len := Name_Len - 2;
1353 Set_Casing (Mixed_Case);
1354 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
1357 -- Add a qualifying period
1364 if RE_Image (2) = 'E
' then
1373 -- Add entity name and closing quote to message
1375 Name_Len := RE_Image'Length - S + 1;
1376 Name_Buffer (1 .. Name_Len) := RE_Image (S .. RE_Image'Last);
1377 Set_Casing (Mixed_Case);
1378 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
1387 M (P + 1 .. P + Msg'Length) := Msg;
1388 P := P + Msg'Length;
1390 -- Output message at current error node location
1392 RTE_Error_Msg (M (1 .. P));
1393 end Output_Entity_Name;
1399 function RE_Chars (E : RE_Id) return Name_Id is
1400 RE_Name_Chars : constant String := RE_Id'Image (E);
1403 -- Copy name skipping initial RE_ or RO_XX characters
1405 if RE_Name_Chars (1 .. 2) = "RE
" then
1406 for J in 4 .. RE_Name_Chars'Last loop
1407 Name_Buffer (J - 3) := Fold_Lower (RE_Name_Chars (J));
1410 Name_Len := RE_Name_Chars'Length - 3;
1413 for J in 7 .. RE_Name_Chars'Last loop
1414 Name_Buffer (J - 6) := Fold_Lower (RE_Name_Chars (J));
1417 Name_Len := RE_Name_Chars'Length - 6;
1427 function RTE (E : RE_Id) return Entity_Id is
1428 procedure Check_RPC;
1429 -- Reject programs that make use of distribution features not supported
1430 -- on the current target. Also check that the PCS is compatible with the
1431 -- code generator version. On such targets (Vxworks, others?) we provide
1432 -- a minimal body for System.Rpc that only supplies an implementation of
1435 function Find_Local_Entity (E : RE_Id) return Entity_Id;
1436 -- This function is used when entity E is in this compilation's main
1437 -- unit. It gets the value from the already compiled declaration.
1443 procedure Check_RPC is
1445 -- Bypass this check if debug flag -gnatdR set
1447 if Debug_Flag_RR then
1451 -- Otherwise we need the check if we are going after one of the
1452 -- critical entities in System.RPC / System.Partition_Interface.
1458 E = RE_Params_Stream_Type
1460 E = RE_Request_Access
1462 -- If generating RCI stubs, check that we have a real PCS
1464 if (Distribution_Stub_Mode = Generate_Receiver_Stub_Body
1466 Distribution_Stub_Mode = Generate_Caller_Stub_Body)
1467 and then Get_PCS_Name = Name_No_DSA
1470 Write_Str ("distribution feature
not supported
");
1472 raise Unrecoverable_Error;
1474 -- In all cases, check Exp_Dist and System.Partition_Interface
1477 elsif Get_PCS_Version /=
1478 Exp_Dist.PCS_Version_Number (Get_PCS_Name)
1481 Write_Str ("PCS version mismatch
: expander
");
1482 Write_Int (Exp_Dist.PCS_Version_Number (Get_PCS_Name));
1483 Write_Str (", PCS
(");
1484 Write_Name (Get_PCS_Name);
1486 Write_Int (Get_PCS_Version);
1488 raise Unrecoverable_Error;
1493 -----------------------
1494 -- Find_Local_Entity --
1495 -----------------------
1497 function Find_Local_Entity (E : RE_Id) return Entity_Id is
1498 RE_Str : constant String := RE_Id'Image (E);
1502 Save_Nam : constant String := Name_Buffer (1 .. Name_Len);
1503 -- Save name buffer and length over call
1506 Name_Len := Natural'Max (0, RE_Str'Length - 3);
1507 Name_Buffer (1 .. Name_Len) :=
1508 RE_Str (RE_Str'First + 3 .. RE_Str'Last);
1511 Ent := Entity_Id (Get_Name_Table_Int (Nam));
1513 Name_Len := Save_Nam'Length;
1514 Name_Buffer (1 .. Name_Len) := Save_Nam;
1517 end Find_Local_Entity;
1521 U_Id : constant RTU_Id := RE_Unit_Table (E);
1522 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
1526 Pkg_Ent : Entity_Id;
1528 Save_Front_End_Inlining : constant Boolean := Front_End_Inlining;
1529 -- This flag is used to disable front-end inlining when RTE is invoked.
1530 -- This prevents the analysis of other runtime bodies when a particular
1531 -- spec is loaded through Rtsfind. This is both efficient, and prevents
1532 -- spurious visibility conflicts between use-visible user entities, and
1533 -- entities in run-time packages.
1535 -- Start of processing for RTE
1538 -- Doing a rtsfind in system.ads is special, as we cannot do this
1539 -- when compiling System itself. So if we are compiling system then
1540 -- we should already have acquired and processed the declaration
1541 -- of the entity. The test is to see if this compilation's main unit
1542 -- is System. If so, return the value from the already compiled
1543 -- declaration and otherwise do a regular find.
1545 -- Not pleasant, but these kinds of annoying recursion scenarios when
1546 -- writing an Ada compiler in Ada have to be broken somewhere.
1548 if Present (Main_Unit_Entity)
1549 and then Chars (Main_Unit_Entity) = Name_System
1550 and then Analyzed (Main_Unit_Entity)
1551 and then not Is_Child_Unit (Main_Unit_Entity)
1553 return Check_CRT (E, Find_Local_Entity (E));
1556 Front_End_Inlining := False;
1558 -- Load unit if unit not previously loaded
1560 if No (RE_Table (E)) then
1561 Load_RTU (U_Id, Id => E);
1562 Lib_Unit := Unit (Cunit (U.Unum));
1564 -- In the subprogram case, we are all done, the entity we want
1565 -- is the entity for the subprogram itself. Note that we do not
1566 -- bother to check that it is the entity that was requested.
1567 -- the only way that could fail to be the case is if runtime is
1568 -- hopelessly misconfigured, and it isn't worth testing for this.
1570 if Nkind (Lib_Unit) = N_Subprogram_Declaration then
1571 RE_Table (E) := U.Entity;
1573 -- Otherwise we must have the package case. First check package
1574 -- entity itself (e.g. RTE_Name for System.Interrupts.Name)
1577 pragma Assert (Nkind (Lib_Unit) = N_Package_Declaration);
1578 Ename := RE_Chars (E);
1580 -- First we search the package entity chain. If the package
1581 -- only has a limited view, scan the corresponding list of
1582 -- incomplete types.
1584 if From_Limited_With (U.Entity) then
1585 Pkg_Ent := First_Entity (Limited_View (U.Entity));
1587 Pkg_Ent := First_Entity (U.Entity);
1590 while Present (Pkg_Ent) loop
1591 if Ename = Chars (Pkg_Ent) then
1592 RE_Table (E) := Pkg_Ent;
1597 Next_Entity (Pkg_Ent);
1600 -- If we did not find the entity in the package entity chain,
1601 -- then check if the package entity itself matches. Note that
1602 -- we do this check after searching the entity chain, since
1603 -- the rule is that in case of ambiguity, we prefer the entity
1604 -- defined within the package, rather than the package itself.
1606 if Ename = Chars (U.Entity) then
1607 RE_Table (E) := U.Entity;
1610 -- If we didn't find the entity we want, something is wrong.
1611 -- We just leave RE_Table (E) set to Empty and the appropriate
1612 -- action will be taken by Check_CRT when we exit.
1619 -- Record whether the secondary stack is in use in order to generate
1620 -- the proper binder code. No action is taken when the secondary stack
1621 -- is pulled within an ignored Ghost context because all this code will
1624 if U_Id = System_Secondary_Stack and then Ghost_Mode /= Ignore then
1625 Sec_Stack_Used := True;
1629 Front_End_Inlining := Save_Front_End_Inlining;
1631 return Check_CRT (E, RE_Table (E));
1638 function RTE_Available (E : RE_Id) return Boolean is
1640 pragma Warnings (Off, Dummy);
1644 Save_RTE_Available_Call : constant Boolean := RTE_Available_Call;
1645 Save_RTE_Is_Available : constant Boolean := RTE_Is_Available;
1646 -- These are saved recursively because the call to load a unit
1647 -- caused by an upper level call may perform a recursive call
1648 -- to this routine during analysis of the corresponding unit.
1651 RTE_Available_Call := True;
1652 RTE_Is_Available := True;
1654 Result := RTE_Is_Available;
1655 RTE_Available_Call := Save_RTE_Available_Call;
1656 RTE_Is_Available := Save_RTE_Is_Available;
1660 when RE_Not_Available =>
1661 RTE_Available_Call := Save_RTE_Available_Call;
1662 RTE_Is_Available := Save_RTE_Is_Available;
1666 --------------------------
1667 -- RTE_Record_Component --
1668 --------------------------
1670 function RTE_Record_Component (E : RE_Id) return Entity_Id is
1671 U_Id : constant RTU_Id := RE_Unit_Table (E);
1672 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
1675 Found_E : Entity_Id;
1677 Pkg_Ent : Entity_Id;
1679 -- The following flag is used to disable front-end inlining when
1680 -- RTE_Record_Component is invoked. This prevents the analysis of other
1681 -- runtime bodies when a particular spec is loaded through Rtsfind. This
1682 -- is both efficient, and it prevents spurious visibility conflicts
1683 -- between use-visible user entities, and entities in run-time packages.
1685 Save_Front_End_Inlining : Boolean;
1688 -- Note: Contrary to subprogram RTE, there is no need to do any special
1689 -- management with package system.ads because it has no record type
1692 Save_Front_End_Inlining := Front_End_Inlining;
1693 Front_End_Inlining := False;
1695 -- Load unit if unit not previously loaded
1697 if No (U.Entity) then
1698 Load_RTU (U_Id, Id => E);
1701 Lib_Unit := Unit (Cunit (U.Unum));
1703 pragma Assert (Nkind (Lib_Unit) = N_Package_Declaration);
1704 Ename := RE_Chars (E);
1706 -- Search the entity in the components of record type declarations
1707 -- found in the package entity chain.
1710 Pkg_Ent := First_Entity (U.Entity);
1711 Search : while Present (Pkg_Ent) loop
1712 if Is_Record_Type (Pkg_Ent) then
1713 E1 := First_Entity (Pkg_Ent);
1714 while Present (E1) loop
1715 if Ename = Chars (E1) then
1716 pragma Assert (No (Found_E));
1724 Next_Entity (Pkg_Ent);
1727 -- If we didn't find the entity we want, something is wrong. The
1728 -- appropriate action will be taken by Check_CRT when we exit.
1732 Front_End_Inlining := Save_Front_End_Inlining;
1733 return Check_CRT (E, Found_E);
1734 end RTE_Record_Component;
1736 ------------------------------------
1737 -- RTE_Record_Component_Available --
1738 ------------------------------------
1740 function RTE_Record_Component_Available (E : RE_Id) return Boolean is
1742 pragma Warnings (Off, Dummy);
1746 Save_RTE_Available_Call : constant Boolean := RTE_Available_Call;
1747 Save_RTE_Is_Available : constant Boolean := RTE_Is_Available;
1748 -- These are saved recursively because the call to load a unit
1749 -- caused by an upper level call may perform a recursive call
1750 -- to this routine during analysis of the corresponding unit.
1753 RTE_Available_Call := True;
1754 RTE_Is_Available := True;
1755 Dummy := RTE_Record_Component (E);
1756 Result := RTE_Is_Available;
1757 RTE_Available_Call := Save_RTE_Available_Call;
1758 RTE_Is_Available := Save_RTE_Is_Available;
1762 when RE_Not_Available =>
1763 RTE_Available_Call := Save_RTE_Available_Call;
1764 RTE_Is_Available := Save_RTE_Is_Available;
1766 end RTE_Record_Component_Available;
1772 procedure RTE_Error_Msg (Msg : String) is
1774 if RTE_Available_Call then
1775 RTE_Is_Available := False;
1777 Error_Msg_N (Msg, Current_Error_Node);
1779 -- Bump count of violations if we are in configurable run-time
1780 -- mode and this is not a continuation message.
1782 if Configurable_Run_Time_Mode and then Msg (Msg'First) /= '\' then
1783 Configurable_Run_Time_Violations :=
1784 Configurable_Run_Time_Violations + 1;
1793 function RTU_Entity (U : RTU_Id) return Entity_Id is
1795 return RT_Unit_Table (U).Entity;
1802 function RTU_Loaded (U : RTU_Id) return Boolean is
1804 return Present (RT_Unit_Table (U).Entity);
1807 --------------------
1808 -- Set_RTU_Loaded --
1809 --------------------
1811 procedure Set_RTU_Loaded (N : Node_Id) is
1812 Loc : constant Source_Ptr := Sloc (N);
1813 Unum : constant Unit_Number_Type := Get_Source_Unit (Loc);
1814 Uname : constant Unit_Name_Type := Unit_Name (Unum);
1815 E : constant Entity_Id :=
1816 Defining_Entity (Unit (Cunit (Unum)));
1818 pragma Assert (Is_Predefined_Unit (Unum));
1820 -- Loop through entries in RTU table looking for matching entry
1822 for U_Id in RTU_Id'Range loop
1824 -- Here we have a match
1826 if Get_Unit_Name (U_Id) = Uname then
1828 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
1829 -- The RT_Unit_Table entry that may need updating
1832 -- If entry is not set, set it now, and indicate that it was
1833 -- loaded through an explicit context clause.
1835 if No (U.Entity) then
1837 Uname => Get_Unit_Name (U_Id),
1839 First_Implicit_With => Empty);
1848 -------------------------
1849 -- SPARK_Implicit_Load --
1850 -------------------------
1852 procedure SPARK_Implicit_Load (E : RE_Id) is
1854 pragma Assert (GNATprove_Mode);
1856 -- Force loading of a predefined unit
1858 Discard_Node (RTE (E));
1859 end SPARK_Implicit_Load;