OSDN Git Service

2007-08-14 Geert Bosch <bosch@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / rtsfind.adb
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-2007, 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 ------------------------------------------------------------------------------
26
27 with Atree;    use Atree;
28 with Casing;   use Casing;
29 with Csets;    use Csets;
30 with Debug;    use Debug;
31 with Einfo;    use Einfo;
32 with Elists;   use Elists;
33 with Errout;   use Errout;
34 with Fname;    use Fname;
35 with Fname.UF; use Fname.UF;
36 with Gnatvsn;  use Gnatvsn;
37 with Lib;      use Lib;
38 with Lib.Load; use Lib.Load;
39 with Namet;    use Namet;
40 with Nlists;   use Nlists;
41 with Nmake;    use Nmake;
42 with Output;   use Output;
43 with Opt;      use Opt;
44 with Restrict; use Restrict;
45 with Sem;      use Sem;
46 with Sem_Ch7;  use Sem_Ch7;
47 with Sem_Dist; use Sem_Dist;
48 with Sem_Util; use Sem_Util;
49 with Sinfo;    use Sinfo;
50 with Stand;    use Stand;
51 with Snames;   use Snames;
52 with Tbuild;   use Tbuild;
53 with Uname;    use Uname;
54
55 package body Rtsfind is
56
57    RTE_Available_Call : Boolean := False;
58    --  Set True during call to RTE from RTE_Available (or from call to
59    --  RTE_Record_Component from RTE_Record_Component_Available). Tells
60    --  the called subprogram to set RTE_Is_Available to False rather than
61    --  generating an error message.
62
63    RTE_Is_Available : Boolean;
64    --  Set True by RTE_Available on entry. When RTE_Available_Call is set
65    --  True, set False if RTE would otherwise generate an error message.
66
67    ----------------
68    -- Unit table --
69    ----------------
70
71    --  The unit table has one entry for each unit included in the definition
72    --  of the type RTU_Id in the spec. The table entries are initialized in
73    --  Initialize to set the Entity field to Empty, indicating that the
74    --  corresponding unit has not yet been loaded. The fields are set when
75    --  a unit is loaded to contain the defining entity for the unit, the
76    --  unit name, and the unit number.
77
78    --  Note that a unit can be loaded either by a call to find an entity
79    --  within the unit (e.g. RTE), or by an explicit with of the unit. In
80    --  the latter case it is critical to make a call to Set_RTU_Loaded to
81    --  ensure that the entry in this table reflects the load.
82
83    type RT_Unit_Table_Record is record
84       Entity : Entity_Id;
85       Uname  : Unit_Name_Type;
86       Unum   : Unit_Number_Type;
87       Withed : Boolean;
88    end record;
89
90    RT_Unit_Table : array (RTU_Id) of RT_Unit_Table_Record;
91
92    --------------------------
93    -- Runtime Entity Table --
94    --------------------------
95
96    --  There is one entry in the runtime entity table for each entity that is
97    --  included in the definition of the RE_Id type in the spec. The entries
98    --  are set by Initialize_Rtsfind to contain Empty, indicating that the
99    --  entity has not yet been located. Once the entity is located for the
100    --  first time, its ID is stored in this array, so that subsequent calls
101    --  for the same entity can be satisfied immediately.
102
103    --  NOTE: In order to avoid conflicts between record components and subprgs
104    --        that have the same name (ie. subprogram External_Tag and component
105    --        External_Tag of package Ada.Tags) this table is not used with
106    --        Record_Components.
107
108    RE_Table : array (RE_Id) of Entity_Id;
109
110    --------------------------
111    -- Generation of WITH's --
112    --------------------------
113
114    --  When a unit is implicitly loaded as a result of a call to RTE, it
115    --  is necessary to create an implicit WITH to ensure that the object
116    --  is correctly loaded by the binder. Such WITH statements are only
117    --  required when the request is from the extended main unit (if a
118    --  client needs a WITH, that will be taken care of when the client
119    --  is compiled).
120
121    --  We always attach the WITH to the main unit. This is not perfectly
122    --  accurate in terms of elaboration requirements, but it is close
123    --  enough, since the units that are accessed using rtsfind do not
124    --  have delicate elaboration requirements.
125
126    --  The flag Withed in the unit table record is initially set to False.
127    --  It is set True if a WITH has been generated for the main unit for
128    --  the corresponding unit.
129
130    -----------------------
131    -- Local Subprograms --
132    -----------------------
133
134    function Check_CRT (E : RE_Id; Eid : Entity_Id) return Entity_Id;
135    --  Check entity Eid to ensure that configurable run-time restrictions
136    --  are met. May generate an error message and raise RE_Not_Available
137    --  if the entity E does not exist (i.e. Eid is Empty)
138
139    procedure Entity_Not_Defined (Id : RE_Id);
140    --  Outputs error messages for an entity that is not defined in the
141    --  run-time library (the form of the error message is tailored for
142    --  no run time/configurable run time mode as required).
143
144    function Get_Unit_Name (U_Id : RTU_Id) return Unit_Name_Type;
145    --  Retrieves the Unit Name given a unit id represented by its
146    --  enumeration value in RTU_Id.
147
148    procedure Load_Fail (S : String; U_Id : RTU_Id; Id : RE_Id);
149    --  Internal procedure called if we can't sucessfully locate or
150    --  process a run-time unit. The parameters give information about
151    --  the error message to be given. S is a reason for failing to
152    --  compile the file and U_Id is the unit id. RE_Id is the RE_Id
153    --  originally passed to RTE. The message in S is one of the
154    --  following:
155    --
156    --     "not found"
157    --     "had parser errors"
158    --     "had semantic errors"
159    --
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).
163
164    procedure Load_RTU
165      (U_Id        : RTU_Id;
166       Id          : RE_Id   := RE_Null;
167       Use_Setting : Boolean := False);
168    --  Load the unit whose Id is given if not already loaded. The unit is
169    --  loaded, analyzed, and added to the WITH list, and the entry in
170    --  RT_Unit_Table is updated to reflect the load. Use_Setting is used
171    --  to indicate the initial setting for the Is_Potentially_Use_Visible
172    --  flag of the entity for the loaded unit (if it is indeed loaded).
173    --  A value of False means nothing special need be done. A value of
174    --  True indicates that this flag must be set to True. It is needed
175    --  only in the Text_IO_Kludge procedure, which may materialize an
176    --  entity of Text_IO (or [Wide_]Wide_Text_IO) that was previously unknown.
177    --  Id is the RE_Id value of the entity which was originally requested.
178    --  Id is used only for error message detail, and if it is RE_Null, then
179    --  the attempt to output the entity name is ignored.
180
181    function Make_Unit_Name (E : RE_Id; N : Node_Id) return Node_Id;
182    --  If the unit is a child unit, build fully qualified name for use in
183    --  With_Clause.
184
185    procedure Output_Entity_Name (Id : RE_Id; Msg : String);
186    --  Output continuation error message giving qualified name of entity
187    --  corresponding to Id, appending the string given by Msg. This call
188    --  is only effective in All_Errors mode.
189
190    function RE_Chars (E : RE_Id) return Name_Id;
191    --  Given a RE_Id value returns the Chars of the corresponding entity
192
193    procedure RTE_Error_Msg (Msg : String);
194    --  Generates a message by calling Error_Msg_N specifying Current_Error_Node
195    --  as the node location using the given Msg text. Special processing in the
196    --  case where RTE_Available_Call is set. In this case, no message is output
197    --  and instead RTE_Is_Available is set to False. Note that this can only be
198    --  used if you are sure that the message comes directly or indirectly from
199    --  a call to the RTE function.
200
201    ---------------
202    -- Check_CRT --
203    ---------------
204
205    function Check_CRT (E : RE_Id; Eid : Entity_Id) return Entity_Id is
206       U_Id : constant RTU_Id := RE_Unit_Table (E);
207
208    begin
209       if No (Eid) then
210          Entity_Not_Defined (E);
211          raise RE_Not_Available;
212
213       --  Entity is available
214
215       else
216          --  If in No_Run_Time mode and entity is not in one of the
217          --  specially permitted units, raise the exception.
218
219          if No_Run_Time_Mode
220            and then not OK_No_Run_Time_Unit (U_Id)
221          then
222             Entity_Not_Defined (E);
223             raise RE_Not_Available;
224          end if;
225
226          --  Otherwise entity is accessible
227
228          return Eid;
229       end if;
230    end Check_CRT;
231
232    ------------------------
233    -- Entity_Not_Defined --
234    ------------------------
235
236    procedure Entity_Not_Defined (Id : RE_Id) is
237    begin
238       if No_Run_Time_Mode then
239
240          --  If the error occurs when compiling the body of a predefined
241          --  unit for inlining purposes, the body must be illegal in this
242          --  mode, and there is no point in continuing.
243
244          if Is_Predefined_File_Name
245            (Unit_File_Name (Get_Source_Unit (Sloc (Current_Error_Node))))
246          then
247             Error_Msg_N
248               ("construct not allowed in no run time mode!",
249                  Current_Error_Node);
250             raise Unrecoverable_Error;
251
252          else
253             RTE_Error_Msg ("|construct not allowed in no run time mode");
254          end if;
255
256       elsif Configurable_Run_Time_Mode then
257          RTE_Error_Msg ("|construct not allowed in this configuration>");
258       else
259          RTE_Error_Msg ("run-time configuration error");
260       end if;
261
262       Output_Entity_Name (Id, "not defined");
263    end Entity_Not_Defined;
264
265    -------------------
266    -- Get_Unit_Name --
267    -------------------
268
269    function Get_Unit_Name (U_Id : RTU_Id) return Unit_Name_Type is
270       Uname_Chars : constant String := RTU_Id'Image (U_Id);
271
272    begin
273       Name_Len := Uname_Chars'Length;
274       Name_Buffer (1 .. Name_Len) := Uname_Chars;
275       Set_Casing (All_Lower_Case);
276
277       if U_Id in Ada_Child then
278          Name_Buffer (4) := '.';
279
280          if U_Id in Ada_Calendar_Child then
281             Name_Buffer (13) := '.';
282
283          elsif U_Id in Ada_Finalization_Child then
284             Name_Buffer (17) := '.';
285
286          elsif U_Id in Ada_Interrupts_Child then
287             Name_Buffer (15) := '.';
288
289          elsif U_Id in Ada_Real_Time_Child then
290             Name_Buffer (14) := '.';
291
292          elsif U_Id in Ada_Streams_Child then
293             Name_Buffer (12) := '.';
294
295          elsif U_Id in Ada_Text_IO_Child then
296             Name_Buffer (12) := '.';
297
298          elsif U_Id in Ada_Wide_Text_IO_Child then
299             Name_Buffer (17) := '.';
300
301          elsif U_Id in Ada_Wide_Wide_Text_IO_Child then
302             Name_Buffer (22) := '.';
303          end if;
304
305       elsif U_Id in Interfaces_Child then
306          Name_Buffer (11) := '.';
307
308       elsif U_Id in System_Child then
309          Name_Buffer (7) := '.';
310
311          if U_Id in System_Tasking_Child then
312             Name_Buffer (15) := '.';
313          end if;
314
315          if U_Id in System_Tasking_Restricted_Child then
316             Name_Buffer (26) := '.';
317          end if;
318
319          if U_Id in System_Tasking_Protected_Objects_Child then
320             Name_Buffer (33) := '.';
321          end if;
322
323          if U_Id in System_Tasking_Async_Delays_Child then
324             Name_Buffer (28) := '.';
325          end if;
326       end if;
327
328       --  Add %s at end for spec
329
330       Name_Buffer (Name_Len + 1) := '%';
331       Name_Buffer (Name_Len + 2) := 's';
332       Name_Len := Name_Len + 2;
333
334       return Name_Find;
335    end Get_Unit_Name;
336
337    ----------------
338    -- Initialize --
339    ----------------
340
341    procedure Initialize is
342    begin
343       --  Initialize the unit table
344
345       for J in RTU_Id loop
346          RT_Unit_Table (J).Entity := Empty;
347       end loop;
348
349       for J in RE_Id loop
350          RE_Table (J) := Empty;
351       end loop;
352
353       RTE_Is_Available := False;
354    end Initialize;
355
356    ------------
357    -- Is_RTE --
358    ------------
359
360    function Is_RTE (Ent : Entity_Id; E : RE_Id) return Boolean is
361       E_Unit_Name   : Unit_Name_Type;
362       Ent_Unit_Name : Unit_Name_Type;
363
364       S  : Entity_Id;
365       E1 : Entity_Id;
366       E2 : Entity_Id;
367
368    begin
369       if No (Ent) then
370          return False;
371
372       --  If E has already a corresponding entity, check it directly,
373       --  going to full views if they exist to deal with the incomplete
374       --  and private type cases properly.
375
376       elsif Present (RE_Table (E)) then
377          E1 := Ent;
378
379          if Is_Type (E1) and then Present (Full_View (E1)) then
380             E1 := Full_View (E1);
381          end if;
382
383          E2 := RE_Table (E);
384
385          if Is_Type (E2) and then Present (Full_View (E2)) then
386             E2 := Full_View (E2);
387          end if;
388
389          return E1 = E2;
390       end if;
391
392       --  If the unit containing E is not loaded, we already know that
393       --  the entity we have cannot have come from this unit.
394
395       E_Unit_Name := Get_Unit_Name (RE_Unit_Table (E));
396
397       if not Is_Loaded (E_Unit_Name) then
398          return False;
399       end if;
400
401       --  Here the unit containing the entity is loaded. We have not made
402       --  an explicit call to RTE to get the entity in question, but we may
403       --  have obtained a reference to it indirectly from some other entity
404       --  in the same unit, or some other unit that references it.
405
406       --  Get the defining unit of the entity
407
408       S := Scope (Ent);
409
410       if Ekind (S) /= E_Package then
411          return False;
412       end if;
413
414       Ent_Unit_Name := Get_Unit_Name (Unit_Declaration_Node (S));
415
416       --  If the defining unit of the entity we are testing is not the
417       --  unit containing E, then they cannot possibly match.
418
419       if Ent_Unit_Name /= E_Unit_Name then
420          return False;
421       end if;
422
423       --  If the units match, then compare the names (remember that no
424       --  overloading is permitted in entities fetched using Rtsfind).
425
426       if RE_Chars (E) = Chars (Ent) then
427          RE_Table (E) := Ent;
428
429          --  If front-end inlining is enabled, we may be within a body that
430          --  contains inlined functions, which has not been retrieved through
431          --  rtsfind, and therefore is not yet recorded in the RT_Unit_Table.
432          --  Add the unit information now, it must be fully available.
433
434          declare
435             U : RT_Unit_Table_Record
436                   renames  RT_Unit_Table (RE_Unit_Table (E));
437          begin
438             if No (U.Entity) then
439                U.Entity := S;
440                U.Uname  := E_Unit_Name;
441                U.Unum   := Get_Source_Unit (S);
442             end if;
443          end;
444
445          return True;
446       else
447          return False;
448       end if;
449    end Is_RTE;
450
451    ------------
452    -- Is_RTU --
453    ------------
454
455    function Is_RTU (Ent : Entity_Id;  U : RTU_Id) return Boolean is
456       E : constant Entity_Id := RT_Unit_Table (U).Entity;
457    begin
458       return Present (E) and then E = Ent;
459    end Is_RTU;
460
461    ----------------------------
462    -- Is_Text_IO_Kludge_Unit --
463    ----------------------------
464
465    function Is_Text_IO_Kludge_Unit (Nam : Node_Id) return Boolean is
466       Prf : Node_Id;
467       Sel : Node_Id;
468
469    begin
470       if Nkind (Nam) /= N_Expanded_Name then
471          return False;
472       end if;
473
474       Prf := Prefix (Nam);
475       Sel := Selector_Name (Nam);
476
477       if Nkind (Sel) /= N_Expanded_Name
478         or else Nkind (Prf) /= N_Identifier
479         or else Chars (Prf) /= Name_Ada
480       then
481          return False;
482       end if;
483
484       Prf := Prefix (Sel);
485       Sel := Selector_Name (Sel);
486
487       return
488         Nkind (Prf) = N_Identifier
489           and then
490            (Chars (Prf) = Name_Text_IO
491               or else
492             Chars (Prf) = Name_Wide_Text_IO
493               or else
494             Chars (Prf) = Name_Wide_Wide_Text_IO)
495           and then
496         Nkind (Sel) = N_Identifier
497           and then
498         Chars (Sel) in Text_IO_Package_Name;
499    end Is_Text_IO_Kludge_Unit;
500
501    ---------------
502    -- Load_Fail --
503    ---------------
504
505    procedure Load_Fail (S : String; U_Id : RTU_Id; Id : RE_Id) is
506       M : String (1 .. 100);
507       P : Natural := 0;
508
509    begin
510       --  Output header message
511
512       if Configurable_Run_Time_Mode then
513          RTE_Error_Msg ("construct not allowed in configurable run-time mode");
514       else
515          RTE_Error_Msg ("run-time library configuration error");
516       end if;
517
518       --  Output file name and reason string
519
520       if S /= "not found"
521         or else not Configurable_Run_Time_Mode
522         or else All_Errors_Mode
523       then
524          M (1 .. 6) := "\file ";
525          P := 6;
526
527          Get_Name_String
528            (Get_File_Name (RT_Unit_Table (U_Id).Uname, Subunit => False));
529          M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
530          P := P + Name_Len;
531
532          M (P + 1) := ' ';
533          P := P + 1;
534
535          M (P + 1 .. P + S'Length) := S;
536          P := P + S'Length;
537
538          RTE_Error_Msg (M (1 .. P));
539
540          --  Output entity name
541
542          Output_Entity_Name (Id, "not available");
543       end if;
544
545       --  In configurable run time mode, we raise RE_Not_Available, and we hope
546       --  the caller deals gracefully with this. If we are in normal full run
547       --  time mode, a load failure is considered fatal and unrecoverable.
548
549       if Configurable_Run_Time_Mode then
550          raise RE_Not_Available;
551       else
552          raise Unrecoverable_Error;
553       end if;
554    end Load_Fail;
555
556    --------------
557    -- Load_RTU --
558    --------------
559
560    procedure Load_RTU
561      (U_Id        : RTU_Id;
562       Id          : RE_Id   := RE_Null;
563       Use_Setting : Boolean := False)
564    is
565       U        : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
566       Priv_Par : constant Elist_Id := New_Elmt_List;
567       Lib_Unit : Node_Id;
568
569       procedure Save_Private_Visibility;
570       --  If the current unit is the body of child unit or the spec of a
571       --  private child unit, the private declarations of the parent (s)
572       --  are visible. If the unit to be loaded is another public sibling,
573       --  its compilation will affect the visibility of the common ancestors.
574       --  Indicate those that must be restored.
575
576       procedure Restore_Private_Visibility;
577       --  Restore the visibility of ancestors after compiling RTU
578
579       --------------------------------
580       -- Restore_Private_Visibility --
581       --------------------------------
582
583       procedure Restore_Private_Visibility is
584          E_Par : Elmt_Id;
585
586       begin
587          E_Par := First_Elmt (Priv_Par);
588
589          while Present (E_Par) loop
590             if not In_Private_Part (Node (E_Par)) then
591                Install_Private_Declarations (Node (E_Par));
592             end if;
593
594             Next_Elmt (E_Par);
595          end loop;
596       end Restore_Private_Visibility;
597
598       -----------------------------
599       -- Save_Private_Visibility --
600       -----------------------------
601
602       procedure Save_Private_Visibility is
603          Par : Entity_Id;
604
605       begin
606          Par := Scope (Current_Scope);
607
608          while Present (Par)
609            and then Par /= Standard_Standard
610          loop
611             if Ekind (Par) = E_Package
612               and then Is_Compilation_Unit (Par)
613               and then In_Private_Part (Par)
614             then
615                Append_Elmt (Par, Priv_Par);
616             end if;
617
618             Par := Scope (Par);
619          end loop;
620       end Save_Private_Visibility;
621
622    --  Start of processing for Load_RTU
623
624    begin
625       --  Nothing to do if unit is already loaded
626
627       if Present (U.Entity) then
628          return;
629       end if;
630
631       --  Note if secondary stack is used
632
633       if U_Id = System_Secondary_Stack then
634          Opt.Sec_Stack_Used := True;
635       end if;
636
637       --  Otherwise we need to load the unit, First build unit name
638       --  from the enumeration literal name in type RTU_Id.
639
640       U.Uname  := Get_Unit_Name (U_Id);
641       U.Withed := False;
642
643       declare
644          Loaded : Boolean;
645          pragma Warnings (Off, Loaded);
646       begin
647          Loaded := Is_Loaded (U.Uname);
648       end;
649
650       --  Now do the load call, note that setting Error_Node to Empty is
651       --  a signal to Load_Unit that we will regard a failure to find the
652       --  file as a fatal error, and that it should not output any kind
653       --  of diagnostics, since we will take care of it here.
654
655       U.Unum :=
656         Load_Unit
657           (Load_Name  => U.Uname,
658            Required   => False,
659            Subunit    => False,
660            Error_Node => Empty);
661
662       if U.Unum = No_Unit then
663          Load_Fail ("not found", U_Id, Id);
664       elsif Fatal_Error (U.Unum) then
665          Load_Fail ("had parser errors", U_Id, Id);
666       end if;
667
668       --  Make sure that the unit is analyzed
669
670       declare
671          Was_Analyzed : constant Boolean :=
672                           Analyzed (Cunit (Current_Sem_Unit));
673
674       begin
675          --  Pretend that the current unit is analyzed, in case it is System
676          --  or some such. This allows us to put some declarations, such as
677          --  exceptions and packed arrays of Boolean, into System even though
678          --  expanding them requires System...
679
680          --  This is a bit odd but works fine. If the RTS unit does not depend
681          --  in any way on the current unit, then it never gets back into the
682          --  current unit's tree, and the change we make to the current unit
683          --  tree is never noticed by anyone (it is undone in a moment). That
684          --  is the normal situation.
685
686          --  If the RTS Unit *does* depend on the current unit, for instance,
687          --  when you are compiling System, then you had better have finished
688          --  analyzing the part of System that is depended on before you try
689          --  to load the RTS Unit. This means having the System ordered in an
690          --  appropriate manner.
691
692          Set_Analyzed (Cunit (Current_Sem_Unit), True);
693
694          if not Analyzed (Cunit (U.Unum)) then
695
696             --  If the unit is already loaded through a limited_with clauses,
697             --  the relevant entities must already be available. We do not
698             --  want to load and analyze the unit because this would create
699             --  a real semantic dependence when the purpose of the limited_with
700             --  is precisely to avoid such.
701
702             if From_With_Type (Cunit_Entity (U.Unum)) then
703                null;
704
705             else
706                Save_Private_Visibility;
707                Semantics (Cunit (U.Unum));
708                Restore_Private_Visibility;
709
710                if Fatal_Error (U.Unum) then
711                   Load_Fail ("had semantic errors", U_Id, Id);
712                end if;
713             end if;
714          end if;
715
716          --  Undo the pretence
717
718          Set_Analyzed (Cunit (Current_Sem_Unit), Was_Analyzed);
719       end;
720
721       Lib_Unit := Unit (Cunit (U.Unum));
722       U.Entity := Defining_Entity (Lib_Unit);
723
724       if Use_Setting then
725          Set_Is_Potentially_Use_Visible (U.Entity, True);
726       end if;
727    end Load_RTU;
728
729    --------------------
730    -- Make_Unit_Name --
731    --------------------
732
733    function Make_Unit_Name (E : RE_Id; N : Node_Id) return Node_Id is
734       U_Id : constant RTU_Id := RE_Unit_Table (E);
735       U    : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
736       Nam  : Node_Id;
737       Scop : Entity_Id;
738
739    begin
740       Nam  := New_Reference_To (U.Entity, Standard_Location);
741       Scop := Scope (U.Entity);
742
743       if Nkind (N) = N_Defining_Program_Unit_Name then
744          while Scop /= Standard_Standard loop
745             Nam :=
746               Make_Expanded_Name (Standard_Location,
747                 Chars  => Chars (U.Entity),
748                 Prefix => New_Reference_To (Scop, Standard_Location),
749                 Selector_Name => Nam);
750             Set_Entity (Nam, U.Entity);
751
752             Scop := Scope (Scop);
753          end loop;
754       end if;
755
756       return Nam;
757    end Make_Unit_Name;
758
759    -----------------------
760    -- Output_Entity_Name --
761    ------------------------
762
763    procedure Output_Entity_Name (Id : RE_Id; Msg : String) is
764       M : String (1 .. 2048);
765       P : Natural := 0;
766       --  M (1 .. P) is current message to be output
767
768       RE_Image : constant String := RE_Id'Image (Id);
769
770    begin
771       if Id = RE_Null or else not All_Errors_Mode then
772          return;
773       end if;
774
775       M (1 .. 9) := "\entity """;
776       P := 9;
777
778       --  Add unit name to message, excluding %s or %b at end
779
780       Get_Name_String (Get_Unit_Name (RE_Unit_Table (Id)));
781       Name_Len := Name_Len - 2;
782       Set_Casing (Mixed_Case);
783       M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
784       P := P + Name_Len;
785
786       --  Add a qualifying period
787
788       M (P + 1) := '.';
789       P := P + 1;
790
791       --  Add entity name and closing quote to message
792
793       Name_Len := RE_Image'Length - 3;
794       Name_Buffer (1 .. Name_Len) := RE_Image (4 .. RE_Image'Length);
795       Set_Casing (Mixed_Case);
796       M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
797       P := P + Name_Len;
798       M (P + 1) := '"';
799       P := P + 1;
800
801       --  Add message
802
803       M (P + 1) := ' ';
804       P := P + 1;
805       M (P + 1 .. P + Msg'Length) := Msg;
806       P := P + Msg'Length;
807
808       --  Output message at current error node location
809
810       RTE_Error_Msg (M (1 .. P));
811    end Output_Entity_Name;
812
813    --------------
814    -- RE_Chars --
815    --------------
816
817    function RE_Chars (E : RE_Id) return Name_Id is
818       RE_Name_Chars : constant String := RE_Id'Image (E);
819
820    begin
821       --  Copy name skipping initial RE_ or RO_XX characters
822
823       if RE_Name_Chars (1 .. 2) = "RE" then
824          for J in 4 .. RE_Name_Chars'Last loop
825             Name_Buffer (J - 3) := Fold_Lower (RE_Name_Chars (J));
826          end loop;
827
828          Name_Len := RE_Name_Chars'Length - 3;
829
830       else
831          for J in 7 .. RE_Name_Chars'Last loop
832             Name_Buffer (J - 6) := Fold_Lower (RE_Name_Chars (J));
833          end loop;
834
835          Name_Len := RE_Name_Chars'Length - 6;
836       end if;
837
838       return Name_Find;
839    end RE_Chars;
840
841    ---------
842    -- RTE --
843    ---------
844
845    function RTE (E : RE_Id) return Entity_Id is
846       U_Id : constant RTU_Id := RE_Unit_Table (E);
847       U    : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
848
849       Lib_Unit : Node_Id;
850       Pkg_Ent  : Entity_Id;
851       Ename    : Name_Id;
852
853       --  The following flag is used to disable front-end inlining when RTE
854       --  is invoked. This prevents the analysis of other runtime bodies when
855       --  a particular spec is loaded through Rtsfind. This is both efficient,
856       --  and it prevents spurious visibility conflicts between use-visible
857       --  user entities, and entities in run-time packages.
858
859       --  In configurable run-time mode, subprograms marked Inlined_Always must
860       --  be inlined, so in the case we retain the Front_End_Inlining mode.
861
862       Save_Front_End_Inlining : Boolean;
863
864       procedure Check_RPC;
865       --  Reject programs that make use of distribution features not supported
866       --  on the current target. Also check that the PCS is compatible with
867       --  the code generator version. On such targets (VMS, Vxworks, others?)
868       --  we provide a minimal body for System.Rpc that only supplies an
869       --  implementation of Partition_Id.
870
871       function Find_Local_Entity (E : RE_Id) return Entity_Id;
872       --  This function is used when entity E is in this compilation's main
873       --  unit. It gets the value from the already compiled declaration.
874
875       ---------------
876       -- Check_RPC --
877       ---------------
878
879       procedure Check_RPC is
880
881          procedure Check_RPC_Failure (Msg : String);
882          pragma No_Return (Check_RPC_Failure);
883          --  Display Msg on standard error and raise Unrecoverable_Error
884
885          -----------------------
886          -- Check_RPC_Failure --
887          -----------------------
888
889          procedure Check_RPC_Failure (Msg : String) is
890          begin
891             Set_Standard_Error;
892             Write_Str (Msg);
893             Write_Eol;
894             raise Unrecoverable_Error;
895          end Check_RPC_Failure;
896
897       --  Start of processing for Check_RPC
898
899       begin
900          --  Bypass this check if debug flag -gnatdR set
901
902          if Debug_Flag_RR then
903             return;
904          end if;
905
906          --  Otherwise we need the check if we are going after one of
907          --  the critical entities in System.RPC in stubs mode.
908
909          --  ??? Should we do this for other s-parint entities too?
910
911          if (Distribution_Stub_Mode = Generate_Receiver_Stub_Body
912                       or else
913                         Distribution_Stub_Mode = Generate_Caller_Stub_Body)
914            and then (E = RE_Do_Rpc
915                        or else
916                      E = RE_Do_Apc
917                        or else
918                      E = RE_Params_Stream_Type
919                        or else
920                      E = RE_Request_Access)
921          then
922             if Get_PCS_Name = Name_No_DSA then
923                Check_RPC_Failure ("distribution feature not supported");
924
925             elsif Get_PCS_Version /= Gnatvsn.PCS_Version_Number then
926                Check_RPC_Failure ("PCS version mismatch");
927
928             end if;
929          end if;
930       end Check_RPC;
931
932       -----------------------
933       -- Find_Local_Entity --
934       -----------------------
935
936       function Find_Local_Entity (E : RE_Id) return Entity_Id is
937          RE_Str : constant String := RE_Id'Image (E);
938          Nam    : Name_Id;
939          Ent    : Entity_Id;
940
941          Save_Nam : constant String := Name_Buffer (1 .. Name_Len);
942          --  Save name buffer and length over call
943
944       begin
945          Name_Len := Natural'Max (0, RE_Str'Length - 3);
946          Name_Buffer (1 .. Name_Len) :=
947            RE_Str (RE_Str'First + 3 .. RE_Str'Last);
948
949          Nam := Name_Find;
950          Ent := Entity_Id (Get_Name_Table_Info (Nam));
951
952          Name_Len := Save_Nam'Length;
953          Name_Buffer (1 .. Name_Len) := Save_Nam;
954
955          return Ent;
956       end Find_Local_Entity;
957
958    --  Start of processing for RTE
959
960    begin
961       --  Doing a rtsfind in system.ads is special, as we cannot do this
962       --  when compiling System itself. So if we are compiling system then
963       --  we should already have acquired and processed the declaration
964       --  of the entity. The test is to see if this compilation's main unit
965       --  is System. If so, return the value from the already compiled
966       --  declaration and otherwise do a regular find.
967
968       --  Not pleasant, but these kinds of annoying recursion when
969       --  writing an Ada compiler in Ada have to be broken somewhere!
970
971       if Present (Main_Unit_Entity)
972         and then Chars (Main_Unit_Entity) = Name_System
973         and then Analyzed (Main_Unit_Entity)
974         and then not Is_Child_Unit (Main_Unit_Entity)
975       then
976          return Check_CRT (E, Find_Local_Entity (E));
977       end if;
978
979       Save_Front_End_Inlining := Front_End_Inlining;
980       Front_End_Inlining := Configurable_Run_Time_Mode;
981
982       --  Load unit if unit not previously loaded
983
984       if No (RE_Table (E)) then
985          Load_RTU (U_Id, Id => E);
986          Lib_Unit := Unit (Cunit (U.Unum));
987
988          --  In the subprogram case, we are all done, the entity we want
989          --  is the entity for the subprogram itself. Note that we do not
990          --  bother to check that it is the entity that was requested.
991          --  the only way that could fail to be the case is if runtime is
992          --  hopelessly misconfigured, and it isn't worth testing for this.
993
994          if Nkind (Lib_Unit) = N_Subprogram_Declaration then
995             RE_Table (E) := U.Entity;
996
997          --  Otherwise we must have the package case. First check package
998          --  entity itself (e.g. RTE_Name for System.Interrupts.Name)
999
1000          else
1001             pragma Assert (Nkind (Lib_Unit) = N_Package_Declaration);
1002             Ename := RE_Chars (E);
1003
1004             --  First we search the package entity chain. If the package
1005             --  only has a limited view, scan the corresponding list of
1006             --  incomplete types.
1007
1008             if From_With_Type (U.Entity) then
1009                Pkg_Ent := First_Entity (Limited_View (U.Entity));
1010             else
1011                Pkg_Ent := First_Entity (U.Entity);
1012             end if;
1013
1014             while Present (Pkg_Ent) loop
1015                if Ename = Chars (Pkg_Ent) then
1016                   RE_Table (E) := Pkg_Ent;
1017                   Check_RPC;
1018                   goto Found;
1019                end if;
1020
1021                Next_Entity (Pkg_Ent);
1022             end loop;
1023
1024             --  If we did not find the entity in the package entity chain,
1025             --  then check if the package entity itself matches. Note that
1026             --  we do this check after searching the entity chain, since
1027             --  the rule is that in case of ambiguity, we prefer the entity
1028             --  defined within the package, rather than the package itself.
1029
1030             if Ename = Chars (U.Entity) then
1031                RE_Table (E) := U.Entity;
1032             end if;
1033
1034             --  If we didn't find the entity we want, something is wrong.
1035             --  We just leave RE_Table (E) set to Empty and the appropriate
1036             --  action will be taken by Check_CRT when we exit.
1037
1038          end if;
1039       end if;
1040
1041       --  See if we have to generate a WITH for this entity. We generate
1042       --  a WITH if the current unit is part of the extended main code
1043       --  unit, and if we have not already added the with. The WITH is
1044       --  added to the appropriate unit (the current one). We do not need
1045       --  to generate a WITH for a call issued from RTE_Available.
1046
1047    <<Found>>
1048       if (not U.Withed)
1049         and then
1050           In_Extended_Main_Code_Unit (Cunit_Entity (Current_Sem_Unit))
1051         and then not RTE_Available_Call
1052       then
1053          U.Withed := True;
1054
1055          declare
1056             Withn    : Node_Id;
1057             Lib_Unit : Node_Id;
1058
1059          begin
1060             Lib_Unit := Unit (Cunit (U.Unum));
1061             Withn :=
1062               Make_With_Clause (Standard_Location,
1063                 Name =>
1064                   Make_Unit_Name
1065                     (E, Defining_Unit_Name (Specification (Lib_Unit))));
1066             Set_Library_Unit          (Withn, Cunit (U.Unum));
1067             Set_Corresponding_Spec    (Withn, U.Entity);
1068             Set_First_Name            (Withn, True);
1069             Set_Implicit_With         (Withn, True);
1070
1071             Mark_Rewrite_Insertion (Withn);
1072             Append (Withn, Context_Items (Cunit (Current_Sem_Unit)));
1073             Check_Restriction_No_Dependence (Name (Withn), Current_Error_Node);
1074          end;
1075       end if;
1076
1077       Front_End_Inlining := Save_Front_End_Inlining;
1078       return Check_CRT (E, RE_Table (E));
1079    end RTE;
1080
1081    -------------------
1082    -- RTE_Available --
1083    -------------------
1084
1085    function RTE_Available (E : RE_Id) return Boolean is
1086       Dummy : Entity_Id;
1087       pragma Warnings (Off, Dummy);
1088
1089       Result : Boolean;
1090
1091       Save_RTE_Available_Call : constant Boolean := RTE_Available_Call;
1092       Save_RTE_Is_Available   : constant Boolean := RTE_Is_Available;
1093       --  These are saved recursively because the call to load a unit
1094       --  caused by an upper level call may perform a recursive call
1095       --  to this routine during analysis of the corresponding unit.
1096
1097    begin
1098       RTE_Available_Call := True;
1099       RTE_Is_Available := True;
1100       Dummy := RTE (E);
1101       Result := RTE_Is_Available;
1102       RTE_Available_Call := Save_RTE_Available_Call;
1103       RTE_Is_Available   := Save_RTE_Is_Available;
1104       return Result;
1105
1106    exception
1107       when RE_Not_Available =>
1108          RTE_Available_Call := Save_RTE_Available_Call;
1109          RTE_Is_Available   := Save_RTE_Is_Available;
1110          return False;
1111    end RTE_Available;
1112
1113    --------------------------
1114    -- RTE_Record_Component --
1115    --------------------------
1116
1117    function RTE_Record_Component (E : RE_Id) return Entity_Id is
1118       U_Id     : constant RTU_Id := RE_Unit_Table (E);
1119       U        : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
1120       E1       : Entity_Id;
1121       Ename    : Name_Id;
1122       Found_E  : Entity_Id;
1123       Lib_Unit : Node_Id;
1124       Pkg_Ent  : Entity_Id;
1125
1126       --  The following flag is used to disable front-end inlining when
1127       --  RTE_Record_Component is invoked. This prevents the analysis of other
1128       --  runtime bodies when a particular spec is loaded through Rtsfind. This
1129       --  is both efficient, and it prevents spurious visibility conflicts
1130       --  between use-visible user entities, and entities in run-time packages.
1131
1132       --  In configurable run-time mode, subprograms marked Inlined_Always must
1133       --  be inlined, so in the case we retain the Front_End_Inlining mode.
1134
1135       Save_Front_End_Inlining : Boolean;
1136
1137    begin
1138       --  Note: Contrary to subprogram RTE, there is no need to do any special
1139       --  management with package system.ads because it has no record type
1140       --  declarations.
1141
1142       Save_Front_End_Inlining := Front_End_Inlining;
1143       Front_End_Inlining      := Configurable_Run_Time_Mode;
1144
1145       --  Load unit if unit not previously loaded
1146
1147       if not Present (U.Entity) then
1148          Load_RTU (U_Id, Id => E);
1149       end if;
1150
1151       Lib_Unit := Unit (Cunit (U.Unum));
1152
1153       pragma Assert (Nkind (Lib_Unit) = N_Package_Declaration);
1154       Ename := RE_Chars (E);
1155
1156       --  Search the entity in the components of record type declarations
1157       --  found in the package entity chain.
1158
1159       Found_E := Empty;
1160       Pkg_Ent := First_Entity (U.Entity);
1161       Search : while Present (Pkg_Ent) loop
1162          if Is_Record_Type (Pkg_Ent) then
1163             E1 := First_Entity (Pkg_Ent);
1164             while Present (E1) loop
1165                if Ename = Chars (E1) then
1166                   pragma Assert (not Present (Found_E));
1167                   Found_E := E1;
1168                end if;
1169
1170                Next_Entity (E1);
1171             end loop;
1172          end if;
1173
1174          Next_Entity (Pkg_Ent);
1175       end loop Search;
1176
1177       --  If we didn't find the entity we want, something is wrong. The
1178       --  appropriate action will be taken by Check_CRT when we exit.
1179
1180       --  Cenerate a with-clause if the current unit is part of the extended
1181       --  main code unit, and if we have not already added the with. The clause
1182       --  is added to the appropriate unit (the current one). We do not need to
1183       --  generate it for a call issued from RTE_Component_Available.
1184
1185       if (not U.Withed)
1186         and then
1187           In_Extended_Main_Code_Unit (Cunit_Entity (Current_Sem_Unit))
1188         and then not RTE_Available_Call
1189       then
1190          U.Withed := True;
1191
1192          declare
1193             Withn    : Node_Id;
1194             Lib_Unit : Node_Id;
1195
1196          begin
1197             Lib_Unit := Unit (Cunit (U.Unum));
1198             Withn :=
1199               Make_With_Clause (Standard_Location,
1200                 Name =>
1201                   Make_Unit_Name
1202                     (E, Defining_Unit_Name (Specification (Lib_Unit))));
1203             Set_Library_Unit          (Withn, Cunit (U.Unum));
1204             Set_Corresponding_Spec    (Withn, U.Entity);
1205             Set_First_Name            (Withn, True);
1206             Set_Implicit_With         (Withn, True);
1207
1208             Mark_Rewrite_Insertion (Withn);
1209             Append (Withn, Context_Items (Cunit (Current_Sem_Unit)));
1210             Check_Restriction_No_Dependence (Name (Withn), Current_Error_Node);
1211          end;
1212       end if;
1213
1214       Front_End_Inlining := Save_Front_End_Inlining;
1215       return Check_CRT (E, Found_E);
1216    end RTE_Record_Component;
1217
1218    ------------------------------------
1219    -- RTE_Record_Component_Available --
1220    ------------------------------------
1221
1222    function RTE_Record_Component_Available (E : RE_Id) return Boolean is
1223       Dummy : Entity_Id;
1224       pragma Warnings (Off, Dummy);
1225
1226       Result : Boolean;
1227
1228       Save_RTE_Available_Call : constant Boolean := RTE_Available_Call;
1229       Save_RTE_Is_Available   : constant Boolean := RTE_Is_Available;
1230       --  These are saved recursively because the call to load a unit
1231       --  caused by an upper level call may perform a recursive call
1232       --  to this routine during analysis of the corresponding unit.
1233
1234    begin
1235       RTE_Available_Call := True;
1236       RTE_Is_Available := True;
1237       Dummy := RTE_Record_Component (E);
1238       Result := RTE_Is_Available;
1239       RTE_Available_Call := Save_RTE_Available_Call;
1240       RTE_Is_Available   := Save_RTE_Is_Available;
1241       return Result;
1242
1243    exception
1244       when RE_Not_Available =>
1245          RTE_Available_Call := Save_RTE_Available_Call;
1246          RTE_Is_Available   := Save_RTE_Is_Available;
1247          return False;
1248    end RTE_Record_Component_Available;
1249
1250    -------------------
1251    -- RTE_Error_Msg --
1252    -------------------
1253
1254    procedure RTE_Error_Msg (Msg : String) is
1255    begin
1256       if RTE_Available_Call then
1257          RTE_Is_Available := False;
1258       else
1259          Error_Msg_N (Msg, Current_Error_Node);
1260
1261          --  Bump count of violations if we are in configurable run-time
1262          --  mode and this is not a continuation message.
1263
1264          if Configurable_Run_Time_Mode and then Msg (Msg'First) /= '\' then
1265             Configurable_Run_Time_Violations :=
1266               Configurable_Run_Time_Violations + 1;
1267          end if;
1268       end if;
1269    end RTE_Error_Msg;
1270
1271    ----------------
1272    -- RTU_Entity --
1273    ----------------
1274
1275    function RTU_Entity (U : RTU_Id) return Entity_Id is
1276    begin
1277       return RT_Unit_Table (U).Entity;
1278    end RTU_Entity;
1279
1280    ----------------
1281    -- RTU_Loaded --
1282    ----------------
1283
1284    function RTU_Loaded (U : RTU_Id) return Boolean is
1285    begin
1286       return Present (RT_Unit_Table (U).Entity);
1287    end RTU_Loaded;
1288
1289    --------------------
1290    -- Set_RTU_Loaded --
1291    --------------------
1292
1293    procedure Set_RTU_Loaded (N : Node_Id) is
1294       Loc   : constant Source_Ptr       := Sloc (N);
1295       Unum  : constant Unit_Number_Type := Get_Source_Unit (Loc);
1296       Uname : constant Unit_Name_Type   := Unit_Name (Unum);
1297       E     : constant Entity_Id        :=
1298                 Defining_Entity (Unit (Cunit (Unum)));
1299    begin
1300       pragma Assert (Is_Predefined_File_Name (Unit_File_Name (Unum)));
1301
1302       --  Loop through entries in RTU table looking for matching entry
1303
1304       for U_Id in RTU_Id'Range loop
1305
1306          --  Here we have a match
1307
1308          if Get_Unit_Name (U_Id) = Uname then
1309             declare
1310                U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
1311                --  The RT_Unit_Table entry that may need updating
1312
1313             begin
1314                --  If entry is not set, set it now
1315
1316                if No (U.Entity) then
1317                   U.Entity := E;
1318                   U.Uname  := Get_Unit_Name (U_Id);
1319                   U.Unum   := Unum;
1320                   U.Withed := False;
1321                end if;
1322
1323                return;
1324             end;
1325          end if;
1326       end loop;
1327    end Set_RTU_Loaded;
1328
1329    --------------------
1330    -- Text_IO_Kludge --
1331    --------------------
1332
1333    procedure Text_IO_Kludge (Nam : Node_Id) is
1334       Chrs : Name_Id;
1335
1336       type Name_Map_Type is array (Text_IO_Package_Name) of RTU_Id;
1337
1338       Name_Map : constant Name_Map_Type := Name_Map_Type'(
1339         Name_Decimal_IO     => Ada_Text_IO_Decimal_IO,
1340         Name_Enumeration_IO => Ada_Text_IO_Enumeration_IO,
1341         Name_Fixed_IO       => Ada_Text_IO_Fixed_IO,
1342         Name_Float_IO       => Ada_Text_IO_Float_IO,
1343         Name_Integer_IO     => Ada_Text_IO_Integer_IO,
1344         Name_Modular_IO     => Ada_Text_IO_Modular_IO);
1345
1346       Wide_Name_Map : constant Name_Map_Type := Name_Map_Type'(
1347         Name_Decimal_IO     => Ada_Wide_Text_IO_Decimal_IO,
1348         Name_Enumeration_IO => Ada_Wide_Text_IO_Enumeration_IO,
1349         Name_Fixed_IO       => Ada_Wide_Text_IO_Fixed_IO,
1350         Name_Float_IO       => Ada_Wide_Text_IO_Float_IO,
1351         Name_Integer_IO     => Ada_Wide_Text_IO_Integer_IO,
1352         Name_Modular_IO     => Ada_Wide_Text_IO_Modular_IO);
1353
1354       Wide_Wide_Name_Map : constant Name_Map_Type := Name_Map_Type'(
1355         Name_Decimal_IO     => Ada_Wide_Wide_Text_IO_Decimal_IO,
1356         Name_Enumeration_IO => Ada_Wide_Wide_Text_IO_Enumeration_IO,
1357         Name_Fixed_IO       => Ada_Wide_Wide_Text_IO_Fixed_IO,
1358         Name_Float_IO       => Ada_Wide_Wide_Text_IO_Float_IO,
1359         Name_Integer_IO     => Ada_Wide_Wide_Text_IO_Integer_IO,
1360         Name_Modular_IO     => Ada_Wide_Wide_Text_IO_Modular_IO);
1361
1362    begin
1363       --  Nothing to do if name is not identifier or a selected component
1364       --  whose selector_name is not an identifier.
1365
1366       if Nkind (Nam) = N_Identifier then
1367          Chrs := Chars (Nam);
1368
1369       elsif Nkind (Nam) = N_Selected_Component
1370         and then Nkind (Selector_Name (Nam)) = N_Identifier
1371       then
1372          Chrs := Chars (Selector_Name (Nam));
1373
1374       else
1375          return;
1376       end if;
1377
1378       --  Nothing to do if name is not one of the Text_IO subpackages
1379       --  Otherwise look through loaded units, and if we find Text_IO
1380       --  or [Wide_]Wide_Text_IO already loaded, then load the proper child.
1381
1382       if Chrs in Text_IO_Package_Name then
1383          for U in Main_Unit .. Last_Unit loop
1384             Get_Name_String (Unit_File_Name (U));
1385
1386             if Name_Len = 12 then
1387
1388                --  Here is where we do the loads if we find one of the units
1389                --  Ada.Text_IO or Ada.[Wide_]Wide_Text_IO. An interesting
1390                --  detail is that these units may already be used (i.e. their
1391                --  In_Use flags may be set). Normally when the In_Use flag is
1392                --  set, the Is_Potentially_Use_Visible flag of all entities in
1393                --  the package is set, but the new entity we are mysteriously
1394                --  adding was not there to have its flag set at the time. So
1395                --  that's why we pass the extra parameter to RTU_Find, to make
1396                --  sure the flag does get set now. Given that those generic
1397                --  packages are in fact child units, we must indicate that
1398                --  they are visible.
1399
1400                if Name_Buffer (1 .. 12) = "a-textio.ads" then
1401                   Load_RTU
1402                     (Name_Map (Chrs),
1403                      Use_Setting => In_Use (Cunit_Entity (U)));
1404                   Set_Is_Visible_Child_Unit
1405                     (RT_Unit_Table (Name_Map (Chrs)).Entity);
1406
1407                elsif Name_Buffer (1 .. 12) = "a-witeio.ads" then
1408                   Load_RTU
1409                     (Wide_Name_Map (Chrs),
1410                      Use_Setting => In_Use (Cunit_Entity (U)));
1411                   Set_Is_Visible_Child_Unit
1412                     (RT_Unit_Table (Wide_Name_Map (Chrs)).Entity);
1413
1414                elsif Name_Buffer (1 .. 12) = "a-ztexio.ads" then
1415                   Load_RTU
1416                     (Wide_Wide_Name_Map (Chrs),
1417                      Use_Setting => In_Use (Cunit_Entity (U)));
1418                   Set_Is_Visible_Child_Unit
1419                     (RT_Unit_Table (Wide_Wide_Name_Map (Chrs)).Entity);
1420                end if;
1421             end if;
1422          end loop;
1423       end if;
1424
1425    exception
1426       --  Generate error message if run-time unit not available
1427
1428       when RE_Not_Available =>
1429          Error_Msg_N ("& not available", Nam);
1430    end Text_IO_Kludge;
1431
1432 end Rtsfind;