1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Casing; use Casing;
29 with Csets; use Csets;
30 with Debug; use Debug;
31 with Einfo; use Einfo;
32 with Elists; use Elists;
33 with Errout; use Errout;
34 with Fname; use Fname;
35 with Fname.UF; use Fname.UF;
36 with Gnatvsn; use Gnatvsn;
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;
44 with Restrict; use Restrict;
46 with Sem_Ch7; use Sem_Ch7;
47 with Sem_Dist; use Sem_Dist;
48 with Sem_Util; use Sem_Util;
49 with Sinfo; use Sinfo;
50 with Stand; use Stand;
51 with Snames; use Snames;
52 with Tbuild; use Tbuild;
53 with Uname; use Uname;
55 package body Rtsfind is
57 RTE_Available_Call : Boolean := False;
58 -- Set True during call to RTE from RTE_Available (or from call to
59 -- RTE_Record_Component from RTE_Record_Component_Available). Tells
60 -- the called subprogram to set RTE_Is_Available to False rather than
61 -- generating an error message.
63 RTE_Is_Available : Boolean;
64 -- Set True by RTE_Available on entry. When RTE_Available_Call is set
65 -- True, set False if RTE would otherwise generate an error message.
71 -- The unit table has one entry for each unit included in the definition
72 -- of the type RTU_Id in the spec. The table entries are initialized in
73 -- Initialize to set the Entity field to Empty, indicating that the
74 -- corresponding unit has not yet been loaded. The fields are set when
75 -- a unit is loaded to contain the defining entity for the unit, the
76 -- unit name, and the unit number.
78 -- Note that a unit can be loaded either by a call to find an entity
79 -- within the unit (e.g. RTE), or by an explicit with of the unit. In
80 -- the latter case it is critical to make a call to Set_RTU_Loaded to
81 -- ensure that the entry in this table reflects the load.
83 type RT_Unit_Table_Record is record
85 Uname : Unit_Name_Type;
86 Unum : Unit_Number_Type;
90 RT_Unit_Table : array (RTU_Id) of RT_Unit_Table_Record;
92 --------------------------
93 -- Runtime Entity Table --
94 --------------------------
96 -- There is one entry in the runtime entity table for each entity that is
97 -- included in the definition of the RE_Id type in the spec. The entries
98 -- are set by Initialize_Rtsfind to contain Empty, indicating that the
99 -- entity has not yet been located. Once the entity is located for the
100 -- first time, its ID is stored in this array, so that subsequent calls
101 -- for the same entity can be satisfied immediately.
103 -- NOTE: In order to avoid conflicts between record components and subprgs
104 -- that have the same name (ie. subprogram External_Tag and component
105 -- External_Tag of package Ada.Tags) this table is not used with
106 -- Record_Components.
108 RE_Table : array (RE_Id) of Entity_Id;
110 --------------------------
111 -- Generation of WITH's --
112 --------------------------
114 -- When a unit is implicitly loaded as a result of a call to RTE, it
115 -- is necessary to create an implicit WITH to ensure that the object
116 -- is correctly loaded by the binder. Such WITH statements are only
117 -- required when the request is from the extended main unit (if a
118 -- client needs a WITH, that will be taken care of when the client
121 -- We always attach the WITH to the main unit. This is not perfectly
122 -- accurate in terms of elaboration requirements, but it is close
123 -- enough, since the units that are accessed using rtsfind do not
124 -- have delicate elaboration requirements.
126 -- The flag Withed in the unit table record is initially set to False.
127 -- It is set True if a WITH has been generated for the main unit for
128 -- the corresponding unit.
130 -----------------------
131 -- Local Subprograms --
132 -----------------------
134 function Check_CRT (E : RE_Id; Eid : Entity_Id) return Entity_Id;
135 -- Check entity Eid to ensure that configurable run-time restrictions
136 -- are met. May generate an error message and raise RE_Not_Available
137 -- if the entity E does not exist (i.e. Eid is Empty)
139 procedure Entity_Not_Defined (Id : RE_Id);
140 -- Outputs error messages for an entity that is not defined in the
141 -- run-time library (the form of the error message is tailored for
142 -- no run time/configurable run time mode as required).
144 function Get_Unit_Name (U_Id : RTU_Id) return Unit_Name_Type;
145 -- Retrieves the Unit Name given a unit id represented by its
146 -- enumeration value in RTU_Id.
148 procedure Load_Fail (S : String; U_Id : RTU_Id; Id : RE_Id);
149 -- Internal procedure called if we can't sucessfully locate or
150 -- process a run-time unit. The parameters give information about
151 -- the error message to be given. S is a reason for failing to
152 -- compile the file and U_Id is the unit id. RE_Id is the RE_Id
153 -- originally passed to RTE. The message in S is one of the
157 -- "had parser errors"
158 -- "had semantic errors"
160 -- The "not found" case is treated specially in that it is considered
161 -- a normal situation in configurable run-time mode (and the message in
162 -- this case is suppressed unless we are operating in All_Errors_Mode).
166 Id : RE_Id := RE_Null;
167 Use_Setting : Boolean := False);
168 -- Load the unit whose Id is given if not already loaded. The unit is
169 -- loaded, analyzed, and added to the WITH list, and the entry in
170 -- RT_Unit_Table is updated to reflect the load. Use_Setting is used
171 -- to indicate the initial setting for the Is_Potentially_Use_Visible
172 -- flag of the entity for the loaded unit (if it is indeed loaded).
173 -- A value of False means nothing special need be done. A value of
174 -- True indicates that this flag must be set to True. It is needed
175 -- only in the Text_IO_Kludge procedure, which may materialize an
176 -- entity of Text_IO (or [Wide_]Wide_Text_IO) that was previously unknown.
177 -- Id is the RE_Id value of the entity which was originally requested.
178 -- Id is used only for error message detail, and if it is RE_Null, then
179 -- the attempt to output the entity name is ignored.
181 function Make_Unit_Name (E : RE_Id; N : Node_Id) return Node_Id;
182 -- If the unit is a child unit, build fully qualified name for use in
185 procedure Output_Entity_Name (Id : RE_Id; Msg : String);
186 -- Output continuation error message giving qualified name of entity
187 -- corresponding to Id, appending the string given by Msg. This call
188 -- is only effective in All_Errors mode.
190 function RE_Chars (E : RE_Id) return Name_Id;
191 -- Given a RE_Id value returns the Chars of the corresponding entity
193 procedure RTE_Error_Msg (Msg : String);
194 -- Generates a message by calling Error_Msg_N specifying Current_Error_Node
195 -- as the node location using the given Msg text. Special processing in the
196 -- case where RTE_Available_Call is set. In this case, no message is output
197 -- and instead RTE_Is_Available is set to False. Note that this can only be
198 -- used if you are sure that the message comes directly or indirectly from
199 -- a call to the RTE function.
205 function Check_CRT (E : RE_Id; Eid : Entity_Id) return Entity_Id is
206 U_Id : constant RTU_Id := RE_Unit_Table (E);
210 Entity_Not_Defined (E);
211 raise RE_Not_Available;
213 -- Entity is available
216 -- If in No_Run_Time mode and entity is not in one of the
217 -- specially permitted units, raise the exception.
220 and then not OK_No_Run_Time_Unit (U_Id)
222 Entity_Not_Defined (E);
223 raise RE_Not_Available;
226 -- Otherwise entity is accessible
232 ------------------------
233 -- Entity_Not_Defined --
234 ------------------------
236 procedure Entity_Not_Defined (Id : RE_Id) is
238 if No_Run_Time_Mode then
240 -- If the error occurs when compiling the body of a predefined
241 -- unit for inlining purposes, the body must be illegal in this
242 -- mode, and there is no point in continuing.
244 if Is_Predefined_File_Name
245 (Unit_File_Name (Get_Source_Unit (Sloc (Current_Error_Node))))
248 ("construct not allowed in no run time mode!",
250 raise Unrecoverable_Error;
253 RTE_Error_Msg ("|construct not allowed in no run time mode");
256 elsif Configurable_Run_Time_Mode then
257 RTE_Error_Msg ("|construct not allowed in this configuration>");
259 RTE_Error_Msg ("run-time configuration error");
262 Output_Entity_Name (Id, "not defined");
263 end Entity_Not_Defined;
269 function Get_Unit_Name (U_Id : RTU_Id) return Unit_Name_Type is
270 Uname_Chars : constant String := RTU_Id'Image (U_Id);
273 Name_Len := Uname_Chars'Length;
274 Name_Buffer (1 .. Name_Len) := Uname_Chars;
275 Set_Casing (All_Lower_Case);
277 if U_Id in Ada_Child then
278 Name_Buffer (4) := '.';
280 if U_Id in Ada_Calendar_Child then
281 Name_Buffer (13) := '.';
283 elsif U_Id in Ada_Finalization_Child then
284 Name_Buffer (17) := '.';
286 elsif U_Id in Ada_Interrupts_Child then
287 Name_Buffer (15) := '.';
289 elsif U_Id in Ada_Real_Time_Child then
290 Name_Buffer (14) := '.';
292 elsif U_Id in Ada_Streams_Child then
293 Name_Buffer (12) := '.';
295 elsif U_Id in Ada_Text_IO_Child then
296 Name_Buffer (12) := '.';
298 elsif U_Id in Ada_Wide_Text_IO_Child then
299 Name_Buffer (17) := '.';
301 elsif U_Id in Ada_Wide_Wide_Text_IO_Child then
302 Name_Buffer (22) := '.';
305 elsif U_Id in Interfaces_Child then
306 Name_Buffer (11) := '.';
308 elsif U_Id in System_Child then
309 Name_Buffer (7) := '.';
311 if U_Id in System_Tasking_Child then
312 Name_Buffer (15) := '.';
315 if U_Id in System_Tasking_Restricted_Child then
316 Name_Buffer (26) := '.';
319 if U_Id in System_Tasking_Protected_Objects_Child then
320 Name_Buffer (33) := '.';
323 if U_Id in System_Tasking_Async_Delays_Child then
324 Name_Buffer (28) := '.';
328 -- Add %s at end for spec
330 Name_Buffer (Name_Len + 1) := '%';
331 Name_Buffer (Name_Len + 2) := 's';
332 Name_Len := Name_Len + 2;
341 procedure Initialize is
343 -- Initialize the unit table
346 RT_Unit_Table (J).Entity := Empty;
350 RE_Table (J) := Empty;
353 RTE_Is_Available := False;
360 function Is_RTE (Ent : Entity_Id; E : RE_Id) return Boolean is
361 E_Unit_Name : Unit_Name_Type;
362 Ent_Unit_Name : Unit_Name_Type;
372 -- If E has already a corresponding entity, check it directly,
373 -- going to full views if they exist to deal with the incomplete
374 -- and private type cases properly.
376 elsif Present (RE_Table (E)) then
379 if Is_Type (E1) and then Present (Full_View (E1)) then
380 E1 := Full_View (E1);
385 if Is_Type (E2) and then Present (Full_View (E2)) then
386 E2 := Full_View (E2);
392 -- If the unit containing E is not loaded, we already know that
393 -- the entity we have cannot have come from this unit.
395 E_Unit_Name := Get_Unit_Name (RE_Unit_Table (E));
397 if not Is_Loaded (E_Unit_Name) then
401 -- Here the unit containing the entity is loaded. We have not made
402 -- an explicit call to RTE to get the entity in question, but we may
403 -- have obtained a reference to it indirectly from some other entity
404 -- in the same unit, or some other unit that references it.
406 -- Get the defining unit of the entity
410 if Ekind (S) /= E_Package then
414 Ent_Unit_Name := Get_Unit_Name (Unit_Declaration_Node (S));
416 -- If the defining unit of the entity we are testing is not the
417 -- unit containing E, then they cannot possibly match.
419 if Ent_Unit_Name /= E_Unit_Name then
423 -- If the units match, then compare the names (remember that no
424 -- overloading is permitted in entities fetched using Rtsfind).
426 if RE_Chars (E) = Chars (Ent) then
429 -- If front-end inlining is enabled, we may be within a body that
430 -- contains inlined functions, which has not been retrieved through
431 -- rtsfind, and therefore is not yet recorded in the RT_Unit_Table.
432 -- Add the unit information now, it must be fully available.
435 U : RT_Unit_Table_Record
436 renames RT_Unit_Table (RE_Unit_Table (E));
438 if No (U.Entity) then
440 U.Uname := E_Unit_Name;
441 U.Unum := Get_Source_Unit (S);
455 function Is_RTU (Ent : Entity_Id; U : RTU_Id) return Boolean is
456 E : constant Entity_Id := RT_Unit_Table (U).Entity;
458 return Present (E) and then E = Ent;
461 ----------------------------
462 -- Is_Text_IO_Kludge_Unit --
463 ----------------------------
465 function Is_Text_IO_Kludge_Unit (Nam : Node_Id) return Boolean is
470 if Nkind (Nam) /= N_Expanded_Name then
475 Sel := Selector_Name (Nam);
477 if Nkind (Sel) /= N_Expanded_Name
478 or else Nkind (Prf) /= N_Identifier
479 or else Chars (Prf) /= Name_Ada
485 Sel := Selector_Name (Sel);
488 Nkind (Prf) = N_Identifier
490 (Chars (Prf) = Name_Text_IO
492 Chars (Prf) = Name_Wide_Text_IO
494 Chars (Prf) = Name_Wide_Wide_Text_IO)
496 Nkind (Sel) = N_Identifier
498 Chars (Sel) in Text_IO_Package_Name;
499 end Is_Text_IO_Kludge_Unit;
505 procedure Load_Fail (S : String; U_Id : RTU_Id; Id : RE_Id) is
506 M : String (1 .. 100);
510 -- Output header message
512 if Configurable_Run_Time_Mode then
513 RTE_Error_Msg ("construct not allowed in configurable run-time mode");
515 RTE_Error_Msg ("run-time library configuration error");
518 -- Output file name and reason string
521 or else not Configurable_Run_Time_Mode
522 or else All_Errors_Mode
524 M (1 .. 6) := "\file ";
528 (Get_File_Name (RT_Unit_Table (U_Id).Uname, Subunit => False));
529 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
535 M (P + 1 .. P + S'Length) := S;
538 RTE_Error_Msg (M (1 .. P));
540 -- Output entity name
542 Output_Entity_Name (Id, "not available");
545 -- In configurable run time mode, we raise RE_Not_Available, and we hope
546 -- the caller deals gracefully with this. If we are in normal full run
547 -- time mode, a load failure is considered fatal and unrecoverable.
549 if Configurable_Run_Time_Mode then
550 raise RE_Not_Available;
552 raise Unrecoverable_Error;
562 Id : RE_Id := RE_Null;
563 Use_Setting : Boolean := False)
565 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
566 Priv_Par : constant Elist_Id := New_Elmt_List;
569 procedure Save_Private_Visibility;
570 -- If the current unit is the body of child unit or the spec of a
571 -- private child unit, the private declarations of the parent (s)
572 -- are visible. If the unit to be loaded is another public sibling,
573 -- its compilation will affect the visibility of the common ancestors.
574 -- Indicate those that must be restored.
576 procedure Restore_Private_Visibility;
577 -- Restore the visibility of ancestors after compiling RTU
579 --------------------------------
580 -- Restore_Private_Visibility --
581 --------------------------------
583 procedure Restore_Private_Visibility is
587 E_Par := First_Elmt (Priv_Par);
589 while Present (E_Par) loop
590 if not In_Private_Part (Node (E_Par)) then
591 Install_Private_Declarations (Node (E_Par));
596 end Restore_Private_Visibility;
598 -----------------------------
599 -- Save_Private_Visibility --
600 -----------------------------
602 procedure Save_Private_Visibility is
606 Par := Scope (Current_Scope);
609 and then Par /= Standard_Standard
611 if Ekind (Par) = E_Package
612 and then Is_Compilation_Unit (Par)
613 and then In_Private_Part (Par)
615 Append_Elmt (Par, Priv_Par);
620 end Save_Private_Visibility;
622 -- Start of processing for Load_RTU
625 -- Nothing to do if unit is already loaded
627 if Present (U.Entity) then
631 -- Note if secondary stack is used
633 if U_Id = System_Secondary_Stack then
634 Opt.Sec_Stack_Used := True;
637 -- Otherwise we need to load the unit, First build unit name
638 -- from the enumeration literal name in type RTU_Id.
640 U.Uname := Get_Unit_Name (U_Id);
645 pragma Warnings (Off, Loaded);
647 Loaded := Is_Loaded (U.Uname);
650 -- Now do the load call, note that setting Error_Node to Empty is
651 -- a signal to Load_Unit that we will regard a failure to find the
652 -- file as a fatal error, and that it should not output any kind
653 -- of diagnostics, since we will take care of it here.
657 (Load_Name => U.Uname,
660 Error_Node => Empty);
662 if U.Unum = No_Unit then
663 Load_Fail ("not found", U_Id, Id);
664 elsif Fatal_Error (U.Unum) then
665 Load_Fail ("had parser errors", U_Id, Id);
668 -- Make sure that the unit is analyzed
671 Was_Analyzed : constant Boolean :=
672 Analyzed (Cunit (Current_Sem_Unit));
675 -- Pretend that the current unit is analyzed, in case it is System
676 -- or some such. This allows us to put some declarations, such as
677 -- exceptions and packed arrays of Boolean, into System even though
678 -- expanding them requires System...
680 -- This is a bit odd but works fine. If the RTS unit does not depend
681 -- in any way on the current unit, then it never gets back into the
682 -- current unit's tree, and the change we make to the current unit
683 -- tree is never noticed by anyone (it is undone in a moment). That
684 -- is the normal situation.
686 -- If the RTS Unit *does* depend on the current unit, for instance,
687 -- when you are compiling System, then you had better have finished
688 -- analyzing the part of System that is depended on before you try
689 -- to load the RTS Unit. This means having the System ordered in an
690 -- appropriate manner.
692 Set_Analyzed (Cunit (Current_Sem_Unit), True);
694 if not Analyzed (Cunit (U.Unum)) then
696 -- If the unit is already loaded through a limited_with clauses,
697 -- the relevant entities must already be available. We do not
698 -- want to load and analyze the unit because this would create
699 -- a real semantic dependence when the purpose of the limited_with
700 -- is precisely to avoid such.
702 if From_With_Type (Cunit_Entity (U.Unum)) then
706 Save_Private_Visibility;
707 Semantics (Cunit (U.Unum));
708 Restore_Private_Visibility;
710 if Fatal_Error (U.Unum) then
711 Load_Fail ("had semantic errors", U_Id, Id);
718 Set_Analyzed (Cunit (Current_Sem_Unit), Was_Analyzed);
721 Lib_Unit := Unit (Cunit (U.Unum));
722 U.Entity := Defining_Entity (Lib_Unit);
725 Set_Is_Potentially_Use_Visible (U.Entity, True);
733 function Make_Unit_Name (E : RE_Id; N : Node_Id) return Node_Id is
734 U_Id : constant RTU_Id := RE_Unit_Table (E);
735 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
740 Nam := New_Reference_To (U.Entity, Standard_Location);
741 Scop := Scope (U.Entity);
743 if Nkind (N) = N_Defining_Program_Unit_Name then
744 while Scop /= Standard_Standard loop
746 Make_Expanded_Name (Standard_Location,
747 Chars => Chars (U.Entity),
748 Prefix => New_Reference_To (Scop, Standard_Location),
749 Selector_Name => Nam);
750 Set_Entity (Nam, U.Entity);
752 Scop := Scope (Scop);
759 -----------------------
760 -- Output_Entity_Name --
761 ------------------------
763 procedure Output_Entity_Name (Id : RE_Id; Msg : String) is
764 M : String (1 .. 2048);
766 -- M (1 .. P) is current message to be output
768 RE_Image : constant String := RE_Id'Image (Id);
771 if Id = RE_Null or else not All_Errors_Mode then
775 M (1 .. 9) := "\entity """;
778 -- Add unit name to message, excluding %s or %b at end
780 Get_Name_String (Get_Unit_Name (RE_Unit_Table (Id)));
781 Name_Len := Name_Len - 2;
782 Set_Casing (Mixed_Case);
783 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
786 -- Add a qualifying period
791 -- Add entity name and closing quote to message
793 Name_Len := RE_Image'Length - 3;
794 Name_Buffer (1 .. Name_Len) := RE_Image (4 .. RE_Image'Length);
795 Set_Casing (Mixed_Case);
796 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
805 M (P + 1 .. P + Msg'Length) := Msg;
808 -- Output message at current error node location
810 RTE_Error_Msg (M (1 .. P));
811 end Output_Entity_Name;
817 function RE_Chars (E : RE_Id) return Name_Id is
818 RE_Name_Chars : constant String := RE_Id'Image (E);
821 -- Copy name skipping initial RE_ or RO_XX characters
823 if RE_Name_Chars (1 .. 2) = "RE" then
824 for J in 4 .. RE_Name_Chars'Last loop
825 Name_Buffer (J - 3) := Fold_Lower (RE_Name_Chars (J));
828 Name_Len := RE_Name_Chars'Length - 3;
831 for J in 7 .. RE_Name_Chars'Last loop
832 Name_Buffer (J - 6) := Fold_Lower (RE_Name_Chars (J));
835 Name_Len := RE_Name_Chars'Length - 6;
845 function RTE (E : RE_Id) return Entity_Id is
846 U_Id : constant RTU_Id := RE_Unit_Table (E);
847 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
853 -- The following flag is used to disable front-end inlining when RTE
854 -- is invoked. This prevents the analysis of other runtime bodies when
855 -- a particular spec is loaded through Rtsfind. This is both efficient,
856 -- and it prevents spurious visibility conflicts between use-visible
857 -- user entities, and entities in run-time packages.
859 -- In configurable run-time mode, subprograms marked Inlined_Always must
860 -- be inlined, so in the case we retain the Front_End_Inlining mode.
862 Save_Front_End_Inlining : Boolean;
865 -- Reject programs that make use of distribution features not supported
866 -- on the current target. Also check that the PCS is compatible with
867 -- the code generator version. On such targets (VMS, Vxworks, others?)
868 -- we provide a minimal body for System.Rpc that only supplies an
869 -- implementation of Partition_Id.
871 function Find_Local_Entity (E : RE_Id) return Entity_Id;
872 -- This function is used when entity E is in this compilation's main
873 -- unit. It gets the value from the already compiled declaration.
879 procedure Check_RPC is
881 procedure Check_RPC_Failure (Msg : String);
882 pragma No_Return (Check_RPC_Failure);
883 -- Display Msg on standard error and raise Unrecoverable_Error
885 -----------------------
886 -- Check_RPC_Failure --
887 -----------------------
889 procedure Check_RPC_Failure (Msg : String) is
894 raise Unrecoverable_Error;
895 end Check_RPC_Failure;
897 -- Start of processing for Check_RPC
900 -- Bypass this check if debug flag -gnatdR set
902 if Debug_Flag_RR then
906 -- Otherwise we need the check if we are going after one of
907 -- the critical entities in System.RPC in stubs mode.
909 -- ??? Should we do this for other s-parint entities too?
911 if (Distribution_Stub_Mode = Generate_Receiver_Stub_Body
913 Distribution_Stub_Mode = Generate_Caller_Stub_Body)
914 and then (E = RE_Do_Rpc
918 E = RE_Params_Stream_Type
920 E = RE_Request_Access)
922 if Get_PCS_Name = Name_No_DSA then
923 Check_RPC_Failure ("distribution feature not supported");
925 elsif Get_PCS_Version /= Gnatvsn.PCS_Version_Number then
926 Check_RPC_Failure ("PCS version mismatch");
932 -----------------------
933 -- Find_Local_Entity --
934 -----------------------
936 function Find_Local_Entity (E : RE_Id) return Entity_Id is
937 RE_Str : constant String := RE_Id'Image (E);
941 Save_Nam : constant String := Name_Buffer (1 .. Name_Len);
942 -- Save name buffer and length over call
945 Name_Len := Natural'Max (0, RE_Str'Length - 3);
946 Name_Buffer (1 .. Name_Len) :=
947 RE_Str (RE_Str'First + 3 .. RE_Str'Last);
950 Ent := Entity_Id (Get_Name_Table_Info (Nam));
952 Name_Len := Save_Nam'Length;
953 Name_Buffer (1 .. Name_Len) := Save_Nam;
956 end Find_Local_Entity;
958 -- Start of processing for RTE
961 -- Doing a rtsfind in system.ads is special, as we cannot do this
962 -- when compiling System itself. So if we are compiling system then
963 -- we should already have acquired and processed the declaration
964 -- of the entity. The test is to see if this compilation's main unit
965 -- is System. If so, return the value from the already compiled
966 -- declaration and otherwise do a regular find.
968 -- Not pleasant, but these kinds of annoying recursion when
969 -- writing an Ada compiler in Ada have to be broken somewhere!
971 if Present (Main_Unit_Entity)
972 and then Chars (Main_Unit_Entity) = Name_System
973 and then Analyzed (Main_Unit_Entity)
974 and then not Is_Child_Unit (Main_Unit_Entity)
976 return Check_CRT (E, Find_Local_Entity (E));
979 Save_Front_End_Inlining := Front_End_Inlining;
980 Front_End_Inlining := Configurable_Run_Time_Mode;
982 -- Load unit if unit not previously loaded
984 if No (RE_Table (E)) then
985 Load_RTU (U_Id, Id => E);
986 Lib_Unit := Unit (Cunit (U.Unum));
988 -- In the subprogram case, we are all done, the entity we want
989 -- is the entity for the subprogram itself. Note that we do not
990 -- bother to check that it is the entity that was requested.
991 -- the only way that could fail to be the case is if runtime is
992 -- hopelessly misconfigured, and it isn't worth testing for this.
994 if Nkind (Lib_Unit) = N_Subprogram_Declaration then
995 RE_Table (E) := U.Entity;
997 -- Otherwise we must have the package case. First check package
998 -- entity itself (e.g. RTE_Name for System.Interrupts.Name)
1001 pragma Assert (Nkind (Lib_Unit) = N_Package_Declaration);
1002 Ename := RE_Chars (E);
1004 -- First we search the package entity chain. If the package
1005 -- only has a limited view, scan the corresponding list of
1006 -- incomplete types.
1008 if From_With_Type (U.Entity) then
1009 Pkg_Ent := First_Entity (Limited_View (U.Entity));
1011 Pkg_Ent := First_Entity (U.Entity);
1014 while Present (Pkg_Ent) loop
1015 if Ename = Chars (Pkg_Ent) then
1016 RE_Table (E) := Pkg_Ent;
1021 Next_Entity (Pkg_Ent);
1024 -- If we did not find the entity in the package entity chain,
1025 -- then check if the package entity itself matches. Note that
1026 -- we do this check after searching the entity chain, since
1027 -- the rule is that in case of ambiguity, we prefer the entity
1028 -- defined within the package, rather than the package itself.
1030 if Ename = Chars (U.Entity) then
1031 RE_Table (E) := U.Entity;
1034 -- If we didn't find the entity we want, something is wrong.
1035 -- We just leave RE_Table (E) set to Empty and the appropriate
1036 -- action will be taken by Check_CRT when we exit.
1041 -- See if we have to generate a WITH for this entity. We generate
1042 -- a WITH if the current unit is part of the extended main code
1043 -- unit, and if we have not already added the with. The WITH is
1044 -- added to the appropriate unit (the current one). We do not need
1045 -- to generate a WITH for a call issued from RTE_Available.
1050 In_Extended_Main_Code_Unit (Cunit_Entity (Current_Sem_Unit))
1051 and then not RTE_Available_Call
1060 Lib_Unit := Unit (Cunit (U.Unum));
1062 Make_With_Clause (Standard_Location,
1065 (E, Defining_Unit_Name (Specification (Lib_Unit))));
1066 Set_Library_Unit (Withn, Cunit (U.Unum));
1067 Set_Corresponding_Spec (Withn, U.Entity);
1068 Set_First_Name (Withn, True);
1069 Set_Implicit_With (Withn, True);
1071 Mark_Rewrite_Insertion (Withn);
1072 Append (Withn, Context_Items (Cunit (Current_Sem_Unit)));
1073 Check_Restriction_No_Dependence (Name (Withn), Current_Error_Node);
1077 Front_End_Inlining := Save_Front_End_Inlining;
1078 return Check_CRT (E, RE_Table (E));
1085 function RTE_Available (E : RE_Id) return Boolean is
1087 pragma Warnings (Off, Dummy);
1091 Save_RTE_Available_Call : constant Boolean := RTE_Available_Call;
1092 Save_RTE_Is_Available : constant Boolean := RTE_Is_Available;
1093 -- These are saved recursively because the call to load a unit
1094 -- caused by an upper level call may perform a recursive call
1095 -- to this routine during analysis of the corresponding unit.
1098 RTE_Available_Call := True;
1099 RTE_Is_Available := True;
1101 Result := RTE_Is_Available;
1102 RTE_Available_Call := Save_RTE_Available_Call;
1103 RTE_Is_Available := Save_RTE_Is_Available;
1107 when RE_Not_Available =>
1108 RTE_Available_Call := Save_RTE_Available_Call;
1109 RTE_Is_Available := Save_RTE_Is_Available;
1113 --------------------------
1114 -- RTE_Record_Component --
1115 --------------------------
1117 function RTE_Record_Component (E : RE_Id) return Entity_Id is
1118 U_Id : constant RTU_Id := RE_Unit_Table (E);
1119 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
1122 Found_E : Entity_Id;
1124 Pkg_Ent : Entity_Id;
1126 -- The following flag is used to disable front-end inlining when
1127 -- RTE_Record_Component is invoked. This prevents the analysis of other
1128 -- runtime bodies when a particular spec is loaded through Rtsfind. This
1129 -- is both efficient, and it prevents spurious visibility conflicts
1130 -- between use-visible user entities, and entities in run-time packages.
1132 -- In configurable run-time mode, subprograms marked Inlined_Always must
1133 -- be inlined, so in the case we retain the Front_End_Inlining mode.
1135 Save_Front_End_Inlining : Boolean;
1138 -- Note: Contrary to subprogram RTE, there is no need to do any special
1139 -- management with package system.ads because it has no record type
1142 Save_Front_End_Inlining := Front_End_Inlining;
1143 Front_End_Inlining := Configurable_Run_Time_Mode;
1145 -- Load unit if unit not previously loaded
1147 if not Present (U.Entity) then
1148 Load_RTU (U_Id, Id => E);
1151 Lib_Unit := Unit (Cunit (U.Unum));
1153 pragma Assert (Nkind (Lib_Unit) = N_Package_Declaration);
1154 Ename := RE_Chars (E);
1156 -- Search the entity in the components of record type declarations
1157 -- found in the package entity chain.
1160 Pkg_Ent := First_Entity (U.Entity);
1161 Search : while Present (Pkg_Ent) loop
1162 if Is_Record_Type (Pkg_Ent) then
1163 E1 := First_Entity (Pkg_Ent);
1164 while Present (E1) loop
1165 if Ename = Chars (E1) then
1166 pragma Assert (not Present (Found_E));
1174 Next_Entity (Pkg_Ent);
1177 -- If we didn't find the entity we want, something is wrong. The
1178 -- appropriate action will be taken by Check_CRT when we exit.
1180 -- Cenerate a with-clause if the current unit is part of the extended
1181 -- main code unit, and if we have not already added the with. The clause
1182 -- is added to the appropriate unit (the current one). We do not need to
1183 -- generate it for a call issued from RTE_Component_Available.
1187 In_Extended_Main_Code_Unit (Cunit_Entity (Current_Sem_Unit))
1188 and then not RTE_Available_Call
1197 Lib_Unit := Unit (Cunit (U.Unum));
1199 Make_With_Clause (Standard_Location,
1202 (E, Defining_Unit_Name (Specification (Lib_Unit))));
1203 Set_Library_Unit (Withn, Cunit (U.Unum));
1204 Set_Corresponding_Spec (Withn, U.Entity);
1205 Set_First_Name (Withn, True);
1206 Set_Implicit_With (Withn, True);
1208 Mark_Rewrite_Insertion (Withn);
1209 Append (Withn, Context_Items (Cunit (Current_Sem_Unit)));
1210 Check_Restriction_No_Dependence (Name (Withn), Current_Error_Node);
1214 Front_End_Inlining := Save_Front_End_Inlining;
1215 return Check_CRT (E, Found_E);
1216 end RTE_Record_Component;
1218 ------------------------------------
1219 -- RTE_Record_Component_Available --
1220 ------------------------------------
1222 function RTE_Record_Component_Available (E : RE_Id) return Boolean is
1224 pragma Warnings (Off, Dummy);
1228 Save_RTE_Available_Call : constant Boolean := RTE_Available_Call;
1229 Save_RTE_Is_Available : constant Boolean := RTE_Is_Available;
1230 -- These are saved recursively because the call to load a unit
1231 -- caused by an upper level call may perform a recursive call
1232 -- to this routine during analysis of the corresponding unit.
1235 RTE_Available_Call := True;
1236 RTE_Is_Available := True;
1237 Dummy := RTE_Record_Component (E);
1238 Result := RTE_Is_Available;
1239 RTE_Available_Call := Save_RTE_Available_Call;
1240 RTE_Is_Available := Save_RTE_Is_Available;
1244 when RE_Not_Available =>
1245 RTE_Available_Call := Save_RTE_Available_Call;
1246 RTE_Is_Available := Save_RTE_Is_Available;
1248 end RTE_Record_Component_Available;
1254 procedure RTE_Error_Msg (Msg : String) is
1256 if RTE_Available_Call then
1257 RTE_Is_Available := False;
1259 Error_Msg_N (Msg, Current_Error_Node);
1261 -- Bump count of violations if we are in configurable run-time
1262 -- mode and this is not a continuation message.
1264 if Configurable_Run_Time_Mode and then Msg (Msg'First) /= '\' then
1265 Configurable_Run_Time_Violations :=
1266 Configurable_Run_Time_Violations + 1;
1275 function RTU_Entity (U : RTU_Id) return Entity_Id is
1277 return RT_Unit_Table (U).Entity;
1284 function RTU_Loaded (U : RTU_Id) return Boolean is
1286 return Present (RT_Unit_Table (U).Entity);
1289 --------------------
1290 -- Set_RTU_Loaded --
1291 --------------------
1293 procedure Set_RTU_Loaded (N : Node_Id) is
1294 Loc : constant Source_Ptr := Sloc (N);
1295 Unum : constant Unit_Number_Type := Get_Source_Unit (Loc);
1296 Uname : constant Unit_Name_Type := Unit_Name (Unum);
1297 E : constant Entity_Id :=
1298 Defining_Entity (Unit (Cunit (Unum)));
1300 pragma Assert (Is_Predefined_File_Name (Unit_File_Name (Unum)));
1302 -- Loop through entries in RTU table looking for matching entry
1304 for U_Id in RTU_Id'Range loop
1306 -- Here we have a match
1308 if Get_Unit_Name (U_Id) = Uname then
1310 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
1311 -- The RT_Unit_Table entry that may need updating
1314 -- If entry is not set, set it now
1316 if No (U.Entity) then
1318 U.Uname := Get_Unit_Name (U_Id);
1329 --------------------
1330 -- Text_IO_Kludge --
1331 --------------------
1333 procedure Text_IO_Kludge (Nam : Node_Id) is
1336 type Name_Map_Type is array (Text_IO_Package_Name) of RTU_Id;
1338 Name_Map : constant Name_Map_Type := Name_Map_Type'(
1339 Name_Decimal_IO => Ada_Text_IO_Decimal_IO,
1340 Name_Enumeration_IO => Ada_Text_IO_Enumeration_IO,
1341 Name_Fixed_IO => Ada_Text_IO_Fixed_IO,
1342 Name_Float_IO => Ada_Text_IO_Float_IO,
1343 Name_Integer_IO => Ada_Text_IO_Integer_IO,
1344 Name_Modular_IO => Ada_Text_IO_Modular_IO);
1346 Wide_Name_Map : constant Name_Map_Type := Name_Map_Type'(
1347 Name_Decimal_IO => Ada_Wide_Text_IO_Decimal_IO,
1348 Name_Enumeration_IO => Ada_Wide_Text_IO_Enumeration_IO,
1349 Name_Fixed_IO => Ada_Wide_Text_IO_Fixed_IO,
1350 Name_Float_IO => Ada_Wide_Text_IO_Float_IO,
1351 Name_Integer_IO => Ada_Wide_Text_IO_Integer_IO,
1352 Name_Modular_IO => Ada_Wide_Text_IO_Modular_IO);
1354 Wide_Wide_Name_Map : constant Name_Map_Type := Name_Map_Type'(
1355 Name_Decimal_IO => Ada_Wide_Wide_Text_IO_Decimal_IO,
1356 Name_Enumeration_IO => Ada_Wide_Wide_Text_IO_Enumeration_IO,
1357 Name_Fixed_IO => Ada_Wide_Wide_Text_IO_Fixed_IO,
1358 Name_Float_IO => Ada_Wide_Wide_Text_IO_Float_IO,
1359 Name_Integer_IO => Ada_Wide_Wide_Text_IO_Integer_IO,
1360 Name_Modular_IO => Ada_Wide_Wide_Text_IO_Modular_IO);
1363 -- Nothing to do if name is not identifier or a selected component
1364 -- whose selector_name is not an identifier.
1366 if Nkind (Nam) = N_Identifier then
1367 Chrs := Chars (Nam);
1369 elsif Nkind (Nam) = N_Selected_Component
1370 and then Nkind (Selector_Name (Nam)) = N_Identifier
1372 Chrs := Chars (Selector_Name (Nam));
1378 -- Nothing to do if name is not one of the Text_IO subpackages
1379 -- Otherwise look through loaded units, and if we find Text_IO
1380 -- or [Wide_]Wide_Text_IO already loaded, then load the proper child.
1382 if Chrs in Text_IO_Package_Name then
1383 for U in Main_Unit .. Last_Unit loop
1384 Get_Name_String (Unit_File_Name (U));
1386 if Name_Len = 12 then
1388 -- Here is where we do the loads if we find one of the units
1389 -- Ada.Text_IO or Ada.[Wide_]Wide_Text_IO. An interesting
1390 -- detail is that these units may already be used (i.e. their
1391 -- In_Use flags may be set). Normally when the In_Use flag is
1392 -- set, the Is_Potentially_Use_Visible flag of all entities in
1393 -- the package is set, but the new entity we are mysteriously
1394 -- adding was not there to have its flag set at the time. So
1395 -- that's why we pass the extra parameter to RTU_Find, to make
1396 -- sure the flag does get set now. Given that those generic
1397 -- packages are in fact child units, we must indicate that
1398 -- they are visible.
1400 if Name_Buffer (1 .. 12) = "a-textio.ads" then
1403 Use_Setting => In_Use (Cunit_Entity (U)));
1404 Set_Is_Visible_Child_Unit
1405 (RT_Unit_Table (Name_Map (Chrs)).Entity);
1407 elsif Name_Buffer (1 .. 12) = "a-witeio.ads" then
1409 (Wide_Name_Map (Chrs),
1410 Use_Setting => In_Use (Cunit_Entity (U)));
1411 Set_Is_Visible_Child_Unit
1412 (RT_Unit_Table (Wide_Name_Map (Chrs)).Entity);
1414 elsif Name_Buffer (1 .. 12) = "a-ztexio.ads" then
1416 (Wide_Wide_Name_Map (Chrs),
1417 Use_Setting => In_Use (Cunit_Entity (U)));
1418 Set_Is_Visible_Child_Unit
1419 (RT_Unit_Table (Wide_Wide_Name_Map (Chrs)).Entity);
1426 -- Generate error message if run-time unit not available
1428 when RE_Not_Available =>
1429 Error_Msg_N ("& not available", Nam);