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