Merge -r 127928:132243 from trunk
[official-gcc.git] / gcc / ada / lib-load.adb
blobf439926b4cbaf4087bc5172fe7666111d174c833
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- L I B . L O A D --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2007, 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 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;
34 with Opt; use Opt;
35 with Osint; use Osint;
36 with Osint.C; use Osint.C;
37 with Output; use Output;
38 with Par;
39 with Restrict; use Restrict;
40 with Scn; use Scn;
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);
78 N : File_Name_Type;
79 X : Source_File_Index;
81 begin
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
92 if Name_Len >= 5
93 and then Name_Buffer (Name_Len - 3 .. Name_Len) = ".adb"
94 then
95 Name_Buffer (Name_Len) := 's';
97 -- Change .2.ada to .1.ada (Rational convention)
99 elsif Name_Len >= 7
100 and then Name_Buffer (Name_Len - 5 .. Name_Len) = ".2.ada"
101 then
102 Name_Buffer (Name_Len - 4) := '1';
104 -- Change .ada to _.ada (DEC convention)
106 elsif Name_Len >= 5
107 and then Name_Buffer (Name_Len - 3 .. Name_Len) = ".ada"
108 then
109 Name_Buffer (Name_Len - 3 .. Name_Len + 1) := "_.ada";
110 Name_Len := Name_Len + 1;
112 -- No match, don't make the change
114 else
115 return;
116 end if;
118 -- Try loading the spec
120 N := Name_Find;
121 X := Load_Source_File (N);
123 -- No change if we did not find the spec
125 if X = No_Source_File then
126 return;
127 end if;
129 -- Otherwise modify Main_Unit entry to point to spec
131 U.Unit_File_Name := N;
132 U.Source_Index := X;
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;
145 Cunit : Node_Id;
146 Du_Name : Node_Or_Entity_Id;
147 End_Lab : Node_Id;
148 Save_CS : constant Boolean := Get_Comes_From_Source_Default;
150 begin
151 -- The created dummy package unit does not come from source
153 Set_Comes_From_Source_Default (False);
155 -- Normal package
157 if Nkind (Name (With_Node)) = N_Identifier then
158 Cunit_Entity :=
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);
164 -- Child package
166 else
167 Cunit_Entity :=
168 Make_Defining_Identifier (No_Location,
169 Chars => Chars (Selector_Name (Name (With_Node))));
170 Du_Name :=
171 Make_Defining_Program_Unit_Name (No_Location,
172 Name => New_Copy_Tree (Prefix (Name (With_Node))),
173 Defining_Identifier => Cunit_Entity);
175 Set_Is_Child_Unit (Cunit_Entity);
177 End_Lab :=
178 Make_Designator (No_Location,
179 Name => New_Copy_Tree (Prefix (Name (With_Node))),
180 Identifier => New_Occurrence_Of (Cunit_Entity, No_Location));
181 end if;
183 Set_Scope (Cunit_Entity, Standard_Standard);
185 Cunit :=
186 Make_Compilation_Unit (No_Location,
187 Context_Items => Empty_List,
188 Unit =>
189 Make_Package_Declaration (No_Location,
190 Specification =>
191 Make_Package_Specification (No_Location,
192 Defining_Unit_Name => Du_Name,
193 Visible_Declarations => Empty_List,
194 End_Label => End_Lab)),
195 Aux_Decls_Node =>
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;
206 Unum := Units.Last;
208 Units.Table (Unum) := (
209 Cunit => Cunit,
210 Cunit_Entity => Cunit_Entity,
211 Dependency_Num => 0,
212 Dynamic_Elab => False,
213 Error_Location => Sloc (With_Node),
214 Expected_Unit => Spec_Name,
215 Fatal_Error => True,
216 Generate_Code => False,
217 Has_RACW => False,
218 Is_Compiler_Unit => False,
219 Ident_String => Empty,
220 Loading => False,
221 Main_Priority => Default_Main_Priority,
222 Munit_Index => 0,
223 Serial_Number => 0,
224 Source_Index => No_Source_File,
225 Unit_File_Name => Get_File_Name (Spec_Name, Subunit => False),
226 Unit_Name => Spec_Name,
227 Version => 0);
229 Set_Comes_From_Source_Default (Save_CS);
230 Set_Error_Posted (Cunit_Entity);
231 Set_Error_Posted (Cunit);
232 return Unum;
233 end Create_Dummy_Package_Unit;
235 -----------------------------
236 -- From_Limited_With_Chain --
237 -----------------------------
239 function From_Limited_With_Chain return Boolean is
240 Curr_Num : constant Unit_Number_Type :=
241 Load_Stack.Table (Load_Stack.Last).Unit_Number;
243 begin
244 -- True if the current load operation is through a limited_with clause
245 -- and we are not within a loop of regular with_clauses.
247 for U in reverse Load_Stack.First .. Load_Stack.Last - 1 loop
248 if Load_Stack.Table (U).Unit_Number = Curr_Num then
249 return False;
251 elsif Present (Load_Stack.Table (U).With_Node)
252 and then Limited_Present (Load_Stack.Table (U).With_Node)
253 then
254 return True;
255 end if;
256 end loop;
258 return False;
259 end From_Limited_With_Chain;
261 ----------------
262 -- Initialize --
263 ----------------
265 procedure Initialize is
266 begin
267 Units.Init;
268 Load_Stack.Init;
269 end Initialize;
271 ------------------------
272 -- Initialize_Version --
273 ------------------------
275 procedure Initialize_Version (U : Unit_Number_Type) is
276 begin
277 Units.Table (U).Version := Source_Checksum (Source_Index (U));
278 end Initialize_Version;
280 ----------------------
281 -- Load_Main_Source --
282 ----------------------
284 procedure Load_Main_Source is
285 Fname : File_Name_Type;
286 Version : Word := 0;
288 begin
289 Load_Stack.Increment_Last;
290 Load_Stack.Table (Load_Stack.Last) := (Main_Unit, Empty);
292 -- Initialize unit table entry for Main_Unit. Note that we don't know
293 -- the unit name yet, that gets filled in when the parser parses the
294 -- main unit, at which time a check is made that it matches the main
295 -- file name, and then the Unit_Name field is set. The Cunit and
296 -- Cunit_Entity fields also get filled in later by the parser.
298 Units.Increment_Last;
299 Fname := Next_Main_Source;
301 Units.Table (Main_Unit).Unit_File_Name := Fname;
303 if Fname /= No_File then
304 Main_Source_File := Load_Source_File (Fname);
305 Current_Error_Source_File := Main_Source_File;
307 if Main_Source_File /= No_Source_File then
308 Version := Source_Checksum (Main_Source_File);
309 end if;
311 Units.Table (Main_Unit) := (
312 Cunit => Empty,
313 Cunit_Entity => Empty,
314 Dependency_Num => 0,
315 Dynamic_Elab => False,
316 Error_Location => No_Location,
317 Expected_Unit => No_Unit_Name,
318 Fatal_Error => False,
319 Generate_Code => False,
320 Has_RACW => False,
321 Is_Compiler_Unit => False,
322 Ident_String => Empty,
323 Loading => True,
324 Main_Priority => Default_Main_Priority,
325 Munit_Index => 0,
326 Serial_Number => 0,
327 Source_Index => Main_Source_File,
328 Unit_File_Name => Fname,
329 Unit_Name => No_Unit_Name,
330 Version => Version);
331 end if;
332 end Load_Main_Source;
334 ---------------
335 -- Load_Unit --
336 ---------------
338 function Load_Unit
339 (Load_Name : Unit_Name_Type;
340 Required : Boolean;
341 Error_Node : Node_Id;
342 Subunit : Boolean;
343 Corr_Body : Unit_Number_Type := No_Unit;
344 Renamings : Boolean := False;
345 With_Node : Node_Id := Empty) return Unit_Number_Type
347 Calling_Unit : Unit_Number_Type;
348 Uname_Actual : Unit_Name_Type;
349 Unum : Unit_Number_Type;
350 Unump : Unit_Number_Type;
351 Fname : File_Name_Type;
352 Src_Ind : Source_File_Index;
354 -- Start of processing for Load_Unit
356 begin
357 -- If renamings are allowed and we have a child unit name, then we
358 -- must first load the parent to deal with finding the real name.
360 if Renamings and then Is_Child_Name (Load_Name) then
361 Unump :=
362 Load_Unit
363 (Load_Name => Get_Parent_Spec_Name (Load_Name),
364 Required => Required,
365 Subunit => False,
366 Renamings => True,
367 Error_Node => Error_Node);
369 if Unump = No_Unit then
370 return No_Unit;
371 end if;
373 -- If parent is a renaming, then we use the renamed package as
374 -- the actual parent for the subsequent load operation.
376 if Nkind (Unit (Cunit (Unump))) = N_Package_Renaming_Declaration then
377 Uname_Actual :=
378 New_Child
379 (Load_Name, Get_Unit_Name (Name (Unit (Cunit (Unump)))));
381 -- Save the renaming entity, to establish its visibility when
382 -- installing the context. The implicit with is on this entity,
383 -- not on the package it renames.
385 if Nkind (Error_Node) = N_With_Clause
386 and then Nkind (Name (Error_Node)) = N_Selected_Component
387 then
388 declare
389 Par : Node_Id := Name (Error_Node);
391 begin
392 while Nkind (Par) = N_Selected_Component
393 and then Chars (Selector_Name (Par)) /=
394 Chars (Cunit_Entity (Unump))
395 loop
396 Par := Prefix (Par);
397 end loop;
399 -- Case of some intermediate parent is a renaming
401 if Nkind (Par) = N_Selected_Component then
402 Set_Entity (Selector_Name (Par), Cunit_Entity (Unump));
404 -- Case where the ultimate parent is a renaming
406 else
407 Set_Entity (Par, Cunit_Entity (Unump));
408 end if;
409 end;
410 end if;
412 -- If the parent is not a renaming, then get its name (this may
413 -- be different from the parent spec name obtained above because
414 -- of renamings higher up in the hierarchy).
416 else
417 Uname_Actual := New_Child (Load_Name, Unit_Name (Unump));
418 end if;
420 -- Here if unit to be loaded is not a child unit
422 else
423 Uname_Actual := Load_Name;
424 end if;
426 Fname := Get_File_Name (Uname_Actual, Subunit);
428 if Debug_Flag_L then
429 Write_Eol;
430 Write_Str ("*** Load request for unit: ");
431 Write_Unit_Name (Load_Name);
433 if Required then
434 Write_Str (" (Required = True)");
435 else
436 Write_Str (" (Required = False)");
437 end if;
439 Write_Eol;
441 if Uname_Actual /= Load_Name then
442 Write_Str ("*** Actual unit loaded: ");
443 Write_Unit_Name (Uname_Actual);
444 end if;
445 end if;
447 -- Capture error location if it is for the main unit. The idea is to
448 -- post errors on the main unit location, not the most recent unit.
449 -- Note: Unit_Name (Main_Unit) is not set if we are parsing gnat.adc.
451 if Present (Error_Node)
452 and then Unit_Name (Main_Unit) /= No_Unit_Name
453 then
454 -- It seems like In_Extended_Main_Source_Unit (Error_Node) would
455 -- do the trick here, but that's wrong, it is much too early to
456 -- call this routine. We are still in the parser, and the required
457 -- semantic information is not established yet. So we base the
458 -- judgment on unit names.
460 Get_External_Unit_Name_String (Unit_Name (Main_Unit));
462 declare
463 Main_Unit_Name : constant String := Name_Buffer (1 .. Name_Len);
465 begin
466 Get_External_Unit_Name_String
467 (Unit_Name (Get_Source_Unit (Error_Node)));
469 -- If the two names are identical, then for sure we are part
470 -- of the extended main unit
472 if Main_Unit_Name = Name_Buffer (1 .. Name_Len) then
473 Load_Msg_Sloc := Sloc (Error_Node);
475 -- If the load is called from a with_type clause, the error
476 -- node is correct.
478 -- Otherwise, check for the subunit case, and if so, consider
479 -- we have a match if one name is a prefix of the other name.
481 else
482 if Nkind (Unit (Cunit (Main_Unit))) = N_Subunit
483 or else
484 Nkind (Unit (Cunit (Get_Source_Unit (Error_Node)))) =
485 N_Subunit
486 then
487 Name_Len := Integer'Min (Name_Len, Main_Unit_Name'Length);
489 if Name_Buffer (1 .. Name_Len)
491 Main_Unit_Name (1 .. Name_Len)
492 then
493 Load_Msg_Sloc := Sloc (Error_Node);
494 end if;
495 end if;
496 end if;
497 end;
498 end if;
500 -- If we are generating error messages, then capture calling unit
502 if Present (Error_Node) then
503 Calling_Unit := Get_Source_Unit (Error_Node);
504 else
505 Calling_Unit := No_Unit;
506 end if;
508 -- See if we already have an entry for this unit
510 Unum := Main_Unit;
512 while Unum <= Units.Last loop
513 exit when Uname_Actual = Units.Table (Unum).Unit_Name;
514 Unum := Unum + 1;
515 end loop;
517 -- Whether or not the entry was found, Unum is now the right value,
518 -- since it is one more than Units.Last (i.e. the index of the new
519 -- entry we will create) in the not found case.
521 -- A special check is necessary in the unit not found case. If the unit
522 -- is not found, but the file in which it lives has already been loaded,
523 -- then we have the problem that the file does not contain the unit that
524 -- is needed. We simply treat this as a file not found condition.
526 -- We skip this test in multiple unit per file mode since in this
527 -- case we can have multiple units from the same source file.
529 if Unum > Units.Last and then Get_Unit_Index (Uname_Actual) = 0 then
530 for J in Units.First .. Units.Last loop
531 if Fname = Units.Table (J).Unit_File_Name then
532 if Debug_Flag_L then
533 Write_Str (" file does not contain unit, Unit_Number = ");
534 Write_Int (Int (Unum));
535 Write_Eol;
536 Write_Eol;
537 end if;
539 if Present (Error_Node) then
540 if Is_Predefined_File_Name (Fname) then
541 Error_Msg_Unit_1 := Uname_Actual;
542 Error_Msg
543 ("$$ is not a language defined unit", Load_Msg_Sloc);
544 else
545 Error_Msg_File_1 := Fname;
546 Error_Msg_Unit_1 := Uname_Actual;
547 Error_Msg ("File{ does not contain unit$", Load_Msg_Sloc);
548 end if;
550 Write_Dependency_Chain;
551 return No_Unit;
553 else
554 return No_Unit;
555 end if;
556 end if;
557 end loop;
558 end if;
560 -- If we are proceeding with load, then make load stack entry,
561 -- and indicate the kind of with_clause responsible for the load.
563 Load_Stack.Increment_Last;
564 Load_Stack.Table (Load_Stack.Last) := (Unum, With_Node);
566 -- Case of entry already in table
568 if Unum <= Units.Last then
570 -- Here is where we check for a circular dependency, which is
571 -- an attempt to load a unit which is currently in the process
572 -- of being loaded. We do *not* care about a circular chain that
573 -- leads back to a body, because this kind of circular dependence
574 -- legitimately occurs (e.g. two package bodies that contain
575 -- inlined subprogram referenced by the other).
577 -- Ada 2005 (AI-50217): We also ignore limited_with clauses, because
578 -- their purpose is precisely to create legal circular structures.
580 if Loading (Unum)
581 and then (Is_Spec_Name (Units.Table (Unum).Unit_Name)
582 or else Acts_As_Spec (Units.Table (Unum).Cunit))
583 and then (Nkind (Error_Node) /= N_With_Clause
584 or else not Limited_Present (Error_Node))
585 and then not From_Limited_With_Chain
586 then
587 if Debug_Flag_L then
588 Write_Str (" circular dependency encountered");
589 Write_Eol;
590 end if;
592 if Present (Error_Node) then
593 Error_Msg ("circular unit dependency", Load_Msg_Sloc);
594 Write_Dependency_Chain;
595 else
596 Load_Stack.Decrement_Last;
597 end if;
599 return No_Unit;
600 end if;
602 if Debug_Flag_L then
603 Write_Str (" unit already in file table, Unit_Number = ");
604 Write_Int (Int (Unum));
605 Write_Eol;
606 end if;
608 Load_Stack.Decrement_Last;
609 return Unum;
611 -- Unit is not already in table, so try to open the file
613 else
614 if Debug_Flag_L then
615 Write_Str (" attempt unit load, Unit_Number = ");
616 Write_Int (Int (Unum));
617 Write_Eol;
618 end if;
620 Src_Ind := Load_Source_File (Fname);
622 -- Make a partial entry in the file table, used even in the file not
623 -- found case to print the dependency chain including the last entry
625 Units.Increment_Last;
626 Units.Table (Unum).Unit_Name := Uname_Actual;
628 -- File was found
630 if Src_Ind /= No_Source_File then
631 Units.Table (Unum) := (
632 Cunit => Empty,
633 Cunit_Entity => Empty,
634 Dependency_Num => 0,
635 Dynamic_Elab => False,
636 Error_Location => Sloc (Error_Node),
637 Expected_Unit => Uname_Actual,
638 Fatal_Error => False,
639 Generate_Code => False,
640 Has_RACW => False,
641 Is_Compiler_Unit => False,
642 Ident_String => Empty,
643 Loading => True,
644 Main_Priority => Default_Main_Priority,
645 Munit_Index => 0,
646 Serial_Number => 0,
647 Source_Index => Src_Ind,
648 Unit_File_Name => Fname,
649 Unit_Name => Uname_Actual,
650 Version => Source_Checksum (Src_Ind));
652 -- Parse the new unit
654 declare
655 Save_Index : constant Nat := Multiple_Unit_Index;
656 begin
657 Multiple_Unit_Index := Get_Unit_Index (Uname_Actual);
658 Units.Table (Unum).Munit_Index := Multiple_Unit_Index;
659 Initialize_Scanner (Unum, Source_Index (Unum));
660 Discard_List (Par (Configuration_Pragmas => False));
661 Multiple_Unit_Index := Save_Index;
662 Set_Loading (Unum, False);
663 end;
665 -- If spec is irrelevant, then post errors and quit
667 if Corr_Body /= No_Unit
668 and then Spec_Is_Irrelevant (Unum, Corr_Body)
669 then
670 Error_Msg_File_1 := Unit_File_Name (Corr_Body);
671 Error_Msg
672 ("cannot compile subprogram in file {!", Load_Msg_Sloc);
673 Error_Msg_File_1 := Unit_File_Name (Unum);
674 Error_Msg
675 ("\incorrect spec in file { must be removed first!",
676 Load_Msg_Sloc);
677 return No_Unit;
678 end if;
680 -- If loaded unit had a fatal error, then caller inherits it!
682 if Units.Table (Unum).Fatal_Error
683 and then Present (Error_Node)
684 then
685 Units.Table (Calling_Unit).Fatal_Error := True;
686 end if;
688 -- Remove load stack entry and return the entry in the file table
690 Load_Stack.Decrement_Last;
691 return Unum;
693 -- Case of file not found
695 else
696 if Debug_Flag_L then
697 Write_Str (" file was not found, load failed");
698 Write_Eol;
699 end if;
701 -- Generate message if unit required
703 if Required and then Present (Error_Node) then
704 if Is_Predefined_File_Name (Fname) then
706 -- This is a predefined library unit which is not present
707 -- in the run time. If a predefined unit is not available
708 -- it may very likely be the case that there is also pragma
709 -- Restriction forbidding its usage. This is typically the
710 -- case when building a configurable run time, where the
711 -- usage of certain run-time units units is restricted by
712 -- means of both the corresponding pragma Restriction (such
713 -- as No_Calendar), and by not including the unit. Hence,
714 -- we check whether this predefined unit is forbidden, so
715 -- that the message about the restriction violation is
716 -- generated, if needed.
718 Check_Restricted_Unit (Load_Name, Error_Node);
720 Error_Msg_Unit_1 := Uname_Actual;
721 Error_Msg
722 ("$$ is not a predefined library unit", Load_Msg_Sloc);
724 else
725 Error_Msg_File_1 := Fname;
726 Error_Msg ("file{ not found", Load_Msg_Sloc);
727 end if;
729 Write_Dependency_Chain;
731 -- Remove unit from stack, to avoid cascaded errors on
732 -- subsequent missing files.
734 Load_Stack.Decrement_Last;
735 Units.Decrement_Last;
737 -- If unit not required, remove load stack entry and the junk
738 -- file table entry, and return No_Unit to indicate not found,
740 else
741 Load_Stack.Decrement_Last;
742 Units.Decrement_Last;
743 end if;
745 return No_Unit;
746 end if;
747 end if;
748 end Load_Unit;
750 ------------------------
751 -- Make_Instance_Unit --
752 ------------------------
754 -- If the unit is an instance, it appears as a package declaration, but
755 -- contains both declaration and body of the instance. The body becomes
756 -- the main unit of the compilation, and the declaration is inserted
757 -- at the end of the unit table. The main unit now has the name of a
758 -- body, which is constructed from the name of the original spec,
759 -- and is attached to the compilation node of the original unit. The
760 -- declaration has been attached to a new compilation unit node, and
761 -- code will have to be generated for it.
763 procedure Make_Instance_Unit (N : Node_Id) is
764 Sind : constant Source_File_Index := Source_Index (Main_Unit);
765 begin
766 Units.Increment_Last;
767 Units.Table (Units.Last) := Units.Table (Main_Unit);
768 Units.Table (Units.Last).Cunit := Library_Unit (N);
769 Units.Table (Units.Last).Generate_Code := True;
770 Units.Table (Main_Unit).Cunit := N;
771 Units.Table (Main_Unit).Unit_Name :=
772 Get_Body_Name (Unit_Name (Get_Cunit_Unit_Number (Library_Unit (N))));
773 Units.Table (Main_Unit).Version := Source_Checksum (Sind);
774 end Make_Instance_Unit;
776 ------------------------
777 -- Spec_Is_Irrelevant --
778 ------------------------
780 function Spec_Is_Irrelevant
781 (Spec_Unit : Unit_Number_Type;
782 Body_Unit : Unit_Number_Type) return Boolean
784 Sunit : constant Node_Id := Cunit (Spec_Unit);
785 Bunit : constant Node_Id := Cunit (Body_Unit);
787 begin
788 -- The spec is irrelevant if the body is a subprogram body, and the
789 -- spec is other than a subprogram spec or generic subprogram spec.
790 -- Note that the names must be the same, we don't need to check that,
791 -- because we already know that from the fact that the file names are
792 -- the same.
794 return
795 Nkind (Unit (Bunit)) = N_Subprogram_Body
796 and then Nkind (Unit (Sunit)) /= N_Subprogram_Declaration
797 and then Nkind (Unit (Sunit)) /= N_Generic_Subprogram_Declaration;
798 end Spec_Is_Irrelevant;
800 --------------------
801 -- Version_Update --
802 --------------------
804 procedure Version_Update (U : Node_Id; From : Node_Id) is
805 Unum : constant Unit_Number_Type := Get_Cunit_Unit_Number (U);
806 Fnum : constant Unit_Number_Type := Get_Cunit_Unit_Number (From);
807 begin
808 if Source_Index (Fnum) /= No_Source_File then
809 Units.Table (Unum).Version :=
810 Units.Table (Unum).Version
812 Source_Checksum (Source_Index (Fnum));
813 end if;
814 end Version_Update;
816 ----------------------------
817 -- Write_Dependency_Chain --
818 ----------------------------
820 procedure Write_Dependency_Chain is
821 begin
822 -- The dependency chain is only written if it is at least two entries
823 -- deep, otherwise it is trivial (the main unit depending on a unit
824 -- that it obviously directly depends on).
826 if Load_Stack.Last - 1 > Load_Stack.First then
827 for U in Load_Stack.First .. Load_Stack.Last - 1 loop
828 Error_Msg_Unit_1 :=
829 Unit_Name (Load_Stack.Table (U).Unit_Number);
830 Error_Msg_Unit_2 :=
831 Unit_Name (Load_Stack.Table (U + 1).Unit_Number);
832 Error_Msg ("$ depends on $!", Load_Msg_Sloc);
833 end loop;
834 end if;
835 end Write_Dependency_Chain;
837 end Lib.Load;