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 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 Elists; use Elists;
32 with Errout; use Errout;
33 with Exp_Dist; use Exp_Dist;
34 with Fname; use Fname;
35 with Fname.UF; use Fname.UF;
37 with Lib.Load; use Lib.Load;
38 with Namet; use Namet;
39 with Nlists; use Nlists;
40 with Nmake; use Nmake;
41 with Output; use Output;
43 with Restrict; use Restrict;
45 with Sem_Ch7; use Sem_Ch7;
46 with Sem_Dist; use Sem_Dist;
47 with Sem_Util; use Sem_Util;
48 with Sinfo; use Sinfo;
49 with Stand; use Stand;
50 with Snames; use Snames;
51 with Tbuild; use Tbuild;
52 with Uname; use Uname;
54 package body Rtsfind is
56 RTE_Available_Call : Boolean := False;
57 -- Set True during call to RTE from RTE_Available (or from call to
58 -- RTE_Record_Component from RTE_Record_Component_Available). Tells
59 -- the called subprogram to set RTE_Is_Available to False rather than
60 -- generating an error message.
62 RTE_Is_Available : Boolean;
63 -- Set True by RTE_Available on entry. When RTE_Available_Call is set
64 -- True, set False if RTE would otherwise generate an error message.
70 -- The unit table has one entry for each unit included in the definition
71 -- of the type RTU_Id in the spec. The table entries are initialized in
72 -- Initialize to set the Entity field to Empty, indicating that the
73 -- corresponding unit has not yet been loaded. The fields are set when
74 -- a unit is loaded to contain the defining entity for the unit, the
75 -- unit name, and the unit number.
77 -- Note that a unit can be loaded either by a call to find an entity
78 -- within the unit (e.g. RTE), or by an explicit with of the unit. In
79 -- the latter case it is critical to make a call to Set_RTU_Loaded to
80 -- ensure that the entry in this table reflects the load.
82 type RT_Unit_Table_Record is record
84 Uname : Unit_Name_Type;
85 Unum : Unit_Number_Type;
89 RT_Unit_Table : array (RTU_Id) of RT_Unit_Table_Record;
91 --------------------------
92 -- Runtime Entity Table --
93 --------------------------
95 -- There is one entry in the runtime entity table for each entity that is
96 -- included in the definition of the RE_Id type in the spec. The entries
97 -- are set by Initialize_Rtsfind to contain Empty, indicating that the
98 -- entity has not yet been located. Once the entity is located for the
99 -- first time, its ID is stored in this array, so that subsequent calls
100 -- for the same entity can be satisfied immediately.
102 -- NOTE: In order to avoid conflicts between record components and subprgs
103 -- that have the same name (ie. subprogram External_Tag and component
104 -- External_Tag of package Ada.Tags) this table is not used with
105 -- Record_Components.
107 RE_Table : array (RE_Id) of Entity_Id;
109 --------------------------
110 -- Generation of WITH's --
111 --------------------------
113 -- When a unit is implicitly loaded as a result of a call to RTE, it
114 -- is necessary to create an implicit WITH to ensure that the object
115 -- is correctly loaded by the binder. Such WITH statements are only
116 -- required when the request is from the extended main unit (if a
117 -- client needs a WITH, that will be taken care of when the client
120 -- We always attach the WITH to the main unit. This is not perfectly
121 -- accurate in terms of elaboration requirements, but it is close
122 -- enough, since the units that are accessed using rtsfind do not
123 -- have delicate elaboration requirements.
125 -- The flag Withed in the unit table record is initially set to False.
126 -- It is set True if a WITH has been generated for the main unit for
127 -- the corresponding unit.
129 -----------------------
130 -- Local Subprograms --
131 -----------------------
133 function Check_CRT (E : RE_Id; Eid : Entity_Id) return Entity_Id;
134 -- Check entity Eid to ensure that configurable run-time restrictions
135 -- are met. May generate an error message and raise RE_Not_Available
136 -- if the entity E does not exist (i.e. Eid is Empty)
138 procedure Entity_Not_Defined (Id : RE_Id);
139 -- Outputs error messages for an entity that is not defined in the
140 -- run-time library (the form of the error message is tailored for
141 -- no run time/configurable run time mode as required).
143 function Get_Unit_Name (U_Id : RTU_Id) return Unit_Name_Type;
144 -- Retrieves the Unit Name given a unit id represented by its
145 -- enumeration value in RTU_Id.
147 procedure Load_Fail (S : String; U_Id : RTU_Id; Id : RE_Id);
148 -- Internal procedure called if we can't sucessfully locate or
149 -- process a run-time unit. The parameters give information about
150 -- the error message to be given. S is a reason for failing to
151 -- compile the file and U_Id is the unit id. RE_Id is the RE_Id
152 -- originally passed to RTE. The message in S is one of the
156 -- "had parser errors"
157 -- "had semantic errors"
159 -- The "not found" case is treated specially in that it is considered
160 -- a normal situation in configurable run-time mode (and the message in
161 -- this case is suppressed unless we are operating in All_Errors_Mode).
165 Id : RE_Id := RE_Null;
166 Use_Setting : Boolean := False);
167 -- Load the unit whose Id is given if not already loaded. The unit is
168 -- loaded, analyzed, and added to the WITH list, and the entry in
169 -- RT_Unit_Table is updated to reflect the load. Use_Setting is used
170 -- to indicate the initial setting for the Is_Potentially_Use_Visible
171 -- flag of the entity for the loaded unit (if it is indeed loaded).
172 -- A value of False means nothing special need be done. A value of
173 -- True indicates that this flag must be set to True. It is needed
174 -- only in the Text_IO_Kludge procedure, which may materialize an
175 -- entity of Text_IO (or [Wide_]Wide_Text_IO) that was previously unknown.
176 -- Id is the RE_Id value of the entity which was originally requested.
177 -- Id is used only for error message detail, and if it is RE_Null, then
178 -- the attempt to output the entity name is ignored.
180 function Make_Unit_Name (E : RE_Id; N : Node_Id) return Node_Id;
181 -- If the unit is a child unit, build fully qualified name for use in
184 procedure Output_Entity_Name (Id : RE_Id; Msg : String);
185 -- Output continuation error message giving qualified name of entity
186 -- corresponding to Id, appending the string given by Msg. This call
187 -- is only effective in All_Errors mode.
189 function RE_Chars (E : RE_Id) return Name_Id;
190 -- Given a RE_Id value returns the Chars of the corresponding entity
192 procedure RTE_Error_Msg (Msg : String);
193 -- Generates a message by calling Error_Msg_N specifying Current_Error_Node
194 -- as the node location using the given Msg text. Special processing in the
195 -- case where RTE_Available_Call is set. In this case, no message is output
196 -- and instead RTE_Is_Available is set to False. Note that this can only be
197 -- used if you are sure that the message comes directly or indirectly from
198 -- a call to the RTE function.
204 function Check_CRT (E : RE_Id; Eid : Entity_Id) return Entity_Id is
205 U_Id : constant RTU_Id := RE_Unit_Table (E);
209 Entity_Not_Defined (E);
210 raise RE_Not_Available;
212 -- Entity is available
215 -- If in No_Run_Time mode and entity is not in one of the
216 -- specially permitted units, raise the exception.
219 and then not OK_No_Run_Time_Unit (U_Id)
221 Entity_Not_Defined (E);
222 raise RE_Not_Available;
225 -- Otherwise entity is accessible
231 ------------------------
232 -- Entity_Not_Defined --
233 ------------------------
235 procedure Entity_Not_Defined (Id : RE_Id) is
237 if No_Run_Time_Mode then
239 -- If the error occurs when compiling the body of a predefined
240 -- unit for inlining purposes, the body must be illegal in this
241 -- mode, and there is no point in continuing.
243 if Is_Predefined_File_Name
244 (Unit_File_Name (Get_Source_Unit (Sloc (Current_Error_Node))))
247 ("construct not allowed in no run time mode!",
249 raise Unrecoverable_Error;
252 RTE_Error_Msg ("|construct not allowed in no run time mode");
255 elsif Configurable_Run_Time_Mode then
256 RTE_Error_Msg ("|construct not allowed in this configuration>");
258 RTE_Error_Msg ("run-time configuration error");
261 Output_Entity_Name (Id, "not defined");
262 end Entity_Not_Defined;
268 function Get_Unit_Name (U_Id : RTU_Id) return Unit_Name_Type is
269 Uname_Chars : constant String := RTU_Id'Image (U_Id);
272 Name_Len := Uname_Chars'Length;
273 Name_Buffer (1 .. Name_Len) := Uname_Chars;
274 Set_Casing (All_Lower_Case);
276 if U_Id in Ada_Child then
277 Name_Buffer (4) := '.';
279 if U_Id in Ada_Calendar_Child then
280 Name_Buffer (13) := '.';
282 elsif U_Id in Ada_Finalization_Child then
283 Name_Buffer (17) := '.';
285 elsif U_Id in Ada_Interrupts_Child then
286 Name_Buffer (15) := '.';
288 elsif U_Id in Ada_Real_Time_Child then
289 Name_Buffer (14) := '.';
291 elsif U_Id in Ada_Streams_Child then
292 Name_Buffer (12) := '.';
294 elsif U_Id in Ada_Text_IO_Child then
295 Name_Buffer (12) := '.';
297 elsif U_Id in Ada_Wide_Text_IO_Child then
298 Name_Buffer (17) := '.';
300 elsif U_Id in Ada_Wide_Wide_Text_IO_Child then
301 Name_Buffer (22) := '.';
304 elsif U_Id in Interfaces_Child then
305 Name_Buffer (11) := '.';
307 elsif U_Id in System_Child then
308 Name_Buffer (7) := '.';
310 if U_Id in System_Tasking_Child then
311 Name_Buffer (15) := '.';
314 if U_Id in System_Tasking_Restricted_Child then
315 Name_Buffer (26) := '.';
318 if U_Id in System_Tasking_Protected_Objects_Child then
319 Name_Buffer (33) := '.';
322 if U_Id in System_Tasking_Async_Delays_Child then
323 Name_Buffer (28) := '.';
327 -- Add %s at end for spec
329 Name_Buffer (Name_Len + 1) := '%';
330 Name_Buffer (Name_Len + 2) := 's';
331 Name_Len := Name_Len + 2;
340 procedure Initialize is
342 -- Initialize the unit table
345 RT_Unit_Table (J).Entity := Empty;
349 RE_Table (J) := Empty;
352 RTE_Is_Available := False;
359 function Is_RTE (Ent : Entity_Id; E : RE_Id) return Boolean is
360 E_Unit_Name : Unit_Name_Type;
361 Ent_Unit_Name : Unit_Name_Type;
371 -- If E has already a corresponding entity, check it directly,
372 -- going to full views if they exist to deal with the incomplete
373 -- and private type cases properly.
375 elsif Present (RE_Table (E)) then
378 if Is_Type (E1) and then Present (Full_View (E1)) then
379 E1 := Full_View (E1);
384 if Is_Type (E2) and then Present (Full_View (E2)) then
385 E2 := Full_View (E2);
391 -- If the unit containing E is not loaded, we already know that
392 -- the entity we have cannot have come from this unit.
394 E_Unit_Name := Get_Unit_Name (RE_Unit_Table (E));
396 if not Is_Loaded (E_Unit_Name) then
400 -- Here the unit containing the entity is loaded. We have not made
401 -- an explicit call to RTE to get the entity in question, but we may
402 -- have obtained a reference to it indirectly from some other entity
403 -- in the same unit, or some other unit that references it.
405 -- Get the defining unit of the entity
409 if Ekind (S) /= E_Package then
413 Ent_Unit_Name := Get_Unit_Name (Unit_Declaration_Node (S));
415 -- If the defining unit of the entity we are testing is not the
416 -- unit containing E, then they cannot possibly match.
418 if Ent_Unit_Name /= E_Unit_Name then
422 -- If the units match, then compare the names (remember that no
423 -- overloading is permitted in entities fetched using Rtsfind).
425 if RE_Chars (E) = Chars (Ent) then
428 -- If front-end inlining is enabled, we may be within a body that
429 -- contains inlined functions, which has not been retrieved through
430 -- rtsfind, and therefore is not yet recorded in the RT_Unit_Table.
431 -- Add the unit information now, it must be fully available.
434 U : RT_Unit_Table_Record
435 renames RT_Unit_Table (RE_Unit_Table (E));
437 if No (U.Entity) then
439 U.Uname := E_Unit_Name;
440 U.Unum := Get_Source_Unit (S);
454 function Is_RTU (Ent : Entity_Id; U : RTU_Id) return Boolean is
455 E : constant Entity_Id := RT_Unit_Table (U).Entity;
457 return Present (E) and then E = Ent;
460 ----------------------------
461 -- Is_Text_IO_Kludge_Unit --
462 ----------------------------
464 function Is_Text_IO_Kludge_Unit (Nam : Node_Id) return Boolean is
469 if Nkind (Nam) /= N_Expanded_Name then
474 Sel := Selector_Name (Nam);
476 if Nkind (Sel) /= N_Expanded_Name
477 or else Nkind (Prf) /= N_Identifier
478 or else Chars (Prf) /= Name_Ada
484 Sel := Selector_Name (Sel);
487 Nkind (Prf) = N_Identifier
489 (Chars (Prf) = Name_Text_IO
491 Chars (Prf) = Name_Wide_Text_IO
493 Chars (Prf) = Name_Wide_Wide_Text_IO)
495 Nkind (Sel) = N_Identifier
497 Chars (Sel) in Text_IO_Package_Name;
498 end Is_Text_IO_Kludge_Unit;
504 procedure Load_Fail (S : String; U_Id : RTU_Id; Id : RE_Id) is
505 M : String (1 .. 100);
509 -- Output header message
511 if Configurable_Run_Time_Mode then
512 RTE_Error_Msg ("construct not allowed in configurable run-time mode");
514 RTE_Error_Msg ("run-time library configuration error");
517 -- Output file name and reason string
520 or else not Configurable_Run_Time_Mode
521 or else All_Errors_Mode
523 M (1 .. 6) := "\file ";
527 (Get_File_Name (RT_Unit_Table (U_Id).Uname, Subunit => False));
528 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
534 M (P + 1 .. P + S'Length) := S;
537 RTE_Error_Msg (M (1 .. P));
539 -- Output entity name
541 Output_Entity_Name (Id, "not available");
544 -- In configurable run time mode, we raise RE_Not_Available, and we hope
545 -- the caller deals gracefully with this. If we are in normal full run
546 -- time mode, a load failure is considered fatal and unrecoverable.
548 if Configurable_Run_Time_Mode then
549 raise RE_Not_Available;
551 raise Unrecoverable_Error;
561 Id : RE_Id := RE_Null;
562 Use_Setting : Boolean := False)
564 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
565 Priv_Par : constant Elist_Id := New_Elmt_List;
568 procedure Save_Private_Visibility;
569 -- If the current unit is the body of child unit or the spec of a
570 -- private child unit, the private declarations of the parent (s)
571 -- are visible. If the unit to be loaded is another public sibling,
572 -- its compilation will affect the visibility of the common ancestors.
573 -- Indicate those that must be restored.
575 procedure Restore_Private_Visibility;
576 -- Restore the visibility of ancestors after compiling RTU
578 --------------------------------
579 -- Restore_Private_Visibility --
580 --------------------------------
582 procedure Restore_Private_Visibility is
586 E_Par := First_Elmt (Priv_Par);
587 while Present (E_Par) loop
588 if not In_Private_Part (Node (E_Par)) then
589 Install_Private_Declarations (Node (E_Par));
594 end Restore_Private_Visibility;
596 -----------------------------
597 -- Save_Private_Visibility --
598 -----------------------------
600 procedure Save_Private_Visibility is
604 Par := Scope (Current_Scope);
606 and then Par /= Standard_Standard
608 if Ekind (Par) = E_Package
609 and then Is_Compilation_Unit (Par)
610 and then In_Private_Part (Par)
612 Append_Elmt (Par, Priv_Par);
617 end Save_Private_Visibility;
619 -- Start of processing for Load_RTU
622 -- Nothing to do if unit is already loaded
624 if Present (U.Entity) then
628 -- Note if secondary stack is used
630 if U_Id = System_Secondary_Stack then
631 Opt.Sec_Stack_Used := True;
634 -- Otherwise we need to load the unit, First build unit name
635 -- from the enumeration literal name in type RTU_Id.
637 U.Uname := Get_Unit_Name (U_Id);
642 pragma Warnings (Off, Loaded);
644 Loaded := Is_Loaded (U.Uname);
647 -- Now do the load call, note that setting Error_Node to Empty is
648 -- a signal to Load_Unit that we will regard a failure to find the
649 -- file as a fatal error, and that it should not output any kind
650 -- of diagnostics, since we will take care of it here.
652 -- We save style checking switches and turn off style checking for
653 -- loading the unit, since we don't want any style checking!
656 Save_Style_Check : constant Boolean := Style_Check;
658 Style_Check := False;
661 (Load_Name => U.Uname,
664 Error_Node => Empty);
665 Style_Check := Save_Style_Check;
668 -- Check for bad unit load
670 if U.Unum = No_Unit then
671 Load_Fail ("not found", U_Id, Id);
672 elsif Fatal_Error (U.Unum) then
673 Load_Fail ("had parser errors", U_Id, Id);
676 -- Make sure that the unit is analyzed
679 Was_Analyzed : constant Boolean :=
680 Analyzed (Cunit (Current_Sem_Unit));
683 -- Pretend that the current unit is analyzed, in case it is System
684 -- or some such. This allows us to put some declarations, such as
685 -- exceptions and packed arrays of Boolean, into System even though
686 -- expanding them requires System...
688 -- This is a bit odd but works fine. If the RTS unit does not depend
689 -- in any way on the current unit, then it never gets back into the
690 -- current unit's tree, and the change we make to the current unit
691 -- tree is never noticed by anyone (it is undone in a moment). That
692 -- is the normal situation.
694 -- If the RTS Unit *does* depend on the current unit, for instance,
695 -- when you are compiling System, then you had better have finished
696 -- analyzing the part of System that is depended on before you try
697 -- to load the RTS Unit. This means having the System ordered in an
698 -- appropriate manner.
700 Set_Analyzed (Cunit (Current_Sem_Unit), True);
702 if not Analyzed (Cunit (U.Unum)) then
704 -- If the unit is already loaded through a limited_with clauses,
705 -- the relevant entities must already be available. We do not
706 -- want to load and analyze the unit because this would create
707 -- a real semantic dependence when the purpose of the limited_with
708 -- is precisely to avoid such.
710 if From_With_Type (Cunit_Entity (U.Unum)) then
714 Save_Private_Visibility;
715 Semantics (Cunit (U.Unum));
716 Restore_Private_Visibility;
718 if Fatal_Error (U.Unum) then
719 Load_Fail ("had semantic errors", U_Id, Id);
726 Set_Analyzed (Cunit (Current_Sem_Unit), Was_Analyzed);
729 Lib_Unit := Unit (Cunit (U.Unum));
730 U.Entity := Defining_Entity (Lib_Unit);
733 Set_Is_Potentially_Use_Visible (U.Entity, True);
741 function Make_Unit_Name (E : RE_Id; N : Node_Id) return Node_Id is
742 U_Id : constant RTU_Id := RE_Unit_Table (E);
743 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
748 Nam := New_Reference_To (U.Entity, Standard_Location);
749 Scop := Scope (U.Entity);
751 if Nkind (N) = N_Defining_Program_Unit_Name then
752 while Scop /= Standard_Standard loop
754 Make_Expanded_Name (Standard_Location,
755 Chars => Chars (U.Entity),
756 Prefix => New_Reference_To (Scop, Standard_Location),
757 Selector_Name => Nam);
758 Set_Entity (Nam, U.Entity);
760 Scop := Scope (Scop);
767 -----------------------
768 -- Output_Entity_Name --
769 ------------------------
771 procedure Output_Entity_Name (Id : RE_Id; Msg : String) is
772 M : String (1 .. 2048);
774 -- M (1 .. P) is current message to be output
776 RE_Image : constant String := RE_Id'Image (Id);
779 if Id = RE_Null or else not All_Errors_Mode then
783 M (1 .. 9) := "\entity """;
786 -- Add unit name to message, excluding %s or %b at end
788 Get_Name_String (Get_Unit_Name (RE_Unit_Table (Id)));
789 Name_Len := Name_Len - 2;
790 Set_Casing (Mixed_Case);
791 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
794 -- Add a qualifying period
799 -- Add entity name and closing quote to message
801 Name_Len := RE_Image'Length - 3;
802 Name_Buffer (1 .. Name_Len) := RE_Image (4 .. RE_Image'Length);
803 Set_Casing (Mixed_Case);
804 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
813 M (P + 1 .. P + Msg'Length) := Msg;
816 -- Output message at current error node location
818 RTE_Error_Msg (M (1 .. P));
819 end Output_Entity_Name;
825 function RE_Chars (E : RE_Id) return Name_Id is
826 RE_Name_Chars : constant String := RE_Id'Image (E);
829 -- Copy name skipping initial RE_ or RO_XX characters
831 if RE_Name_Chars (1 .. 2) = "RE" then
832 for J in 4 .. RE_Name_Chars'Last loop
833 Name_Buffer (J - 3) := Fold_Lower (RE_Name_Chars (J));
836 Name_Len := RE_Name_Chars'Length - 3;
839 for J in 7 .. RE_Name_Chars'Last loop
840 Name_Buffer (J - 6) := Fold_Lower (RE_Name_Chars (J));
843 Name_Len := RE_Name_Chars'Length - 6;
853 function RTE (E : RE_Id) return Entity_Id is
854 U_Id : constant RTU_Id := RE_Unit_Table (E);
855 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
861 -- The following flag is used to disable front-end inlining when RTE
862 -- is invoked. This prevents the analysis of other runtime bodies when
863 -- a particular spec is loaded through Rtsfind. This is both efficient,
864 -- and it prevents spurious visibility conflicts between use-visible
865 -- user entities, and entities in run-time packages.
867 -- In configurable run-time mode, subprograms marked Inlined_Always must
868 -- be inlined, so in the case we retain the Front_End_Inlining mode.
870 Save_Front_End_Inlining : Boolean;
873 -- Reject programs that make use of distribution features not supported
874 -- on the current target. Also check that the PCS is compatible with
875 -- the code generator version. On such targets (VMS, Vxworks, others?)
876 -- we provide a minimal body for System.Rpc that only supplies an
877 -- implementation of Partition_Id.
879 function Find_Local_Entity (E : RE_Id) return Entity_Id;
880 -- This function is used when entity E is in this compilation's main
881 -- unit. It gets the value from the already compiled declaration.
887 procedure Check_RPC is
889 procedure Check_RPC_Failure (Msg : String);
890 pragma No_Return (Check_RPC_Failure);
891 -- Display Msg on standard error and raise Unrecoverable_Error
893 -----------------------
894 -- Check_RPC_Failure --
895 -----------------------
897 procedure Check_RPC_Failure (Msg : String) is
902 raise Unrecoverable_Error;
903 end Check_RPC_Failure;
905 -- Start of processing for Check_RPC
908 -- Bypass this check if debug flag -gnatdR set
910 if Debug_Flag_RR then
914 -- Otherwise we need the check if we are going after one of
915 -- the critical entities in System.RPC in stubs mode.
917 -- ??? Should we do this for other s-parint entities too?
919 if (Distribution_Stub_Mode = Generate_Receiver_Stub_Body
921 Distribution_Stub_Mode = Generate_Caller_Stub_Body)
922 and then (E = RE_Do_Rpc
926 E = RE_Params_Stream_Type
928 E = RE_Request_Access)
930 if Get_PCS_Name = Name_No_DSA then
931 Check_RPC_Failure ("distribution feature not supported");
933 elsif Get_PCS_Version /= Exp_Dist.PCS_Version_Number then
934 Check_RPC_Failure ("PCS version mismatch");
940 -----------------------
941 -- Find_Local_Entity --
942 -----------------------
944 function Find_Local_Entity (E : RE_Id) return Entity_Id is
945 RE_Str : constant String := RE_Id'Image (E);
949 Save_Nam : constant String := Name_Buffer (1 .. Name_Len);
950 -- Save name buffer and length over call
953 Name_Len := Natural'Max (0, RE_Str'Length - 3);
954 Name_Buffer (1 .. Name_Len) :=
955 RE_Str (RE_Str'First + 3 .. RE_Str'Last);
958 Ent := Entity_Id (Get_Name_Table_Info (Nam));
960 Name_Len := Save_Nam'Length;
961 Name_Buffer (1 .. Name_Len) := Save_Nam;
964 end Find_Local_Entity;
966 -- Start of processing for RTE
969 -- Doing a rtsfind in system.ads is special, as we cannot do this
970 -- when compiling System itself. So if we are compiling system then
971 -- we should already have acquired and processed the declaration
972 -- of the entity. The test is to see if this compilation's main unit
973 -- is System. If so, return the value from the already compiled
974 -- declaration and otherwise do a regular find.
976 -- Not pleasant, but these kinds of annoying recursion when
977 -- writing an Ada compiler in Ada have to be broken somewhere!
979 if Present (Main_Unit_Entity)
980 and then Chars (Main_Unit_Entity) = Name_System
981 and then Analyzed (Main_Unit_Entity)
982 and then not Is_Child_Unit (Main_Unit_Entity)
984 return Check_CRT (E, Find_Local_Entity (E));
987 Save_Front_End_Inlining := Front_End_Inlining;
988 Front_End_Inlining := Configurable_Run_Time_Mode;
990 -- Load unit if unit not previously loaded
992 if No (RE_Table (E)) then
993 Load_RTU (U_Id, Id => E);
994 Lib_Unit := Unit (Cunit (U.Unum));
996 -- In the subprogram case, we are all done, the entity we want
997 -- is the entity for the subprogram itself. Note that we do not
998 -- bother to check that it is the entity that was requested.
999 -- the only way that could fail to be the case is if runtime is
1000 -- hopelessly misconfigured, and it isn't worth testing for this.
1002 if Nkind (Lib_Unit) = N_Subprogram_Declaration then
1003 RE_Table (E) := U.Entity;
1005 -- Otherwise we must have the package case. First check package
1006 -- entity itself (e.g. RTE_Name for System.Interrupts.Name)
1009 pragma Assert (Nkind (Lib_Unit) = N_Package_Declaration);
1010 Ename := RE_Chars (E);
1012 -- First we search the package entity chain. If the package
1013 -- only has a limited view, scan the corresponding list of
1014 -- incomplete types.
1016 if From_With_Type (U.Entity) then
1017 Pkg_Ent := First_Entity (Limited_View (U.Entity));
1019 Pkg_Ent := First_Entity (U.Entity);
1022 while Present (Pkg_Ent) loop
1023 if Ename = Chars (Pkg_Ent) then
1024 RE_Table (E) := Pkg_Ent;
1029 Next_Entity (Pkg_Ent);
1032 -- If we did not find the entity in the package entity chain,
1033 -- then check if the package entity itself matches. Note that
1034 -- we do this check after searching the entity chain, since
1035 -- the rule is that in case of ambiguity, we prefer the entity
1036 -- defined within the package, rather than the package itself.
1038 if Ename = Chars (U.Entity) then
1039 RE_Table (E) := U.Entity;
1042 -- If we didn't find the entity we want, something is wrong.
1043 -- We just leave RE_Table (E) set to Empty and the appropriate
1044 -- action will be taken by Check_CRT when we exit.
1049 -- See if we have to generate a WITH for this entity. We generate
1050 -- a WITH if the current unit is part of the extended main code
1051 -- unit, and if we have not already added the with. The WITH is
1052 -- added to the appropriate unit (the current one). We do not need
1053 -- to generate a WITH for a call issued from RTE_Available.
1058 In_Extended_Main_Code_Unit (Cunit_Entity (Current_Sem_Unit))
1059 and then not RTE_Available_Call
1068 Lib_Unit := Unit (Cunit (U.Unum));
1070 Make_With_Clause (Standard_Location,
1073 (E, Defining_Unit_Name (Specification (Lib_Unit))));
1074 Set_Library_Unit (Withn, Cunit (U.Unum));
1075 Set_Corresponding_Spec (Withn, U.Entity);
1076 Set_First_Name (Withn, True);
1077 Set_Implicit_With (Withn, True);
1079 Mark_Rewrite_Insertion (Withn);
1080 Append (Withn, Context_Items (Cunit (Current_Sem_Unit)));
1081 Check_Restriction_No_Dependence (Name (Withn), Current_Error_Node);
1085 Front_End_Inlining := Save_Front_End_Inlining;
1086 return Check_CRT (E, RE_Table (E));
1093 function RTE_Available (E : RE_Id) return Boolean is
1095 pragma Warnings (Off, Dummy);
1099 Save_RTE_Available_Call : constant Boolean := RTE_Available_Call;
1100 Save_RTE_Is_Available : constant Boolean := RTE_Is_Available;
1101 -- These are saved recursively because the call to load a unit
1102 -- caused by an upper level call may perform a recursive call
1103 -- to this routine during analysis of the corresponding unit.
1106 RTE_Available_Call := True;
1107 RTE_Is_Available := True;
1109 Result := RTE_Is_Available;
1110 RTE_Available_Call := Save_RTE_Available_Call;
1111 RTE_Is_Available := Save_RTE_Is_Available;
1115 when RE_Not_Available =>
1116 RTE_Available_Call := Save_RTE_Available_Call;
1117 RTE_Is_Available := Save_RTE_Is_Available;
1121 --------------------------
1122 -- RTE_Record_Component --
1123 --------------------------
1125 function RTE_Record_Component (E : RE_Id) return Entity_Id is
1126 U_Id : constant RTU_Id := RE_Unit_Table (E);
1127 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
1130 Found_E : Entity_Id;
1132 Pkg_Ent : Entity_Id;
1134 -- The following flag is used to disable front-end inlining when
1135 -- RTE_Record_Component is invoked. This prevents the analysis of other
1136 -- runtime bodies when a particular spec is loaded through Rtsfind. This
1137 -- is both efficient, and it prevents spurious visibility conflicts
1138 -- between use-visible user entities, and entities in run-time packages.
1140 -- In configurable run-time mode, subprograms marked Inlined_Always must
1141 -- be inlined, so in the case we retain the Front_End_Inlining mode.
1143 Save_Front_End_Inlining : Boolean;
1146 -- Note: Contrary to subprogram RTE, there is no need to do any special
1147 -- management with package system.ads because it has no record type
1150 Save_Front_End_Inlining := Front_End_Inlining;
1151 Front_End_Inlining := Configurable_Run_Time_Mode;
1153 -- Load unit if unit not previously loaded
1155 if not Present (U.Entity) then
1156 Load_RTU (U_Id, Id => E);
1159 Lib_Unit := Unit (Cunit (U.Unum));
1161 pragma Assert (Nkind (Lib_Unit) = N_Package_Declaration);
1162 Ename := RE_Chars (E);
1164 -- Search the entity in the components of record type declarations
1165 -- found in the package entity chain.
1168 Pkg_Ent := First_Entity (U.Entity);
1169 Search : while Present (Pkg_Ent) loop
1170 if Is_Record_Type (Pkg_Ent) then
1171 E1 := First_Entity (Pkg_Ent);
1172 while Present (E1) loop
1173 if Ename = Chars (E1) then
1174 pragma Assert (not Present (Found_E));
1182 Next_Entity (Pkg_Ent);
1185 -- If we didn't find the entity we want, something is wrong. The
1186 -- appropriate action will be taken by Check_CRT when we exit.
1188 -- Cenerate a with-clause if the current unit is part of the extended
1189 -- main code unit, and if we have not already added the with. The clause
1190 -- is added to the appropriate unit (the current one). We do not need to
1191 -- generate it for a call issued from RTE_Component_Available.
1195 In_Extended_Main_Code_Unit (Cunit_Entity (Current_Sem_Unit))
1196 and then not RTE_Available_Call
1205 Lib_Unit := Unit (Cunit (U.Unum));
1207 Make_With_Clause (Standard_Location,
1210 (E, Defining_Unit_Name (Specification (Lib_Unit))));
1211 Set_Library_Unit (Withn, Cunit (U.Unum));
1212 Set_Corresponding_Spec (Withn, U.Entity);
1213 Set_First_Name (Withn, True);
1214 Set_Implicit_With (Withn, True);
1216 Mark_Rewrite_Insertion (Withn);
1217 Append (Withn, Context_Items (Cunit (Current_Sem_Unit)));
1218 Check_Restriction_No_Dependence (Name (Withn), Current_Error_Node);
1222 Front_End_Inlining := Save_Front_End_Inlining;
1223 return Check_CRT (E, Found_E);
1224 end RTE_Record_Component;
1226 ------------------------------------
1227 -- RTE_Record_Component_Available --
1228 ------------------------------------
1230 function RTE_Record_Component_Available (E : RE_Id) return Boolean is
1232 pragma Warnings (Off, Dummy);
1236 Save_RTE_Available_Call : constant Boolean := RTE_Available_Call;
1237 Save_RTE_Is_Available : constant Boolean := RTE_Is_Available;
1238 -- These are saved recursively because the call to load a unit
1239 -- caused by an upper level call may perform a recursive call
1240 -- to this routine during analysis of the corresponding unit.
1243 RTE_Available_Call := True;
1244 RTE_Is_Available := True;
1245 Dummy := RTE_Record_Component (E);
1246 Result := RTE_Is_Available;
1247 RTE_Available_Call := Save_RTE_Available_Call;
1248 RTE_Is_Available := Save_RTE_Is_Available;
1252 when RE_Not_Available =>
1253 RTE_Available_Call := Save_RTE_Available_Call;
1254 RTE_Is_Available := Save_RTE_Is_Available;
1256 end RTE_Record_Component_Available;
1262 procedure RTE_Error_Msg (Msg : String) is
1264 if RTE_Available_Call then
1265 RTE_Is_Available := False;
1267 Error_Msg_N (Msg, Current_Error_Node);
1269 -- Bump count of violations if we are in configurable run-time
1270 -- mode and this is not a continuation message.
1272 if Configurable_Run_Time_Mode and then Msg (Msg'First) /= '\' then
1273 Configurable_Run_Time_Violations :=
1274 Configurable_Run_Time_Violations + 1;
1283 function RTU_Entity (U : RTU_Id) return Entity_Id is
1285 return RT_Unit_Table (U).Entity;
1292 function RTU_Loaded (U : RTU_Id) return Boolean is
1294 return Present (RT_Unit_Table (U).Entity);
1297 --------------------
1298 -- Set_RTU_Loaded --
1299 --------------------
1301 procedure Set_RTU_Loaded (N : Node_Id) is
1302 Loc : constant Source_Ptr := Sloc (N);
1303 Unum : constant Unit_Number_Type := Get_Source_Unit (Loc);
1304 Uname : constant Unit_Name_Type := Unit_Name (Unum);
1305 E : constant Entity_Id :=
1306 Defining_Entity (Unit (Cunit (Unum)));
1308 pragma Assert (Is_Predefined_File_Name (Unit_File_Name (Unum)));
1310 -- Loop through entries in RTU table looking for matching entry
1312 for U_Id in RTU_Id'Range loop
1314 -- Here we have a match
1316 if Get_Unit_Name (U_Id) = Uname then
1318 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
1319 -- The RT_Unit_Table entry that may need updating
1322 -- If entry is not set, set it now
1324 if No (U.Entity) then
1326 U.Uname := Get_Unit_Name (U_Id);
1337 --------------------
1338 -- Text_IO_Kludge --
1339 --------------------
1341 procedure Text_IO_Kludge (Nam : Node_Id) is
1344 type Name_Map_Type is array (Text_IO_Package_Name) of RTU_Id;
1346 Name_Map : constant Name_Map_Type := Name_Map_Type'(
1347 Name_Decimal_IO => Ada_Text_IO_Decimal_IO,
1348 Name_Enumeration_IO => Ada_Text_IO_Enumeration_IO,
1349 Name_Fixed_IO => Ada_Text_IO_Fixed_IO,
1350 Name_Float_IO => Ada_Text_IO_Float_IO,
1351 Name_Integer_IO => Ada_Text_IO_Integer_IO,
1352 Name_Modular_IO => Ada_Text_IO_Modular_IO);
1354 Wide_Name_Map : constant Name_Map_Type := Name_Map_Type'(
1355 Name_Decimal_IO => Ada_Wide_Text_IO_Decimal_IO,
1356 Name_Enumeration_IO => Ada_Wide_Text_IO_Enumeration_IO,
1357 Name_Fixed_IO => Ada_Wide_Text_IO_Fixed_IO,
1358 Name_Float_IO => Ada_Wide_Text_IO_Float_IO,
1359 Name_Integer_IO => Ada_Wide_Text_IO_Integer_IO,
1360 Name_Modular_IO => Ada_Wide_Text_IO_Modular_IO);
1362 Wide_Wide_Name_Map : constant Name_Map_Type := Name_Map_Type'(
1363 Name_Decimal_IO => Ada_Wide_Wide_Text_IO_Decimal_IO,
1364 Name_Enumeration_IO => Ada_Wide_Wide_Text_IO_Enumeration_IO,
1365 Name_Fixed_IO => Ada_Wide_Wide_Text_IO_Fixed_IO,
1366 Name_Float_IO => Ada_Wide_Wide_Text_IO_Float_IO,
1367 Name_Integer_IO => Ada_Wide_Wide_Text_IO_Integer_IO,
1368 Name_Modular_IO => Ada_Wide_Wide_Text_IO_Modular_IO);
1371 -- Nothing to do if name is not identifier or a selected component
1372 -- whose selector_name is not an identifier.
1374 if Nkind (Nam) = N_Identifier then
1375 Chrs := Chars (Nam);
1377 elsif Nkind (Nam) = N_Selected_Component
1378 and then Nkind (Selector_Name (Nam)) = N_Identifier
1380 Chrs := Chars (Selector_Name (Nam));
1386 -- Nothing to do if name is not one of the Text_IO subpackages
1387 -- Otherwise look through loaded units, and if we find Text_IO
1388 -- or [Wide_]Wide_Text_IO already loaded, then load the proper child.
1390 if Chrs in Text_IO_Package_Name then
1391 for U in Main_Unit .. Last_Unit loop
1392 Get_Name_String (Unit_File_Name (U));
1394 if Name_Len = 12 then
1396 -- Here is where we do the loads if we find one of the units
1397 -- Ada.Text_IO or Ada.[Wide_]Wide_Text_IO. An interesting
1398 -- detail is that these units may already be used (i.e. their
1399 -- In_Use flags may be set). Normally when the In_Use flag is
1400 -- set, the Is_Potentially_Use_Visible flag of all entities in
1401 -- the package is set, but the new entity we are mysteriously
1402 -- adding was not there to have its flag set at the time. So
1403 -- that's why we pass the extra parameter to RTU_Find, to make
1404 -- sure the flag does get set now. Given that those generic
1405 -- packages are in fact child units, we must indicate that
1406 -- they are visible.
1408 if Name_Buffer (1 .. 12) = "a-textio.ads" then
1411 Use_Setting => In_Use (Cunit_Entity (U)));
1412 Set_Is_Visible_Child_Unit
1413 (RT_Unit_Table (Name_Map (Chrs)).Entity);
1415 elsif Name_Buffer (1 .. 12) = "a-witeio.ads" then
1417 (Wide_Name_Map (Chrs),
1418 Use_Setting => In_Use (Cunit_Entity (U)));
1419 Set_Is_Visible_Child_Unit
1420 (RT_Unit_Table (Wide_Name_Map (Chrs)).Entity);
1422 elsif Name_Buffer (1 .. 12) = "a-ztexio.ads" then
1424 (Wide_Wide_Name_Map (Chrs),
1425 Use_Setting => In_Use (Cunit_Entity (U)));
1426 Set_Is_Visible_Child_Unit
1427 (RT_Unit_Table (Wide_Wide_Name_Map (Chrs)).Entity);
1434 -- Generate error message if run-time unit not available
1436 when RE_Not_Available =>
1437 Error_Msg_N ("& not available", Nam);