1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, 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 Save_CS
: constant Boolean := Get_Comes_From_Source_Default
;
151 -- The created dummy package unit does not come from source
153 Set_Comes_From_Source_Default
(False);
157 if Nkind
(Name
(With_Node
)) = N_Identifier
then
159 Make_Defining_Identifier
(No_Location
,
160 Chars
=> Chars
(Name
(With_Node
)));
161 Du_Name
:= Cunit_Entity
;
162 End_Lab
:= New_Occurrence_Of
(Cunit_Entity
, No_Location
);
168 Make_Defining_Identifier
(No_Location
,
169 Chars
=> Chars
(Selector_Name
(Name
(With_Node
))));
171 Make_Defining_Program_Unit_Name
(No_Location
,
172 Name
=> Copy_Separate_Tree
(Prefix
(Name
(With_Node
))),
173 Defining_Identifier
=> Cunit_Entity
);
175 Set_Is_Child_Unit
(Cunit_Entity
);
178 Make_Designator
(No_Location
,
179 Name
=> Copy_Separate_Tree
(Prefix
(Name
(With_Node
))),
180 Identifier
=> New_Occurrence_Of
(Cunit_Entity
, No_Location
));
183 Set_Scope
(Cunit_Entity
, Standard_Standard
);
186 Make_Compilation_Unit
(No_Location
,
187 Context_Items
=> Empty_List
,
189 Make_Package_Declaration
(No_Location
,
191 Make_Package_Specification
(No_Location
,
192 Defining_Unit_Name
=> Du_Name
,
193 Visible_Declarations
=> Empty_List
,
194 End_Label
=> End_Lab
)),
196 Make_Compilation_Unit_Aux
(No_Location
));
198 -- Mark the dummy package as analyzed to prevent analysis of this
199 -- (non-existent) unit in -gnatQ mode because at the moment the
200 -- structure and attributes of this dummy package does not allow
201 -- a normal analysis of this unit
203 Set_Analyzed
(Cunit
);
205 Units
.Increment_Last
;
208 Units
.Table
(Unum
) := (
210 Cunit_Entity
=> Cunit_Entity
,
212 Dynamic_Elab
=> False,
213 Error_Location
=> Sloc
(With_Node
),
214 Expected_Unit
=> Spec_Name
,
216 Generate_Code
=> False,
217 Has_Allocator
=> False,
219 Is_Compiler_Unit
=> False,
220 Ident_String
=> Empty
,
222 Main_Priority
=> Default_Main_Priority
,
223 Main_CPU
=> Default_Main_CPU
,
226 Source_Index
=> No_Source_File
,
227 Unit_File_Name
=> Get_File_Name
(Spec_Name
, Subunit
=> False),
228 Unit_Name
=> Spec_Name
,
232 Set_Comes_From_Source_Default
(Save_CS
);
233 Set_Error_Posted
(Cunit_Entity
);
234 Set_Error_Posted
(Cunit
);
236 end Create_Dummy_Package_Unit
;
238 -----------------------------
239 -- From_Limited_With_Chain --
240 -----------------------------
242 function From_Limited_With_Chain
return Boolean is
243 Curr_Num
: constant Unit_Number_Type
:=
244 Load_Stack
.Table
(Load_Stack
.Last
).Unit_Number
;
247 -- True if the current load operation is through a limited_with clause
248 -- and we are not within a loop of regular with_clauses.
250 for U
in reverse Load_Stack
.First
.. Load_Stack
.Last
- 1 loop
251 if Load_Stack
.Table
(U
).Unit_Number
= Curr_Num
then
254 elsif Present
(Load_Stack
.Table
(U
).With_Node
)
255 and then Limited_Present
(Load_Stack
.Table
(U
).With_Node
)
262 end From_Limited_With_Chain
;
268 procedure Initialize
is
274 ------------------------
275 -- Initialize_Version --
276 ------------------------
278 procedure Initialize_Version
(U
: Unit_Number_Type
) is
280 Units
.Table
(U
).Version
:= Source_Checksum
(Source_Index
(U
));
281 end Initialize_Version
;
283 ----------------------
284 -- Load_Main_Source --
285 ----------------------
287 procedure Load_Main_Source
is
288 Fname
: File_Name_Type
;
292 Load_Stack
.Increment_Last
;
293 Load_Stack
.Table
(Load_Stack
.Last
) := (Main_Unit
, Empty
);
295 -- Initialize unit table entry for Main_Unit. Note that we don't know
296 -- the unit name yet, that gets filled in when the parser parses the
297 -- main unit, at which time a check is made that it matches the main
298 -- file name, and then the Unit_Name field is set. The Cunit and
299 -- Cunit_Entity fields also get filled in later by the parser.
301 Units
.Increment_Last
;
302 Fname
:= Next_Main_Source
;
304 Units
.Table
(Main_Unit
).Unit_File_Name
:= Fname
;
306 if Fname
/= No_File
then
307 Main_Source_File
:= Load_Source_File
(Fname
);
308 Current_Error_Source_File
:= Main_Source_File
;
310 if Main_Source_File
/= No_Source_File
then
311 Version
:= Source_Checksum
(Main_Source_File
);
314 Units
.Table
(Main_Unit
) := (
316 Cunit_Entity
=> Empty
,
318 Dynamic_Elab
=> False,
319 Error_Location
=> No_Location
,
320 Expected_Unit
=> No_Unit_Name
,
321 Fatal_Error
=> False,
322 Generate_Code
=> False,
323 Has_Allocator
=> False,
325 Is_Compiler_Unit
=> False,
326 Ident_String
=> Empty
,
328 Main_Priority
=> Default_Main_Priority
,
329 Main_CPU
=> Default_Main_CPU
,
332 Source_Index
=> Main_Source_File
,
333 Unit_File_Name
=> Fname
,
334 Unit_Name
=> No_Unit_Name
,
338 end Load_Main_Source
;
345 (Load_Name
: Unit_Name_Type
;
347 Error_Node
: Node_Id
;
349 Corr_Body
: Unit_Number_Type
:= No_Unit
;
350 Renamings
: Boolean := False;
351 With_Node
: Node_Id
:= Empty
;
352 PMES
: Boolean := False) return Unit_Number_Type
354 Calling_Unit
: Unit_Number_Type
;
355 Uname_Actual
: Unit_Name_Type
;
356 Unum
: Unit_Number_Type
;
357 Unump
: Unit_Number_Type
;
358 Fname
: File_Name_Type
;
359 Src_Ind
: Source_File_Index
;
360 Save_PMES
: constant Boolean := Parsing_Main_Extended_Source
;
363 Parsing_Main_Extended_Source
:= PMES
;
365 -- If renamings are allowed and we have a child unit name, then we
366 -- must first load the parent to deal with finding the real name.
367 -- Retain the with_clause that names the child, so that if it is
368 -- limited, the parent is loaded under the same condition.
370 if Renamings
and then Is_Child_Name
(Load_Name
) then
373 (Load_Name
=> Get_Parent_Spec_Name
(Load_Name
),
374 Required
=> Required
,
377 Error_Node
=> Error_Node
,
378 With_Node
=> With_Node
);
380 if Unump
= No_Unit
then
381 Parsing_Main_Extended_Source
:= Save_PMES
;
385 -- If parent is a renaming, then we use the renamed package as
386 -- the actual parent for the subsequent load operation.
388 if Nkind
(Unit
(Cunit
(Unump
))) = N_Package_Renaming_Declaration
then
391 (Load_Name
, Get_Unit_Name
(Name
(Unit
(Cunit
(Unump
)))));
393 -- Save the renaming entity, to establish its visibility when
394 -- installing the context. The implicit with is on this entity,
395 -- not on the package it renames.
397 if Nkind
(Error_Node
) = N_With_Clause
398 and then Nkind
(Name
(Error_Node
)) = N_Selected_Component
401 Par
: Node_Id
:= Name
(Error_Node
);
404 while Nkind
(Par
) = N_Selected_Component
405 and then Chars
(Selector_Name
(Par
)) /=
406 Chars
(Cunit_Entity
(Unump
))
411 -- Case of some intermediate parent is a renaming
413 if Nkind
(Par
) = N_Selected_Component
then
414 Set_Entity
(Selector_Name
(Par
), Cunit_Entity
(Unump
));
416 -- Case where the ultimate parent is a renaming
419 Set_Entity
(Par
, Cunit_Entity
(Unump
));
424 -- If the parent is not a renaming, then get its name (this may
425 -- be different from the parent spec name obtained above because
426 -- of renamings higher up in the hierarchy).
429 Uname_Actual
:= New_Child
(Load_Name
, Unit_Name
(Unump
));
432 -- Here if unit to be loaded is not a child unit
435 Uname_Actual
:= Load_Name
;
438 Fname
:= Get_File_Name
(Uname_Actual
, Subunit
);
442 Write_Str
("*** Load request for unit: ");
443 Write_Unit_Name
(Load_Name
);
446 Write_Str
(" (Required = True)");
448 Write_Str
(" (Required = False)");
453 if Uname_Actual
/= Load_Name
then
454 Write_Str
("*** Actual unit loaded: ");
455 Write_Unit_Name
(Uname_Actual
);
459 -- Capture error location if it is for the main unit. The idea is to
460 -- post errors on the main unit location, not the most recent unit.
461 -- Note: Unit_Name (Main_Unit) is not set if we are parsing gnat.adc.
463 if Present
(Error_Node
)
464 and then Unit_Name
(Main_Unit
) /= No_Unit_Name
466 -- It seems like In_Extended_Main_Source_Unit (Error_Node) would
467 -- do the trick here, but that's wrong, it is much too early to
468 -- call this routine. We are still in the parser, and the required
469 -- semantic information is not established yet. So we base the
470 -- judgment on unit names.
472 Get_External_Unit_Name_String
(Unit_Name
(Main_Unit
));
475 Main_Unit_Name
: constant String := Name_Buffer
(1 .. Name_Len
);
478 Get_External_Unit_Name_String
479 (Unit_Name
(Get_Source_Unit
(Error_Node
)));
481 -- If the two names are identical, then for sure we are part
482 -- of the extended main unit
484 if Main_Unit_Name
= Name_Buffer
(1 .. Name_Len
) then
485 Load_Msg_Sloc
:= Sloc
(Error_Node
);
487 -- If the load is called from a with_type clause, the error
490 -- Otherwise, check for the subunit case, and if so, consider
491 -- we have a match if one name is a prefix of the other name.
494 if Nkind
(Unit
(Cunit
(Main_Unit
))) = N_Subunit
496 Nkind
(Unit
(Cunit
(Get_Source_Unit
(Error_Node
)))) =
499 Name_Len
:= Integer'Min (Name_Len
, Main_Unit_Name
'Length);
501 if Name_Buffer
(1 .. Name_Len
)
503 Main_Unit_Name
(1 .. Name_Len
)
505 Load_Msg_Sloc
:= Sloc
(Error_Node
);
512 -- If we are generating error messages, then capture calling unit
514 if Present
(Error_Node
) then
515 Calling_Unit
:= Get_Source_Unit
(Error_Node
);
517 Calling_Unit
:= No_Unit
;
520 -- See if we already have an entry for this unit
523 while Unum
<= Units
.Last
loop
524 exit when Uname_Actual
= Units
.Table
(Unum
).Unit_Name
;
528 -- Whether or not the entry was found, Unum is now the right value,
529 -- since it is one more than Units.Last (i.e. the index of the new
530 -- entry we will create) in the not found case.
532 -- A special check is necessary in the unit not found case. If the unit
533 -- is not found, but the file in which it lives has already been loaded,
534 -- then we have the problem that the file does not contain the unit that
535 -- is needed. We simply treat this as a file not found condition.
537 -- We skip this test in multiple unit per file mode since in this
538 -- case we can have multiple units from the same source file.
540 if Unum
> Units
.Last
and then Get_Unit_Index
(Uname_Actual
) = 0 then
541 for J
in Units
.First
.. Units
.Last
loop
542 if Fname
= Units
.Table
(J
).Unit_File_Name
then
544 Write_Str
(" file does not contain unit, Unit_Number = ");
545 Write_Int
(Int
(Unum
));
550 if Present
(Error_Node
) then
551 if Is_Predefined_File_Name
(Fname
) then
552 Error_Msg_Unit_1
:= Uname_Actual
;
554 ("$$ is not a language defined unit", Load_Msg_Sloc
);
556 Error_Msg_File_1
:= Fname
;
557 Error_Msg_Unit_1
:= Uname_Actual
;
558 Error_Msg
("File{ does not contain unit$", Load_Msg_Sloc
);
561 Write_Dependency_Chain
;
573 -- If we are proceeding with load, then make load stack entry,
574 -- and indicate the kind of with_clause responsible for the load.
576 Load_Stack
.Increment_Last
;
577 Load_Stack
.Table
(Load_Stack
.Last
) := (Unum
, With_Node
);
579 -- Case of entry already in table
581 if Unum
<= Units
.Last
then
583 -- Here is where we check for a circular dependency, which is
584 -- an attempt to load a unit which is currently in the process
585 -- of being loaded. We do *not* care about a circular chain that
586 -- leads back to a body, because this kind of circular dependence
587 -- legitimately occurs (e.g. two package bodies that contain
588 -- inlined subprogram referenced by the other).
590 -- Ada 2005 (AI-50217): We also ignore limited_with clauses, because
591 -- their purpose is precisely to create legal circular structures.
594 and then (Is_Spec_Name
(Units
.Table
(Unum
).Unit_Name
)
595 or else Acts_As_Spec
(Units
.Table
(Unum
).Cunit
))
596 and then (Nkind
(Error_Node
) /= N_With_Clause
597 or else not Limited_Present
(Error_Node
))
598 and then not From_Limited_With_Chain
601 Write_Str
(" circular dependency encountered");
605 if Present
(Error_Node
) then
606 Error_Msg
("circular unit dependency", Load_Msg_Sloc
);
607 Write_Dependency_Chain
;
609 Load_Stack
.Decrement_Last
;
617 Write_Str
(" unit already in file table, Unit_Number = ");
618 Write_Int
(Int
(Unum
));
622 Load_Stack
.Decrement_Last
;
625 -- Unit is not already in table, so try to open the file
629 Write_Str
(" attempt unit load, Unit_Number = ");
630 Write_Int
(Int
(Unum
));
634 Src_Ind
:= Load_Source_File
(Fname
);
636 -- Make a partial entry in the file table, used even in the file not
637 -- found case to print the dependency chain including the last entry
639 Units
.Increment_Last
;
640 Units
.Table
(Unum
).Unit_Name
:= Uname_Actual
;
644 if Src_Ind
/= No_Source_File
then
645 Units
.Table
(Unum
) := (
647 Cunit_Entity
=> Empty
,
649 Dynamic_Elab
=> False,
650 Error_Location
=> Sloc
(Error_Node
),
651 Expected_Unit
=> Uname_Actual
,
652 Fatal_Error
=> False,
653 Generate_Code
=> False,
654 Has_Allocator
=> False,
656 Is_Compiler_Unit
=> False,
657 Ident_String
=> Empty
,
659 Main_Priority
=> Default_Main_Priority
,
660 Main_CPU
=> Default_Main_CPU
,
663 Source_Index
=> Src_Ind
,
664 Unit_File_Name
=> Fname
,
665 Unit_Name
=> Uname_Actual
,
666 Version
=> Source_Checksum
(Src_Ind
),
669 -- Parse the new unit
672 Save_Index
: constant Nat
:= Multiple_Unit_Index
;
673 Save_PMES
: constant Boolean := Parsing_Main_Extended_Source
;
676 Multiple_Unit_Index
:= Get_Unit_Index
(Uname_Actual
);
677 Units
.Table
(Unum
).Munit_Index
:= Multiple_Unit_Index
;
678 Initialize_Scanner
(Unum
, Source_Index
(Unum
));
680 if Calling_Unit
= Main_Unit
and then Subunit
then
681 Parsing_Main_Extended_Source
:= True;
684 Discard_List
(Par
(Configuration_Pragmas
=> False));
686 Parsing_Main_Extended_Source
:= Save_PMES
;
688 Multiple_Unit_Index
:= Save_Index
;
689 Set_Loading
(Unum
, False);
692 -- If spec is irrelevant, then post errors and quit
694 if Corr_Body
/= No_Unit
695 and then Spec_Is_Irrelevant
(Unum
, Corr_Body
)
697 Error_Msg_File_1
:= Unit_File_Name
(Corr_Body
);
699 ("cannot compile subprogram in file {!", Load_Msg_Sloc
);
700 Error_Msg_File_1
:= Unit_File_Name
(Unum
);
702 ("\incorrect spec in file { must be removed first!",
708 -- If loaded unit had a fatal error, then caller inherits it!
710 if Units
.Table
(Unum
).Fatal_Error
711 and then Present
(Error_Node
)
713 Units
.Table
(Calling_Unit
).Fatal_Error
:= True;
716 -- Remove load stack entry and return the entry in the file table
718 Load_Stack
.Decrement_Last
;
720 -- All done, return unit number
724 -- Case of file not found
728 Write_Str
(" file was not found, load failed");
732 -- Generate message if unit required
734 if Required
and then Present
(Error_Node
) then
735 if Is_Predefined_File_Name
(Fname
) then
737 -- This is a predefined library unit which is not present
738 -- in the run time. If a predefined unit is not available
739 -- it may very likely be the case that there is also pragma
740 -- Restriction forbidding its usage. This is typically the
741 -- case when building a configurable run time, where the
742 -- usage of certain run-time units is restricted by means
743 -- of both the corresponding pragma Restriction (such as
744 -- No_Calendar), and by not including the unit. Hence, we
745 -- check whether this predefined unit is forbidden, so that
746 -- the message about the restriction violation is generated,
749 Check_Restricted_Unit
(Load_Name
, Error_Node
);
751 Error_Msg_Unit_1
:= Uname_Actual
;
753 ("$$ is not a predefined library unit", Load_Msg_Sloc
);
756 Error_Msg_File_1
:= Fname
;
757 Error_Msg
("file{ not found", Load_Msg_Sloc
);
760 Write_Dependency_Chain
;
762 -- Remove unit from stack, to avoid cascaded errors on
763 -- subsequent missing files.
765 Load_Stack
.Decrement_Last
;
766 Units
.Decrement_Last
;
768 -- If unit not required, remove load stack entry and the junk
769 -- file table entry, and return No_Unit to indicate not found,
772 Load_Stack
.Decrement_Last
;
773 Units
.Decrement_Last
;
781 -- Here to exit, with result in Unum
784 Parsing_Main_Extended_Source
:= Save_PMES
;
788 --------------------------
789 -- Make_Child_Decl_Unit --
790 --------------------------
792 procedure Make_Child_Decl_Unit
(N
: Node_Id
) is
793 Unit_Decl
: constant Node_Id
:= Library_Unit
(N
);
796 Units
.Increment_Last
;
797 Units
.Table
(Units
.Last
) := Units
.Table
(Get_Cunit_Unit_Number
(N
));
798 Units
.Table
(Units
.Last
).Unit_Name
:=
799 Get_Spec_Name
(Unit_Name
(Get_Cunit_Unit_Number
(N
)));
800 Units
.Table
(Units
.Last
).Cunit
:= Unit_Decl
;
801 Units
.Table
(Units
.Last
).Cunit_Entity
:=
803 (Defining_Unit_Name
(Specification
(Unit
(Unit_Decl
))));
805 -- The library unit created for of a child subprogram unit plays no
806 -- role in code generation and binding, so label it accordingly.
808 Units
.Table
(Units
.Last
).Generate_Code
:= False;
809 Set_Has_No_Elaboration_Code
(Unit_Decl
);
810 end Make_Child_Decl_Unit
;
812 ------------------------
813 -- Make_Instance_Unit --
814 ------------------------
816 -- If the unit is an instance, it appears as a package declaration, but
817 -- contains both declaration and body of the instance. The body becomes
818 -- the main unit of the compilation, and the declaration is inserted
819 -- at the end of the unit table. The main unit now has the name of a
820 -- body, which is constructed from the name of the original spec,
821 -- and is attached to the compilation node of the original unit. The
822 -- declaration has been attached to a new compilation unit node, and
823 -- code will have to be generated for it.
825 procedure Make_Instance_Unit
(N
: Node_Id
; In_Main
: Boolean) is
826 Sind
: constant Source_File_Index
:= Source_Index
(Main_Unit
);
829 Units
.Increment_Last
;
832 Units
.Table
(Units
.Last
) := Units
.Table
(Main_Unit
);
833 Units
.Table
(Units
.Last
).Cunit
:= Library_Unit
(N
);
834 Units
.Table
(Units
.Last
).Generate_Code
:= True;
835 Units
.Table
(Main_Unit
).Cunit
:= N
;
836 Units
.Table
(Main_Unit
).Unit_Name
:=
838 (Unit_Name
(Get_Cunit_Unit_Number
(Library_Unit
(N
))));
839 Units
.Table
(Main_Unit
).Version
:= Source_Checksum
(Sind
);
842 -- Duplicate information from instance unit, for the body. The unit
843 -- node N has been rewritten as a body, but it was placed in the
844 -- units table when first loaded as a declaration.
846 Units
.Table
(Units
.Last
) := Units
.Table
(Get_Cunit_Unit_Number
(N
));
847 Units
.Table
(Units
.Last
).Cunit
:= Library_Unit
(N
);
849 end Make_Instance_Unit
;
851 ------------------------
852 -- Spec_Is_Irrelevant --
853 ------------------------
855 function Spec_Is_Irrelevant
856 (Spec_Unit
: Unit_Number_Type
;
857 Body_Unit
: Unit_Number_Type
) return Boolean
859 Sunit
: constant Node_Id
:= Cunit
(Spec_Unit
);
860 Bunit
: constant Node_Id
:= Cunit
(Body_Unit
);
863 -- The spec is irrelevant if the body is a subprogram body, and the spec
864 -- is other than a subprogram spec or generic subprogram spec. Note that
865 -- the names must be the same, we don't need to check that, because we
866 -- already know that from the fact that the file names are the same.
869 Nkind
(Unit
(Bunit
)) = N_Subprogram_Body
870 and then Nkind
(Unit
(Sunit
)) /= N_Subprogram_Declaration
871 and then Nkind
(Unit
(Sunit
)) /= N_Generic_Subprogram_Declaration
;
872 end Spec_Is_Irrelevant
;
878 procedure Version_Update
(U
: Node_Id
; From
: Node_Id
) is
879 Unum
: constant Unit_Number_Type
:= Get_Cunit_Unit_Number
(U
);
880 Fnum
: constant Unit_Number_Type
:= Get_Cunit_Unit_Number
(From
);
882 if Source_Index
(Fnum
) /= No_Source_File
then
883 Units
.Table
(Unum
).Version
:=
884 Units
.Table
(Unum
).Version
886 Source_Checksum
(Source_Index
(Fnum
));
890 ----------------------------
891 -- Write_Dependency_Chain --
892 ----------------------------
894 procedure Write_Dependency_Chain
is
896 -- The dependency chain is only written if it is at least two entries
897 -- deep, otherwise it is trivial (the main unit depending on a unit
898 -- that it obviously directly depends on).
900 if Load_Stack
.Last
- 1 > Load_Stack
.First
then
901 for U
in Load_Stack
.First
.. Load_Stack
.Last
- 1 loop
903 Unit_Name
(Load_Stack
.Table
(U
).Unit_Number
);
905 Unit_Name
(Load_Stack
.Table
(U
+ 1).Unit_Number
);
906 Error_Msg
("$ depends on $!", Load_Msg_Sloc
);
909 end Write_Dependency_Chain
;