1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2017, 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 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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Debug
; use Debug
;
28 with Einfo
; use Einfo
;
29 with Errout
; use Errout
;
30 with Fname
; use Fname
;
31 with Fname
.UF
; use Fname
.UF
;
32 with Nlists
; use Nlists
;
33 with Nmake
; use Nmake
;
35 with Osint
; use Osint
;
36 with Osint
.C
; use Osint
.C
;
37 with Output
; use Output
;
39 with Restrict
; use Restrict
;
41 with Sinfo
; use Sinfo
;
42 with Sinput
; use Sinput
;
43 with Sinput
.L
; use Sinput
.L
;
44 with Stand
; use Stand
;
45 with Tbuild
; use Tbuild
;
46 with Uname
; use Uname
;
48 package body Lib
.Load
is
50 -----------------------
51 -- Local Subprograms --
52 -----------------------
54 function From_Limited_With_Chain
return Boolean;
55 -- Check whether a possible circular dependence includes units that
56 -- have been loaded through limited_with clauses, in which case there
57 -- is no real circularity.
59 function Spec_Is_Irrelevant
60 (Spec_Unit
: Unit_Number_Type
;
61 Body_Unit
: Unit_Number_Type
) return Boolean;
62 -- The Spec_Unit and Body_Unit parameters are the unit numbers of the
63 -- spec file that corresponds to the main unit which is a body. This
64 -- function determines if the spec file is irrelevant and will be
65 -- overridden by the body as described in RM 10.1.4(4). See description
66 -- in "Special Handling of Subprogram Bodies" for further details.
68 procedure Write_Dependency_Chain
;
69 -- This procedure is used to generate error message info lines that
70 -- trace the current dependency chain when a load error occurs.
72 ------------------------------
73 -- Change_Main_Unit_To_Spec --
74 ------------------------------
76 procedure Change_Main_Unit_To_Spec
is
77 U
: Unit_Record
renames Units
.Table
(Main_Unit
);
79 X
: Source_File_Index
;
82 -- Get name of unit body
84 Get_Name_String
(U
.Unit_File_Name
);
86 -- Note: for the following we should really generalize and consult the
87 -- file name pattern data, but for now we just deal with the common
88 -- naming cases, which is probably good enough in practice ???
90 -- Change .adb to .ads
93 and then Name_Buffer
(Name_Len
- 3 .. Name_Len
) = ".adb"
95 Name_Buffer
(Name_Len
) := 's';
97 -- Change .2.ada to .1.ada (Rational convention)
100 and then Name_Buffer
(Name_Len
- 5 .. Name_Len
) = ".2.ada"
102 Name_Buffer
(Name_Len
- 4) := '1';
104 -- Change .ada to _.ada (DEC convention)
107 and then Name_Buffer
(Name_Len
- 3 .. Name_Len
) = ".ada"
109 Name_Buffer
(Name_Len
- 3 .. Name_Len
+ 1) := "_.ada";
110 Name_Len
:= Name_Len
+ 1;
112 -- No match, don't make the change
118 -- Try loading the spec
121 X
:= Load_Source_File
(N
);
123 -- No change if we did not find the spec
125 if X
= No_Source_File
then
129 -- Otherwise modify Main_Unit entry to point to spec
131 U
.Unit_File_Name
:= N
;
133 end Change_Main_Unit_To_Spec
;
135 -------------------------------
136 -- Create_Dummy_Package_Unit --
137 -------------------------------
139 function Create_Dummy_Package_Unit
140 (With_Node
: Node_Id
;
141 Spec_Name
: Unit_Name_Type
) return Unit_Number_Type
143 Unum
: Unit_Number_Type
;
144 Cunit_Entity
: Entity_Id
;
146 Du_Name
: Node_Or_Entity_Id
;
148 Fname
: constant File_Name_Type
:=
149 Get_File_Name
(Spec_Name
, Subunit
=> False);
150 Pre_Name
: constant Boolean :=
151 Is_Predefined_File_Name
(Fname
, Renamings_Included
=> False);
152 Ren_Name
: constant Boolean :=
153 Is_Predefined_Renaming_File_Name
(Fname
);
154 GNAT_Name
: constant Boolean :=
155 Is_GNAT_File_Name
(Fname
);
156 Save_CS
: constant Boolean := Get_Comes_From_Source_Default
;
159 -- The created dummy package unit does not come from source
161 Set_Comes_From_Source_Default
(False);
165 if Nkind
(Name
(With_Node
)) = N_Identifier
then
167 Make_Defining_Identifier
(No_Location
,
168 Chars
=> Chars
(Name
(With_Node
)));
169 Du_Name
:= Cunit_Entity
;
170 End_Lab
:= New_Occurrence_Of
(Cunit_Entity
, No_Location
);
176 Make_Defining_Identifier
(No_Location
,
177 Chars
=> Chars
(Selector_Name
(Name
(With_Node
))));
179 Make_Defining_Program_Unit_Name
(No_Location
,
180 Name
=> Copy_Separate_Tree
(Prefix
(Name
(With_Node
))),
181 Defining_Identifier
=> Cunit_Entity
);
183 Set_Is_Child_Unit
(Cunit_Entity
);
186 Make_Designator
(No_Location
,
187 Name
=> Copy_Separate_Tree
(Prefix
(Name
(With_Node
))),
188 Identifier
=> New_Occurrence_Of
(Cunit_Entity
, No_Location
));
191 Set_Scope
(Cunit_Entity
, Standard_Standard
);
194 Make_Compilation_Unit
(No_Location
,
195 Context_Items
=> Empty_List
,
197 Make_Package_Declaration
(No_Location
,
199 Make_Package_Specification
(No_Location
,
200 Defining_Unit_Name
=> Du_Name
,
201 Visible_Declarations
=> Empty_List
,
202 End_Label
=> End_Lab
)),
204 Make_Compilation_Unit_Aux
(No_Location
));
206 -- Mark the dummy package as analyzed to prevent analysis of this
207 -- (non-existent) unit in -gnatQ mode because at the moment the
208 -- structure and attributes of this dummy package does not allow
209 -- a normal analysis of this unit
211 Set_Analyzed
(Cunit
);
213 Units
.Increment_Last
;
216 Units
.Table
(Unum
) :=
218 Cunit_Entity
=> Cunit_Entity
,
220 Dynamic_Elab
=> False,
221 Error_Location
=> Sloc
(With_Node
),
222 Expected_Unit
=> Spec_Name
,
223 Fatal_Error
=> Error_Detected
,
224 Generate_Code
=> False,
227 Ident_String
=> Empty
,
229 Is_Predefined_Renaming
=> Ren_Name
,
230 Is_Predefined_Unit
=> Pre_Name
or Ren_Name
,
231 Is_Internal_Unit
=> Pre_Name
or Ren_Name
or GNAT_Name
,
235 Main_Priority
=> Default_Main_Priority
,
236 Main_CPU
=> Default_Main_CPU
,
238 No_Elab_Code_All
=> False,
240 Source_Index
=> No_Source_File
,
241 Unit_File_Name
=> Fname
,
242 Unit_Name
=> Spec_Name
,
246 Set_Comes_From_Source_Default
(Save_CS
);
247 Set_Error_Posted
(Cunit_Entity
);
248 Set_Error_Posted
(Cunit
);
250 end Create_Dummy_Package_Unit
;
252 -----------------------------
253 -- From_Limited_With_Chain --
254 -----------------------------
256 function From_Limited_With_Chain
return Boolean is
257 Curr_Num
: constant Unit_Number_Type
:=
258 Load_Stack
.Table
(Load_Stack
.Last
).Unit_Number
;
261 -- True if the current load operation is through a limited_with clause
262 -- and we are not within a loop of regular with_clauses.
264 for U
in reverse Load_Stack
.First
.. Load_Stack
.Last
- 1 loop
265 if Load_Stack
.Table
(U
).Unit_Number
= Curr_Num
then
268 elsif Present
(Load_Stack
.Table
(U
).With_Node
)
269 and then Limited_Present
(Load_Stack
.Table
(U
).With_Node
)
276 end From_Limited_With_Chain
;
282 procedure Initialize
is
288 ------------------------
289 -- Initialize_Version --
290 ------------------------
292 procedure Initialize_Version
(U
: Unit_Number_Type
) is
294 Units
.Table
(U
).Version
:= Source_Checksum
(Source_Index
(U
));
295 end Initialize_Version
;
297 ----------------------
298 -- Load_Main_Source --
299 ----------------------
301 procedure Load_Main_Source
is
302 Fname
: constant File_Name_Type
:= Next_Main_Source
;
303 Pre_Name
: constant Boolean :=
304 Is_Predefined_File_Name
(Fname
, Renamings_Included
=> False);
305 Ren_Name
: constant Boolean :=
306 Is_Predefined_Renaming_File_Name
(Fname
);
307 GNAT_Name
: constant Boolean :=
308 Is_GNAT_File_Name
(Fname
);
312 Load_Stack
.Increment_Last
;
313 Load_Stack
.Table
(Load_Stack
.Last
) := (Main_Unit
, Empty
);
315 -- Initialize unit table entry for Main_Unit. Note that we don't know
316 -- the unit name yet, that gets filled in when the parser parses the
317 -- main unit, at which time a check is made that it matches the main
318 -- file name, and then the Unit_Name field is set. The Cunit and
319 -- Cunit_Entity fields also get filled in later by the parser.
321 Units
.Increment_Last
;
323 Units
.Table
(Main_Unit
).Unit_File_Name
:= Fname
;
325 if Fname
/= No_File
then
326 Main_Source_File
:= Load_Source_File
(Fname
);
327 Current_Error_Source_File
:= Main_Source_File
;
329 if Main_Source_File
/= No_Source_File
then
330 Version
:= Source_Checksum
(Main_Source_File
);
333 Units
.Table
(Main_Unit
) :=
335 Cunit_Entity
=> Empty
,
337 Dynamic_Elab
=> False,
338 Error_Location
=> No_Location
,
339 Expected_Unit
=> No_Unit_Name
,
341 Generate_Code
=> False,
344 Ident_String
=> Empty
,
346 Is_Predefined_Renaming
=> Ren_Name
,
347 Is_Predefined_Unit
=> Pre_Name
or Ren_Name
,
348 Is_Internal_Unit
=> Pre_Name
or Ren_Name
or GNAT_Name
,
352 Main_Priority
=> Default_Main_Priority
,
353 Main_CPU
=> Default_Main_CPU
,
355 No_Elab_Code_All
=> False,
357 Source_Index
=> Main_Source_File
,
358 Unit_File_Name
=> Fname
,
359 Unit_Name
=> No_Unit_Name
,
363 end Load_Main_Source
;
370 (Load_Name
: Unit_Name_Type
;
372 Error_Node
: Node_Id
;
374 Corr_Body
: Unit_Number_Type
:= No_Unit
;
375 Renamings
: Boolean := False;
376 With_Node
: Node_Id
:= Empty
;
377 PMES
: Boolean := False) return Unit_Number_Type
379 Calling_Unit
: Unit_Number_Type
;
380 Uname_Actual
: Unit_Name_Type
;
381 Unum
: Unit_Number_Type
;
382 Unump
: Unit_Number_Type
;
383 Fname
: File_Name_Type
;
387 Src_Ind
: Source_File_Index
;
388 Save_PMES
: constant Boolean := Parsing_Main_Extended_Source
;
390 Save_Cunit_Restrictions
: constant Save_Cunit_Boolean_Restrictions
:=
391 Cunit_Boolean_Restrictions_Save
;
392 -- Save current restrictions for restore at end
395 Parsing_Main_Extended_Source
:= PMES
;
397 -- Initialize restrictions to config restrictions for unit to load if
398 -- it is part of the main extended source, otherwise reset them.
400 -- Note: it's a bit odd but PMES is False for subunits, which is why
401 -- we have the OR here. Should be investigated some time???
403 if PMES
or Subunit
then
404 Restore_Config_Cunit_Boolean_Restrictions
;
406 Reset_Cunit_Boolean_Restrictions
;
409 -- If renamings are allowed and we have a child unit name, then we
410 -- must first load the parent to deal with finding the real name.
411 -- Retain the with_clause that names the child, so that if it is
412 -- limited, the parent is loaded under the same condition.
414 if Renamings
and then Is_Child_Name
(Load_Name
) then
417 (Load_Name
=> Get_Parent_Spec_Name
(Load_Name
),
418 Required
=> Required
,
421 Error_Node
=> Error_Node
,
422 With_Node
=> With_Node
);
424 if Unump
= No_Unit
then
425 Parsing_Main_Extended_Source
:= Save_PMES
;
429 -- If parent is a renaming, then we use the renamed package as
430 -- the actual parent for the subsequent load operation.
432 if Nkind
(Unit
(Cunit
(Unump
))) = N_Package_Renaming_Declaration
then
435 (Load_Name
, Get_Unit_Name
(Name
(Unit
(Cunit
(Unump
)))));
437 -- If the load is for a with_clause, for visibility purposes both
438 -- the renamed entity and renaming one must be available in the
439 -- current unit: the renamed one in order to retrieve the child
440 -- unit, and the original one because it may be used as a prefix
441 -- in the body of the current unit. We add an explicit with_clause
442 -- for the original parent so that the renaming declaration is
443 -- properly loaded and analyzed.
445 if Present
(With_Node
) then
446 Insert_After
(With_Node
,
447 Make_With_Clause
(Sloc
(With_Node
),
448 Name
=> Copy_Separate_Tree
(Prefix
(Name
(With_Node
)))));
451 -- Save the renaming entity, to establish its visibility when
452 -- installing the context. The implicit with is on this entity,
453 -- not on the package it renames. This is somewhat redundant given
454 -- the with_clause just created, but it simplifies subsequent
455 -- expansion of the current with_clause. Optimizable ???
457 if Nkind
(Error_Node
) = N_With_Clause
458 and then Nkind
(Name
(Error_Node
)) = N_Selected_Component
461 Par
: Node_Id
:= Name
(Error_Node
);
464 while Nkind
(Par
) = N_Selected_Component
465 and then Chars
(Selector_Name
(Par
)) /=
466 Chars
(Cunit_Entity
(Unump
))
471 -- Case of some intermediate parent is a renaming
473 if Nkind
(Par
) = N_Selected_Component
then
474 Set_Entity
(Selector_Name
(Par
), Cunit_Entity
(Unump
));
476 -- Case where the ultimate parent is a renaming
479 Set_Entity
(Par
, Cunit_Entity
(Unump
));
484 -- If the parent is not a renaming, then get its name (this may
485 -- be different from the parent spec name obtained above because
486 -- of renamings higher up in the hierarchy).
489 Uname_Actual
:= New_Child
(Load_Name
, Unit_Name
(Unump
));
492 -- Here if unit to be loaded is not a child unit
495 Uname_Actual
:= Load_Name
;
498 Fname
:= Get_File_Name
(Uname_Actual
, Subunit
);
500 Is_Predefined_File_Name
(Fname
, Renamings_Included
=> False);
501 Ren_Name
:= Is_Predefined_Renaming_File_Name
(Fname
);
502 GNAT_Name
:= Is_GNAT_File_Name
(Fname
);
506 Write_Str
("*** Load request for unit: ");
507 Write_Unit_Name
(Load_Name
);
510 Write_Str
(" (Required = True)");
512 Write_Str
(" (Required = False)");
517 if Uname_Actual
/= Load_Name
then
518 Write_Str
("*** Actual unit loaded: ");
519 Write_Unit_Name
(Uname_Actual
);
523 -- Capture error location if it is for the main unit. The idea is to
524 -- post errors on the main unit location, not the most recent unit.
525 -- Note: Unit_Name (Main_Unit) is not set if we are parsing gnat.adc.
527 if Present
(Error_Node
)
528 and then Unit_Name
(Main_Unit
) /= No_Unit_Name
530 -- It seems like In_Extended_Main_Source_Unit (Error_Node) would
531 -- do the trick here, but that's wrong, it is much too early to
532 -- call this routine. We are still in the parser, and the required
533 -- semantic information is not established yet. So we base the
534 -- judgment on unit names.
536 Get_External_Unit_Name_String
(Unit_Name
(Main_Unit
));
539 Main_Unit_Name
: constant String := Name_Buffer
(1 .. Name_Len
);
542 Get_External_Unit_Name_String
543 (Unit_Name
(Get_Source_Unit
(Error_Node
)));
545 -- If the two names are identical, then for sure we are part
546 -- of the extended main unit
548 if Main_Unit_Name
= Name_Buffer
(1 .. Name_Len
) then
549 Load_Msg_Sloc
:= Sloc
(Error_Node
);
551 -- If the load is called from a with_type clause, the error
554 -- Otherwise, check for the subunit case, and if so, consider
555 -- we have a match if one name is a prefix of the other name.
558 if Nkind
(Unit
(Cunit
(Main_Unit
))) = N_Subunit
560 Nkind
(Unit
(Cunit
(Get_Source_Unit
(Error_Node
)))) =
563 Name_Len
:= Integer'Min (Name_Len
, Main_Unit_Name
'Length);
565 if Name_Buffer
(1 .. Name_Len
)
567 Main_Unit_Name
(1 .. Name_Len
)
569 Load_Msg_Sloc
:= Sloc
(Error_Node
);
576 -- If we are generating error messages, then capture calling unit
578 if Present
(Error_Node
) then
579 Calling_Unit
:= Get_Source_Unit
(Error_Node
);
581 Calling_Unit
:= No_Unit
;
584 -- See if we already have an entry for this unit
587 while Unum
<= Units
.Last
loop
588 exit when Uname_Actual
= Units
.Table
(Unum
).Unit_Name
;
592 -- Whether or not the entry was found, Unum is now the right value,
593 -- since it is one more than Units.Last (i.e. the index of the new
594 -- entry we will create) in the not found case.
596 -- A special check is necessary in the unit not found case. If the unit
597 -- is not found, but the file in which it lives has already been loaded,
598 -- then we have the problem that the file does not contain the unit that
599 -- is needed. We simply treat this as a file not found condition.
601 -- We skip this test in multiple unit per file mode since in this
602 -- case we can have multiple units from the same source file.
604 if Unum
> Units
.Last
and then Get_Unit_Index
(Uname_Actual
) = 0 then
605 for J
in Units
.First
.. Units
.Last
loop
606 if Fname
= Units
.Table
(J
).Unit_File_Name
then
608 Write_Str
(" file does not contain unit, Unit_Number = ");
609 Write_Int
(Int
(Unum
));
614 if Present
(Error_Node
) then
615 Get_Name_String
(Fname
);
617 if Is_Predefined_File_Name
(Fname
) then
618 Error_Msg_Unit_1
:= Uname_Actual
;
620 ("$$ is not a language defined unit", Load_Msg_Sloc
);
622 Error_Msg_File_1
:= Fname
;
623 Error_Msg_Unit_1
:= Uname_Actual
;
624 Error_Msg
("File{ does not contain unit$", Load_Msg_Sloc
);
627 Write_Dependency_Chain
;
639 -- If we are proceeding with load, then make load stack entry,
640 -- and indicate the kind of with_clause responsible for the load.
642 Load_Stack
.Increment_Last
;
643 Load_Stack
.Table
(Load_Stack
.Last
) := (Unum
, With_Node
);
645 -- Case of entry already in table
647 if Unum
<= Units
.Last
then
649 -- Here is where we check for a circular dependency, which is
650 -- an attempt to load a unit which is currently in the process
651 -- of being loaded. We do *not* care about a circular chain that
652 -- leads back to a body, because this kind of circular dependence
653 -- legitimately occurs (e.g. two package bodies that contain
654 -- inlined subprogram referenced by the other).
656 -- Ada 2005 (AI-50217): We also ignore limited_with clauses, because
657 -- their purpose is precisely to create legal circular structures.
660 and then (Is_Spec_Name
(Units
.Table
(Unum
).Unit_Name
)
661 or else Acts_As_Spec
(Units
.Table
(Unum
).Cunit
))
662 and then (Nkind
(Error_Node
) /= N_With_Clause
663 or else not Limited_Present
(Error_Node
))
664 and then not From_Limited_With_Chain
667 Write_Str
(" circular dependency encountered");
671 if Present
(Error_Node
) then
672 Error_Msg
("circular unit dependency", Load_Msg_Sloc
);
673 Write_Dependency_Chain
;
675 Load_Stack
.Decrement_Last
;
683 Write_Str
(" unit already in file table, Unit_Number = ");
684 Write_Int
(Int
(Unum
));
688 Load_Stack
.Decrement_Last
;
691 -- Unit is not already in table, so try to open the file
695 Write_Str
(" attempt unit load, Unit_Number = ");
696 Write_Int
(Int
(Unum
));
700 Src_Ind
:= Load_Source_File
(Fname
);
702 -- Make a partial entry in the file table, used even in the file not
703 -- found case to print the dependency chain including the last entry
705 Units
.Increment_Last
;
706 Units
.Table
(Unum
).Unit_Name
:= Uname_Actual
;
710 if Src_Ind
/= No_Source_File
then
711 Units
.Table
(Unum
) :=
713 Cunit_Entity
=> Empty
,
715 Dynamic_Elab
=> False,
716 Error_Location
=> Sloc
(Error_Node
),
717 Expected_Unit
=> Uname_Actual
,
719 Generate_Code
=> False,
722 Ident_String
=> Empty
,
724 Is_Predefined_Renaming
=> Ren_Name
,
725 Is_Predefined_Unit
=> Pre_Name
or Ren_Name
,
726 Is_Internal_Unit
=> Pre_Name
or Ren_Name
or GNAT_Name
,
730 Main_Priority
=> Default_Main_Priority
,
731 Main_CPU
=> Default_Main_CPU
,
733 No_Elab_Code_All
=> False,
735 Source_Index
=> Src_Ind
,
736 Unit_File_Name
=> Fname
,
737 Unit_Name
=> Uname_Actual
,
738 Version
=> Source_Checksum
(Src_Ind
),
741 -- Parse the new unit
744 Save_Index
: constant Nat
:= Multiple_Unit_Index
;
745 Save_PMES
: constant Boolean := Parsing_Main_Extended_Source
;
748 Multiple_Unit_Index
:= Get_Unit_Index
(Uname_Actual
);
749 Units
.Table
(Unum
).Munit_Index
:= Multiple_Unit_Index
;
750 Initialize_Scanner
(Unum
, Source_Index
(Unum
));
752 if Calling_Unit
= Main_Unit
and then Subunit
then
753 Parsing_Main_Extended_Source
:= True;
756 Discard_List
(Par
(Configuration_Pragmas
=> False));
758 Parsing_Main_Extended_Source
:= Save_PMES
;
760 Multiple_Unit_Index
:= Save_Index
;
761 Set_Loading
(Unum
, False);
764 -- If spec is irrelevant, then post errors and quit
766 if Corr_Body
/= No_Unit
767 and then Spec_Is_Irrelevant
(Unum
, Corr_Body
)
769 Error_Msg_File_1
:= Unit_File_Name
(Corr_Body
);
771 ("cannot compile subprogram in file {!", Load_Msg_Sloc
);
772 Error_Msg_File_1
:= Unit_File_Name
(Unum
);
774 ("\incorrect spec in file { must be removed first!",
780 -- If loaded unit had an error, then caller inherits setting
782 if Present
(Error_Node
) then
783 case Units
.Table
(Unum
).Fatal_Error
is
785 -- Nothing to do if with'ed unit had no error
790 -- If with'ed unit had a detected fatal error, propagate it
792 when Error_Detected
=>
793 Units
.Table
(Calling_Unit
).Fatal_Error
:= Error_Detected
;
795 -- If with'ed unit had an ignored error, then propagate it
796 -- but do not overide an existring setting.
798 when Error_Ignored
=>
799 if Units
.Table
(Calling_Unit
).Fatal_Error
= None
then
800 Units
.Table
(Calling_Unit
).Fatal_Error
:=
806 -- Remove load stack entry and return the entry in the file table
808 Load_Stack
.Decrement_Last
;
810 -- All done, return unit number
814 -- Case of file not found
818 Write_Str
(" file was not found, load failed");
822 -- Generate message if unit required
825 Get_Name_String
(Fname
);
827 if Is_Predefined_File_Name
(Fname
) then
829 -- This is a predefined library unit which is not present
830 -- in the run time. If a predefined unit is not available
831 -- it may very likely be the case that there is also pragma
832 -- Restriction forbidding its usage. This is typically the
833 -- case when building a configurable run time, where the
834 -- usage of certain run-time units is restricted by means
835 -- of both the corresponding pragma Restriction (such as
836 -- No_Calendar), and by not including the unit. Hence, we
837 -- check whether this predefined unit is forbidden, so that
838 -- the message about the restriction violation is generated,
841 if Present
(Error_Node
) then
842 Check_Restricted_Unit
(Load_Name
, Error_Node
);
845 Error_Msg_Unit_1
:= Uname_Actual
;
847 ("$$ is not a predefined library unit", Load_Msg_Sloc
);
850 Error_Msg_File_1
:= Fname
;
851 Error_Msg
("file{ not found", Load_Msg_Sloc
);
854 Write_Dependency_Chain
;
856 -- Remove unit from stack, to avoid cascaded errors on
857 -- subsequent missing files.
859 Load_Stack
.Decrement_Last
;
860 Units
.Decrement_Last
;
862 -- If unit not required, remove load stack entry and the junk
863 -- file table entry, and return No_Unit to indicate not found,
866 Load_Stack
.Decrement_Last
;
867 Units
.Decrement_Last
;
875 -- Here to exit, with result in Unum
878 Parsing_Main_Extended_Source
:= Save_PMES
;
879 Cunit_Boolean_Restrictions_Restore
(Save_Cunit_Restrictions
);
883 --------------------------
884 -- Make_Child_Decl_Unit --
885 --------------------------
887 procedure Make_Child_Decl_Unit
(N
: Node_Id
) is
888 Unit_Decl
: constant Node_Id
:= Library_Unit
(N
);
891 Units
.Increment_Last
;
892 Units
.Table
(Units
.Last
) := Units
.Table
(Get_Cunit_Unit_Number
(N
));
893 Units
.Table
(Units
.Last
).Unit_Name
:=
894 Get_Spec_Name
(Unit_Name
(Get_Cunit_Unit_Number
(N
)));
895 Units
.Table
(Units
.Last
).Cunit
:= Unit_Decl
;
896 Units
.Table
(Units
.Last
).Cunit_Entity
:=
898 (Defining_Unit_Name
(Specification
(Unit
(Unit_Decl
))));
900 -- The library unit created for of a child subprogram unit plays no
901 -- role in code generation and binding, so label it accordingly.
903 Units
.Table
(Units
.Last
).Generate_Code
:= False;
904 Set_Has_No_Elaboration_Code
(Unit_Decl
);
905 end Make_Child_Decl_Unit
;
907 ------------------------
908 -- Make_Instance_Unit --
909 ------------------------
911 -- If the unit is an instance, it appears as a package declaration, but
912 -- contains both declaration and body of the instance. The body becomes
913 -- the main unit of the compilation, and the declaration is inserted
914 -- at the end of the unit table. The main unit now has the name of a
915 -- body, which is constructed from the name of the original spec,
916 -- and is attached to the compilation node of the original unit. The
917 -- declaration has been attached to a new compilation unit node, and
918 -- code will have to be generated for it.
920 procedure Make_Instance_Unit
(N
: Node_Id
; In_Main
: Boolean) is
921 Sind
: constant Source_File_Index
:= Source_Index
(Main_Unit
);
924 Units
.Increment_Last
;
927 Units
.Table
(Units
.Last
) := Units
.Table
(Main_Unit
);
928 Units
.Table
(Units
.Last
).Cunit
:= Library_Unit
(N
);
929 Units
.Table
(Units
.Last
).Generate_Code
:= True;
930 Units
.Table
(Main_Unit
).Cunit
:= N
;
931 Units
.Table
(Main_Unit
).Unit_Name
:=
933 (Unit_Name
(Get_Cunit_Unit_Number
(Library_Unit
(N
))));
934 Units
.Table
(Main_Unit
).Version
:= Source_Checksum
(Sind
);
937 -- Duplicate information from instance unit, for the body. The unit
938 -- node N has been rewritten as a body, but it was placed in the
939 -- units table when first loaded as a declaration.
941 Units
.Table
(Units
.Last
) := Units
.Table
(Get_Cunit_Unit_Number
(N
));
942 Units
.Table
(Units
.Last
).Cunit
:= Library_Unit
(N
);
944 end Make_Instance_Unit
;
946 ------------------------
947 -- Spec_Is_Irrelevant --
948 ------------------------
950 function Spec_Is_Irrelevant
951 (Spec_Unit
: Unit_Number_Type
;
952 Body_Unit
: Unit_Number_Type
) return Boolean
954 Sunit
: constant Node_Id
:= Cunit
(Spec_Unit
);
955 Bunit
: constant Node_Id
:= Cunit
(Body_Unit
);
958 -- The spec is irrelevant if the body is a subprogram body, and the spec
959 -- is other than a subprogram spec or generic subprogram spec. Note that
960 -- the names must be the same, we don't need to check that, because we
961 -- already know that from the fact that the file names are the same.
964 Nkind
(Unit
(Bunit
)) = N_Subprogram_Body
965 and then Nkind
(Unit
(Sunit
)) /= N_Subprogram_Declaration
966 and then Nkind
(Unit
(Sunit
)) /= N_Generic_Subprogram_Declaration
;
967 end Spec_Is_Irrelevant
;
973 procedure Version_Update
(U
: Node_Id
; From
: Node_Id
) is
974 Unum
: constant Unit_Number_Type
:= Get_Cunit_Unit_Number
(U
);
975 Fnum
: constant Unit_Number_Type
:= Get_Cunit_Unit_Number
(From
);
977 if Source_Index
(Fnum
) /= No_Source_File
then
978 Units
.Table
(Unum
).Version
:=
979 Units
.Table
(Unum
).Version
981 Source_Checksum
(Source_Index
(Fnum
));
985 ----------------------------
986 -- Write_Dependency_Chain --
987 ----------------------------
989 procedure Write_Dependency_Chain
is
991 -- The dependency chain is only written if it is at least two entries
992 -- deep, otherwise it is trivial (the main unit depending on a unit
993 -- that it obviously directly depends on).
995 if Load_Stack
.Last
- 1 > Load_Stack
.First
then
996 for U
in Load_Stack
.First
.. Load_Stack
.Last
- 1 loop
998 Unit_Name
(Load_Stack
.Table
(U
).Unit_Number
);
1000 Unit_Name
(Load_Stack
.Table
(U
+ 1).Unit_Number
);
1001 Error_Msg
("$ depends on $!", Load_Msg_Sloc
);
1004 end Write_Dependency_Chain
;