2014-09-15 Andreas Krebbel <Andreas.Krebbel@de.ibm.com>
[official-gcc.git] / gcc / ada / rtsfind.adb
bloba31215f960bce267099983f8ce5b4bf3bbfd6397
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-2014, 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 ------------------------------------------------------------------------------
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_Aux; use Sem_Aux;
46 with Sem_Ch7; use Sem_Ch7;
47 with Sem_Dist; use Sem_Dist;
48 with Sem_Util; use Sem_Util;
49 with Sinfo; use Sinfo;
50 with Stand; use Stand;
51 with Snames; use Snames;
52 with Tbuild; use Tbuild;
53 with Uname; use Uname;
55 package body Rtsfind is
57 RTE_Available_Call : Boolean := False;
58 -- Set True during call to RTE from RTE_Available (or from call to
59 -- RTE_Record_Component from RTE_Record_Component_Available). Tells
60 -- the called subprogram to set RTE_Is_Available to False rather than
61 -- generating an error message.
63 RTE_Is_Available : Boolean;
64 -- Set True by RTE_Available on entry. When RTE_Available_Call is set
65 -- True, set False if RTE would otherwise generate an error message.
67 ----------------
68 -- Unit table --
69 ----------------
71 -- The unit table has one entry for each unit included in the definition
72 -- of the type RTU_Id in the spec. The table entries are initialized in
73 -- Initialize to set the Entity field to Empty, indicating that the
74 -- corresponding unit has not yet been loaded. The fields are set when
75 -- a unit is loaded to contain the defining entity for the unit, the
76 -- unit name, and the unit number.
78 -- Note that a unit can be loaded either by a call to find an entity
79 -- within the unit (e.g. RTE), or by an explicit with of the unit. In
80 -- the latter case it is critical to make a call to Set_RTU_Loaded to
81 -- ensure that the entry in this table reflects the load.
83 -- A unit retrieved through rtsfind may end up in the context of several
84 -- other units, in addition to the main unit. These additional with_clauses
85 -- are needed to generate a proper traversal order for CodePeer. To
86 -- minimize somewhat the redundancy created by numerous calls to rtsfind
87 -- from different units, we keep track of the list of implicit with_clauses
88 -- already created for the current loaded unit.
90 type RT_Unit_Table_Record is record
91 Entity : Entity_Id;
92 Uname : Unit_Name_Type;
93 First_Implicit_With : Node_Id;
94 Unum : Unit_Number_Type;
95 end record;
97 RT_Unit_Table : array (RTU_Id) of RT_Unit_Table_Record;
99 --------------------------
100 -- Runtime Entity Table --
101 --------------------------
103 -- There is one entry in the runtime entity table for each entity that is
104 -- included in the definition of the RE_Id type in the spec. The entries
105 -- are set by Initialize_Rtsfind to contain Empty, indicating that the
106 -- entity has not yet been located. Once the entity is located for the
107 -- first time, its ID is stored in this array, so that subsequent calls
108 -- for the same entity can be satisfied immediately.
110 -- NOTE: In order to avoid conflicts between record components and subprgs
111 -- that have the same name (i.e. subprogram External_Tag and
112 -- component External_Tag of package Ada.Tags) this table is not used
113 -- with Record_Components.
115 RE_Table : array (RE_Id) of Entity_Id;
117 --------------------------------
118 -- Generation of with_clauses --
119 --------------------------------
121 -- When a unit is implicitly loaded as a result of a call to RTE, it is
122 -- necessary to create one or two implicit with_clauses. We add such
123 -- with_clauses to the extended main unit if needed, and also to whatever
124 -- unit needs them, which is not necessarily the main unit. The former
125 -- ensures that the object is correctly loaded by the binder. The latter
126 -- is necessary for CodePeer.
128 -- The field First_Implicit_With in the unit table record are used to
129 -- avoid creating duplicate with_clauses.
131 -----------------------
132 -- Local Subprograms --
133 -----------------------
135 function Check_CRT (E : RE_Id; Eid : Entity_Id) return Entity_Id;
136 -- Check entity Eid to ensure that configurable run-time restrictions are
137 -- met. May generate an error message (if RTE_Available_Call is false) and
138 -- raise RE_Not_Available if entity E does not exist (e.g. Eid is Empty).
139 -- Also check that entity is not overloaded.
141 procedure Entity_Not_Defined (Id : RE_Id);
142 -- Outputs error messages for an entity that is not defined in the run-time
143 -- library (the form of the error message is tailored for no run time or
144 -- configurable run time mode as required).
146 function Get_Unit_Name (U_Id : RTU_Id) return Unit_Name_Type;
147 -- Retrieves the Unit Name given a unit id represented by its enumeration
148 -- value in RTU_Id.
150 procedure Load_Fail (S : String; U_Id : RTU_Id; Id : RE_Id);
151 pragma No_Return (Load_Fail);
152 -- Internal procedure called if we can't successfully locate or process a
153 -- run-time unit. The parameters give information about the error message
154 -- to be given. S is a reason for failing to compile the file and U_Id is
155 -- the unit id. RE_Id is the RE_Id originally passed to RTE. The message in
156 -- S is one of the following:
158 -- "not found"
159 -- "had parser errors"
160 -- "had semantic errors"
162 -- The "not found" case is treated specially in that it is considered
163 -- a normal situation in configurable run-time mode, and generates
164 -- a warning, but is otherwise ignored.
166 procedure Load_RTU
167 (U_Id : RTU_Id;
168 Id : RE_Id := RE_Null;
169 Use_Setting : Boolean := False);
170 -- Load the unit whose Id is given if not already loaded. The unit is
171 -- loaded and analyzed, and the entry in RT_Unit_Table is updated to
172 -- reflect the load. Use_Setting is used to indicate the initial setting
173 -- for the Is_Potentially_Use_Visible flag of the entity for the loaded
174 -- unit (if it is indeed loaded). A value of False means nothing special
175 -- need be done. A value of True indicates that this flag must be set to
176 -- True. It is needed only in the Check_Text_IO_Special_Unit procedure,
177 -- which may materialize an entity of Text_IO (or [Wide_]Wide_Text_IO) that
178 -- was previously unknown. Id is the RE_Id value of the entity which was
179 -- originally requested. Id is used only for error message detail, and if
180 -- it is RE_Null, then the attempt to output the entity name is ignored.
182 function Make_Unit_Name
183 (U : RT_Unit_Table_Record;
184 N : Node_Id) return Node_Id;
185 -- If the unit is a child unit, build fully qualified name for use in
186 -- With_Clause.
188 procedure Maybe_Add_With (U : in out RT_Unit_Table_Record);
189 -- If necessary, add an implicit with_clause from the current unit to the
190 -- one represented by U.
192 procedure Output_Entity_Name (Id : RE_Id; Msg : String);
193 -- Output continuation error message giving qualified name of entity
194 -- corresponding to Id, appending the string given by Msg. This call
195 -- is only effective in All_Errors mode.
197 function RE_Chars (E : RE_Id) return Name_Id;
198 -- Given a RE_Id value returns the Chars of the corresponding entity
200 procedure RTE_Error_Msg (Msg : String);
201 -- Generates a message by calling Error_Msg_N specifying Current_Error_Node
202 -- as the node location using the given Msg text. Special processing in the
203 -- case where RTE_Available_Call is set. In this case, no message is output
204 -- and instead RTE_Is_Available is set to False. Note that this can only be
205 -- used if you are sure that the message comes directly or indirectly from
206 -- a call to the RTE function.
208 ---------------
209 -- Check_CRT --
210 ---------------
212 function Check_CRT (E : RE_Id; Eid : Entity_Id) return Entity_Id is
213 U_Id : constant RTU_Id := RE_Unit_Table (E);
215 begin
216 if No (Eid) then
217 if RTE_Available_Call then
218 RTE_Is_Available := False;
219 else
220 Entity_Not_Defined (E);
221 end if;
223 raise RE_Not_Available;
225 -- Entity is available
227 else
228 -- If in No_Run_Time mode and entity is neither in the current unit
229 -- nor in one of the specially permitted units, raise the exception.
231 if No_Run_Time_Mode
232 and then not OK_No_Run_Time_Unit (U_Id)
234 -- If the entity being referenced is defined in the current scope,
235 -- using it is always fine as such usage can never introduce any
236 -- dependency on an additional unit. The presence of this test
237 -- helps generating meaningful error messages for CRT violations.
239 and then Scope (Eid) /= Current_Scope
240 then
241 Entity_Not_Defined (E);
242 raise RE_Not_Available;
243 end if;
245 -- Check entity is not overloaded, checking for special exceptions
247 if Has_Homonym (Eid)
248 and then E /= RE_Save_Occurrence
249 then
250 Set_Standard_Error;
251 Write_Str ("Run-time configuration error (");
252 Write_Str ("rtsfind entity """);
253 Get_Decoded_Name_String (Chars (Eid));
254 Set_Casing (Mixed_Case);
255 Write_Str (Name_Buffer (1 .. Name_Len));
256 Write_Str (""" is overloaded)");
257 Write_Eol;
258 raise Unrecoverable_Error;
259 end if;
261 -- Otherwise entity is accessible
263 return Eid;
264 end if;
265 end Check_CRT;
267 --------------------------------
268 -- Check_Text_IO_Special_Unit --
269 --------------------------------
271 procedure Check_Text_IO_Special_Unit (Nam : Node_Id) is
272 Chrs : Name_Id;
274 type Name_Map_Type is array (Text_IO_Package_Name) of RTU_Id;
276 Name_Map : constant Name_Map_Type := Name_Map_Type'(
277 Name_Decimal_IO => Ada_Text_IO_Decimal_IO,
278 Name_Enumeration_IO => Ada_Text_IO_Enumeration_IO,
279 Name_Fixed_IO => Ada_Text_IO_Fixed_IO,
280 Name_Float_IO => Ada_Text_IO_Float_IO,
281 Name_Integer_IO => Ada_Text_IO_Integer_IO,
282 Name_Modular_IO => Ada_Text_IO_Modular_IO);
284 Wide_Name_Map : constant Name_Map_Type := Name_Map_Type'(
285 Name_Decimal_IO => Ada_Wide_Text_IO_Decimal_IO,
286 Name_Enumeration_IO => Ada_Wide_Text_IO_Enumeration_IO,
287 Name_Fixed_IO => Ada_Wide_Text_IO_Fixed_IO,
288 Name_Float_IO => Ada_Wide_Text_IO_Float_IO,
289 Name_Integer_IO => Ada_Wide_Text_IO_Integer_IO,
290 Name_Modular_IO => Ada_Wide_Text_IO_Modular_IO);
292 Wide_Wide_Name_Map : constant Name_Map_Type := Name_Map_Type'(
293 Name_Decimal_IO => Ada_Wide_Wide_Text_IO_Decimal_IO,
294 Name_Enumeration_IO => Ada_Wide_Wide_Text_IO_Enumeration_IO,
295 Name_Fixed_IO => Ada_Wide_Wide_Text_IO_Fixed_IO,
296 Name_Float_IO => Ada_Wide_Wide_Text_IO_Float_IO,
297 Name_Integer_IO => Ada_Wide_Wide_Text_IO_Integer_IO,
298 Name_Modular_IO => Ada_Wide_Wide_Text_IO_Modular_IO);
300 To_Load : RTU_Id;
301 -- Unit to be loaded, from one of the above maps
303 begin
304 -- Nothing to do if name is not an identifier or a selected component
305 -- whose selector_name is an identifier.
307 if Nkind (Nam) = N_Identifier then
308 Chrs := Chars (Nam);
310 elsif Nkind (Nam) = N_Selected_Component
311 and then Nkind (Selector_Name (Nam)) = N_Identifier
312 then
313 Chrs := Chars (Selector_Name (Nam));
315 else
316 return;
317 end if;
319 -- Nothing to do if name is not one of the Text_IO subpackages
320 -- Otherwise look through loaded units, and if we find Text_IO
321 -- or [Wide_]Wide_Text_IO already loaded, then load the proper child.
323 if Chrs in Text_IO_Package_Name then
324 for U in Main_Unit .. Last_Unit loop
325 Get_Name_String (Unit_File_Name (U));
327 if Name_Len = 12 then
329 -- Here is where we do the loads if we find one of the units
330 -- Ada.Text_IO or Ada.[Wide_]Wide_Text_IO. An interesting
331 -- detail is that these units may already be used (i.e. their
332 -- In_Use flags may be set). Normally when the In_Use flag is
333 -- set, the Is_Potentially_Use_Visible flag of all entities in
334 -- the package is set, but the new entity we are mysteriously
335 -- adding was not there to have its flag set at the time. So
336 -- that's why we pass the extra parameter to RTU_Find, to make
337 -- sure the flag does get set now. Given that those generic
338 -- packages are in fact child units, we must indicate that
339 -- they are visible.
341 if Name_Buffer (1 .. 12) = "a-textio.ads" then
342 To_Load := Name_Map (Chrs);
344 elsif Name_Buffer (1 .. 12) = "a-witeio.ads" then
345 To_Load := Wide_Name_Map (Chrs);
347 elsif Name_Buffer (1 .. 12) = "a-ztexio.ads" then
348 To_Load := Wide_Wide_Name_Map (Chrs);
350 else
351 goto Continue;
352 end if;
354 Load_RTU (To_Load, Use_Setting => In_Use (Cunit_Entity (U)));
355 Set_Is_Visible_Lib_Unit (RT_Unit_Table (To_Load).Entity);
357 -- Prevent creation of an implicit 'with' from (for example)
358 -- Ada.Wide_Text_IO.Integer_IO to Ada.Text_IO.Integer_IO,
359 -- because these could create cycles. First check whether the
360 -- simple names match ("integer_io" = "integer_io"), and then
361 -- check whether the parent is indeed one of the
362 -- [[Wide_]Wide_]Text_IO packages.
364 if Chrs = Chars (Cunit_Entity (Current_Sem_Unit)) then
365 declare
366 Parent_Name : constant Unit_Name_Type :=
367 Get_Parent_Spec_Name
368 (Unit_Name (Current_Sem_Unit));
370 begin
371 if Parent_Name /= No_Unit_Name then
372 Get_Name_String (Parent_Name);
374 declare
375 P : String renames Name_Buffer (1 .. Name_Len);
376 begin
377 if P = "ada.text_io%s" or else
378 P = "ada.wide_text_io%s" or else
379 P = "ada.wide_wide_text_io%s"
380 then
381 goto Continue;
382 end if;
383 end;
384 end if;
385 end;
386 end if;
388 -- Add an implicit with clause from the current unit to the
389 -- [[Wide_]Wide_]Text_IO child (if necessary).
391 Maybe_Add_With (RT_Unit_Table (To_Load));
392 end if;
394 <<Continue>> null;
395 end loop;
396 end if;
398 exception
399 -- Generate error message if run-time unit not available
401 when RE_Not_Available =>
402 Error_Msg_N ("& not available", Nam);
403 end Check_Text_IO_Special_Unit;
405 ------------------------
406 -- Entity_Not_Defined --
407 ------------------------
409 procedure Entity_Not_Defined (Id : RE_Id) is
410 begin
411 if No_Run_Time_Mode then
413 -- If the error occurs when compiling the body of a predefined
414 -- unit for inlining purposes, the body must be illegal in this
415 -- mode, and there is no point in continuing.
417 if Is_Predefined_File_Name
418 (Unit_File_Name (Get_Source_Unit (Sloc (Current_Error_Node))))
419 then
420 Error_Msg_N
421 ("construct not allowed in no run time mode!",
422 Current_Error_Node);
423 raise Unrecoverable_Error;
425 else
426 RTE_Error_Msg ("|construct not allowed in no run time mode");
427 end if;
429 elsif Configurable_Run_Time_Mode then
430 RTE_Error_Msg ("|construct not allowed in this configuration>");
431 else
432 RTE_Error_Msg ("run-time configuration error");
433 end if;
435 Output_Entity_Name (Id, "not defined");
436 end Entity_Not_Defined;
438 -------------------
439 -- Get_Unit_Name --
440 -------------------
442 function Get_Unit_Name (U_Id : RTU_Id) return Unit_Name_Type is
443 Uname_Chars : constant String := RTU_Id'Image (U_Id);
445 begin
446 Name_Len := Uname_Chars'Length;
447 Name_Buffer (1 .. Name_Len) := Uname_Chars;
448 Set_Casing (All_Lower_Case);
450 if U_Id in Ada_Child then
451 Name_Buffer (4) := '.';
453 if U_Id in Ada_Calendar_Child then
454 Name_Buffer (13) := '.';
456 elsif U_Id in Ada_Dispatching_Child then
457 Name_Buffer (16) := '.';
459 elsif U_Id in Ada_Interrupts_Child then
460 Name_Buffer (15) := '.';
462 elsif U_Id in Ada_Numerics_Child then
463 Name_Buffer (13) := '.';
465 elsif U_Id in Ada_Real_Time_Child then
466 Name_Buffer (14) := '.';
468 elsif U_Id in Ada_Streams_Child then
469 Name_Buffer (12) := '.';
471 elsif U_Id in Ada_Strings_Child then
472 Name_Buffer (12) := '.';
474 elsif U_Id in Ada_Text_IO_Child then
475 Name_Buffer (12) := '.';
477 elsif U_Id in Ada_Wide_Text_IO_Child then
478 Name_Buffer (17) := '.';
480 elsif U_Id in Ada_Wide_Wide_Text_IO_Child then
481 Name_Buffer (22) := '.';
482 end if;
484 elsif U_Id in Interfaces_Child then
485 Name_Buffer (11) := '.';
487 elsif U_Id in System_Child then
488 Name_Buffer (7) := '.';
490 if U_Id in System_Dim_Child then
491 Name_Buffer (11) := '.';
492 end if;
494 if U_Id in System_Multiprocessors_Child then
495 Name_Buffer (23) := '.';
496 end if;
498 if U_Id in System_Storage_Pools_Child then
499 Name_Buffer (21) := '.';
500 end if;
502 if U_Id in System_Strings_Child then
503 Name_Buffer (15) := '.';
504 end if;
506 if U_Id in System_Tasking_Child then
507 Name_Buffer (15) := '.';
508 end if;
510 if U_Id in System_Tasking_Restricted_Child then
511 Name_Buffer (26) := '.';
512 end if;
514 if U_Id in System_Tasking_Protected_Objects_Child then
515 Name_Buffer (33) := '.';
516 end if;
518 if U_Id in System_Tasking_Async_Delays_Child then
519 Name_Buffer (28) := '.';
520 end if;
521 end if;
523 -- Add %s at end for spec
525 Name_Buffer (Name_Len + 1) := '%';
526 Name_Buffer (Name_Len + 2) := 's';
527 Name_Len := Name_Len + 2;
529 return Name_Find;
530 end Get_Unit_Name;
532 ----------------
533 -- Initialize --
534 ----------------
536 procedure Initialize is
537 begin
538 -- Initialize the unit table
540 for J in RTU_Id loop
541 RT_Unit_Table (J).Entity := Empty;
542 end loop;
544 for J in RE_Id loop
545 RE_Table (J) := Empty;
546 end loop;
548 RTE_Is_Available := False;
549 end Initialize;
551 ------------
552 -- Is_RTE --
553 ------------
555 function Is_RTE (Ent : Entity_Id; E : RE_Id) return Boolean is
556 E_Unit_Name : Unit_Name_Type;
557 Ent_Unit_Name : Unit_Name_Type;
559 S : Entity_Id;
560 E1 : Entity_Id;
561 E2 : Entity_Id;
563 begin
564 if No (Ent) then
565 return False;
567 -- If E has already a corresponding entity, check it directly,
568 -- going to full views if they exist to deal with the incomplete
569 -- and private type cases properly.
571 elsif Present (RE_Table (E)) then
572 E1 := Ent;
574 if Is_Type (E1) and then Present (Full_View (E1)) then
575 E1 := Full_View (E1);
576 end if;
578 E2 := RE_Table (E);
580 if Is_Type (E2) and then Present (Full_View (E2)) then
581 E2 := Full_View (E2);
582 end if;
584 return E1 = E2;
585 end if;
587 -- If the unit containing E is not loaded, we already know that the
588 -- entity we have cannot have come from this unit.
590 E_Unit_Name := Get_Unit_Name (RE_Unit_Table (E));
592 if not Is_Loaded (E_Unit_Name) then
593 return False;
594 end if;
596 -- Here the unit containing the entity is loaded. We have not made
597 -- an explicit call to RTE to get the entity in question, but we may
598 -- have obtained a reference to it indirectly from some other entity
599 -- in the same unit, or some other unit that references it.
601 -- Get the defining unit of the entity
603 S := Scope (Ent);
605 if No (S) or else Ekind (S) /= E_Package then
606 return False;
607 end if;
609 Ent_Unit_Name := Get_Unit_Name (Unit_Declaration_Node (S));
611 -- If the defining unit of the entity we are testing is not the
612 -- unit containing E, then they cannot possibly match.
614 if Ent_Unit_Name /= E_Unit_Name then
615 return False;
616 end if;
618 -- If the units match, then compare the names (remember that no
619 -- overloading is permitted in entities fetched using Rtsfind).
621 if RE_Chars (E) = Chars (Ent) then
622 RE_Table (E) := Ent;
624 -- If front-end inlining is enabled, we may be within a body that
625 -- contains inlined functions, which has not been retrieved through
626 -- rtsfind, and therefore is not yet recorded in the RT_Unit_Table.
627 -- Add the unit information now, it must be fully available.
629 declare
630 U : RT_Unit_Table_Record
631 renames RT_Unit_Table (RE_Unit_Table (E));
632 begin
633 if No (U.Entity) then
634 U.Entity := S;
635 U.Uname := E_Unit_Name;
636 U.Unum := Get_Source_Unit (S);
637 end if;
638 end;
640 return True;
641 else
642 return False;
643 end if;
644 end Is_RTE;
646 ------------
647 -- Is_RTU --
648 ------------
650 function Is_RTU (Ent : Entity_Id; U : RTU_Id) return Boolean is
651 E : constant Entity_Id := RT_Unit_Table (U).Entity;
652 begin
653 return Present (E) and then E = Ent;
654 end Is_RTU;
656 -----------------------------
657 -- Is_Text_IO_Special_Unit --
658 -----------------------------
660 function Is_Text_IO_Special_Unit (Nam : Node_Id) return Boolean is
661 Prf : Node_Id;
662 Sel : Node_Id;
664 begin
665 if Nkind (Nam) /= N_Expanded_Name then
666 return False;
667 end if;
669 Prf := Prefix (Nam);
670 Sel := Selector_Name (Nam);
672 if Nkind (Sel) /= N_Expanded_Name
673 or else Nkind (Prf) /= N_Identifier
674 or else Chars (Prf) /= Name_Ada
675 then
676 return False;
677 end if;
679 Prf := Prefix (Sel);
680 Sel := Selector_Name (Sel);
682 return
683 Nkind (Prf) = N_Identifier
684 and then
685 Nam_In (Chars (Prf), Name_Text_IO,
686 Name_Wide_Text_IO,
687 Name_Wide_Wide_Text_IO)
688 and then Nkind (Sel) = N_Identifier
689 and then Chars (Sel) in Text_IO_Package_Name;
690 end Is_Text_IO_Special_Unit;
692 ---------------
693 -- Load_Fail --
694 ---------------
696 procedure Load_Fail (S : String; U_Id : RTU_Id; Id : RE_Id) is
697 M : String (1 .. 100);
698 P : Natural := 0;
700 begin
701 -- Output header message
703 if Configurable_Run_Time_Mode then
704 RTE_Error_Msg ("construct not allowed in configurable run-time mode");
705 else
706 RTE_Error_Msg ("run-time library configuration error");
707 end if;
709 -- Output file name and reason string
711 M (1 .. 6) := "\file ";
712 P := 6;
714 Get_Name_String
715 (Get_File_Name (RT_Unit_Table (U_Id).Uname, Subunit => False));
716 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
717 P := P + Name_Len;
719 M (P + 1) := ' ';
720 P := P + 1;
722 M (P + 1 .. P + S'Length) := S;
723 P := P + S'Length;
725 RTE_Error_Msg (M (1 .. P));
727 -- Output entity name
729 Output_Entity_Name (Id, "not available");
731 -- In configurable run time mode, we raise RE_Not_Available, and the
732 -- caller is expected to deal gracefully with this. In the case of a
733 -- call to RTE_Available, this exception will be caught in Rtsfind,
734 -- and result in a returned value of False for the call.
736 if Configurable_Run_Time_Mode then
737 raise RE_Not_Available;
739 -- Here we have a load failure in normal full run time mode. See if we
740 -- are in the context of an RTE_Available call. If so, we just raise
741 -- RE_Not_Available. This can happen if a unit is unavailable, which
742 -- happens for example in the VM case, where the run-time is not
743 -- complete, but we do not regard it as a configurable run-time.
744 -- If the caller has done an explicit call to RTE_Available, then
745 -- clearly the caller is prepared to deal with a result of False.
747 elsif RTE_Available_Call then
748 RTE_Is_Available := False;
749 raise RE_Not_Available;
751 -- If we are not in the context of an RTE_Available call, we are really
752 -- trying to load an entity that is not there, and that should never
753 -- happen, so in this case we signal a fatal error.
755 else
756 raise Unrecoverable_Error;
757 end if;
758 end Load_Fail;
760 --------------
761 -- Load_RTU --
762 --------------
764 procedure Load_RTU
765 (U_Id : RTU_Id;
766 Id : RE_Id := RE_Null;
767 Use_Setting : Boolean := False)
769 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
770 Priv_Par : constant Elist_Id := New_Elmt_List;
771 Lib_Unit : Node_Id;
773 procedure Save_Private_Visibility;
774 -- If the current unit is the body of child unit or the spec of a
775 -- private child unit, the private declarations of the parent(s) are
776 -- visible. If the unit to be loaded is another public sibling, its
777 -- compilation will affect the visibility of the common ancestors.
778 -- Indicate those that must be restored.
780 procedure Restore_Private_Visibility;
781 -- Restore the visibility of ancestors after compiling RTU
783 --------------------------------
784 -- Restore_Private_Visibility --
785 --------------------------------
787 procedure Restore_Private_Visibility is
788 E_Par : Elmt_Id;
790 begin
791 E_Par := First_Elmt (Priv_Par);
792 while Present (E_Par) loop
793 if not In_Private_Part (Node (E_Par)) then
794 Install_Private_Declarations (Node (E_Par));
795 end if;
797 Next_Elmt (E_Par);
798 end loop;
799 end Restore_Private_Visibility;
801 -----------------------------
802 -- Save_Private_Visibility --
803 -----------------------------
805 procedure Save_Private_Visibility is
806 Par : Entity_Id;
808 begin
809 Par := Scope (Current_Scope);
810 while Present (Par)
811 and then Par /= Standard_Standard
812 loop
813 if Ekind (Par) = E_Package
814 and then Is_Compilation_Unit (Par)
815 and then In_Private_Part (Par)
816 then
817 Append_Elmt (Par, Priv_Par);
818 end if;
820 Par := Scope (Par);
821 end loop;
822 end Save_Private_Visibility;
824 -- Start of processing for Load_RTU
826 begin
827 -- Nothing to do if unit is already loaded
829 if Present (U.Entity) then
830 return;
831 end if;
833 -- Note if secondary stack is used
835 if U_Id = System_Secondary_Stack then
836 Opt.Sec_Stack_Used := True;
837 end if;
839 -- Otherwise we need to load the unit, First build unit name
840 -- from the enumeration literal name in type RTU_Id.
842 U.Uname := Get_Unit_Name (U_Id);
843 U. First_Implicit_With := Empty;
845 -- Now do the load call, note that setting Error_Node to Empty is
846 -- a signal to Load_Unit that we will regard a failure to find the
847 -- file as a fatal error, and that it should not output any kind
848 -- of diagnostics, since we will take care of it here.
850 -- We save style checking switches and turn off style checking for
851 -- loading the unit, since we don't want any style checking.
853 declare
854 Save_Style_Check : constant Boolean := Style_Check;
855 begin
856 Style_Check := False;
857 U.Unum :=
858 Load_Unit
859 (Load_Name => U.Uname,
860 Required => False,
861 Subunit => False,
862 Error_Node => Empty);
863 Style_Check := Save_Style_Check;
864 end;
866 -- Check for bad unit load
868 if U.Unum = No_Unit then
869 Load_Fail ("not found", U_Id, Id);
870 elsif Fatal_Error (U.Unum) then
871 Load_Fail ("had parser errors", U_Id, Id);
872 end if;
874 -- Make sure that the unit is analyzed
876 declare
877 Was_Analyzed : constant Boolean :=
878 Analyzed (Cunit (Current_Sem_Unit));
880 begin
881 -- Pretend that the current unit is analyzed, in case it is System
882 -- or some such. This allows us to put some declarations, such as
883 -- exceptions and packed arrays of Boolean, into System even though
884 -- expanding them requires System...
886 -- This is a bit odd but works fine. If the RTS unit does not depend
887 -- in any way on the current unit, then it never gets back into the
888 -- current unit's tree, and the change we make to the current unit
889 -- tree is never noticed by anyone (it is undone in a moment). That
890 -- is the normal situation.
892 -- If the RTS Unit *does* depend on the current unit, for instance,
893 -- when you are compiling System, then you had better have finished
894 -- analyzing the part of System that is depended on before you try to
895 -- load the RTS Unit. This means having the code in System ordered in
896 -- an appropriate manner.
898 Set_Analyzed (Cunit (Current_Sem_Unit), True);
900 if not Analyzed (Cunit (U.Unum)) then
902 -- If the unit is already loaded through a limited_with_clause,
903 -- the relevant entities must already be available. We do not
904 -- want to load and analyze the unit because this would create
905 -- a real semantic dependence when the purpose of the limited_with
906 -- is precisely to avoid such.
908 if From_Limited_With (Cunit_Entity (U.Unum)) then
909 null;
911 else
912 Save_Private_Visibility;
913 Semantics (Cunit (U.Unum));
914 Restore_Private_Visibility;
916 if Fatal_Error (U.Unum) then
917 Load_Fail ("had semantic errors", U_Id, Id);
918 end if;
919 end if;
920 end if;
922 -- Undo the pretence
924 Set_Analyzed (Cunit (Current_Sem_Unit), Was_Analyzed);
925 end;
927 Lib_Unit := Unit (Cunit (U.Unum));
928 U.Entity := Defining_Entity (Lib_Unit);
930 if Use_Setting then
931 Set_Is_Potentially_Use_Visible (U.Entity, True);
932 end if;
933 end Load_RTU;
935 --------------------
936 -- Make_Unit_Name --
937 --------------------
939 function Make_Unit_Name
940 (U : RT_Unit_Table_Record;
941 N : Node_Id) return Node_Id is
943 Nam : Node_Id;
944 Scop : Entity_Id;
946 begin
947 Nam := New_Occurrence_Of (U.Entity, Standard_Location);
948 Scop := Scope (U.Entity);
950 if Nkind (N) = N_Defining_Program_Unit_Name then
951 while Scop /= Standard_Standard loop
952 Nam :=
953 Make_Expanded_Name (Standard_Location,
954 Chars => Chars (U.Entity),
955 Prefix => New_Occurrence_Of (Scop, Standard_Location),
956 Selector_Name => Nam);
957 Set_Entity (Nam, U.Entity);
959 Scop := Scope (Scop);
960 end loop;
961 end if;
963 return Nam;
964 end Make_Unit_Name;
966 --------------------
967 -- Maybe_Add_With --
968 --------------------
970 procedure Maybe_Add_With (U : in out RT_Unit_Table_Record) is
971 begin
972 -- We do not need to generate a with_clause for a call issued from
973 -- RTE_Component_Available. However, for CodePeer, we need these
974 -- additional with's, because for a sequence like "if RTE_Available (X)
975 -- then ... RTE (X)" the RTE call fails to create some necessary with's.
977 if RTE_Available_Call and not Generate_SCIL then
978 return;
979 end if;
981 -- Avoid creating directly self-referential with clauses
983 if Current_Sem_Unit = U.Unum then
984 return;
985 end if;
987 -- Add the with_clause, if we have not already added an implicit with
988 -- for this unit to the current compilation unit.
990 declare
991 LibUnit : constant Node_Id := Unit (Cunit (U.Unum));
992 Clause : Node_Id;
993 Withn : Node_Id;
995 begin
996 Clause := U.First_Implicit_With;
997 while Present (Clause) loop
998 if Parent (Clause) = Cunit (Current_Sem_Unit) then
999 return;
1000 end if;
1002 Clause := Next_Implicit_With (Clause);
1003 end loop;
1005 Withn :=
1006 Make_With_Clause (Standard_Location,
1007 Name =>
1008 Make_Unit_Name
1009 (U, Defining_Unit_Name (Specification (LibUnit))));
1011 Set_Library_Unit (Withn, Cunit (U.Unum));
1012 Set_Corresponding_Spec (Withn, U.Entity);
1013 Set_First_Name (Withn, True);
1014 Set_Implicit_With (Withn, True);
1015 Set_Next_Implicit_With (Withn, U.First_Implicit_With);
1017 U.First_Implicit_With := Withn;
1019 Mark_Rewrite_Insertion (Withn);
1020 Append (Withn, Context_Items (Cunit (Current_Sem_Unit)));
1021 Check_Restriction_No_Dependence (Name (Withn), Current_Error_Node);
1022 end;
1023 end Maybe_Add_With;
1025 ------------------------
1026 -- Output_Entity_Name --
1027 ------------------------
1029 procedure Output_Entity_Name (Id : RE_Id; Msg : String) is
1030 M : String (1 .. 2048);
1031 P : Natural := 0;
1032 -- M (1 .. P) is current message to be output
1034 RE_Image : constant String := RE_Id'Image (Id);
1036 begin
1037 if Id = RE_Null then
1038 return;
1039 end if;
1041 M (1 .. 9) := "\entity """;
1042 P := 9;
1044 -- Add unit name to message, excluding %s or %b at end
1046 Get_Name_String (Get_Unit_Name (RE_Unit_Table (Id)));
1047 Name_Len := Name_Len - 2;
1048 Set_Casing (Mixed_Case);
1049 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
1050 P := P + Name_Len;
1052 -- Add a qualifying period
1054 M (P + 1) := '.';
1055 P := P + 1;
1057 -- Add entity name and closing quote to message
1059 Name_Len := RE_Image'Length - 3;
1060 Name_Buffer (1 .. Name_Len) := RE_Image (4 .. RE_Image'Length);
1061 Set_Casing (Mixed_Case);
1062 M (P + 1 .. P + Name_Len) := Name_Buffer (1 .. Name_Len);
1063 P := P + Name_Len;
1064 M (P + 1) := '"';
1065 P := P + 1;
1067 -- Add message
1069 M (P + 1) := ' ';
1070 P := P + 1;
1071 M (P + 1 .. P + Msg'Length) := Msg;
1072 P := P + Msg'Length;
1074 -- Output message at current error node location
1076 RTE_Error_Msg (M (1 .. P));
1077 end Output_Entity_Name;
1079 --------------
1080 -- RE_Chars --
1081 --------------
1083 function RE_Chars (E : RE_Id) return Name_Id is
1084 RE_Name_Chars : constant String := RE_Id'Image (E);
1086 begin
1087 -- Copy name skipping initial RE_ or RO_XX characters
1089 if RE_Name_Chars (1 .. 2) = "RE" then
1090 for J in 4 .. RE_Name_Chars'Last loop
1091 Name_Buffer (J - 3) := Fold_Lower (RE_Name_Chars (J));
1092 end loop;
1094 Name_Len := RE_Name_Chars'Length - 3;
1096 else
1097 for J in 7 .. RE_Name_Chars'Last loop
1098 Name_Buffer (J - 6) := Fold_Lower (RE_Name_Chars (J));
1099 end loop;
1101 Name_Len := RE_Name_Chars'Length - 6;
1102 end if;
1104 return Name_Find;
1105 end RE_Chars;
1107 ---------
1108 -- RTE --
1109 ---------
1111 function RTE (E : RE_Id) return Entity_Id is
1112 U_Id : constant RTU_Id := RE_Unit_Table (E);
1113 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
1115 Lib_Unit : Node_Id;
1116 Pkg_Ent : Entity_Id;
1117 Ename : Name_Id;
1119 -- The following flag is used to disable front-end inlining when RTE
1120 -- is invoked. This prevents the analysis of other runtime bodies when
1121 -- a particular spec is loaded through Rtsfind. This is both efficient,
1122 -- and it prevents spurious visibility conflicts between use-visible
1123 -- user entities, and entities in run-time packages.
1125 Save_Front_End_Inlining : Boolean;
1127 procedure Check_RPC;
1128 -- Reject programs that make use of distribution features not supported
1129 -- on the current target. Also check that the PCS is compatible with the
1130 -- code generator version. On such targets (Vxworks, others?) we provide
1131 -- a minimal body for System.Rpc that only supplies an implementation of
1132 -- Partition_Id.
1134 function Find_Local_Entity (E : RE_Id) return Entity_Id;
1135 -- This function is used when entity E is in this compilation's main
1136 -- unit. It gets the value from the already compiled declaration.
1138 ---------------
1139 -- Check_RPC --
1140 ---------------
1142 procedure Check_RPC is
1143 begin
1144 -- Bypass this check if debug flag -gnatdR set
1146 if Debug_Flag_RR then
1147 return;
1148 end if;
1150 -- Otherwise we need the check if we are going after one of the
1151 -- critical entities in System.RPC / System.Partition_Interface.
1153 if E = RE_Do_Rpc
1154 or else
1155 E = RE_Do_Apc
1156 or else
1157 E = RE_Params_Stream_Type
1158 or else
1159 E = RE_Request_Access
1160 then
1161 -- If generating RCI stubs, check that we have a real PCS
1163 if (Distribution_Stub_Mode = Generate_Receiver_Stub_Body
1164 or else
1165 Distribution_Stub_Mode = Generate_Caller_Stub_Body)
1166 and then Get_PCS_Name = Name_No_DSA
1167 then
1168 Set_Standard_Error;
1169 Write_Str ("distribution feature not supported");
1170 Write_Eol;
1171 raise Unrecoverable_Error;
1173 -- In all cases, check Exp_Dist and System.Partition_Interface
1174 -- consistency.
1176 elsif Get_PCS_Version /=
1177 Exp_Dist.PCS_Version_Number (Get_PCS_Name)
1178 then
1179 Set_Standard_Error;
1180 Write_Str ("PCS version mismatch: expander ");
1181 Write_Int (Exp_Dist.PCS_Version_Number (Get_PCS_Name));
1182 Write_Str (", PCS (");
1183 Write_Name (Get_PCS_Name);
1184 Write_Str (") ");
1185 Write_Int (Get_PCS_Version);
1186 Write_Eol;
1187 raise Unrecoverable_Error;
1188 end if;
1189 end if;
1190 end Check_RPC;
1192 -----------------------
1193 -- Find_Local_Entity --
1194 -----------------------
1196 function Find_Local_Entity (E : RE_Id) return Entity_Id is
1197 RE_Str : constant String := RE_Id'Image (E);
1198 Nam : Name_Id;
1199 Ent : Entity_Id;
1201 Save_Nam : constant String := Name_Buffer (1 .. Name_Len);
1202 -- Save name buffer and length over call
1204 begin
1205 Name_Len := Natural'Max (0, RE_Str'Length - 3);
1206 Name_Buffer (1 .. Name_Len) :=
1207 RE_Str (RE_Str'First + 3 .. RE_Str'Last);
1209 Nam := Name_Find;
1210 Ent := Entity_Id (Get_Name_Table_Info (Nam));
1212 Name_Len := Save_Nam'Length;
1213 Name_Buffer (1 .. Name_Len) := Save_Nam;
1215 return Ent;
1216 end Find_Local_Entity;
1218 -- Start of processing for RTE
1220 begin
1221 -- Doing a rtsfind in system.ads is special, as we cannot do this
1222 -- when compiling System itself. So if we are compiling system then
1223 -- we should already have acquired and processed the declaration
1224 -- of the entity. The test is to see if this compilation's main unit
1225 -- is System. If so, return the value from the already compiled
1226 -- declaration and otherwise do a regular find.
1228 -- Not pleasant, but these kinds of annoying recursion when
1229 -- writing an Ada compiler in Ada have to be broken somewhere.
1231 if Present (Main_Unit_Entity)
1232 and then Chars (Main_Unit_Entity) = Name_System
1233 and then Analyzed (Main_Unit_Entity)
1234 and then not Is_Child_Unit (Main_Unit_Entity)
1235 then
1236 return Check_CRT (E, Find_Local_Entity (E));
1237 end if;
1239 Save_Front_End_Inlining := Front_End_Inlining;
1240 Front_End_Inlining := False;
1242 -- Load unit if unit not previously loaded
1244 if No (RE_Table (E)) then
1245 Load_RTU (U_Id, Id => E);
1246 Lib_Unit := Unit (Cunit (U.Unum));
1248 -- In the subprogram case, we are all done, the entity we want
1249 -- is the entity for the subprogram itself. Note that we do not
1250 -- bother to check that it is the entity that was requested.
1251 -- the only way that could fail to be the case is if runtime is
1252 -- hopelessly misconfigured, and it isn't worth testing for this.
1254 if Nkind (Lib_Unit) = N_Subprogram_Declaration then
1255 RE_Table (E) := U.Entity;
1257 -- Otherwise we must have the package case. First check package
1258 -- entity itself (e.g. RTE_Name for System.Interrupts.Name)
1260 else
1261 pragma Assert (Nkind (Lib_Unit) = N_Package_Declaration);
1262 Ename := RE_Chars (E);
1264 -- First we search the package entity chain. If the package
1265 -- only has a limited view, scan the corresponding list of
1266 -- incomplete types.
1268 if From_Limited_With (U.Entity) then
1269 Pkg_Ent := First_Entity (Limited_View (U.Entity));
1270 else
1271 Pkg_Ent := First_Entity (U.Entity);
1272 end if;
1274 while Present (Pkg_Ent) loop
1275 if Ename = Chars (Pkg_Ent) then
1276 RE_Table (E) := Pkg_Ent;
1277 Check_RPC;
1278 goto Found;
1279 end if;
1281 Next_Entity (Pkg_Ent);
1282 end loop;
1284 -- If we did not find the entity in the package entity chain,
1285 -- then check if the package entity itself matches. Note that
1286 -- we do this check after searching the entity chain, since
1287 -- the rule is that in case of ambiguity, we prefer the entity
1288 -- defined within the package, rather than the package itself.
1290 if Ename = Chars (U.Entity) then
1291 RE_Table (E) := U.Entity;
1292 end if;
1294 -- If we didn't find the entity we want, something is wrong.
1295 -- We just leave RE_Table (E) set to Empty and the appropriate
1296 -- action will be taken by Check_CRT when we exit.
1298 end if;
1299 end if;
1301 <<Found>>
1302 Maybe_Add_With (U);
1304 Front_End_Inlining := Save_Front_End_Inlining;
1305 return Check_CRT (E, RE_Table (E));
1306 end RTE;
1308 -------------------
1309 -- RTE_Available --
1310 -------------------
1312 function RTE_Available (E : RE_Id) return Boolean is
1313 Dummy : Entity_Id;
1314 pragma Warnings (Off, Dummy);
1316 Result : Boolean;
1318 Save_RTE_Available_Call : constant Boolean := RTE_Available_Call;
1319 Save_RTE_Is_Available : constant Boolean := RTE_Is_Available;
1320 -- These are saved recursively because the call to load a unit
1321 -- caused by an upper level call may perform a recursive call
1322 -- to this routine during analysis of the corresponding unit.
1324 begin
1325 RTE_Available_Call := True;
1326 RTE_Is_Available := True;
1327 Dummy := RTE (E);
1328 Result := RTE_Is_Available;
1329 RTE_Available_Call := Save_RTE_Available_Call;
1330 RTE_Is_Available := Save_RTE_Is_Available;
1331 return Result;
1333 exception
1334 when RE_Not_Available =>
1335 RTE_Available_Call := Save_RTE_Available_Call;
1336 RTE_Is_Available := Save_RTE_Is_Available;
1337 return False;
1338 end RTE_Available;
1340 --------------------------
1341 -- RTE_Record_Component --
1342 --------------------------
1344 function RTE_Record_Component (E : RE_Id) return Entity_Id is
1345 U_Id : constant RTU_Id := RE_Unit_Table (E);
1346 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
1347 E1 : Entity_Id;
1348 Ename : Name_Id;
1349 Found_E : Entity_Id;
1350 Lib_Unit : Node_Id;
1351 Pkg_Ent : Entity_Id;
1353 -- The following flag is used to disable front-end inlining when
1354 -- RTE_Record_Component is invoked. This prevents the analysis of other
1355 -- runtime bodies when a particular spec is loaded through Rtsfind. This
1356 -- is both efficient, and it prevents spurious visibility conflicts
1357 -- between use-visible user entities, and entities in run-time packages.
1359 Save_Front_End_Inlining : Boolean;
1361 begin
1362 -- Note: Contrary to subprogram RTE, there is no need to do any special
1363 -- management with package system.ads because it has no record type
1364 -- declarations.
1366 Save_Front_End_Inlining := Front_End_Inlining;
1367 Front_End_Inlining := False;
1369 -- Load unit if unit not previously loaded
1371 if not Present (U.Entity) then
1372 Load_RTU (U_Id, Id => E);
1373 end if;
1375 Lib_Unit := Unit (Cunit (U.Unum));
1377 pragma Assert (Nkind (Lib_Unit) = N_Package_Declaration);
1378 Ename := RE_Chars (E);
1380 -- Search the entity in the components of record type declarations
1381 -- found in the package entity chain.
1383 Found_E := Empty;
1384 Pkg_Ent := First_Entity (U.Entity);
1385 Search : while Present (Pkg_Ent) loop
1386 if Is_Record_Type (Pkg_Ent) then
1387 E1 := First_Entity (Pkg_Ent);
1388 while Present (E1) loop
1389 if Ename = Chars (E1) then
1390 pragma Assert (not Present (Found_E));
1391 Found_E := E1;
1392 end if;
1394 Next_Entity (E1);
1395 end loop;
1396 end if;
1398 Next_Entity (Pkg_Ent);
1399 end loop Search;
1401 -- If we didn't find the entity we want, something is wrong. The
1402 -- appropriate action will be taken by Check_CRT when we exit.
1404 Maybe_Add_With (U);
1406 Front_End_Inlining := Save_Front_End_Inlining;
1407 return Check_CRT (E, Found_E);
1408 end RTE_Record_Component;
1410 ------------------------------------
1411 -- RTE_Record_Component_Available --
1412 ------------------------------------
1414 function RTE_Record_Component_Available (E : RE_Id) return Boolean is
1415 Dummy : Entity_Id;
1416 pragma Warnings (Off, Dummy);
1418 Result : Boolean;
1420 Save_RTE_Available_Call : constant Boolean := RTE_Available_Call;
1421 Save_RTE_Is_Available : constant Boolean := RTE_Is_Available;
1422 -- These are saved recursively because the call to load a unit
1423 -- caused by an upper level call may perform a recursive call
1424 -- to this routine during analysis of the corresponding unit.
1426 begin
1427 RTE_Available_Call := True;
1428 RTE_Is_Available := True;
1429 Dummy := RTE_Record_Component (E);
1430 Result := RTE_Is_Available;
1431 RTE_Available_Call := Save_RTE_Available_Call;
1432 RTE_Is_Available := Save_RTE_Is_Available;
1433 return Result;
1435 exception
1436 when RE_Not_Available =>
1437 RTE_Available_Call := Save_RTE_Available_Call;
1438 RTE_Is_Available := Save_RTE_Is_Available;
1439 return False;
1440 end RTE_Record_Component_Available;
1442 -------------------
1443 -- RTE_Error_Msg --
1444 -------------------
1446 procedure RTE_Error_Msg (Msg : String) is
1447 begin
1448 if RTE_Available_Call then
1449 RTE_Is_Available := False;
1450 else
1451 Error_Msg_N (Msg, Current_Error_Node);
1453 -- Bump count of violations if we are in configurable run-time
1454 -- mode and this is not a continuation message.
1456 if Configurable_Run_Time_Mode and then Msg (Msg'First) /= '\' then
1457 Configurable_Run_Time_Violations :=
1458 Configurable_Run_Time_Violations + 1;
1459 end if;
1460 end if;
1461 end RTE_Error_Msg;
1463 ----------------
1464 -- RTU_Entity --
1465 ----------------
1467 function RTU_Entity (U : RTU_Id) return Entity_Id is
1468 begin
1469 return RT_Unit_Table (U).Entity;
1470 end RTU_Entity;
1472 ----------------
1473 -- RTU_Loaded --
1474 ----------------
1476 function RTU_Loaded (U : RTU_Id) return Boolean is
1477 begin
1478 return Present (RT_Unit_Table (U).Entity);
1479 end RTU_Loaded;
1481 --------------------
1482 -- Set_RTU_Loaded --
1483 --------------------
1485 procedure Set_RTU_Loaded (N : Node_Id) is
1486 Loc : constant Source_Ptr := Sloc (N);
1487 Unum : constant Unit_Number_Type := Get_Source_Unit (Loc);
1488 Uname : constant Unit_Name_Type := Unit_Name (Unum);
1489 E : constant Entity_Id :=
1490 Defining_Entity (Unit (Cunit (Unum)));
1491 begin
1492 pragma Assert (Is_Predefined_File_Name (Unit_File_Name (Unum)));
1494 -- Loop through entries in RTU table looking for matching entry
1496 for U_Id in RTU_Id'Range loop
1498 -- Here we have a match
1500 if Get_Unit_Name (U_Id) = Uname then
1501 declare
1502 U : RT_Unit_Table_Record renames RT_Unit_Table (U_Id);
1503 -- The RT_Unit_Table entry that may need updating
1505 begin
1506 -- If entry is not set, set it now, and indicate that it was
1507 -- loaded through an explicit context clause.
1509 if No (U.Entity) then
1510 U := (Entity => E,
1511 Uname => Get_Unit_Name (U_Id),
1512 Unum => Unum,
1513 First_Implicit_With => Empty);
1514 end if;
1516 return;
1517 end;
1518 end if;
1519 end loop;
1520 end Set_RTU_Loaded;
1522 end Rtsfind;