1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, 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 -- A unit retrieved through rtsfind may end up in the context of several
83 -- other units, in addition to the main unit. These additional with_clauses
84 -- are needed to generate a proper traversal order for Inspector. To
85 -- minimize somewhat the redundancy created by numerous calls to rtsfind
86 -- from different units, we keep track of the list of implicit with_clauses
87 -- already created for the current loaded unit.
89 type RT_Unit_Table_Record is record
91 Uname : Unit_Name_Type;
92 First_Implicit_With : Node_Id;
93 Unum : Unit_Number_Type;
96 RT_Unit_Table : array (RTU_Id) of RT_Unit_Table_Record;
98 --------------------------
99 -- Runtime Entity Table --
100 --------------------------
102 -- There is one entry in the runtime entity table for each entity that is
103 -- included in the definition of the RE_Id type in the spec. The entries
104 -- are set by Initialize_Rtsfind to contain Empty, indicating that the
105 -- entity has not yet been located. Once the entity is located for the
106 -- first time, its ID is stored in this array, so that subsequent calls
107 -- for the same entity can be satisfied immediately.
109 -- NOTE: In order to avoid conflicts between record components and subprgs
110 -- that have the same name (i.e. subprogram External_Tag and
111 -- component External_Tag of package Ada.Tags) this table is not used
112 -- with Record_Components.
114 RE_Table : array (RE_Id) of Entity_Id;
116 --------------------------------
117 -- Generation of with_clauses --
118 --------------------------------
120 -- When a unit is implicitly loaded as a result of a call to RTE, it is
121 -- necessary to create one or two implicit with_clauses. We add such
122 -- with_clauses to the extended main unit if needed, and also to whatever
123 -- unit needs them, which is not necessarily the main unit. The former
124 -- ensures that the object is correctly loaded by the binder. The latter
125 -- is necessary for SofCheck Inspector.
127 -- The field First_Implicit_With in the unit table record are used to
128 -- avoid creating duplicate with_clauses.
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 are
136 -- met. May generate an error message (if RTE_Available_Call is false) and
137 -- raise RE_Not_Available if entity E does not exist (e.g. Eid is Empty).
138 -- Above documentation not clear ???
140 procedure Entity_Not_Defined (Id : RE_Id);
141 -- Outputs error messages for an entity that is not defined in the run-time
142 -- library (the form of the error message is tailored for no run time or
143 -- configurable run time mode as required).
145 function Get_Unit_Name (U_Id : RTU_Id) return Unit_Name_Type;
146 -- Retrieves the Unit Name given a unit id represented by its enumeration
149 procedure Load_Fail (S : String; U_Id : RTU_Id; Id : RE_Id);
150 -- Internal procedure called if we can't successfully locate or process a
151 -- run-time unit. The parameters give information about the error message
152 -- to be given. S is a reason for failing to compile the file and U_Id is
153 -- the unit id. RE_Id is the RE_Id originally passed to RTE. The message in
154 -- S is one of the following:
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 and analyzed, and the entry in RT_Unit_Table is updated to
170 -- reflect the load. Use_Setting is used to indicate the initial setting
171 -- for the Is_Potentially_Use_Visible flag of the entity for the loaded
172 -- unit (if it is indeed loaded). A value of False means nothing special
173 -- need be done. A value of True indicates that this flag must be set to
174 -- True. It is needed only in the Text_IO_Kludge procedure, which may
175 -- materialize an entity of Text_IO (or [Wide_]Wide_Text_IO) that was
176 -- previously unknown. Id is the RE_Id value of the entity which was
177 -- originally requested. Id is used only for error message detail, and if
178 -- it is RE_Null, then the attempt to output the entity name is ignored.
180 function Make_Unit_Name
181 (U : RT_Unit_Table_Record;
182 N : Node_Id) return Node_Id;
183 -- If the unit is a child unit, build fully qualified name for use in
186 procedure Maybe_Add_With (U : in out RT_Unit_Table_Record);
187 -- If necessary, add an implicit with_clause from the current unit to the
188 -- one represented by U.
190 procedure Output_Entity_Name (Id : RE_Id; Msg : String);
191 -- Output continuation error message giving qualified name of entity
192 -- corresponding to Id, appending the string given by Msg. This call
193 -- is only effective in All_Errors mode.
195 function RE_Chars (E : RE_Id) return Name_Id;
196 -- Given a RE_Id value returns the Chars of the corresponding entity
198 procedure RTE_Error_Msg (Msg : String);
199 -- Generates a message by calling Error_Msg_N specifying Current_Error_Node
200 -- as the node location using the given Msg text. Special processing in the
201 -- case where RTE_Available_Call is set. In this case, no message is output
202 -- and instead RTE_Is_Available is set to False. Note that this can only be
203 -- used if you are sure that the message comes directly or indirectly from
204 -- a call to the RTE function.
210 function Check_CRT (E : RE_Id; Eid : Entity_Id) return Entity_Id is
211 U_Id : constant RTU_Id := RE_Unit_Table (E);
215 if RTE_Available_Call then
216 RTE_Is_Available := False;
218 Entity_Not_Defined (E);
221 raise RE_Not_Available;
223 -- Entity is available
226 -- If in No_Run_Time mode and entity is not in one of the
227 -- specially permitted units, raise the exception.
230 and then not OK_No_Run_Time_Unit (U_Id)
232 Entity_Not_Defined (E);
233 raise RE_Not_Available;
236 -- Otherwise entity is accessible
242 ------------------------
243 -- Entity_Not_Defined --
244 ------------------------
246 procedure Entity_Not_Defined (Id : RE_Id) is
248 if No_Run_Time_Mode then
250 -- If the error occurs when compiling the body of a predefined
251 -- unit for inlining purposes, the body must be illegal in this
252 -- mode, and there is no point in continuing.
254 if Is_Predefined_File_Name
255 (Unit_File_Name (Get_Source_Unit (Sloc (Current_Error_Node))))
258 ("construct not allowed in no run time mode!",
260 raise Unrecoverable_Error;
263 RTE_Error_Msg ("|construct not allowed in no run time mode");
266 elsif Configurable_Run_Time_Mode then
267 RTE_Error_Msg ("|construct not allowed in this configuration>");
269 RTE_Error_Msg ("run-time configuration error");
272 Output_Entity_Name (Id, "not defined");
273 end Entity_Not_Defined;
279 function Get_Unit_Name (U_Id : RTU_Id) return Unit_Name_Type is
280 Uname_Chars : constant String := RTU_Id'Image (U_Id);
283 Name_Len := Uname_Chars'Length;
284 Name_Buffer (1 .. Name_Len) := Uname_Chars;
285 Set_Casing (All_Lower_Case);
287 if U_Id in Ada_Child then
288 Name_Buffer (4) := '.';
290 if U_Id in Ada_Calendar_Child then
291 Name_Buffer (13) := '.';
293 elsif U_Id in Ada_Dispatching_Child then
294 Name_Buffer (16) := '.';
296 elsif U_Id in Ada_Finalization_Child then
297 Name_Buffer (17) := '.';
299 elsif U_Id in Ada_Interrupts_Child then
300 Name_Buffer (15) := '.';
302 elsif U_Id in Ada_Real_Time_Child then
303 Name_Buffer (14) := '.';
305 elsif U_Id in Ada_Streams_Child then
306 Name_Buffer (12) := '.';
308 elsif U_Id in Ada_Strings_Child then
309 Name_Buffer (12) := '.';
311 elsif U_Id in Ada_Text_IO_Child then
312 Name_Buffer (12) := '.';
314 elsif U_Id in Ada_Wide_Text_IO_Child then
315 Name_Buffer (17) := '.';
317 elsif U_Id in Ada_Wide_Wide_Text_IO_Child then
318 Name_Buffer (22) := '.';
321 elsif U_Id in Interfaces_Child then
322 Name_Buffer (11) := '.';
324 elsif U_Id in System_Child then
325 Name_Buffer (7) := '.';
327 if U_Id in System_Strings_Child then
328 Name_Buffer (15) := '.';
331 if U_Id in System_Tasking_Child then
332 Name_Buffer (15) := '.';
335 if U_Id in System_Tasking_Restricted_Child then
336 Name_Buffer (26) := '.';
339 if U_Id in System_Tasking_Protected_Objects_Child then
340 Name_Buffer (33) := '.';
343 if U_Id in System_Tasking_Async_Delays_Child then
344 Name_Buffer (28) := '.';
348 -- Add %s at end for spec
350 Name_Buffer (Name_Len + 1) := '%';
351 Name_Buffer (Name_Len + 2) := 's';
352 Name_Len := Name_Len + 2;
361 procedure Initialize is
363 -- Initialize the unit table
366 RT_Unit_Table (J).Entity := Empty;
370 RE_Table (J) := Empty;
373 RTE_Is_Available := False;
380 function Is_RTE (Ent : Entity_Id; E : RE_Id) return Boolean is
381 E_Unit_Name : Unit_Name_Type;
382 Ent_Unit_Name : Unit_Name_Type;
392 -- If E has already a corresponding entity, check it directly,
393 -- going to full views if they exist to deal with the incomplete
394 -- and private type cases properly.
396 elsif Present (RE_Table (E)) then
399 if Is_Type (E1) and then Present (Full_View (E1)) then
400 E1 := Full_View (E1);
405 if Is_Type (E2) and then Present (Full_View (E2)) then
406 E2 := Full_View (E2);
412 -- If the unit containing E is not loaded, we already know that
413 -- the entity we have cannot have come from this unit.
415 E_Unit_Name := Get_Unit_Name (RE_Unit_Table (E));
417 if not Is_Loaded (E_Unit_Name) then
421 -- Here the unit containing the entity is loaded. We have not made
422 -- an explicit call to RTE to get the entity in question, but we may
423 -- have obtained a reference to it indirectly from some other entity
424 -- in the same unit, or some other unit that references it.
426 -- Get the defining unit of the entity
430 if Ekind (S) /= E_Package then
434 Ent_Unit_Name := Get_Unit_Name (Unit_Declaration_Node (S));
436 -- If the defining unit of the entity we are testing is not the
437 -- unit containing E, then they cannot possibly match.
439 if Ent_Unit_Name /= E_Unit_Name then
443 -- If the units match, then compare the names (remember that no
444 -- overloading is permitted in entities fetched using Rtsfind).
446 if RE_Chars (E) = Chars (Ent) then
449 -- If front-end inlining is enabled, we may be within a body that
450 -- contains inlined functions, which has not been retrieved through
451 -- rtsfind, and therefore is not yet recorded in the RT_Unit_Table.
452 -- Add the unit information now, it must be fully available.
455 U : RT_Unit_Table_Record
456 renames RT_Unit_Table (RE_Unit_Table (E));
458 if No (U.Entity) then
460 U.Uname := E_Unit_Name;
461 U.Unum := Get_Source_Unit (S);
475 function Is_RTU (Ent : Entity_Id; U : RTU_Id) return Boolean is
476 E : constant Entity_Id := RT_Unit_Table (U).Entity;
478 return Present (E) and then E = Ent;
481 ----------------------------
482 -- Is_Text_IO_Kludge_Unit --
483 ----------------------------
485 function Is_Text_IO_Kludge_Unit (Nam : Node_Id) return Boolean is
490 if Nkind (Nam) /= N_Expanded_Name then
495 Sel := Selector_Name (Nam);
497 if Nkind (Sel) /= N_Expanded_Name
498 or else Nkind (Prf) /= N_Identifier
499 or else Chars (Prf) /= Name_Ada
505 Sel := Selector_Name (Sel);
508 Nkind (Prf) = N_Identifier
510 (Chars (Prf) = Name_Text_IO
512 Chars (Prf) = Name_Wide_Text_IO
514 Chars (Prf) = Name_Wide_Wide_Text_IO)
516 Nkind (Sel) = N_Identifier
518 Chars (Sel) in Text_IO_Package_Name;
519 end Is_Text_IO_Kludge_Unit;
525 procedure Load_Fail (S : String; U_Id : RTU_Id; Id : RE_Id) is
526 M : String (1 .. 100);
530 -- Output header message
532 if Configurable_Run_Time_Mode then
533 RTE_Error_Msg ("construct not allowed in configurable run-time mode");
535 RTE_Error_Msg ("run-time library configuration error");
538 -- Output file name and reason string
541 or else not Configurable_Run_Time_Mode
542 or else All_Errors_Mode
544 M (1 .. 6) := "\file ";
548 (Get_File_Name (RT_Unit_Table (U_Id).Uname, Subunit => False));
549 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
555 M (P + 1 .. P + S'Length) := S;
558 RTE_Error_Msg (M (1 .. P));
560 -- Output entity name
562 Output_Entity_Name (Id, "not available");
565 -- In configurable run time mode, we raise RE_Not_Available, and the
566 -- caller is expected to deal gracefully with this. In the case of a
567 -- call to RTE_Available, this exception will be caught in Rtsfind,
568 -- and result in a returned value of False for the call.
570 if Configurable_Run_Time_Mode then
571 raise RE_Not_Available;
573 -- Here we have a load failure in normal full run time mode. See if we
574 -- are in the context of an RTE_Available call. If so, we just raise
575 -- RE_Not_Available. This can happen if a unit is unavailable, which
576 -- happens for example in the VM case, where the run-time is not
577 -- complete, but we do not regard it as a configurable run-time.
578 -- If the caller has done an explicit call to RTE_Available, then
579 -- clearly the caller is prepared to deal with a result of False.
581 elsif RTE_Available_Call then
582 RTE_Is_Available := False;
583 raise RE_Not_Available;
585 -- If we are not in the context of an RTE_Available call, we are really
586 -- trying to load an entity that is not there, and that should never
587 -- happen, so in this case we signal a fatal error.
590 raise Unrecoverable_Error;
600 Id : RE_Id := RE_Null;
601 Use_Setting : Boolean := False)
603 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
604 Priv_Par : constant Elist_Id := New_Elmt_List;
607 procedure Save_Private_Visibility;
608 -- If the current unit is the body of child unit or the spec of a
609 -- private child unit, the private declarations of the parent(s) are
610 -- visible. If the unit to be loaded is another public sibling, its
611 -- compilation will affect the visibility of the common ancestors.
612 -- Indicate those that must be restored.
614 procedure Restore_Private_Visibility;
615 -- Restore the visibility of ancestors after compiling RTU
617 --------------------------------
618 -- Restore_Private_Visibility --
619 --------------------------------
621 procedure Restore_Private_Visibility is
625 E_Par := First_Elmt (Priv_Par);
626 while Present (E_Par) loop
627 if not In_Private_Part (Node (E_Par)) then
628 Install_Private_Declarations (Node (E_Par));
633 end Restore_Private_Visibility;
635 -----------------------------
636 -- Save_Private_Visibility --
637 -----------------------------
639 procedure Save_Private_Visibility is
643 Par := Scope (Current_Scope);
645 and then Par /= Standard_Standard
647 if Ekind (Par) = E_Package
648 and then Is_Compilation_Unit (Par)
649 and then In_Private_Part (Par)
651 Append_Elmt (Par, Priv_Par);
656 end Save_Private_Visibility;
658 -- Start of processing for Load_RTU
661 -- Nothing to do if unit is already loaded
663 if Present (U.Entity) then
667 -- Note if secondary stack is used
669 if U_Id = System_Secondary_Stack then
670 Opt.Sec_Stack_Used := True;
673 -- Otherwise we need to load the unit, First build unit name
674 -- from the enumeration literal name in type RTU_Id.
676 U.Uname := Get_Unit_Name (U_Id);
677 U. First_Implicit_With := Empty;
679 -- Now do the load call, note that setting Error_Node to Empty is
680 -- a signal to Load_Unit that we will regard a failure to find the
681 -- file as a fatal error, and that it should not output any kind
682 -- of diagnostics, since we will take care of it here.
684 -- We save style checking switches and turn off style checking for
685 -- loading the unit, since we don't want any style checking!
688 Save_Style_Check : constant Boolean := Style_Check;
690 Style_Check := False;
693 (Load_Name => U.Uname,
696 Error_Node => Empty);
697 Style_Check := Save_Style_Check;
700 -- Check for bad unit load
702 if U.Unum = No_Unit then
703 Load_Fail ("not found", U_Id, Id);
704 elsif Fatal_Error (U.Unum) then
705 Load_Fail ("had parser errors", U_Id, Id);
708 -- Make sure that the unit is analyzed
711 Was_Analyzed : constant Boolean :=
712 Analyzed (Cunit (Current_Sem_Unit));
715 -- Pretend that the current unit is analyzed, in case it is System
716 -- or some such. This allows us to put some declarations, such as
717 -- exceptions and packed arrays of Boolean, into System even though
718 -- expanding them requires System...
720 -- This is a bit odd but works fine. If the RTS unit does not depend
721 -- in any way on the current unit, then it never gets back into the
722 -- current unit's tree, and the change we make to the current unit
723 -- tree is never noticed by anyone (it is undone in a moment). That
724 -- is the normal situation.
726 -- If the RTS Unit *does* depend on the current unit, for instance,
727 -- when you are compiling System, then you had better have finished
728 -- analyzing the part of System that is depended on before you try to
729 -- load the RTS Unit. This means having the code in System ordered in
730 -- an appropriate manner.
732 Set_Analyzed (Cunit (Current_Sem_Unit), True);
734 if not Analyzed (Cunit (U.Unum)) then
736 -- If the unit is already loaded through a limited_with_clause,
737 -- the relevant entities must already be available. We do not
738 -- want to load and analyze the unit because this would create
739 -- a real semantic dependence when the purpose of the limited_with
740 -- is precisely to avoid such.
742 if From_With_Type (Cunit_Entity (U.Unum)) then
746 Save_Private_Visibility;
747 Semantics (Cunit (U.Unum));
748 Restore_Private_Visibility;
750 if Fatal_Error (U.Unum) then
751 Load_Fail ("had semantic errors", U_Id, Id);
758 Set_Analyzed (Cunit (Current_Sem_Unit), Was_Analyzed);
761 Lib_Unit := Unit (Cunit (U.Unum));
762 U.Entity := Defining_Entity (Lib_Unit);
765 Set_Is_Potentially_Use_Visible (U.Entity, True);
773 function Make_Unit_Name
774 (U : RT_Unit_Table_Record;
775 N : Node_Id) return Node_Id is
781 Nam := New_Reference_To (U.Entity, Standard_Location);
782 Scop := Scope (U.Entity);
784 if Nkind (N) = N_Defining_Program_Unit_Name then
785 while Scop /= Standard_Standard loop
787 Make_Expanded_Name (Standard_Location,
788 Chars => Chars (U.Entity),
789 Prefix => New_Reference_To (Scop, Standard_Location),
790 Selector_Name => Nam);
791 Set_Entity (Nam, U.Entity);
793 Scop := Scope (Scop);
804 procedure Maybe_Add_With (U : in out RT_Unit_Table_Record) is
806 -- We do not need to generate a with_clause for a call issued from
807 -- RTE_Component_Available. However, for Inspector, we need these
808 -- additional with's, because for a sequence like "if RTE_Available (X)
809 -- then ... RTE (X)" the RTE call fails to create some necessary
812 if RTE_Available_Call and then not Inspector_Mode then
816 -- Avoid creating directly self-referential with clauses
818 if Current_Sem_Unit = U.Unum then
822 -- Add the with_clause, if not already in the context of the
823 -- current compilation unit.
826 LibUnit : constant Node_Id := Unit (Cunit (U.Unum));
831 Clause := U.First_Implicit_With;
832 while Present (Clause) loop
833 if Parent (Clause) = Cunit (Current_Sem_Unit) then
837 Clause := Next_Implicit_With (Clause);
841 Make_With_Clause (Standard_Location,
844 (U, Defining_Unit_Name (Specification (LibUnit))));
846 Set_Library_Unit (Withn, Cunit (U.Unum));
847 Set_Corresponding_Spec (Withn, U.Entity);
848 Set_First_Name (Withn, True);
849 Set_Implicit_With (Withn, True);
850 Set_Next_Implicit_With (Withn, U.First_Implicit_With);
852 U.First_Implicit_With := Withn;
854 Mark_Rewrite_Insertion (Withn);
855 Append (Withn, Context_Items (Cunit (Current_Sem_Unit)));
856 Check_Restriction_No_Dependence (Name (Withn), Current_Error_Node);
860 ------------------------
861 -- Output_Entity_Name --
862 ------------------------
864 procedure Output_Entity_Name (Id : RE_Id; Msg : String) is
865 M : String (1 .. 2048);
867 -- M (1 .. P) is current message to be output
869 RE_Image : constant String := RE_Id'Image (Id);
872 if Id = RE_Null or else not All_Errors_Mode then
876 M (1 .. 9) := "\entity """;
879 -- Add unit name to message, excluding %s or %b at end
881 Get_Name_String (Get_Unit_Name (RE_Unit_Table (Id)));
882 Name_Len := Name_Len - 2;
883 Set_Casing (Mixed_Case);
884 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
887 -- Add a qualifying period
892 -- Add entity name and closing quote to message
894 Name_Len := RE_Image'Length - 3;
895 Name_Buffer (1 .. Name_Len) := RE_Image (4 .. RE_Image'Length);
896 Set_Casing (Mixed_Case);
897 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
906 M (P + 1 .. P + Msg'Length) := Msg;
909 -- Output message at current error node location
911 RTE_Error_Msg (M (1 .. P));
912 end Output_Entity_Name;
918 function RE_Chars (E : RE_Id) return Name_Id is
919 RE_Name_Chars : constant String := RE_Id'Image (E);
922 -- Copy name skipping initial RE_ or RO_XX characters
924 if RE_Name_Chars (1 .. 2) = "RE" then
925 for J in 4 .. RE_Name_Chars'Last loop
926 Name_Buffer (J - 3) := Fold_Lower (RE_Name_Chars (J));
929 Name_Len := RE_Name_Chars'Length - 3;
932 for J in 7 .. RE_Name_Chars'Last loop
933 Name_Buffer (J - 6) := Fold_Lower (RE_Name_Chars (J));
936 Name_Len := RE_Name_Chars'Length - 6;
946 function RTE (E : RE_Id) return Entity_Id is
947 U_Id : constant RTU_Id := RE_Unit_Table (E);
948 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
954 -- The following flag is used to disable front-end inlining when RTE
955 -- is invoked. This prevents the analysis of other runtime bodies when
956 -- a particular spec is loaded through Rtsfind. This is both efficient,
957 -- and it prevents spurious visibility conflicts between use-visible
958 -- user entities, and entities in run-time packages.
960 Save_Front_End_Inlining : Boolean;
963 -- Reject programs that make use of distribution features not supported
964 -- on the current target. Also check that the PCS is compatible with
965 -- the code generator version. On such targets (VMS, Vxworks, others?)
966 -- we provide a minimal body for System.Rpc that only supplies an
967 -- implementation of Partition_Id.
969 function Find_Local_Entity (E : RE_Id) return Entity_Id;
970 -- This function is used when entity E is in this compilation's main
971 -- unit. It gets the value from the already compiled declaration.
977 procedure Check_RPC is
979 -- Bypass this check if debug flag -gnatdR set
981 if Debug_Flag_RR then
985 -- Otherwise we need the check if we are going after one of the
986 -- critical entities in System.RPC / System.Partition_Interface.
992 E = RE_Params_Stream_Type
994 E = RE_Request_Access
996 -- If generating RCI stubs, check that we have a real PCS
998 if (Distribution_Stub_Mode = Generate_Receiver_Stub_Body
1000 Distribution_Stub_Mode = Generate_Caller_Stub_Body)
1001 and then Get_PCS_Name = Name_No_DSA
1004 Write_Str ("distribution feature not supported");
1006 raise Unrecoverable_Error;
1008 -- In all cases, check Exp_Dist and System.Partition_Interface
1011 elsif Get_PCS_Version /=
1012 Exp_Dist.PCS_Version_Number (Get_PCS_Name)
1015 Write_Str ("PCS version mismatch: expander ");
1016 Write_Int (Exp_Dist.PCS_Version_Number (Get_PCS_Name));
1017 Write_Str (", PCS (");
1018 Write_Name (Get_PCS_Name);
1020 Write_Int (Get_PCS_Version);
1022 raise Unrecoverable_Error;
1027 -----------------------
1028 -- Find_Local_Entity --
1029 -----------------------
1031 function Find_Local_Entity (E : RE_Id) return Entity_Id is
1032 RE_Str : constant String := RE_Id'Image (E);
1036 Save_Nam : constant String := Name_Buffer (1 .. Name_Len);
1037 -- Save name buffer and length over call
1040 Name_Len := Natural'Max (0, RE_Str'Length - 3);
1041 Name_Buffer (1 .. Name_Len) :=
1042 RE_Str (RE_Str'First + 3 .. RE_Str'Last);
1045 Ent := Entity_Id (Get_Name_Table_Info (Nam));
1047 Name_Len := Save_Nam'Length;
1048 Name_Buffer (1 .. Name_Len) := Save_Nam;
1051 end Find_Local_Entity;
1053 -- Start of processing for RTE
1056 -- Doing a rtsfind in system.ads is special, as we cannot do this
1057 -- when compiling System itself. So if we are compiling system then
1058 -- we should already have acquired and processed the declaration
1059 -- of the entity. The test is to see if this compilation's main unit
1060 -- is System. If so, return the value from the already compiled
1061 -- declaration and otherwise do a regular find.
1063 -- Not pleasant, but these kinds of annoying recursion when
1064 -- writing an Ada compiler in Ada have to be broken somewhere!
1066 if Present (Main_Unit_Entity)
1067 and then Chars (Main_Unit_Entity) = Name_System
1068 and then Analyzed (Main_Unit_Entity)
1069 and then not Is_Child_Unit (Main_Unit_Entity)
1071 return Check_CRT (E, Find_Local_Entity (E));
1074 Save_Front_End_Inlining := Front_End_Inlining;
1075 Front_End_Inlining := False;
1077 -- Load unit if unit not previously loaded
1079 if No (RE_Table (E)) then
1080 Load_RTU (U_Id, Id => E);
1081 Lib_Unit := Unit (Cunit (U.Unum));
1083 -- In the subprogram case, we are all done, the entity we want
1084 -- is the entity for the subprogram itself. Note that we do not
1085 -- bother to check that it is the entity that was requested.
1086 -- the only way that could fail to be the case is if runtime is
1087 -- hopelessly misconfigured, and it isn't worth testing for this.
1089 if Nkind (Lib_Unit) = N_Subprogram_Declaration then
1090 RE_Table (E) := U.Entity;
1092 -- Otherwise we must have the package case. First check package
1093 -- entity itself (e.g. RTE_Name for System.Interrupts.Name)
1096 pragma Assert (Nkind (Lib_Unit) = N_Package_Declaration);
1097 Ename := RE_Chars (E);
1099 -- First we search the package entity chain. If the package
1100 -- only has a limited view, scan the corresponding list of
1101 -- incomplete types.
1103 if From_With_Type (U.Entity) then
1104 Pkg_Ent := First_Entity (Limited_View (U.Entity));
1106 Pkg_Ent := First_Entity (U.Entity);
1109 while Present (Pkg_Ent) loop
1110 if Ename = Chars (Pkg_Ent) then
1111 RE_Table (E) := Pkg_Ent;
1116 Next_Entity (Pkg_Ent);
1119 -- If we did not find the entity in the package entity chain,
1120 -- then check if the package entity itself matches. Note that
1121 -- we do this check after searching the entity chain, since
1122 -- the rule is that in case of ambiguity, we prefer the entity
1123 -- defined within the package, rather than the package itself.
1125 if Ename = Chars (U.Entity) then
1126 RE_Table (E) := U.Entity;
1129 -- If we didn't find the entity we want, something is wrong.
1130 -- We just leave RE_Table (E) set to Empty and the appropriate
1131 -- action will be taken by Check_CRT when we exit.
1139 Front_End_Inlining := Save_Front_End_Inlining;
1140 return Check_CRT (E, RE_Table (E));
1147 function RTE_Available (E : RE_Id) return Boolean is
1149 pragma Warnings (Off, Dummy);
1153 Save_RTE_Available_Call : constant Boolean := RTE_Available_Call;
1154 Save_RTE_Is_Available : constant Boolean := RTE_Is_Available;
1155 -- These are saved recursively because the call to load a unit
1156 -- caused by an upper level call may perform a recursive call
1157 -- to this routine during analysis of the corresponding unit.
1160 RTE_Available_Call := True;
1161 RTE_Is_Available := True;
1163 Result := RTE_Is_Available;
1164 RTE_Available_Call := Save_RTE_Available_Call;
1165 RTE_Is_Available := Save_RTE_Is_Available;
1169 when RE_Not_Available =>
1170 RTE_Available_Call := Save_RTE_Available_Call;
1171 RTE_Is_Available := Save_RTE_Is_Available;
1175 --------------------------
1176 -- RTE_Record_Component --
1177 --------------------------
1179 function RTE_Record_Component (E : RE_Id) return Entity_Id is
1180 U_Id : constant RTU_Id := RE_Unit_Table (E);
1181 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
1184 Found_E : Entity_Id;
1186 Pkg_Ent : Entity_Id;
1188 -- The following flag is used to disable front-end inlining when
1189 -- RTE_Record_Component is invoked. This prevents the analysis of other
1190 -- runtime bodies when a particular spec is loaded through Rtsfind. This
1191 -- is both efficient, and it prevents spurious visibility conflicts
1192 -- between use-visible user entities, and entities in run-time packages.
1194 Save_Front_End_Inlining : Boolean;
1197 -- Note: Contrary to subprogram RTE, there is no need to do any special
1198 -- management with package system.ads because it has no record type
1201 Save_Front_End_Inlining := Front_End_Inlining;
1202 Front_End_Inlining := False;
1204 -- Load unit if unit not previously loaded
1206 if not Present (U.Entity) then
1207 Load_RTU (U_Id, Id => E);
1210 Lib_Unit := Unit (Cunit (U.Unum));
1212 pragma Assert (Nkind (Lib_Unit) = N_Package_Declaration);
1213 Ename := RE_Chars (E);
1215 -- Search the entity in the components of record type declarations
1216 -- found in the package entity chain.
1219 Pkg_Ent := First_Entity (U.Entity);
1220 Search : while Present (Pkg_Ent) loop
1221 if Is_Record_Type (Pkg_Ent) then
1222 E1 := First_Entity (Pkg_Ent);
1223 while Present (E1) loop
1224 if Ename = Chars (E1) then
1225 pragma Assert (not Present (Found_E));
1233 Next_Entity (Pkg_Ent);
1236 -- If we didn't find the entity we want, something is wrong. The
1237 -- appropriate action will be taken by Check_CRT when we exit.
1241 Front_End_Inlining := Save_Front_End_Inlining;
1242 return Check_CRT (E, Found_E);
1243 end RTE_Record_Component;
1245 ------------------------------------
1246 -- RTE_Record_Component_Available --
1247 ------------------------------------
1249 function RTE_Record_Component_Available (E : RE_Id) return Boolean is
1251 pragma Warnings (Off, Dummy);
1255 Save_RTE_Available_Call : constant Boolean := RTE_Available_Call;
1256 Save_RTE_Is_Available : constant Boolean := RTE_Is_Available;
1257 -- These are saved recursively because the call to load a unit
1258 -- caused by an upper level call may perform a recursive call
1259 -- to this routine during analysis of the corresponding unit.
1262 RTE_Available_Call := True;
1263 RTE_Is_Available := True;
1264 Dummy := RTE_Record_Component (E);
1265 Result := RTE_Is_Available;
1266 RTE_Available_Call := Save_RTE_Available_Call;
1267 RTE_Is_Available := Save_RTE_Is_Available;
1271 when RE_Not_Available =>
1272 RTE_Available_Call := Save_RTE_Available_Call;
1273 RTE_Is_Available := Save_RTE_Is_Available;
1275 end RTE_Record_Component_Available;
1281 procedure RTE_Error_Msg (Msg : String) is
1283 if RTE_Available_Call then
1284 RTE_Is_Available := False;
1286 Error_Msg_N (Msg, Current_Error_Node);
1288 -- Bump count of violations if we are in configurable run-time
1289 -- mode and this is not a continuation message.
1291 if Configurable_Run_Time_Mode and then Msg (Msg'First) /= '\' then
1292 Configurable_Run_Time_Violations :=
1293 Configurable_Run_Time_Violations + 1;
1302 function RTU_Entity (U : RTU_Id) return Entity_Id is
1304 return RT_Unit_Table (U).Entity;
1311 function RTU_Loaded (U : RTU_Id) return Boolean is
1313 return Present (RT_Unit_Table (U).Entity);
1316 --------------------
1317 -- Set_RTU_Loaded --
1318 --------------------
1320 procedure Set_RTU_Loaded (N : Node_Id) is
1321 Loc : constant Source_Ptr := Sloc (N);
1322 Unum : constant Unit_Number_Type := Get_Source_Unit (Loc);
1323 Uname : constant Unit_Name_Type := Unit_Name (Unum);
1324 E : constant Entity_Id :=
1325 Defining_Entity (Unit (Cunit (Unum)));
1327 pragma Assert (Is_Predefined_File_Name (Unit_File_Name (Unum)));
1329 -- Loop through entries in RTU table looking for matching entry
1331 for U_Id in RTU_Id'Range loop
1333 -- Here we have a match
1335 if Get_Unit_Name (U_Id) = Uname then
1337 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
1338 -- The RT_Unit_Table entry that may need updating
1341 -- If entry is not set, set it now, and indicate that it
1342 -- was loaded through an explicit context clause..
1344 if No (U.Entity) then
1346 Uname => Get_Unit_Name (U_Id),
1348 First_Implicit_With => Empty);
1357 --------------------
1358 -- Text_IO_Kludge --
1359 --------------------
1361 procedure Text_IO_Kludge (Nam : Node_Id) is
1364 type Name_Map_Type is array (Text_IO_Package_Name) of RTU_Id;
1366 Name_Map : constant Name_Map_Type := Name_Map_Type'(
1367 Name_Decimal_IO => Ada_Text_IO_Decimal_IO,
1368 Name_Enumeration_IO => Ada_Text_IO_Enumeration_IO,
1369 Name_Fixed_IO => Ada_Text_IO_Fixed_IO,
1370 Name_Float_IO => Ada_Text_IO_Float_IO,
1371 Name_Integer_IO => Ada_Text_IO_Integer_IO,
1372 Name_Modular_IO => Ada_Text_IO_Modular_IO);
1374 Wide_Name_Map : constant Name_Map_Type := Name_Map_Type'(
1375 Name_Decimal_IO => Ada_Wide_Text_IO_Decimal_IO,
1376 Name_Enumeration_IO => Ada_Wide_Text_IO_Enumeration_IO,
1377 Name_Fixed_IO => Ada_Wide_Text_IO_Fixed_IO,
1378 Name_Float_IO => Ada_Wide_Text_IO_Float_IO,
1379 Name_Integer_IO => Ada_Wide_Text_IO_Integer_IO,
1380 Name_Modular_IO => Ada_Wide_Text_IO_Modular_IO);
1382 Wide_Wide_Name_Map : constant Name_Map_Type := Name_Map_Type'(
1383 Name_Decimal_IO => Ada_Wide_Wide_Text_IO_Decimal_IO,
1384 Name_Enumeration_IO => Ada_Wide_Wide_Text_IO_Enumeration_IO,
1385 Name_Fixed_IO => Ada_Wide_Wide_Text_IO_Fixed_IO,
1386 Name_Float_IO => Ada_Wide_Wide_Text_IO_Float_IO,
1387 Name_Integer_IO => Ada_Wide_Wide_Text_IO_Integer_IO,
1388 Name_Modular_IO => Ada_Wide_Wide_Text_IO_Modular_IO);
1391 -- Unit to be loaded, from one of the above maps
1394 -- Nothing to do if name is not an identifier or a selected component
1395 -- whose selector_name is an identifier.
1397 if Nkind (Nam) = N_Identifier then
1398 Chrs := Chars (Nam);
1400 elsif Nkind (Nam) = N_Selected_Component
1401 and then Nkind (Selector_Name (Nam)) = N_Identifier
1403 Chrs := Chars (Selector_Name (Nam));
1409 -- Nothing to do if name is not one of the Text_IO subpackages
1410 -- Otherwise look through loaded units, and if we find Text_IO
1411 -- or [Wide_]Wide_Text_IO already loaded, then load the proper child.
1413 if Chrs in Text_IO_Package_Name then
1414 for U in Main_Unit .. Last_Unit loop
1415 Get_Name_String (Unit_File_Name (U));
1417 if Name_Len = 12 then
1419 -- Here is where we do the loads if we find one of the units
1420 -- Ada.Text_IO or Ada.[Wide_]Wide_Text_IO. An interesting
1421 -- detail is that these units may already be used (i.e. their
1422 -- In_Use flags may be set). Normally when the In_Use flag is
1423 -- set, the Is_Potentially_Use_Visible flag of all entities in
1424 -- the package is set, but the new entity we are mysteriously
1425 -- adding was not there to have its flag set at the time. So
1426 -- that's why we pass the extra parameter to RTU_Find, to make
1427 -- sure the flag does get set now. Given that those generic
1428 -- packages are in fact child units, we must indicate that
1429 -- they are visible.
1431 if Name_Buffer (1 .. 12) = "a-textio.ads" then
1432 To_Load := Name_Map (Chrs);
1434 elsif Name_Buffer (1 .. 12) = "a-witeio.ads" then
1435 To_Load := Wide_Name_Map (Chrs);
1437 elsif Name_Buffer (1 .. 12) = "a-ztexio.ads" then
1438 To_Load := Wide_Wide_Name_Map (Chrs);
1444 Load_RTU (To_Load, Use_Setting => In_Use (Cunit_Entity (U)));
1445 Set_Is_Visible_Child_Unit (RT_Unit_Table (To_Load).Entity);
1447 -- Prevent creation of an implicit 'with' from (for example)
1448 -- Ada.Wide_Text_IO.Integer_IO to Ada.Text_IO.Integer_IO,
1449 -- because these could create cycles. First check whether the
1450 -- simple names match ("integer_io" = "integer_io"), and then
1451 -- check whether the parent is indeed one of the
1452 -- [[Wide_]Wide_]Text_IO packages.
1454 if Chrs = Chars (Cunit_Entity (Current_Sem_Unit)) then
1456 Parent_Name : constant Unit_Name_Type :=
1457 Get_Parent_Spec_Name
1458 (Unit_Name (Current_Sem_Unit));
1461 if Parent_Name /= No_Unit_Name then
1462 Get_Name_String (Parent_Name);
1465 P : String renames Name_Buffer (1 .. Name_Len);
1467 if P = "ada.text_io%s" or else
1468 P = "ada.wide_text_io%s" or else
1469 P = "ada.wide_wide_text_io%s"
1478 -- Add an implicit with clause from the current unit to the
1479 -- [[Wide_]Wide_]Text_IO child (if necessary).
1481 Maybe_Add_With (RT_Unit_Table (To_Load));
1489 -- Generate error message if run-time unit not available
1491 when RE_Not_Available =>
1492 Error_Msg_N ("& not available", Nam);