OSDN Git Service

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