1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree
; use Atree
;
28 with Casing
; use Casing
;
29 with Csets
; use Csets
;
30 with Debug
; use Debug
;
31 with Einfo
; use Einfo
;
32 with Elists
; use Elists
;
33 with Errout
; use Errout
;
34 with Fname
; use Fname
;
35 with Fname
.UF
; use Fname
.UF
;
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
;
43 with Restrict
; use Restrict
;
45 with Sem_Ch7
; use Sem_Ch7
;
46 with Sem_Util
; use Sem_Util
;
47 with Sinfo
; use Sinfo
;
48 with Stand
; use Stand
;
49 with Snames
; use Snames
;
50 with Tbuild
; use Tbuild
;
51 with Uname
; use Uname
;
53 package body Rtsfind
is
55 RTE_Available_Call
: Boolean := False;
56 -- Set True during call to RTE from RTE_Available. Tells RTE to set
57 -- RTE_Is_Available to False rather than generating an error message.
59 RTE_Is_Available
: Boolean;
60 -- Set True by RTE_Available on entry. When RTE_Available_Call is set
61 -- True, set False if RTE would otherwise generate an error message.
67 -- The unit table has one entry for each unit included in the definition
68 -- of the type RTU_Id in the spec. The table entries are initialized in
69 -- Initialize to set the Entity field to Empty, indicating that the
70 -- corresponding unit has not yet been loaded. The fields are set when
71 -- a unit is loaded to contain the defining entity for the unit, the
72 -- unit name, and the unit number.
74 -- Note that a unit can be loaded either by a call to find an entity
75 -- within the unit (e.g. RTE), or by an explicit with of the unit. In
76 -- the latter case it is critical to make a call to Set_RTU_Loaded to
77 -- ensure that the entry in this table reflects the load.
79 type RT_Unit_Table_Record
is record
81 Uname
: Unit_Name_Type
;
82 Unum
: Unit_Number_Type
;
86 RT_Unit_Table
: array (RTU_Id
) of RT_Unit_Table_Record
;
88 --------------------------
89 -- Runtime Entity Table --
90 --------------------------
92 -- There is one entry in the runtime entity table for each entity that is
93 -- included in the definition of the RE_Id type in the spec. The entries
94 -- are set by Initialize_Rtsfind to contain Empty, indicating that the
95 -- entity has not yet been located. Once the entity is located for the
96 -- first time, its ID is stored in this array, so that subsequent calls
97 -- for the same entity can be satisfied immediately.
99 RE_Table
: array (RE_Id
) of Entity_Id
;
101 --------------------------
102 -- Generation of WITH's --
103 --------------------------
105 -- When a unit is implicitly loaded as a result of a call to RTE, it
106 -- is necessary to create an implicit WITH to ensure that the object
107 -- is correctly loaded by the binder. Such WITH statements are only
108 -- required when the request is from the extended main unit (if a
109 -- client needs a WITH, that will be taken care of when the client
112 -- We always attach the WITH to the main unit. This is not perfectly
113 -- accurate in terms of elaboration requirements, but it is close
114 -- enough, since the units that are accessed using rtsfind do not
115 -- have delicate elaboration requirements.
117 -- The flag Withed in the unit table record is initially set to False.
118 -- It is set True if a WITH has been generated for the main unit for
119 -- the corresponding unit.
121 -----------------------
122 -- Local Subprograms --
123 -----------------------
125 procedure Entity_Not_Defined
(Id
: RE_Id
);
126 -- Outputs error messages for an entity that is not defined in the
127 -- run-time library (the form of the error message is tailored for
128 -- no run time/configurable run time mode as required).
130 procedure Load_Fail
(S
: String; U_Id
: RTU_Id
; Id
: RE_Id
);
131 -- Internal procedure called if we can't sucessfully locate or
132 -- process a run-time unit. The parameters give information about
133 -- the error message to be given. S is a reason for failing to
134 -- compile the file and U_Id is the unit id. RE_Id is the RE_Id
135 -- originally passed to RTE. The message in S is one of the
139 -- "had parser errors"
140 -- "had semantic errors"
142 -- The "not found" case is treated specially in that it is considered
143 -- a normal situation in configurable run-time mode (and the message in
144 -- this case is suppressed unless we are operating in All_Errors_Mode).
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
148 -- enumeration value in RTU_Id.
152 Id
: RE_Id
:= RE_Null
;
153 Use_Setting
: Boolean := False);
154 -- Load the unit whose Id is given if not already loaded. The unit is
155 -- loaded, analyzed, and added to the WITH list, and the entry in
156 -- RT_Unit_Table is updated to reflect the load. Use_Setting is used
157 -- to indicate the initial setting for the Is_Potentially_Use_Visible
158 -- flag of the entity for the loaded unit (if it is indeed loaded).
159 -- A value of False means nothing special need be done. A value of
160 -- True indicates that this flag must be set to True. It is needed
161 -- only in the Text_IO_Kludge procedure, which may materialize an
162 -- entity of Text_IO (or [Wide_]Wide_Text_IO) that was previously unknown.
163 -- Id is the RE_Id value of the entity which was originally requested.
164 -- Id is used only for error message detail, and if it is RE_Null, then
165 -- the attempt to output the entity name is ignored.
167 procedure Output_Entity_Name
(Id
: RE_Id
; Msg
: String);
168 -- Output continuation error message giving qualified name of entity
169 -- corresponding to Id, appending the string given by Msg. This call
170 -- is only effective in All_Errors mode.
172 function RE_Chars
(E
: RE_Id
) return Name_Id
;
173 -- Given a RE_Id value returns the Chars of the corresponding entity.
175 procedure RTE_Error_Msg
(Msg
: String);
176 -- Generates a message by calling Error_Msg_N specifying Current_Error_Node
177 -- as the node location using the given Msg text. Special processing in the
178 -- case where RTE_Available_Call is set. In this case, no message is output
179 -- and instead RTE_Is_Available is set to False. Note that this can only be
180 -- used if you are sure that the message comes directly or indirectly from
181 -- a call to the RTE function.
183 ------------------------
184 -- Entity_Not_Defined --
185 ------------------------
187 procedure Entity_Not_Defined
(Id
: RE_Id
) is
189 if No_Run_Time_Mode
then
191 -- If the error occurs when compiling the body of a predefined
192 -- unit for inlining purposes, the body must be illegal in this
193 -- mode, and there is no point in continuing.
195 if Is_Predefined_File_Name
196 (Unit_File_Name
(Get_Source_Unit
(Sloc
(Current_Error_Node
))))
199 ("construct not allowed in no run time mode!",
201 raise Unrecoverable_Error
;
204 RTE_Error_Msg
("|construct not allowed in no run time mode");
207 elsif Configurable_Run_Time_Mode
then
208 RTE_Error_Msg
("|construct not allowed in this configuration>");
210 RTE_Error_Msg
("run-time configuration error");
213 Output_Entity_Name
(Id
, "not defined");
214 end Entity_Not_Defined
;
220 function Get_Unit_Name
(U_Id
: RTU_Id
) return Unit_Name_Type
is
221 Uname_Chars
: constant String := RTU_Id
'Image (U_Id
);
224 Name_Len
:= Uname_Chars
'Length;
225 Name_Buffer
(1 .. Name_Len
) := Uname_Chars
;
226 Set_Casing
(All_Lower_Case
);
228 if U_Id
in Ada_Child
then
229 Name_Buffer
(4) := '.';
231 if U_Id
in Ada_Calendar_Child
then
232 Name_Buffer
(13) := '.';
234 elsif U_Id
in Ada_Finalization_Child
then
235 Name_Buffer
(17) := '.';
237 elsif U_Id
in Ada_Interrupts_Child
then
238 Name_Buffer
(15) := '.';
240 elsif U_Id
in Ada_Real_Time_Child
then
241 Name_Buffer
(14) := '.';
243 elsif U_Id
in Ada_Streams_Child
then
244 Name_Buffer
(12) := '.';
246 elsif U_Id
in Ada_Text_IO_Child
then
247 Name_Buffer
(12) := '.';
249 elsif U_Id
in Ada_Wide_Text_IO_Child
then
250 Name_Buffer
(17) := '.';
252 elsif U_Id
in Ada_Wide_Wide_Text_IO_Child
then
253 Name_Buffer
(22) := '.';
256 elsif U_Id
in Interfaces_Child
then
257 Name_Buffer
(11) := '.';
259 elsif U_Id
in System_Child
then
260 Name_Buffer
(7) := '.';
262 if U_Id
in System_Tasking_Child
then
263 Name_Buffer
(15) := '.';
266 if U_Id
in System_Tasking_Restricted_Child
then
267 Name_Buffer
(26) := '.';
270 if U_Id
in System_Tasking_Protected_Objects_Child
then
271 Name_Buffer
(33) := '.';
274 if U_Id
in System_Tasking_Async_Delays_Child
then
275 Name_Buffer
(28) := '.';
279 -- Add %s at end for spec
281 Name_Buffer
(Name_Len
+ 1) := '%';
282 Name_Buffer
(Name_Len
+ 2) := 's';
283 Name_Len
:= Name_Len
+ 2;
292 procedure Initialize
is
294 -- Initialize the unit table
297 RT_Unit_Table
(J
).Entity
:= Empty
;
301 RE_Table
(J
) := Empty
;
304 RTE_Is_Available
:= False;
311 function Is_RTE
(Ent
: Entity_Id
; E
: RE_Id
) return Boolean is
312 E_Unit_Name
: Unit_Name_Type
;
313 Ent_Unit_Name
: Unit_Name_Type
;
323 -- If E has already a corresponding entity, check it directly,
324 -- going to full views if they exist to deal with the incomplete
325 -- and private type cases properly.
327 elsif Present
(RE_Table
(E
)) then
330 if Is_Type
(E1
) and then Present
(Full_View
(E1
)) then
331 E1
:= Full_View
(E1
);
336 if Is_Type
(E2
) and then Present
(Full_View
(E2
)) then
337 E2
:= Full_View
(E2
);
343 -- If the unit containing E is not loaded, we already know that
344 -- the entity we have cannot have come from this unit.
346 E_Unit_Name
:= Get_Unit_Name
(RE_Unit_Table
(E
));
348 if not Is_Loaded
(E_Unit_Name
) then
352 -- Here the unit containing the entity is loaded. We have not made
353 -- an explicit call to RTE to get the entity in question, but we may
354 -- have obtained a reference to it indirectly from some other entity
355 -- in the same unit, or some other unit that references it.
357 -- Get the defining unit of the entity
361 if Ekind
(S
) /= E_Package
then
365 Ent_Unit_Name
:= Get_Unit_Name
(Unit_Declaration_Node
(S
));
367 -- If the defining unit of the entity we are testing is not the
368 -- unit containing E, then they cannot possibly match.
370 if Ent_Unit_Name
/= E_Unit_Name
then
374 -- If the units match, then compare the names (remember that no
375 -- overloading is permitted in entities fetched using Rtsfind).
377 if RE_Chars
(E
) = Chars
(Ent
) then
380 -- If front-end inlining is enabled, we may be within a body that
381 -- contains inlined functions, which has not been retrieved through
382 -- rtsfind, and therefore is not yet recorded in the RT_Unit_Table.
383 -- Add the unit information now, it must be fully available.
386 U
: RT_Unit_Table_Record
387 renames RT_Unit_Table
(RE_Unit_Table
(E
));
389 if No
(U
.Entity
) then
391 U
.Uname
:= E_Unit_Name
;
392 U
.Unum
:= Get_Source_Unit
(S
);
406 function Is_RTU
(Ent
: Entity_Id
; U
: RTU_Id
) return Boolean is
407 E
: constant Entity_Id
:= RT_Unit_Table
(U
).Entity
;
409 return Present
(E
) and then E
= Ent
;
412 ----------------------------
413 -- Is_Text_IO_Kludge_Unit --
414 ----------------------------
416 function Is_Text_IO_Kludge_Unit
(Nam
: Node_Id
) return Boolean is
421 if Nkind
(Nam
) /= N_Expanded_Name
then
426 Sel
:= Selector_Name
(Nam
);
428 if Nkind
(Sel
) /= N_Expanded_Name
429 or else Nkind
(Prf
) /= N_Identifier
430 or else Chars
(Prf
) /= Name_Ada
436 Sel
:= Selector_Name
(Sel
);
439 Nkind
(Prf
) = N_Identifier
441 (Chars
(Prf
) = Name_Text_IO
443 Chars
(Prf
) = Name_Wide_Text_IO
445 Chars
(Prf
) = Name_Wide_Wide_Text_IO
)
447 Nkind
(Sel
) = N_Identifier
449 Chars
(Sel
) in Text_IO_Package_Name
;
450 end Is_Text_IO_Kludge_Unit
;
456 procedure Load_Fail
(S
: String; U_Id
: RTU_Id
; Id
: RE_Id
) is
457 M
: String (1 .. 100);
461 -- Output header message
463 if Configurable_Run_Time_Mode
then
464 RTE_Error_Msg
("construct not allowed in configurable run-time mode");
466 RTE_Error_Msg
("run-time library configuration error");
469 -- Output file name and reason string
472 or else not Configurable_Run_Time_Mode
473 or else All_Errors_Mode
475 M
(1 .. 6) := "\file ";
479 (Get_File_Name
(RT_Unit_Table
(U_Id
).Uname
, Subunit
=> False));
480 M
(P
+ 1 .. P
+ Name_Len
) := Name_Buffer
(1 .. Name_Len
);
486 M
(P
+ 1 .. P
+ S
'Length) := S
;
489 RTE_Error_Msg
(M
(1 .. P
));
491 -- Output entity name
493 Output_Entity_Name
(Id
, "not available");
496 raise RE_Not_Available
;
505 Id
: RE_Id
:= RE_Null
;
506 Use_Setting
: Boolean := False)
508 U
: RT_Unit_Table_Record
renames RT_Unit_Table
(U_Id
);
509 Priv_Par
: constant Elist_Id
:= New_Elmt_List
;
512 procedure Save_Private_Visibility
;
513 -- If the current unit is the body of child unit or the spec of a
514 -- private child unit, the private declarations of the parent (s)
515 -- are visible. If the unit to be loaded is another public sibling,
516 -- its compilation will affect the visibility of the common ancestors.
517 -- Indicate those that must be restored.
519 procedure Restore_Private_Visibility
;
520 -- Restore the visibility of ancestors after compiling RTU.
522 --------------------------------
523 -- Restore_Private_Visibility --
524 --------------------------------
526 procedure Restore_Private_Visibility
is
530 E_Par
:= First_Elmt
(Priv_Par
);
532 while Present
(E_Par
) loop
533 if not In_Private_Part
(Node
(E_Par
)) then
534 Install_Private_Declarations
(Node
(E_Par
));
539 end Restore_Private_Visibility
;
541 -----------------------------
542 -- Save_Private_Visibility --
543 -----------------------------
545 procedure Save_Private_Visibility
is
549 Par
:= Scope
(Current_Scope
);
552 and then Par
/= Standard_Standard
554 if Ekind
(Par
) = E_Package
555 and then Is_Compilation_Unit
(Par
)
556 and then In_Private_Part
(Par
)
558 Append_Elmt
(Par
, Priv_Par
);
563 end Save_Private_Visibility
;
565 -- Start of processing for Load_RTU
568 -- Nothing to do if unit is already loaded
570 if Present
(U
.Entity
) then
574 -- Note if secondary stack is used
576 if U_Id
= System_Secondary_Stack
then
577 Opt
.Sec_Stack_Used
:= True;
580 -- Otherwise we need to load the unit, First build unit name
581 -- from the enumeration literal name in type RTU_Id.
583 U
.Uname
:= Get_Unit_Name
(U_Id
);
588 pragma Warnings
(Off
, Loaded
);
590 Loaded
:= Is_Loaded
(U
.Uname
);
593 -- Now do the load call, note that setting Error_Node to Empty is
594 -- a signal to Load_Unit that we will regard a failure to find the
595 -- file as a fatal error, and that it should not output any kind
596 -- of diagnostics, since we will take care of it here.
600 (Load_Name
=> U
.Uname
,
603 Error_Node
=> Empty
);
605 if U
.Unum
= No_Unit
then
606 Load_Fail
("not found", U_Id
, Id
);
607 elsif Fatal_Error
(U
.Unum
) then
608 Load_Fail
("had parser errors", U_Id
, Id
);
611 -- Make sure that the unit is analyzed
614 Was_Analyzed
: constant Boolean :=
615 Analyzed
(Cunit
(Current_Sem_Unit
));
618 -- Pretend that the current unit is analyzed, in case it is System
619 -- or some such. This allows us to put some declarations, such as
620 -- exceptions and packed arrays of Boolean, into System even though
621 -- expanding them requires System...
623 -- This is a bit odd but works fine. If the RTS unit does not depend
624 -- in any way on the current unit, then it never gets back into the
625 -- current unit's tree, and the change we make to the current unit
626 -- tree is never noticed by anyone (it is undone in a moment). That
627 -- is the normal situation.
629 -- If the RTS Unit *does* depend on the current unit, for instance,
630 -- when you are compiling System, then you had better have finished
631 -- analyzing the part of System that is depended on before you try
632 -- to load the RTS Unit. This means having the System ordered in an
633 -- appropriate manner.
635 Set_Analyzed
(Cunit
(Current_Sem_Unit
), True);
637 if not Analyzed
(Cunit
(U
.Unum
)) then
638 Save_Private_Visibility
;
639 Semantics
(Cunit
(U
.Unum
));
640 Restore_Private_Visibility
;
642 if Fatal_Error
(U
.Unum
) then
643 Load_Fail
("had semantic errors", U_Id
, Id
);
649 Set_Analyzed
(Cunit
(Current_Sem_Unit
), Was_Analyzed
);
652 Lib_Unit
:= Unit
(Cunit
(U
.Unum
));
653 U
.Entity
:= Defining_Entity
(Lib_Unit
);
656 Set_Is_Potentially_Use_Visible
(U
.Entity
, True);
660 -----------------------
661 -- Output_Entity_Name --
662 ------------------------
664 procedure Output_Entity_Name
(Id
: RE_Id
; Msg
: String) is
665 M
: String (1 .. 2048);
667 -- M (1 .. P) is current message to be output
669 RE_Image
: constant String := RE_Id
'Image (Id
);
672 if Id
= RE_Null
or else not All_Errors_Mode
then
676 M
(1 .. 9) := "\entity """;
679 -- Add unit name to message, excluding %s or %b at end
681 Get_Name_String
(Get_Unit_Name
(RE_Unit_Table
(Id
)));
682 Name_Len
:= Name_Len
- 2;
683 Set_Casing
(Mixed_Case
);
684 M
(P
+ 1 .. P
+ Name_Len
) := Name_Buffer
(1 .. Name_Len
);
687 -- Add a qualifying period
692 -- Add entity name and closing quote to message
694 Name_Len
:= RE_Image
'Length - 3;
695 Name_Buffer
(1 .. Name_Len
) := RE_Image
(4 .. RE_Image
'Length);
696 Set_Casing
(Mixed_Case
);
697 M
(P
+ 1 .. P
+ Name_Len
) := Name_Buffer
(1 .. Name_Len
);
706 M
(P
+ 1 .. P
+ Msg
'Length) := Msg
;
709 -- Output message at current error node location
711 RTE_Error_Msg
(M
(1 .. P
));
712 end Output_Entity_Name
;
718 function RE_Chars
(E
: RE_Id
) return Name_Id
is
719 RE_Name_Chars
: constant String := RE_Id
'Image (E
);
722 -- Copy name skipping initial RE_ or RO_XX characters
724 if RE_Name_Chars
(1 .. 2) = "RE" then
725 for J
in 4 .. RE_Name_Chars
'Last loop
726 Name_Buffer
(J
- 3) := Fold_Lower
(RE_Name_Chars
(J
));
729 Name_Len
:= RE_Name_Chars
'Length - 3;
732 for J
in 7 .. RE_Name_Chars
'Last loop
733 Name_Buffer
(J
- 6) := Fold_Lower
(RE_Name_Chars
(J
));
736 Name_Len
:= RE_Name_Chars
'Length - 6;
746 function RTE
(E
: RE_Id
) return Entity_Id
is
747 U_Id
: constant RTU_Id
:= RE_Unit_Table
(E
);
748 U
: RT_Unit_Table_Record
renames RT_Unit_Table
(U_Id
);
754 -- The following flag is used to disable front-end inlining when RTE
755 -- is invoked. This prevents the analysis of other runtime bodies when
756 -- a particular spec is loaded through Rtsfind. This is both efficient,
757 -- and it prevents spurious visibility conflicts between use-visible
758 -- user entities, and entities in run-time packages.
760 -- In configurable run-time mode, subprograms marked Inlined_Always must
761 -- be inlined, so in the case we retain the Front_End_Inlining mode.
763 Save_Front_End_Inlining
: Boolean;
765 function Check_CRT
(Eid
: Entity_Id
) return Entity_Id
;
766 -- Check entity Eid to ensure that configurable run-time restrictions
767 -- are met. May generate an error message and raise RE_Not_Available
768 -- if the entity E does not exist (i.e. Eid is Empty)
771 -- Reject programs that make use of distribution features not supported
772 -- on the current target. On such targets (VMS, Vxworks, others?) we
773 -- only provide a minimal body for System.Rpc that only supplies an
774 -- implementation of partition_id.
776 function Find_Local_Entity
(E
: RE_Id
) return Entity_Id
;
777 -- This function is used when entity E is in this compilation's main
778 -- unit. It gets the value from the already compiled declaration.
780 function Make_Unit_Name
(N
: Node_Id
) return Node_Id
;
781 -- If the unit is a child unit, build fully qualified name for use
788 function Check_CRT
(Eid
: Entity_Id
) return Entity_Id
is
791 Entity_Not_Defined
(E
);
792 raise RE_Not_Available
;
794 -- Entity is available
797 -- If in No_Run_Time mode and entity is not in one of the
798 -- specially permitted units, raise the exception.
801 and then not OK_No_Run_Time_Unit
(U_Id
)
803 Entity_Not_Defined
(E
);
804 raise RE_Not_Available
;
807 -- Otherwise entity is accessible
817 procedure Check_RPC
is
819 -- Bypass this check if debug flag -gnatdR set
821 if Debug_Flag_RR
then
825 -- Otherwise we need the check if we are going after one of
826 -- the critical entities in System.RPC in stubs mode.
828 -- ??? Should we do this for other s-parint/s-polint entities
831 if (Distribution_Stub_Mode
= Generate_Receiver_Stub_Body
833 Distribution_Stub_Mode
= Generate_Caller_Stub_Body
)
834 and then (E
= RE_Do_Rpc
838 E
= RE_Params_Stream_Type
840 E
= RE_Request_Access
)
843 DSA_Implementation
: constant Entity_Id
:=
844 RTE
(RE_DSA_Implementation
);
846 if Chars
(Entity
(Expression
847 (Parent
(DSA_Implementation
)))) = Name_No_DSA
850 Write_Str
("distribution feature not supported");
852 raise Unrecoverable_Error
;
858 ------------------------
859 -- Find_System_Entity --
860 ------------------------
862 function Find_Local_Entity
(E
: RE_Id
) return Entity_Id
is
863 RE_Str
: String renames RE_Id
'Image (E
);
866 Save_Nam
: constant String := Name_Buffer
(1 .. Name_Len
);
867 -- Save name buffer and length over call
870 Name_Len
:= Natural'Max (0, RE_Str
'Length - 3);
871 Name_Buffer
(1 .. Name_Len
) :=
872 RE_Str
(RE_Str
'First + 3 .. RE_Str
'Last);
874 Ent
:= Entity_Id
(Get_Name_Table_Info
(Name_Find
));
876 Name_Len
:= Save_Nam
'Length;
877 Name_Buffer
(1 .. Name_Len
) := Save_Nam
;
880 end Find_Local_Entity
;
886 function Make_Unit_Name
(N
: Node_Id
) return Node_Id
is
891 Nam
:= New_Reference_To
(U
.Entity
, Standard_Location
);
892 Scop
:= Scope
(U
.Entity
);
894 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
895 while Scop
/= Standard_Standard
loop
897 Make_Expanded_Name
(Standard_Location
,
898 Chars
=> Chars
(U
.Entity
),
899 Prefix
=> New_Reference_To
(Scop
, Standard_Location
),
900 Selector_Name
=> Nam
);
901 Set_Entity
(Nam
, U
.Entity
);
903 Scop
:= Scope
(Scop
);
910 -- Start of processing for RTE
913 -- Doing a rtsfind in system.ads is special, as we cannot do this
914 -- when compiling System itself. So if we are compiling system then
915 -- we should already have acquired and processed the declaration
916 -- of the entity. The test is to see if this compilation's main unit
917 -- is System. If so, return the value from the already compiled
918 -- declaration and otherwise do a regular find.
920 -- Not pleasant, but these kinds of annoying recursion when
921 -- writing an Ada compiler in Ada have to be broken somewhere!
923 if Present
(Main_Unit_Entity
)
924 and then Chars
(Main_Unit_Entity
) = Name_System
925 and then Analyzed
(Main_Unit_Entity
)
926 and then not Is_Child_Unit
(Main_Unit_Entity
)
928 return Check_CRT
(Find_Local_Entity
(E
));
931 Save_Front_End_Inlining
:= Front_End_Inlining
;
932 Front_End_Inlining
:= Configurable_Run_Time_Mode
;
934 -- Load unit if unit not previously loaded
936 if No
(RE_Table
(E
)) then
937 Load_RTU
(U_Id
, Id
=> E
);
938 Lib_Unit
:= Unit
(Cunit
(U
.Unum
));
940 -- In the subprogram case, we are all done, the entity we want
941 -- is the entity for the subprogram itself. Note that we do not
942 -- bother to check that it is the entity that was requested.
943 -- the only way that could fail to be the case is if runtime is
944 -- hopelessly misconfigured, and it isn't worth testing for this.
946 if Nkind
(Lib_Unit
) = N_Subprogram_Declaration
then
947 RE_Table
(E
) := U
.Entity
;
949 -- Otherwise we must have the package case. First check package
950 -- entity itself (e.g. RTE_Name for System.Interrupts.Name)
953 pragma Assert
(Nkind
(Lib_Unit
) = N_Package_Declaration
);
954 Ename
:= RE_Chars
(E
);
956 -- First we search the package entity chain
958 Pkg_Ent
:= First_Entity
(U
.Entity
);
959 while Present
(Pkg_Ent
) loop
960 if Ename
= Chars
(Pkg_Ent
) then
961 RE_Table
(E
) := Pkg_Ent
;
966 Next_Entity
(Pkg_Ent
);
969 -- If we did not find the entity in the package entity chain,
970 -- then check if the package entity itself matches. Note that
971 -- we do this check after searching the entity chain, since
972 -- the rule is that in case of ambiguity, we prefer the entity
973 -- defined within the package, rather than the package itself.
975 if Ename
= Chars
(U
.Entity
) then
976 RE_Table
(E
) := U
.Entity
;
979 -- If we didn't find the entity we want, something is wrong.
980 -- We just leave RE_Table (E) set to Empty and the appropriate
981 -- action will be taken by Check_CRT when we exit.
986 -- See if we have to generate a WITH for this entity. We generate
987 -- a WITH if the current unit is part of the extended main code
988 -- unit, and if we have not already added the with. The WITH is
989 -- added to the appropriate unit (the current one). We do not need
990 -- to generate a WITH for an ????
995 In_Extended_Main_Code_Unit
(Cunit_Entity
(Current_Sem_Unit
))
996 and then not RTE_Available_Call
1005 Lib_Unit
:= Unit
(Cunit
(U
.Unum
));
1007 Make_With_Clause
(Standard_Location
,
1010 (Defining_Unit_Name
(Specification
(Lib_Unit
))));
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);
1016 Mark_Rewrite_Insertion
(Withn
);
1017 Append
(Withn
, Context_Items
(Cunit
(Current_Sem_Unit
)));
1018 Check_Restriction_No_Dependence
(Name
(Withn
), Current_Error_Node
);
1022 Front_End_Inlining
:= Save_Front_End_Inlining
;
1023 return Check_CRT
(RE_Table
(E
));
1030 function RTE_Available
(E
: RE_Id
) return Boolean is
1032 pragma Warnings
(Off
, Dummy
);
1036 Save_RTE_Available_Call
: constant Boolean := RTE_Available_Call
;
1037 Save_RTE_Is_Available
: constant Boolean := RTE_Is_Available
;
1038 -- These are saved recursively because the call to load a unit
1039 -- caused by an upper level call may perform a recursive call
1040 -- to this routine during analysis of the corresponding unit.
1043 RTE_Available_Call
:= True;
1044 RTE_Is_Available
:= True;
1046 Result
:= RTE_Is_Available
;
1047 RTE_Available_Call
:= Save_RTE_Available_Call
;
1048 RTE_Is_Available
:= Save_RTE_Is_Available
;
1052 when RE_Not_Available
=>
1053 RTE_Available_Call
:= Save_RTE_Available_Call
;
1054 RTE_Is_Available
:= Save_RTE_Is_Available
;
1062 procedure RTE_Error_Msg
(Msg
: String) is
1064 if RTE_Available_Call
then
1065 RTE_Is_Available
:= False;
1067 Error_Msg_N
(Msg
, Current_Error_Node
);
1069 -- Bump count of violations if we are in configurable run-time
1070 -- mode and this is not a continuation message.
1072 if Configurable_Run_Time_Mode
and then Msg
(1) /= '\' then
1073 Configurable_Run_Time_Violations
:=
1074 Configurable_Run_Time_Violations
+ 1;
1083 function RTU_Loaded
(U
: RTU_Id
) return Boolean is
1085 return Present
(RT_Unit_Table
(U
).Entity
);
1088 --------------------
1089 -- Set_RTU_Loaded --
1090 --------------------
1092 procedure Set_RTU_Loaded
(N
: Node_Id
) is
1093 Loc
: constant Source_Ptr
:= Sloc
(N
);
1094 Unum
: constant Unit_Number_Type
:= Get_Source_Unit
(Loc
);
1095 Uname
: constant Unit_Name_Type
:= Unit_Name
(Unum
);
1096 E
: constant Entity_Id
:=
1097 Defining_Entity
(Unit
(Cunit
(Unum
)));
1099 pragma Assert
(Is_Predefined_File_Name
(Unit_File_Name
(Unum
)));
1101 -- Loop through entries in RTU table looking for matching entry
1103 for U_Id
in RTU_Id
'Range loop
1105 -- Here we have a match
1107 if Get_Unit_Name
(U_Id
) = Uname
then
1109 U
: RT_Unit_Table_Record
renames RT_Unit_Table
(U_Id
);
1110 -- The RT_Unit_Table entry that may need updating
1113 -- If entry is not set, set it now
1115 if not Present
(U
.Entity
) then
1117 U
.Uname
:= Get_Unit_Name
(U_Id
);
1128 --------------------
1129 -- Text_IO_Kludge --
1130 --------------------
1132 procedure Text_IO_Kludge
(Nam
: Node_Id
) is
1135 type Name_Map_Type
is array (Text_IO_Package_Name
) of RTU_Id
;
1137 Name_Map
: constant Name_Map_Type
:= Name_Map_Type
'(
1138 Name_Decimal_IO => Ada_Text_IO_Decimal_IO,
1139 Name_Enumeration_IO => Ada_Text_IO_Enumeration_IO,
1140 Name_Fixed_IO => Ada_Text_IO_Fixed_IO,
1141 Name_Float_IO => Ada_Text_IO_Float_IO,
1142 Name_Integer_IO => Ada_Text_IO_Integer_IO,
1143 Name_Modular_IO => Ada_Text_IO_Modular_IO);
1145 Wide_Name_Map : constant Name_Map_Type := Name_Map_Type'(
1146 Name_Decimal_IO
=> Ada_Wide_Text_IO_Decimal_IO
,
1147 Name_Enumeration_IO
=> Ada_Wide_Text_IO_Enumeration_IO
,
1148 Name_Fixed_IO
=> Ada_Wide_Text_IO_Fixed_IO
,
1149 Name_Float_IO
=> Ada_Wide_Text_IO_Float_IO
,
1150 Name_Integer_IO
=> Ada_Wide_Text_IO_Integer_IO
,
1151 Name_Modular_IO
=> Ada_Wide_Text_IO_Modular_IO
);
1153 Wide_Wide_Name_Map
: constant Name_Map_Type
:= Name_Map_Type
'(
1154 Name_Decimal_IO => Ada_Wide_Wide_Text_IO_Decimal_IO,
1155 Name_Enumeration_IO => Ada_Wide_Wide_Text_IO_Enumeration_IO,
1156 Name_Fixed_IO => Ada_Wide_Wide_Text_IO_Fixed_IO,
1157 Name_Float_IO => Ada_Wide_Wide_Text_IO_Float_IO,
1158 Name_Integer_IO => Ada_Wide_Wide_Text_IO_Integer_IO,
1159 Name_Modular_IO => Ada_Wide_Wide_Text_IO_Modular_IO);
1162 -- Nothing to do if name is not identifier or a selected component
1163 -- whose selector_name is not an identifier.
1165 if Nkind (Nam) = N_Identifier then
1166 Chrs := Chars (Nam);
1168 elsif Nkind (Nam) = N_Selected_Component
1169 and then Nkind (Selector_Name (Nam)) = N_Identifier
1171 Chrs := Chars (Selector_Name (Nam));
1177 -- Nothing to do if name is not one of the Text_IO subpackages
1178 -- Otherwise look through loaded units, and if we find Text_IO
1179 -- or [Wide_]Wide_Text_IO already loaded, then load the proper child.
1181 if Chrs in Text_IO_Package_Name then
1182 for U in Main_Unit .. Last_Unit loop
1183 Get_Name_String (Unit_File_Name (U));
1185 if Name_Len = 12 then
1187 -- Here is where we do the loads if we find one of the units
1188 -- Ada.Text_IO or Ada.[Wide_]Wide_Text_IO. An interesting
1189 -- detail is that these units may already be used (i.e. their
1190 -- In_Use flags may be set). Normally when the In_Use flag is
1191 -- set, the Is_Potentially_Use_Visible flag of all entities in
1192 -- the package is set, but the new entity we are mysteriously
1193 -- adding was not there to have its flag set at the time. So
1194 -- that's why we pass the extra parameter to RTU_Find, to make
1195 -- sure the flag does get set now. Given that those generic
1196 -- packages are in fact child units, we must indicate that
1197 -- they are visible.
1199 if Name_Buffer (1 .. 12) = "a-textio.ads" then
1202 Use_Setting => In_Use (Cunit_Entity (U)));
1203 Set_Is_Visible_Child_Unit
1204 (RT_Unit_Table (Name_Map (Chrs)).Entity);
1206 elsif Name_Buffer (1 .. 12) = "a-witeio.ads" then
1208 (Wide_Name_Map (Chrs),
1209 Use_Setting => In_Use (Cunit_Entity (U)));
1210 Set_Is_Visible_Child_Unit
1211 (RT_Unit_Table (Wide_Name_Map (Chrs)).Entity);
1213 elsif Name_Buffer (1 .. 12) = "a-ztexio.ads" then
1215 (Wide_Wide_Name_Map (Chrs),
1216 Use_Setting => In_Use (Cunit_Entity (U)));
1217 Set_Is_Visible_Child_Unit
1218 (RT_Unit_Table (Wide_Wide_Name_Map (Chrs)).Entity);