Makefile.in: Rebuilt.
[official-gcc.git] / gcc / ada / rtsfind.adb
blob2ab53d4ecf7e9d230f1b71a44e0c50b6bdb1012a
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- R T S F I N D --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Casing; use Casing;
29 with Csets; use Csets;
30 with Debug; use Debug;
31 with Einfo; use Einfo;
32 with Elists; use Elists;
33 with Errout; use Errout;
34 with Fname; use Fname;
35 with Fname.UF; use Fname.UF;
36 with Lib; use Lib;
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;
42 with Opt; use Opt;
43 with Restrict; use Restrict;
44 with Sem; use Sem;
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. Tells RTE to set
58 -- RTE_Is_Available to False rather than generating an error message.
60 RTE_Is_Available : Boolean;
61 -- Set True by RTE_Available on entry. When RTE_Available_Call is set
62 -- True, set False if RTE would otherwise generate an error message.
64 ----------------
65 -- Unit table --
66 ----------------
68 -- The unit table has one entry for each unit included in the definition
69 -- of the type RTU_Id in the spec. The table entries are initialized in
70 -- Initialize to set the Entity field to Empty, indicating that the
71 -- corresponding unit has not yet been loaded. The fields are set when
72 -- a unit is loaded to contain the defining entity for the unit, the
73 -- unit name, and the unit number.
75 -- Note that a unit can be loaded either by a call to find an entity
76 -- within the unit (e.g. RTE), or by an explicit with of the unit. In
77 -- the latter case it is critical to make a call to Set_RTU_Loaded to
78 -- ensure that the entry in this table reflects the load.
80 type RT_Unit_Table_Record is record
81 Entity : Entity_Id;
82 Uname : Unit_Name_Type;
83 Unum : Unit_Number_Type;
84 Withed : Boolean;
85 end record;
87 RT_Unit_Table : array (RTU_Id) of RT_Unit_Table_Record;
89 --------------------------
90 -- Runtime Entity Table --
91 --------------------------
93 -- There is one entry in the runtime entity table for each entity that is
94 -- included in the definition of the RE_Id type in the spec. The entries
95 -- are set by Initialize_Rtsfind to contain Empty, indicating that the
96 -- entity has not yet been located. Once the entity is located for the
97 -- first time, its ID is stored in this array, so that subsequent calls
98 -- for the same entity can be satisfied immediately.
100 RE_Table : array (RE_Id) of Entity_Id;
102 --------------------------
103 -- Generation of WITH's --
104 --------------------------
106 -- When a unit is implicitly loaded as a result of a call to RTE, it
107 -- is necessary to create an implicit WITH to ensure that the object
108 -- is correctly loaded by the binder. Such WITH statements are only
109 -- required when the request is from the extended main unit (if a
110 -- client needs a WITH, that will be taken care of when the client
111 -- is compiled).
113 -- We always attach the WITH to the main unit. This is not perfectly
114 -- accurate in terms of elaboration requirements, but it is close
115 -- enough, since the units that are accessed using rtsfind do not
116 -- have delicate elaboration requirements.
118 -- The flag Withed in the unit table record is initially set to False.
119 -- It is set True if a WITH has been generated for the main unit for
120 -- the corresponding unit.
122 -----------------------
123 -- Local Subprograms --
124 -----------------------
126 procedure Entity_Not_Defined (Id : RE_Id);
127 -- Outputs error messages for an entity that is not defined in the
128 -- run-time library (the form of the error message is tailored for
129 -- no run time/configurable run time mode as required).
131 procedure Load_Fail (S : String; U_Id : RTU_Id; Id : RE_Id);
132 -- Internal procedure called if we can't sucessfully locate or
133 -- process a run-time unit. The parameters give information about
134 -- the error message to be given. S is a reason for failing to
135 -- compile the file and U_Id is the unit id. RE_Id is the RE_Id
136 -- originally passed to RTE. The message in S is one of the
137 -- following:
139 -- "not found"
140 -- "had parser errors"
141 -- "had semantic errors"
143 -- The "not found" case is treated specially in that it is considered
144 -- a normal situation in configurable run-time mode (and the message in
145 -- this case is suppressed unless we are operating in All_Errors_Mode).
147 function Get_Unit_Name (U_Id : RTU_Id) return Unit_Name_Type;
148 -- Retrieves the Unit Name given a unit id represented by its
149 -- enumeration value in RTU_Id.
151 procedure Load_RTU
152 (U_Id : RTU_Id;
153 Id : RE_Id := RE_Null;
154 Use_Setting : Boolean := False);
155 -- Load the unit whose Id is given if not already loaded. The unit is
156 -- loaded, analyzed, and added to the WITH list, and the entry in
157 -- RT_Unit_Table is updated to reflect the load. Use_Setting is used
158 -- to indicate the initial setting for the Is_Potentially_Use_Visible
159 -- flag of the entity for the loaded unit (if it is indeed loaded).
160 -- A value of False means nothing special need be done. A value of
161 -- True indicates that this flag must be set to True. It is needed
162 -- only in the Text_IO_Kludge procedure, which may materialize an
163 -- entity of Text_IO (or [Wide_]Wide_Text_IO) that was previously unknown.
164 -- Id is the RE_Id value of the entity which was originally requested.
165 -- Id is used only for error message detail, and if it is RE_Null, then
166 -- the attempt to output the entity name is ignored.
168 procedure Output_Entity_Name (Id : RE_Id; Msg : String);
169 -- Output continuation error message giving qualified name of entity
170 -- corresponding to Id, appending the string given by Msg. This call
171 -- is only effective in All_Errors mode.
173 function RE_Chars (E : RE_Id) return Name_Id;
174 -- Given a RE_Id value returns the Chars of the corresponding entity
176 procedure RTE_Error_Msg (Msg : String);
177 -- Generates a message by calling Error_Msg_N specifying Current_Error_Node
178 -- as the node location using the given Msg text. Special processing in the
179 -- case where RTE_Available_Call is set. In this case, no message is output
180 -- and instead RTE_Is_Available is set to False. Note that this can only be
181 -- used if you are sure that the message comes directly or indirectly from
182 -- a call to the RTE function.
184 ------------------------
185 -- Entity_Not_Defined --
186 ------------------------
188 procedure Entity_Not_Defined (Id : RE_Id) is
189 begin
190 if No_Run_Time_Mode then
192 -- If the error occurs when compiling the body of a predefined
193 -- unit for inlining purposes, the body must be illegal in this
194 -- mode, and there is no point in continuing.
196 if Is_Predefined_File_Name
197 (Unit_File_Name (Get_Source_Unit (Sloc (Current_Error_Node))))
198 then
199 Error_Msg_N
200 ("construct not allowed in no run time mode!",
201 Current_Error_Node);
202 raise Unrecoverable_Error;
204 else
205 RTE_Error_Msg ("|construct not allowed in no run time mode");
206 end if;
208 elsif Configurable_Run_Time_Mode then
209 RTE_Error_Msg ("|construct not allowed in this configuration>");
210 else
211 RTE_Error_Msg ("run-time configuration error");
212 end if;
214 Output_Entity_Name (Id, "not defined");
215 end Entity_Not_Defined;
217 -------------------
218 -- Get_Unit_Name --
219 -------------------
221 function Get_Unit_Name (U_Id : RTU_Id) return Unit_Name_Type is
222 Uname_Chars : constant String := RTU_Id'Image (U_Id);
224 begin
225 Name_Len := Uname_Chars'Length;
226 Name_Buffer (1 .. Name_Len) := Uname_Chars;
227 Set_Casing (All_Lower_Case);
229 if U_Id in Ada_Child then
230 Name_Buffer (4) := '.';
232 if U_Id in Ada_Calendar_Child then
233 Name_Buffer (13) := '.';
235 elsif U_Id in Ada_Finalization_Child then
236 Name_Buffer (17) := '.';
238 elsif U_Id in Ada_Interrupts_Child then
239 Name_Buffer (15) := '.';
241 elsif U_Id in Ada_Real_Time_Child then
242 Name_Buffer (14) := '.';
244 elsif U_Id in Ada_Streams_Child then
245 Name_Buffer (12) := '.';
247 elsif U_Id in Ada_Text_IO_Child then
248 Name_Buffer (12) := '.';
250 elsif U_Id in Ada_Wide_Text_IO_Child then
251 Name_Buffer (17) := '.';
253 elsif U_Id in Ada_Wide_Wide_Text_IO_Child then
254 Name_Buffer (22) := '.';
255 end if;
257 elsif U_Id in Interfaces_Child then
258 Name_Buffer (11) := '.';
260 elsif U_Id in System_Child then
261 Name_Buffer (7) := '.';
263 if U_Id in System_Tasking_Child then
264 Name_Buffer (15) := '.';
265 end if;
267 if U_Id in System_Tasking_Restricted_Child then
268 Name_Buffer (26) := '.';
269 end if;
271 if U_Id in System_Tasking_Protected_Objects_Child then
272 Name_Buffer (33) := '.';
273 end if;
275 if U_Id in System_Tasking_Async_Delays_Child then
276 Name_Buffer (28) := '.';
277 end if;
278 end if;
280 -- Add %s at end for spec
282 Name_Buffer (Name_Len + 1) := '%';
283 Name_Buffer (Name_Len + 2) := 's';
284 Name_Len := Name_Len + 2;
286 return Name_Find;
287 end Get_Unit_Name;
289 ----------------
290 -- Initialize --
291 ----------------
293 procedure Initialize is
294 begin
295 -- Initialize the unit table
297 for J in RTU_Id loop
298 RT_Unit_Table (J).Entity := Empty;
299 end loop;
301 for J in RE_Id loop
302 RE_Table (J) := Empty;
303 end loop;
305 RTE_Is_Available := False;
306 end Initialize;
308 ------------
309 -- Is_RTE --
310 ------------
312 function Is_RTE (Ent : Entity_Id; E : RE_Id) return Boolean is
313 E_Unit_Name : Unit_Name_Type;
314 Ent_Unit_Name : Unit_Name_Type;
316 S : Entity_Id;
317 E1 : Entity_Id;
318 E2 : Entity_Id;
320 begin
321 if No (Ent) then
322 return False;
324 -- If E has already a corresponding entity, check it directly,
325 -- going to full views if they exist to deal with the incomplete
326 -- and private type cases properly.
328 elsif Present (RE_Table (E)) then
329 E1 := Ent;
331 if Is_Type (E1) and then Present (Full_View (E1)) then
332 E1 := Full_View (E1);
333 end if;
335 E2 := RE_Table (E);
337 if Is_Type (E2) and then Present (Full_View (E2)) then
338 E2 := Full_View (E2);
339 end if;
341 return E1 = E2;
342 end if;
344 -- If the unit containing E is not loaded, we already know that
345 -- the entity we have cannot have come from this unit.
347 E_Unit_Name := Get_Unit_Name (RE_Unit_Table (E));
349 if not Is_Loaded (E_Unit_Name) then
350 return False;
351 end if;
353 -- Here the unit containing the entity is loaded. We have not made
354 -- an explicit call to RTE to get the entity in question, but we may
355 -- have obtained a reference to it indirectly from some other entity
356 -- in the same unit, or some other unit that references it.
358 -- Get the defining unit of the entity
360 S := Scope (Ent);
362 if Ekind (S) /= E_Package then
363 return False;
364 end if;
366 Ent_Unit_Name := Get_Unit_Name (Unit_Declaration_Node (S));
368 -- If the defining unit of the entity we are testing is not the
369 -- unit containing E, then they cannot possibly match.
371 if Ent_Unit_Name /= E_Unit_Name then
372 return False;
373 end if;
375 -- If the units match, then compare the names (remember that no
376 -- overloading is permitted in entities fetched using Rtsfind).
378 if RE_Chars (E) = Chars (Ent) then
379 RE_Table (E) := Ent;
381 -- If front-end inlining is enabled, we may be within a body that
382 -- contains inlined functions, which has not been retrieved through
383 -- rtsfind, and therefore is not yet recorded in the RT_Unit_Table.
384 -- Add the unit information now, it must be fully available.
386 declare
387 U : RT_Unit_Table_Record
388 renames RT_Unit_Table (RE_Unit_Table (E));
389 begin
390 if No (U.Entity) then
391 U.Entity := S;
392 U.Uname := E_Unit_Name;
393 U.Unum := Get_Source_Unit (S);
394 end if;
395 end;
397 return True;
398 else
399 return False;
400 end if;
401 end Is_RTE;
403 ------------
404 -- Is_RTU --
405 ------------
407 function Is_RTU (Ent : Entity_Id; U : RTU_Id) return Boolean is
408 E : constant Entity_Id := RT_Unit_Table (U).Entity;
409 begin
410 return Present (E) and then E = Ent;
411 end Is_RTU;
413 ----------------------------
414 -- Is_Text_IO_Kludge_Unit --
415 ----------------------------
417 function Is_Text_IO_Kludge_Unit (Nam : Node_Id) return Boolean is
418 Prf : Node_Id;
419 Sel : Node_Id;
421 begin
422 if Nkind (Nam) /= N_Expanded_Name then
423 return False;
424 end if;
426 Prf := Prefix (Nam);
427 Sel := Selector_Name (Nam);
429 if Nkind (Sel) /= N_Expanded_Name
430 or else Nkind (Prf) /= N_Identifier
431 or else Chars (Prf) /= Name_Ada
432 then
433 return False;
434 end if;
436 Prf := Prefix (Sel);
437 Sel := Selector_Name (Sel);
439 return
440 Nkind (Prf) = N_Identifier
441 and then
442 (Chars (Prf) = Name_Text_IO
443 or else
444 Chars (Prf) = Name_Wide_Text_IO
445 or else
446 Chars (Prf) = Name_Wide_Wide_Text_IO)
447 and then
448 Nkind (Sel) = N_Identifier
449 and then
450 Chars (Sel) in Text_IO_Package_Name;
451 end Is_Text_IO_Kludge_Unit;
453 ---------------
454 -- Load_Fail --
455 ---------------
457 procedure Load_Fail (S : String; U_Id : RTU_Id; Id : RE_Id) is
458 M : String (1 .. 100);
459 P : Natural := 0;
461 begin
462 -- Output header message
464 if Configurable_Run_Time_Mode then
465 RTE_Error_Msg ("construct not allowed in configurable run-time mode");
466 else
467 RTE_Error_Msg ("run-time library configuration error");
468 end if;
470 -- Output file name and reason string
472 if S /= "not found"
473 or else not Configurable_Run_Time_Mode
474 or else All_Errors_Mode
475 then
476 M (1 .. 6) := "\file ";
477 P := 6;
479 Get_Name_String
480 (Get_File_Name (RT_Unit_Table (U_Id).Uname, Subunit => False));
481 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
482 P := P + Name_Len;
484 M (P + 1) := ' ';
485 P := P + 1;
487 M (P + 1 .. P + S'Length) := S;
488 P := P + S'Length;
490 RTE_Error_Msg (M (1 .. P));
492 -- Output entity name
494 Output_Entity_Name (Id, "not available");
495 end if;
497 raise RE_Not_Available;
498 end Load_Fail;
500 --------------
501 -- Load_RTU --
502 --------------
504 procedure Load_RTU
505 (U_Id : RTU_Id;
506 Id : RE_Id := RE_Null;
507 Use_Setting : Boolean := False)
509 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
510 Priv_Par : constant Elist_Id := New_Elmt_List;
511 Lib_Unit : Node_Id;
513 procedure Save_Private_Visibility;
514 -- If the current unit is the body of child unit or the spec of a
515 -- private child unit, the private declarations of the parent (s)
516 -- are visible. If the unit to be loaded is another public sibling,
517 -- its compilation will affect the visibility of the common ancestors.
518 -- Indicate those that must be restored.
520 procedure Restore_Private_Visibility;
521 -- Restore the visibility of ancestors after compiling RTU
523 --------------------------------
524 -- Restore_Private_Visibility --
525 --------------------------------
527 procedure Restore_Private_Visibility is
528 E_Par : Elmt_Id;
530 begin
531 E_Par := First_Elmt (Priv_Par);
533 while Present (E_Par) loop
534 if not In_Private_Part (Node (E_Par)) then
535 Install_Private_Declarations (Node (E_Par));
536 end if;
538 Next_Elmt (E_Par);
539 end loop;
540 end Restore_Private_Visibility;
542 -----------------------------
543 -- Save_Private_Visibility --
544 -----------------------------
546 procedure Save_Private_Visibility is
547 Par : Entity_Id;
549 begin
550 Par := Scope (Current_Scope);
552 while Present (Par)
553 and then Par /= Standard_Standard
554 loop
555 if Ekind (Par) = E_Package
556 and then Is_Compilation_Unit (Par)
557 and then In_Private_Part (Par)
558 then
559 Append_Elmt (Par, Priv_Par);
560 end if;
562 Par := Scope (Par);
563 end loop;
564 end Save_Private_Visibility;
566 -- Start of processing for Load_RTU
568 begin
569 -- Nothing to do if unit is already loaded
571 if Present (U.Entity) then
572 return;
573 end if;
575 -- Note if secondary stack is used
577 if U_Id = System_Secondary_Stack then
578 Opt.Sec_Stack_Used := True;
579 end if;
581 -- Otherwise we need to load the unit, First build unit name
582 -- from the enumeration literal name in type RTU_Id.
584 U.Uname := Get_Unit_Name (U_Id);
585 U.Withed := False;
587 declare
588 Loaded : Boolean;
589 pragma Warnings (Off, Loaded);
590 begin
591 Loaded := Is_Loaded (U.Uname);
592 end;
594 -- Now do the load call, note that setting Error_Node to Empty is
595 -- a signal to Load_Unit that we will regard a failure to find the
596 -- file as a fatal error, and that it should not output any kind
597 -- of diagnostics, since we will take care of it here.
599 U.Unum :=
600 Load_Unit
601 (Load_Name => U.Uname,
602 Required => False,
603 Subunit => False,
604 Error_Node => Empty);
606 if U.Unum = No_Unit then
607 Load_Fail ("not found", U_Id, Id);
608 elsif Fatal_Error (U.Unum) then
609 Load_Fail ("had parser errors", U_Id, Id);
610 end if;
612 -- Make sure that the unit is analyzed
614 declare
615 Was_Analyzed : constant Boolean :=
616 Analyzed (Cunit (Current_Sem_Unit));
618 begin
619 -- Pretend that the current unit is analyzed, in case it is System
620 -- or some such. This allows us to put some declarations, such as
621 -- exceptions and packed arrays of Boolean, into System even though
622 -- expanding them requires System...
624 -- This is a bit odd but works fine. If the RTS unit does not depend
625 -- in any way on the current unit, then it never gets back into the
626 -- current unit's tree, and the change we make to the current unit
627 -- tree is never noticed by anyone (it is undone in a moment). That
628 -- is the normal situation.
630 -- If the RTS Unit *does* depend on the current unit, for instance,
631 -- when you are compiling System, then you had better have finished
632 -- analyzing the part of System that is depended on before you try
633 -- to load the RTS Unit. This means having the System ordered in an
634 -- appropriate manner.
636 Set_Analyzed (Cunit (Current_Sem_Unit), True);
638 if not Analyzed (Cunit (U.Unum)) then
639 Save_Private_Visibility;
640 Semantics (Cunit (U.Unum));
641 Restore_Private_Visibility;
643 if Fatal_Error (U.Unum) then
644 Load_Fail ("had semantic errors", U_Id, Id);
645 end if;
646 end if;
648 -- Undo the pretence
650 Set_Analyzed (Cunit (Current_Sem_Unit), Was_Analyzed);
651 end;
653 Lib_Unit := Unit (Cunit (U.Unum));
654 U.Entity := Defining_Entity (Lib_Unit);
656 if Use_Setting then
657 Set_Is_Potentially_Use_Visible (U.Entity, True);
658 end if;
659 end Load_RTU;
661 -----------------------
662 -- Output_Entity_Name --
663 ------------------------
665 procedure Output_Entity_Name (Id : RE_Id; Msg : String) is
666 M : String (1 .. 2048);
667 P : Natural := 0;
668 -- M (1 .. P) is current message to be output
670 RE_Image : constant String := RE_Id'Image (Id);
672 begin
673 if Id = RE_Null or else not All_Errors_Mode then
674 return;
675 end if;
677 M (1 .. 9) := "\entity """;
678 P := 9;
680 -- Add unit name to message, excluding %s or %b at end
682 Get_Name_String (Get_Unit_Name (RE_Unit_Table (Id)));
683 Name_Len := Name_Len - 2;
684 Set_Casing (Mixed_Case);
685 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
686 P := P + Name_Len;
688 -- Add a qualifying period
690 M (P + 1) := '.';
691 P := P + 1;
693 -- Add entity name and closing quote to message
695 Name_Len := RE_Image'Length - 3;
696 Name_Buffer (1 .. Name_Len) := RE_Image (4 .. RE_Image'Length);
697 Set_Casing (Mixed_Case);
698 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
699 P := P + Name_Len;
700 M (P + 1) := '"';
701 P := P + 1;
703 -- Add message
705 M (P + 1) := ' ';
706 P := P + 1;
707 M (P + 1 .. P + Msg'Length) := Msg;
708 P := P + Msg'Length;
710 -- Output message at current error node location
712 RTE_Error_Msg (M (1 .. P));
713 end Output_Entity_Name;
715 --------------
716 -- RE_Chars --
717 --------------
719 function RE_Chars (E : RE_Id) return Name_Id is
720 RE_Name_Chars : constant String := RE_Id'Image (E);
722 begin
723 -- Copy name skipping initial RE_ or RO_XX characters
725 if RE_Name_Chars (1 .. 2) = "RE" then
726 for J in 4 .. RE_Name_Chars'Last loop
727 Name_Buffer (J - 3) := Fold_Lower (RE_Name_Chars (J));
728 end loop;
730 Name_Len := RE_Name_Chars'Length - 3;
732 else
733 for J in 7 .. RE_Name_Chars'Last loop
734 Name_Buffer (J - 6) := Fold_Lower (RE_Name_Chars (J));
735 end loop;
737 Name_Len := RE_Name_Chars'Length - 6;
738 end if;
740 return Name_Find;
741 end RE_Chars;
743 ---------
744 -- RTE --
745 ---------
747 function RTE (E : RE_Id) return Entity_Id is
748 U_Id : constant RTU_Id := RE_Unit_Table (E);
749 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
751 Lib_Unit : Node_Id;
752 Pkg_Ent : Entity_Id;
753 Ename : Name_Id;
755 -- The following flag is used to disable front-end inlining when RTE
756 -- is invoked. This prevents the analysis of other runtime bodies when
757 -- a particular spec is loaded through Rtsfind. This is both efficient,
758 -- and it prevents spurious visibility conflicts between use-visible
759 -- user entities, and entities in run-time packages.
761 -- In configurable run-time mode, subprograms marked Inlined_Always must
762 -- be inlined, so in the case we retain the Front_End_Inlining mode.
764 Save_Front_End_Inlining : Boolean;
766 function Check_CRT (Eid : Entity_Id) return Entity_Id;
767 -- Check entity Eid to ensure that configurable run-time restrictions
768 -- are met. May generate an error message and raise RE_Not_Available
769 -- if the entity E does not exist (i.e. Eid is Empty)
771 procedure Check_RPC;
772 -- Reject programs that make use of distribution features not supported
773 -- on the current target. On such targets (VMS, Vxworks, others?) we
774 -- only provide a minimal body for System.Rpc that only supplies an
775 -- implementation of partition_id.
777 function Find_Local_Entity (E : RE_Id) return Entity_Id;
778 -- This function is used when entity E is in this compilation's main
779 -- unit. It gets the value from the already compiled declaration.
781 function Make_Unit_Name (N : Node_Id) return Node_Id;
782 -- If the unit is a child unit, build fully qualified name for use
783 -- in With_Clause.
785 ---------------
786 -- Check_CRT --
787 ---------------
789 function Check_CRT (Eid : Entity_Id) return Entity_Id is
790 begin
791 if No (Eid) then
792 Entity_Not_Defined (E);
793 raise RE_Not_Available;
795 -- Entity is available
797 else
798 -- If in No_Run_Time mode and entity is not in one of the
799 -- specially permitted units, raise the exception.
801 if No_Run_Time_Mode
802 and then not OK_No_Run_Time_Unit (U_Id)
803 then
804 Entity_Not_Defined (E);
805 raise RE_Not_Available;
806 end if;
808 -- Otherwise entity is accessible
810 return Eid;
811 end if;
812 end Check_CRT;
814 ---------------
815 -- Check_RPC --
816 ---------------
818 procedure Check_RPC is
819 begin
820 -- Bypass this check if debug flag -gnatdR set
822 if Debug_Flag_RR then
823 return;
824 end if;
826 -- Otherwise we need the check if we are going after one of
827 -- the critical entities in System.RPC in stubs mode.
829 -- ??? Should we do this for other s-parint entities too?
831 if (Distribution_Stub_Mode = Generate_Receiver_Stub_Body
832 or else
833 Distribution_Stub_Mode = Generate_Caller_Stub_Body)
834 and then (E = RE_Do_Rpc
835 or else
836 E = RE_Do_Apc
837 or else
838 E = RE_Params_Stream_Type
839 or else
840 E = RE_Request_Access)
841 and then Get_PCS_Name = Name_No_DSA
842 then
843 Set_Standard_Error;
844 Write_Str ("distribution feature not supported");
845 Write_Eol;
846 raise Unrecoverable_Error;
847 end if;
848 end Check_RPC;
850 ------------------------
851 -- Find_System_Entity --
852 ------------------------
854 function Find_Local_Entity (E : RE_Id) return Entity_Id is
855 RE_Str : String renames RE_Id'Image (E);
856 Ent : Entity_Id;
858 Save_Nam : constant String := Name_Buffer (1 .. Name_Len);
859 -- Save name buffer and length over call
861 begin
862 Name_Len := Natural'Max (0, RE_Str'Length - 3);
863 Name_Buffer (1 .. Name_Len) :=
864 RE_Str (RE_Str'First + 3 .. RE_Str'Last);
866 Ent := Entity_Id (Get_Name_Table_Info (Name_Find));
868 Name_Len := Save_Nam'Length;
869 Name_Buffer (1 .. Name_Len) := Save_Nam;
871 return Ent;
872 end Find_Local_Entity;
874 --------------------
875 -- Make_Unit_Name --
876 --------------------
878 function Make_Unit_Name (N : Node_Id) return Node_Id is
879 Nam : Node_Id;
880 Scop : Entity_Id;
882 begin
883 Nam := New_Reference_To (U.Entity, Standard_Location);
884 Scop := Scope (U.Entity);
886 if Nkind (N) = N_Defining_Program_Unit_Name then
887 while Scop /= Standard_Standard loop
888 Nam :=
889 Make_Expanded_Name (Standard_Location,
890 Chars => Chars (U.Entity),
891 Prefix => New_Reference_To (Scop, Standard_Location),
892 Selector_Name => Nam);
893 Set_Entity (Nam, U.Entity);
895 Scop := Scope (Scop);
896 end loop;
897 end if;
899 return Nam;
900 end Make_Unit_Name;
902 -- Start of processing for RTE
904 begin
905 -- Doing a rtsfind in system.ads is special, as we cannot do this
906 -- when compiling System itself. So if we are compiling system then
907 -- we should already have acquired and processed the declaration
908 -- of the entity. The test is to see if this compilation's main unit
909 -- is System. If so, return the value from the already compiled
910 -- declaration and otherwise do a regular find.
912 -- Not pleasant, but these kinds of annoying recursion when
913 -- writing an Ada compiler in Ada have to be broken somewhere!
915 if Present (Main_Unit_Entity)
916 and then Chars (Main_Unit_Entity) = Name_System
917 and then Analyzed (Main_Unit_Entity)
918 and then not Is_Child_Unit (Main_Unit_Entity)
919 then
920 return Check_CRT (Find_Local_Entity (E));
921 end if;
923 Save_Front_End_Inlining := Front_End_Inlining;
924 Front_End_Inlining := Configurable_Run_Time_Mode;
926 -- Load unit if unit not previously loaded
928 if No (RE_Table (E)) then
929 Load_RTU (U_Id, Id => E);
930 Lib_Unit := Unit (Cunit (U.Unum));
932 -- In the subprogram case, we are all done, the entity we want
933 -- is the entity for the subprogram itself. Note that we do not
934 -- bother to check that it is the entity that was requested.
935 -- the only way that could fail to be the case is if runtime is
936 -- hopelessly misconfigured, and it isn't worth testing for this.
938 if Nkind (Lib_Unit) = N_Subprogram_Declaration then
939 RE_Table (E) := U.Entity;
941 -- Otherwise we must have the package case. First check package
942 -- entity itself (e.g. RTE_Name for System.Interrupts.Name)
944 else
945 pragma Assert (Nkind (Lib_Unit) = N_Package_Declaration);
946 Ename := RE_Chars (E);
948 -- First we search the package entity chain
950 Pkg_Ent := First_Entity (U.Entity);
951 while Present (Pkg_Ent) loop
952 if Ename = Chars (Pkg_Ent) then
953 RE_Table (E) := Pkg_Ent;
954 Check_RPC;
955 goto Found;
956 end if;
958 Next_Entity (Pkg_Ent);
959 end loop;
961 -- If we did not find the entity in the package entity chain,
962 -- then check if the package entity itself matches. Note that
963 -- we do this check after searching the entity chain, since
964 -- the rule is that in case of ambiguity, we prefer the entity
965 -- defined within the package, rather than the package itself.
967 if Ename = Chars (U.Entity) then
968 RE_Table (E) := U.Entity;
969 end if;
971 -- If we didn't find the entity we want, something is wrong.
972 -- We just leave RE_Table (E) set to Empty and the appropriate
973 -- action will be taken by Check_CRT when we exit.
975 end if;
976 end if;
978 -- See if we have to generate a WITH for this entity. We generate
979 -- a WITH if the current unit is part of the extended main code
980 -- unit, and if we have not already added the with. The WITH is
981 -- added to the appropriate unit (the current one). We do not need
982 -- to generate a WITH for an ????
984 <<Found>>
985 if (not U.Withed)
986 and then
987 In_Extended_Main_Code_Unit (Cunit_Entity (Current_Sem_Unit))
988 and then not RTE_Available_Call
989 then
990 U.Withed := True;
992 declare
993 Withn : Node_Id;
994 Lib_Unit : Node_Id;
996 begin
997 Lib_Unit := Unit (Cunit (U.Unum));
998 Withn :=
999 Make_With_Clause (Standard_Location,
1000 Name =>
1001 Make_Unit_Name
1002 (Defining_Unit_Name (Specification (Lib_Unit))));
1003 Set_Library_Unit (Withn, Cunit (U.Unum));
1004 Set_Corresponding_Spec (Withn, U.Entity);
1005 Set_First_Name (Withn, True);
1006 Set_Implicit_With (Withn, True);
1008 Mark_Rewrite_Insertion (Withn);
1009 Append (Withn, Context_Items (Cunit (Current_Sem_Unit)));
1010 Check_Restriction_No_Dependence (Name (Withn), Current_Error_Node);
1011 end;
1012 end if;
1014 Front_End_Inlining := Save_Front_End_Inlining;
1015 return Check_CRT (RE_Table (E));
1016 end RTE;
1018 -------------------
1019 -- RTE_Available --
1020 -------------------
1022 function RTE_Available (E : RE_Id) return Boolean is
1023 Dummy : Entity_Id;
1024 pragma Warnings (Off, Dummy);
1026 Result : Boolean;
1028 Save_RTE_Available_Call : constant Boolean := RTE_Available_Call;
1029 Save_RTE_Is_Available : constant Boolean := RTE_Is_Available;
1030 -- These are saved recursively because the call to load a unit
1031 -- caused by an upper level call may perform a recursive call
1032 -- to this routine during analysis of the corresponding unit.
1034 begin
1035 RTE_Available_Call := True;
1036 RTE_Is_Available := True;
1037 Dummy := RTE (E);
1038 Result := RTE_Is_Available;
1039 RTE_Available_Call := Save_RTE_Available_Call;
1040 RTE_Is_Available := Save_RTE_Is_Available;
1041 return Result;
1043 exception
1044 when RE_Not_Available =>
1045 RTE_Available_Call := Save_RTE_Available_Call;
1046 RTE_Is_Available := Save_RTE_Is_Available;
1047 return False;
1048 end RTE_Available;
1050 -------------------
1051 -- RTE_Error_Msg --
1052 -------------------
1054 procedure RTE_Error_Msg (Msg : String) is
1055 begin
1056 if RTE_Available_Call then
1057 RTE_Is_Available := False;
1058 else
1059 Error_Msg_N (Msg, Current_Error_Node);
1061 -- Bump count of violations if we are in configurable run-time
1062 -- mode and this is not a continuation message.
1064 if Configurable_Run_Time_Mode and then Msg (Msg'First) /= '\' then
1065 Configurable_Run_Time_Violations :=
1066 Configurable_Run_Time_Violations + 1;
1067 end if;
1068 end if;
1069 end RTE_Error_Msg;
1071 ----------------
1072 -- RTU_Loaded --
1073 ----------------
1075 function RTU_Loaded (U : RTU_Id) return Boolean is
1076 begin
1077 return Present (RT_Unit_Table (U).Entity);
1078 end RTU_Loaded;
1080 --------------------
1081 -- Set_RTU_Loaded --
1082 --------------------
1084 procedure Set_RTU_Loaded (N : Node_Id) is
1085 Loc : constant Source_Ptr := Sloc (N);
1086 Unum : constant Unit_Number_Type := Get_Source_Unit (Loc);
1087 Uname : constant Unit_Name_Type := Unit_Name (Unum);
1088 E : constant Entity_Id :=
1089 Defining_Entity (Unit (Cunit (Unum)));
1090 begin
1091 pragma Assert (Is_Predefined_File_Name (Unit_File_Name (Unum)));
1093 -- Loop through entries in RTU table looking for matching entry
1095 for U_Id in RTU_Id'Range loop
1097 -- Here we have a match
1099 if Get_Unit_Name (U_Id) = Uname then
1100 declare
1101 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
1102 -- The RT_Unit_Table entry that may need updating
1104 begin
1105 -- If entry is not set, set it now
1107 if No (U.Entity) then
1108 U.Entity := E;
1109 U.Uname := Get_Unit_Name (U_Id);
1110 U.Unum := Unum;
1111 U.Withed := False;
1112 end if;
1114 return;
1115 end;
1116 end if;
1117 end loop;
1118 end Set_RTU_Loaded;
1120 --------------------
1121 -- Text_IO_Kludge --
1122 --------------------
1124 procedure Text_IO_Kludge (Nam : Node_Id) is
1125 Chrs : Name_Id;
1127 type Name_Map_Type is array (Text_IO_Package_Name) of RTU_Id;
1129 Name_Map : constant Name_Map_Type := Name_Map_Type'(
1130 Name_Decimal_IO => Ada_Text_IO_Decimal_IO,
1131 Name_Enumeration_IO => Ada_Text_IO_Enumeration_IO,
1132 Name_Fixed_IO => Ada_Text_IO_Fixed_IO,
1133 Name_Float_IO => Ada_Text_IO_Float_IO,
1134 Name_Integer_IO => Ada_Text_IO_Integer_IO,
1135 Name_Modular_IO => Ada_Text_IO_Modular_IO);
1137 Wide_Name_Map : constant Name_Map_Type := Name_Map_Type'(
1138 Name_Decimal_IO => Ada_Wide_Text_IO_Decimal_IO,
1139 Name_Enumeration_IO => Ada_Wide_Text_IO_Enumeration_IO,
1140 Name_Fixed_IO => Ada_Wide_Text_IO_Fixed_IO,
1141 Name_Float_IO => Ada_Wide_Text_IO_Float_IO,
1142 Name_Integer_IO => Ada_Wide_Text_IO_Integer_IO,
1143 Name_Modular_IO => Ada_Wide_Text_IO_Modular_IO);
1145 Wide_Wide_Name_Map : constant Name_Map_Type := Name_Map_Type'(
1146 Name_Decimal_IO => Ada_Wide_Wide_Text_IO_Decimal_IO,
1147 Name_Enumeration_IO => Ada_Wide_Wide_Text_IO_Enumeration_IO,
1148 Name_Fixed_IO => Ada_Wide_Wide_Text_IO_Fixed_IO,
1149 Name_Float_IO => Ada_Wide_Wide_Text_IO_Float_IO,
1150 Name_Integer_IO => Ada_Wide_Wide_Text_IO_Integer_IO,
1151 Name_Modular_IO => Ada_Wide_Wide_Text_IO_Modular_IO);
1153 begin
1154 -- Nothing to do if name is not identifier or a selected component
1155 -- whose selector_name is not an identifier.
1157 if Nkind (Nam) = N_Identifier then
1158 Chrs := Chars (Nam);
1160 elsif Nkind (Nam) = N_Selected_Component
1161 and then Nkind (Selector_Name (Nam)) = N_Identifier
1162 then
1163 Chrs := Chars (Selector_Name (Nam));
1165 else
1166 return;
1167 end if;
1169 -- Nothing to do if name is not one of the Text_IO subpackages
1170 -- Otherwise look through loaded units, and if we find Text_IO
1171 -- or [Wide_]Wide_Text_IO already loaded, then load the proper child.
1173 if Chrs in Text_IO_Package_Name then
1174 for U in Main_Unit .. Last_Unit loop
1175 Get_Name_String (Unit_File_Name (U));
1177 if Name_Len = 12 then
1179 -- Here is where we do the loads if we find one of the units
1180 -- Ada.Text_IO or Ada.[Wide_]Wide_Text_IO. An interesting
1181 -- detail is that these units may already be used (i.e. their
1182 -- In_Use flags may be set). Normally when the In_Use flag is
1183 -- set, the Is_Potentially_Use_Visible flag of all entities in
1184 -- the package is set, but the new entity we are mysteriously
1185 -- adding was not there to have its flag set at the time. So
1186 -- that's why we pass the extra parameter to RTU_Find, to make
1187 -- sure the flag does get set now. Given that those generic
1188 -- packages are in fact child units, we must indicate that
1189 -- they are visible.
1191 if Name_Buffer (1 .. 12) = "a-textio.ads" then
1192 Load_RTU
1193 (Name_Map (Chrs),
1194 Use_Setting => In_Use (Cunit_Entity (U)));
1195 Set_Is_Visible_Child_Unit
1196 (RT_Unit_Table (Name_Map (Chrs)).Entity);
1198 elsif Name_Buffer (1 .. 12) = "a-witeio.ads" then
1199 Load_RTU
1200 (Wide_Name_Map (Chrs),
1201 Use_Setting => In_Use (Cunit_Entity (U)));
1202 Set_Is_Visible_Child_Unit
1203 (RT_Unit_Table (Wide_Name_Map (Chrs)).Entity);
1205 elsif Name_Buffer (1 .. 12) = "a-ztexio.ads" then
1206 Load_RTU
1207 (Wide_Wide_Name_Map (Chrs),
1208 Use_Setting => In_Use (Cunit_Entity (U)));
1209 Set_Is_Visible_Child_Unit
1210 (RT_Unit_Table (Wide_Wide_Name_Map (Chrs)).Entity);
1211 end if;
1212 end if;
1213 end loop;
1214 end if;
1215 end Text_IO_Kludge;
1217 end Rtsfind;