1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004, 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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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;
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;
44 with Sem_Ch7; use Sem_Ch7;
45 with Sem_Util; use Sem_Util;
46 with Sinfo; use Sinfo;
47 with Stand; use Stand;
48 with Snames; use Snames;
49 with Tbuild; use Tbuild;
50 with Uname; use Uname;
52 package body Rtsfind is
54 RTE_Available_Call : Boolean := False;
55 -- Set True during call to RTE from RTE_Available. Tells RTE to set
56 -- RTE_Is_Available to False rather than generating an error message.
58 RTE_Is_Available : Boolean;
59 -- Set True by RTE_Available on entry. When RTE_Available_Call is set
60 -- True, set False if RTE would otherwise generate an error message.
66 -- The unit table has one entry for each unit included in the definition
67 -- of the type RTU_Id in the spec. The table entries are initialized in
68 -- Initialize to set the Entity field to Empty, indicating that the
69 -- corresponding unit has not yet been loaded. The fields are set when
70 -- a unit is loaded to contain the defining entity for the unit, the
71 -- unit name, and the unit number.
73 type RT_Unit_Table_Record is record
75 Uname : Unit_Name_Type;
76 Unum : Unit_Number_Type;
80 RT_Unit_Table : array (RTU_Id) of RT_Unit_Table_Record;
82 --------------------------
83 -- Runtime Entity Table --
84 --------------------------
86 -- There is one entry in the runtime entity table for each entity that is
87 -- included in the definition of the RE_Id type in the spec. The entries
88 -- are set by Initialize_Rtsfind to contain Empty, indicating that the
89 -- entity has not yet been located. Once the entity is located for the
90 -- first time, its ID is stored in this array, so that subsequent calls
91 -- for the same entity can be satisfied immediately.
93 RE_Table : array (RE_Id) of Entity_Id;
95 --------------------------
96 -- Generation of WITH's --
97 --------------------------
99 -- When a unit is implicitly loaded as a result of a call to RTE, it
100 -- is necessary to create an implicit WITH to ensure that the object
101 -- is correctly loaded by the binder. Such WITH statements are only
102 -- required when the request is from the extended main unit (if a
103 -- client needs a WITH, that will be taken care of when the client
106 -- We always attach the WITH to the main unit. This is not perfectly
107 -- accurate in terms of elaboration requirements, but it is close
108 -- enough, since the units that are accessed using rtsfind do not
109 -- have delicate elaboration requirements.
111 -- The flag Withed in the unit table record is initially set to False.
112 -- It is set True if a WITH has been generated for the main unit for
113 -- the corresponding unit.
115 -----------------------
116 -- Local Subprograms --
117 -----------------------
119 procedure Entity_Not_Defined (Id : RE_Id);
120 -- Outputs error messages for an entity that is not defined in the
121 -- run-time library (the form of the error message is tailored for
122 -- no run time/configurable run time mode as required).
124 procedure Load_Fail (S : String; U_Id : RTU_Id; Id : RE_Id);
125 -- Internal procedure called if we can't sucessfully locate or
126 -- process a run-time unit. The parameters give information about
127 -- the error message to be given. S is a reason for failing to
128 -- compile the file and U_Id is the unit id. RE_Id is the RE_Id
129 -- originally passed to RTE. The message in S is one of the
133 -- "had parser errors"
134 -- "had semantic errors"
136 -- The "not found" case is treated specially in that it is considered
137 -- a normal situation in configurable run-time mode (and the message in
138 -- this case is suppressed unless we are operating in All_Errors_Mode).
140 function Get_Unit_Name (U_Id : RTU_Id) return Unit_Name_Type;
141 -- Retrieves the Unit Name given a unit id represented by its
142 -- enumaration value in RTU_Id.
146 Id : RE_Id := RE_Null;
147 Use_Setting : Boolean := False);
148 -- Load the unit whose Id is given if not already loaded. The unit is
149 -- loaded, analyzed, and added to the WITH list, and the entry in
150 -- RT_Unit_Table is updated to reflect the load. The second parameter
151 -- indicates the initial setting for the Is_Potentially_Use_Visible
152 -- flag of the entity for the loaded unit (if it is indeed loaded).
153 -- A value of False means nothing special need be done. A value of
154 -- True indicates that this flag must be set to True. It is needed
155 -- only in the Text_IO_Kludge procedure, which may materialize an
156 -- entity of Text_IO (or Wide_Text_IO) that was previously unknown.
157 -- Id is the RE_Id value of the entity which was originally requested.
158 -- Id is used only for error message detail, and if it is RE_Null, then
159 -- the attempt to output the entity name is ignored.
161 procedure Output_Entity_Name (Id : RE_Id; Msg : String);
162 -- Output continuation error message giving qualified name of entity
163 -- corresponding to Id, appending the string given by Msg. This call
164 -- is only effective in All_Errors mode.
166 function RE_Chars (E : RE_Id) return Name_Id;
167 -- Given a RE_Id value returns the Chars of the corresponding entity.
169 procedure RTE_Error_Msg (Msg : String);
170 -- Generates a message by calling Error_Msg_N specifying Current_Error_Node
171 -- as the node location using the given Msg text. Special processing in the
172 -- case where RTE_Available_Call is set. In this case, no message is output
173 -- and instead RTE_Is_Available is set to False. Note that this can only be
174 -- used if you are sure that the message comes directly or indirectly from
175 -- a call to the RTE function.
177 ------------------------
178 -- Entity_Not_Defined --
179 ------------------------
181 procedure Entity_Not_Defined (Id : RE_Id) is
183 if No_Run_Time_Mode then
184 RTE_Error_Msg ("|construct not allowed in no run time mode");
185 elsif Configurable_Run_Time_Mode then
186 RTE_Error_Msg ("|construct not allowed in this configuration>");
188 RTE_Error_Msg ("run-time configuration error");
191 Output_Entity_Name (Id, "not defined");
192 end Entity_Not_Defined;
198 function Get_Unit_Name (U_Id : RTU_Id) return Unit_Name_Type is
199 Uname_Chars : constant String := RTU_Id'Image (U_Id);
202 Name_Len := Uname_Chars'Length;
203 Name_Buffer (1 .. Name_Len) := Uname_Chars;
204 Set_Casing (All_Lower_Case);
206 if U_Id in Ada_Child then
207 Name_Buffer (4) := '.';
209 if U_Id in Ada_Calendar_Child then
210 Name_Buffer (13) := '.';
212 elsif U_Id in Ada_Finalization_Child then
213 Name_Buffer (17) := '.';
215 elsif U_Id in Ada_Interrupts_Child then
216 Name_Buffer (15) := '.';
218 elsif U_Id in Ada_Real_Time_Child then
219 Name_Buffer (14) := '.';
221 elsif U_Id in Ada_Streams_Child then
222 Name_Buffer (12) := '.';
224 elsif U_Id in Ada_Text_IO_Child then
225 Name_Buffer (12) := '.';
227 elsif U_Id in Ada_Wide_Text_IO_Child then
228 Name_Buffer (17) := '.';
231 elsif U_Id in Interfaces_Child then
232 Name_Buffer (11) := '.';
234 elsif U_Id in System_Child then
235 Name_Buffer (7) := '.';
237 if U_Id in System_Tasking_Child then
238 Name_Buffer (15) := '.';
241 if U_Id in System_Tasking_Restricted_Child then
242 Name_Buffer (26) := '.';
245 if U_Id in System_Tasking_Protected_Objects_Child then
246 Name_Buffer (33) := '.';
249 if U_Id in System_Tasking_Async_Delays_Child then
250 Name_Buffer (28) := '.';
254 -- Add %s at end for spec
256 Name_Buffer (Name_Len + 1) := '%';
257 Name_Buffer (Name_Len + 2) := 's';
258 Name_Len := Name_Len + 2;
267 procedure Initialize is
269 -- Initialize the unit table
272 RT_Unit_Table (J).Entity := Empty;
276 RE_Table (J) := Empty;
279 RTE_Is_Available := False;
286 function Is_RTE (Ent : Entity_Id; E : RE_Id) return Boolean is
287 E_Unit_Name : Unit_Name_Type;
288 Ent_Unit_Name : Unit_Name_Type;
298 -- If E has already a corresponding entity, check it directly,
299 -- going to full views if they exist to deal with the incomplete
300 -- and private type cases properly.
302 elsif Present (RE_Table (E)) then
305 if Is_Type (E1) and then Present (Full_View (E1)) then
306 E1 := Full_View (E1);
311 if Is_Type (E2) and then Present (Full_View (E2)) then
312 E2 := Full_View (E2);
318 -- If the unit containing E is not loaded, we already know that
319 -- the entity we have cannot have come from this unit.
321 E_Unit_Name := Get_Unit_Name (RE_Unit_Table (E));
323 if not Is_Loaded (E_Unit_Name) then
327 -- Here the unit containing the entity is loaded. We have not made
328 -- an explicit call to RTE to get the entity in question, but we may
329 -- have obtained a reference to it indirectly from some other entity
330 -- in the same unit, or some other unit that references it.
332 -- Get the defining unit of the entity
336 if Ekind (S) /= E_Package then
340 Ent_Unit_Name := Get_Unit_Name (Unit_Declaration_Node (S));
342 -- If the defining unit of the entity we are testing is not the
343 -- unit containing E, then they cannot possibly match.
345 if Ent_Unit_Name /= E_Unit_Name then
349 -- If the units match, then compare the names (remember that no
350 -- overloading is permitted in entities fetched using Rtsfind).
352 if RE_Chars (E) = Chars (Ent) then
355 -- If front-end inlining is enabled, we may be within a body that
356 -- contains inlined functions, which has not been retrieved through
357 -- rtsfind, and therefore is not yet recorded in the RT_Unit_Table.
358 -- Add the unit information now, it must be fully available.
361 U : RT_Unit_Table_Record
362 renames RT_Unit_Table (RE_Unit_Table (E));
364 if No (U.Entity) then
366 U.Uname := E_Unit_Name;
367 U.Unum := Get_Source_Unit (S);
381 function Is_RTU (Ent : Entity_Id; U : RTU_Id) return Boolean is
382 E : constant Entity_Id := RT_Unit_Table (U).Entity;
384 return Present (E) and then E = Ent;
387 ----------------------------
388 -- Is_Text_IO_Kludge_Unit --
389 ----------------------------
391 function Is_Text_IO_Kludge_Unit (Nam : Node_Id) return Boolean is
396 if Nkind (Nam) /= N_Expanded_Name then
401 Sel := Selector_Name (Nam);
403 if Nkind (Sel) /= N_Expanded_Name
404 or else Nkind (Prf) /= N_Identifier
405 or else Chars (Prf) /= Name_Ada
411 Sel := Selector_Name (Sel);
414 Nkind (Prf) = N_Identifier
416 (Chars (Prf) = Name_Text_IO or else Chars (Prf) = Name_Wide_Text_IO)
418 Nkind (Sel) = N_Identifier
420 Chars (Sel) in Text_IO_Package_Name;
421 end Is_Text_IO_Kludge_Unit;
427 procedure Load_Fail (S : String; U_Id : RTU_Id; Id : RE_Id) is
428 M : String (1 .. 100);
432 -- Output header message
434 if Configurable_Run_Time_Mode then
435 RTE_Error_Msg ("construct not allowed in configurable run-time mode");
437 RTE_Error_Msg ("run-time library configuration error");
440 -- Output file name and reason string
443 or else not Configurable_Run_Time_Mode
444 or else All_Errors_Mode
446 M (1 .. 6) := "\file ";
450 (Get_File_Name (RT_Unit_Table (U_Id).Uname, Subunit => False));
451 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
457 M (P + 1 .. P + S'Length) := S;
460 RTE_Error_Msg (M (1 .. P));
462 -- Output entity name
464 Output_Entity_Name (Id, "not available");
467 raise RE_Not_Available;
476 Id : RE_Id := RE_Null;
477 Use_Setting : Boolean := False)
479 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
480 Priv_Par : constant Elist_Id := New_Elmt_List;
483 procedure Save_Private_Visibility;
484 -- If the current unit is the body of child unit or the spec of a
485 -- private child unit, the private declarations of the parent (s)
486 -- are visible. If the unit to be loaded is another public sibling,
487 -- its compilation will affect the visibility of the common ancestors.
488 -- Indicate those that must be restored.
490 procedure Restore_Private_Visibility;
491 -- Restore the visibility of ancestors after compiling RTU.
493 --------------------------------
494 -- Restore_Private_Visibility --
495 --------------------------------
497 procedure Restore_Private_Visibility is
501 E_Par := First_Elmt (Priv_Par);
503 while Present (E_Par) loop
504 if not In_Private_Part (Node (E_Par)) then
505 Install_Private_Declarations (Node (E_Par));
510 end Restore_Private_Visibility;
512 -----------------------------
513 -- Save_Private_Visibility --
514 -----------------------------
516 procedure Save_Private_Visibility is
520 Par := Scope (Current_Scope);
523 and then Par /= Standard_Standard
525 if Ekind (Par) = E_Package
526 and then Is_Compilation_Unit (Par)
527 and then In_Private_Part (Par)
529 Append_Elmt (Par, Priv_Par);
534 end Save_Private_Visibility;
536 -- Start of processing for Load_RTU
539 -- Nothing to do if unit is already loaded
541 if Present (U.Entity) then
545 -- Note if secondary stack is used
547 if U_Id = System_Secondary_Stack then
548 Opt.Sec_Stack_Used := True;
551 -- Otherwise we need to load the unit, First build unit name
552 -- from the enumeration literal name in type RTU_Id.
554 U.Uname := Get_Unit_Name (U_Id);
559 pragma Warnings (Off, Loaded);
561 Loaded := Is_Loaded (U.Uname);
564 -- Now do the load call, note that setting Error_Node to Empty is
565 -- a signal to Load_Unit that we will regard a failure to find the
566 -- file as a fatal error, and that it should not output any kind
567 -- of diagnostics, since we will take care of it here.
571 (Load_Name => U.Uname,
574 Error_Node => Empty);
576 if U.Unum = No_Unit then
577 Load_Fail ("not found", U_Id, Id);
578 elsif Fatal_Error (U.Unum) then
579 Load_Fail ("had parser errors", U_Id, Id);
582 -- Make sure that the unit is analyzed
585 Was_Analyzed : constant Boolean :=
586 Analyzed (Cunit (Current_Sem_Unit));
589 -- Pretend that the current unit is analyzed, in case it is System
590 -- or some such. This allows us to put some declarations, such as
591 -- exceptions and packed arrays of Boolean, into System even though
592 -- expanding them requires System...
594 -- This is a bit odd but works fine. If the RTS unit does not depend
595 -- in any way on the current unit, then it never gets back into the
596 -- current unit's tree, and the change we make to the current unit
597 -- tree is never noticed by anyone (it is undone in a moment). That
598 -- is the normal situation.
600 -- If the RTS Unit *does* depend on the current unit, for instance,
601 -- when you are compiling System, then you had better have finished
602 -- analyzing the part of System that is depended on before you try
603 -- to load the RTS Unit. This means having the System ordered in an
604 -- appropriate manner.
606 Set_Analyzed (Cunit (Current_Sem_Unit), True);
608 if not Analyzed (Cunit (U.Unum)) then
609 Save_Private_Visibility;
610 Semantics (Cunit (U.Unum));
611 Restore_Private_Visibility;
613 if Fatal_Error (U.Unum) then
614 Load_Fail ("had semantic errors", U_Id, Id);
620 Set_Analyzed (Cunit (Current_Sem_Unit), Was_Analyzed);
623 Lib_Unit := Unit (Cunit (U.Unum));
624 U.Entity := Defining_Entity (Lib_Unit);
627 Set_Is_Potentially_Use_Visible (U.Entity, True);
631 -----------------------
632 -- Output_Entity_Name --
633 ------------------------
635 procedure Output_Entity_Name (Id : RE_Id; Msg : String) is
636 M : String (1 .. 2048);
638 -- M (1 .. P) is current message to be output
640 RE_Image : constant String := RE_Id'Image (Id);
643 if Id = RE_Null or else not All_Errors_Mode then
647 M (1 .. 9) := "\entity """;
650 -- Add unit name to message, excluding %s or %b at end
652 Get_Name_String (Get_Unit_Name (RE_Unit_Table (Id)));
653 Name_Len := Name_Len - 2;
654 Set_Casing (Mixed_Case);
655 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
658 -- Add a qualifying period
663 -- Add entity name and closing quote to message
665 Name_Len := RE_Image'Length - 3;
666 Name_Buffer (1 .. Name_Len) := RE_Image (4 .. RE_Image'Length);
667 Set_Casing (Mixed_Case);
668 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
677 M (P + 1 .. P + Msg'Length) := Msg;
680 -- Output message at current error node location
682 RTE_Error_Msg (M (1 .. P));
683 end Output_Entity_Name;
689 function RE_Chars (E : RE_Id) return Name_Id is
690 RE_Name_Chars : constant String := RE_Id'Image (E);
693 -- Copy name skipping initial RE_ or RO_XX characters
695 if RE_Name_Chars (1 .. 2) = "RE" then
696 for J in 4 .. RE_Name_Chars'Last loop
697 Name_Buffer (J - 3) := Fold_Lower (RE_Name_Chars (J));
700 Name_Len := RE_Name_Chars'Length - 3;
703 for J in 7 .. RE_Name_Chars'Last loop
704 Name_Buffer (J - 6) := Fold_Lower (RE_Name_Chars (J));
707 Name_Len := RE_Name_Chars'Length - 6;
717 function RTE (E : RE_Id) return Entity_Id is
718 U_Id : constant RTU_Id := RE_Unit_Table (E);
719 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
725 -- The following flag is used to disable front-end inlining when RTE
726 -- is invoked. This prevents the analysis of other runtime bodies when
727 -- a particular spec is loaded through Rtsfind. This is both efficient,
728 -- and it prevents spurious visibility conflicts between use-visible
729 -- user entities, and entities in run-time packages.
731 -- In configurable run-time mode, subprograms marked Inlined_Always must
732 -- be inlined, so in the case we retain the Front_End_Inlining mode.
734 Save_Front_End_Inlining : Boolean;
736 function Check_CRT (Eid : Entity_Id) return Entity_Id;
737 -- Check entity Eid to ensure that configurable run-time restrictions
738 -- are met. May generate an error message and raise RE_Not_Available
739 -- if the entity E does not exist (i.e. Eid is Empty)
742 -- Reject programs that make use of distribution features not supported
743 -- on the current target. On such targets (VMS, Vxworks, others?) we
744 -- only provide a minimal body for System.Rpc that only supplies an
745 -- implementation of partition_id.
747 function Find_Local_Entity (E : RE_Id) return Entity_Id;
748 -- This function is used when entity E is in this compilation's main
749 -- unit. It gets the value from the already compiled declaration.
751 function Make_Unit_Name (N : Node_Id) return Node_Id;
752 -- If the unit is a child unit, build fully qualified name for use
759 function Check_CRT (Eid : Entity_Id) return Entity_Id is
762 Entity_Not_Defined (E);
763 raise RE_Not_Available;
765 -- Entity is available
768 -- If in No_Run_Time mode and entity is not in one of the
769 -- specially permitted units, raise the exception.
772 and then not OK_No_Run_Time_Unit (U_Id)
774 Entity_Not_Defined (E);
775 raise RE_Not_Available;
778 -- Otherwise entity is accessible
788 procedure Check_RPC is
790 -- Bypass this check if debug flag -gnatdR set
792 if Debug_Flag_RR then
796 -- Otherwise we need the check if we are going after one of
797 -- the critical entities in System.RPC in stubs mode.
799 -- ??? Should we do this for other s-parint/s-polint entities
802 if (Distribution_Stub_Mode = Generate_Receiver_Stub_Body
804 Distribution_Stub_Mode = Generate_Caller_Stub_Body)
805 and then (E = RE_Do_Rpc
809 E = RE_Params_Stream_Type
814 DSA_Implementation : constant Entity_Id :=
815 RTE (RE_DSA_Implementation);
817 if Chars (Entity (Expression
818 (Parent (DSA_Implementation)))) = Name_No_DSA
821 Write_Str ("distribution feature not supported");
823 raise Unrecoverable_Error;
829 ------------------------
830 -- Find_System_Entity --
831 ------------------------
833 function Find_Local_Entity (E : RE_Id) return Entity_Id is
834 RE_Str : String renames RE_Id'Image (E);
837 Save_Nam : constant String := Name_Buffer (1 .. Name_Len);
838 -- Save name buffer and length over call
841 Name_Len := Natural'Max (0, RE_Str'Length - 3);
842 Name_Buffer (1 .. Name_Len) :=
843 RE_Str (RE_Str'First + 3 .. RE_Str'Last);
845 Ent := Entity_Id (Get_Name_Table_Info (Name_Find));
847 Name_Len := Save_Nam'Length;
848 Name_Buffer (1 .. Name_Len) := Save_Nam;
851 end Find_Local_Entity;
857 function Make_Unit_Name (N : Node_Id) return Node_Id is
862 Nam := New_Reference_To (U.Entity, Standard_Location);
863 Scop := Scope (U.Entity);
865 if Nkind (N) = N_Defining_Program_Unit_Name then
866 while Scop /= Standard_Standard loop
868 Make_Expanded_Name (Standard_Location,
869 Chars => Chars (U.Entity),
870 Prefix => New_Reference_To (Scop, Standard_Location),
871 Selector_Name => Nam);
872 Set_Entity (Nam, U.Entity);
874 Scop := Scope (Scop);
881 -- Start of processing for RTE
884 -- Doing a rtsfind in system.ads is special, as we cannot do this
885 -- when compiling System itself. So if we are compiling system then
886 -- we should already have acquired and processed the declaration
887 -- of the entity. The test is to see if this compilation's main unit
888 -- is System. If so, return the value from the already compiled
889 -- declaration and otherwise do a regular find.
891 -- Not pleasant, but these kinds of annoying recursion when
892 -- writing an Ada compiler in Ada have to be broken somewhere!
894 if Present (Main_Unit_Entity)
895 and then Chars (Main_Unit_Entity) = Name_System
896 and then Analyzed (Main_Unit_Entity)
897 and then not Is_Child_Unit (Main_Unit_Entity)
899 return Check_CRT (Find_Local_Entity (E));
902 Save_Front_End_Inlining := Front_End_Inlining;
903 Front_End_Inlining := Configurable_Run_Time_Mode;
905 -- Load unit if unit not previously loaded
907 if No (RE_Table (E)) then
908 Load_RTU (U_Id, Id => E);
909 Lib_Unit := Unit (Cunit (U.Unum));
911 -- In the subprogram case, we are all done, the entity we want
912 -- is the entity for the subprogram itself. Note that we do not
913 -- bother to check that it is the entity that was requested.
914 -- the only way that could fail to be the case is if runtime is
915 -- hopelessly misconfigured, and it isn't worth testing for this.
917 if Nkind (Lib_Unit) = N_Subprogram_Declaration then
918 RE_Table (E) := U.Entity;
920 -- Otherwise we must have the package case. First check package
921 -- entity itself (e.g. RTE_Name for System.Interrupts.Name)
924 pragma Assert (Nkind (Lib_Unit) = N_Package_Declaration);
925 Ename := RE_Chars (E);
927 -- First we search the package entity chain
929 Pkg_Ent := First_Entity (U.Entity);
930 while Present (Pkg_Ent) loop
931 if Ename = Chars (Pkg_Ent) then
932 RE_Table (E) := Pkg_Ent;
937 Next_Entity (Pkg_Ent);
940 -- If we did not find the entity in the package entity chain,
941 -- then check if the package entity itself matches. Note that
942 -- we do this check after searching the entity chain, since
943 -- the rule is that in case of ambiguity, we prefer the entity
944 -- defined within the package, rather than the package itself.
946 if Ename = Chars (U.Entity) then
947 RE_Table (E) := U.Entity;
950 -- If we didn't find the entity we want, something is wrong.
951 -- We just leave RE_Table (E) set to Empty and the appropriate
952 -- action will be taken by Check_CRT when we exit.
957 -- See if we have to generate a WITH for this entity. We generate
958 -- a WITH if the current unit is part of the extended main code
959 -- unit, and if we have not already added the with. The WITH is
960 -- added to the appropriate unit (the current one). We do not need
961 -- to generate a WITH for an
966 In_Extended_Main_Code_Unit (Cunit_Entity (Current_Sem_Unit))
967 and then not RTE_Available_Call
976 Lib_Unit := Unit (Cunit (U.Unum));
978 Make_With_Clause (Standard_Location,
981 (Defining_Unit_Name (Specification (Lib_Unit))));
982 Set_Library_Unit (Withn, Cunit (U.Unum));
983 Set_Corresponding_Spec (Withn, U.Entity);
984 Set_First_Name (Withn, True);
985 Set_Implicit_With (Withn, True);
987 Mark_Rewrite_Insertion (Withn);
988 Append (Withn, Context_Items (Cunit (Current_Sem_Unit)));
992 Front_End_Inlining := Save_Front_End_Inlining;
993 return Check_CRT (RE_Table (E));
1000 function RTE_Available (E : RE_Id) return Boolean is
1002 pragma Warnings (Off, Dummy);
1006 Save_RTE_Available_Call : constant Boolean := RTE_Available_Call;
1007 Save_RTE_Is_Available : constant Boolean := RTE_Is_Available;
1008 -- These are saved recursively because the call to load a unit
1009 -- caused by an upper level call may perform a recursive call
1010 -- to this routine during analysis of the corresponding unit.
1013 RTE_Available_Call := True;
1014 RTE_Is_Available := True;
1016 Result := RTE_Is_Available;
1017 RTE_Available_Call := Save_RTE_Available_Call;
1018 RTE_Is_Available := Save_RTE_Is_Available;
1022 when RE_Not_Available =>
1023 RTE_Available_Call := Save_RTE_Available_Call;
1024 RTE_Is_Available := Save_RTE_Is_Available;
1032 procedure RTE_Error_Msg (Msg : String) is
1034 if RTE_Available_Call then
1035 RTE_Is_Available := False;
1037 Error_Msg_N (Msg, Current_Error_Node);
1039 -- Bump count of violations if we are in configurable run-time
1040 -- mode and this is not a continuation message.
1042 if Configurable_Run_Time_Mode and then Msg (1) /= '\' then
1043 Configurable_Run_Time_Violations :=
1044 Configurable_Run_Time_Violations + 1;
1053 function RTU_Loaded (U : RTU_Id) return Boolean is
1055 return Present (RT_Unit_Table (U).Entity);
1058 --------------------
1059 -- Text_IO_Kludge --
1060 --------------------
1062 procedure Text_IO_Kludge (Nam : Node_Id) is
1065 type Name_Map_Type is array (Text_IO_Package_Name) of RTU_Id;
1067 Name_Map : constant Name_Map_Type := Name_Map_Type'(
1068 Name_Decimal_IO => Ada_Text_IO_Decimal_IO,
1069 Name_Enumeration_IO => Ada_Text_IO_Enumeration_IO,
1070 Name_Fixed_IO => Ada_Text_IO_Fixed_IO,
1071 Name_Float_IO => Ada_Text_IO_Float_IO,
1072 Name_Integer_IO => Ada_Text_IO_Integer_IO,
1073 Name_Modular_IO => Ada_Text_IO_Modular_IO);
1075 Wide_Name_Map : constant Name_Map_Type := Name_Map_Type'(
1076 Name_Decimal_IO => Ada_Wide_Text_IO_Decimal_IO,
1077 Name_Enumeration_IO => Ada_Wide_Text_IO_Enumeration_IO,
1078 Name_Fixed_IO => Ada_Wide_Text_IO_Fixed_IO,
1079 Name_Float_IO => Ada_Wide_Text_IO_Float_IO,
1080 Name_Integer_IO => Ada_Wide_Text_IO_Integer_IO,
1081 Name_Modular_IO => Ada_Wide_Text_IO_Modular_IO);
1084 -- Nothing to do if name is not identifier or a selected component
1085 -- whose selector_name is not an identifier.
1087 if Nkind (Nam) = N_Identifier then
1088 Chrs := Chars (Nam);
1090 elsif Nkind (Nam) = N_Selected_Component
1091 and then Nkind (Selector_Name (Nam)) = N_Identifier
1093 Chrs := Chars (Selector_Name (Nam));
1099 -- Nothing to do if name is not one of the Text_IO subpackages
1100 -- Otherwise look through loaded units, and if we find Text_IO
1101 -- or Wide_Text_IO already loaded, then load the proper child.
1103 if Chrs in Text_IO_Package_Name then
1104 for U in Main_Unit .. Last_Unit loop
1105 Get_Name_String (Unit_File_Name (U));
1107 if Name_Len = 12 then
1109 -- Here is where we do the loads if we find one of the
1110 -- units Ada.Text_IO or Ada.Wide_Text_IO. An interesting
1111 -- detail is that these units may already be used (i.e.
1112 -- their In_Use flags may be set). Normally when the In_Use
1113 -- flag is set, the Is_Potentially_Use_Visible flag of all
1114 -- entities in the package is set, but the new entity we
1115 -- are mysteriously adding was not there to have its flag
1116 -- set at the time. So that's why we pass the extra parameter
1117 -- to RTU_Find, to make sure the flag does get set now.
1118 -- Given that those generic packages are in fact child units,
1119 -- we must indicate that they are visible.
1121 if Name_Buffer (1 .. 12) = "a-textio.ads" then
1124 Use_Setting => In_Use (Cunit_Entity (U)));
1125 Set_Is_Visible_Child_Unit
1126 (RT_Unit_Table (Name_Map (Chrs)).Entity);
1128 elsif Name_Buffer (1 .. 12) = "a-witeio.ads" then
1130 (Wide_Name_Map (Chrs),
1131 Use_Setting => In_Use (Cunit_Entity (U)));
1132 Set_Is_Visible_Child_Unit
1133 (RT_Unit_Table (Wide_Name_Map (Chrs)).Entity);