[multiple changes]
[gcc.git] / gcc / ada / lib-writ.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- L I B . W R I T --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2011, 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 ------------------------------------------------------------------------------
25
26 with ALI; use ALI;
27 with Atree; use Atree;
28 with Casing; use Casing;
29 with Einfo; use Einfo;
30 with Errout; use Errout;
31 with Fname; use Fname;
32 with Fname.UF; use Fname.UF;
33 with Lib.Util; use Lib.Util;
34 with Lib.Xref; use Lib.Xref;
35 use Lib.Xref.Alfa;
36 with Nlists; use Nlists;
37 with Gnatvsn; use Gnatvsn;
38 with Opt; use Opt;
39 with Osint; use Osint;
40 with Osint.C; use Osint.C;
41 with Par;
42 with Par_SCO; use Par_SCO;
43 with Restrict; use Restrict;
44 with Rident; use Rident;
45 with Scn; use Scn;
46 with Sinfo; use Sinfo;
47 with Sinput; use Sinput;
48 with Snames; use Snames;
49 with Stringt; use Stringt;
50 with Tbuild; use Tbuild;
51 with Uname; use Uname;
52
53 with System.Case_Util; use System.Case_Util;
54 with System.WCh_Con; use System.WCh_Con;
55
56 package body Lib.Writ is
57
58 -----------------------
59 -- Local Subprograms --
60 -----------------------
61
62 procedure Write_Unit_Name (N : Node_Id);
63 -- Used to write out the unit name for R (pragma Restriction) lines
64 -- for uses of Restriction (No_Dependence => unit-name).
65
66 ----------------------------------
67 -- Add_Preprocessing_Dependency --
68 ----------------------------------
69
70 procedure Add_Preprocessing_Dependency (S : Source_File_Index) is
71 begin
72 Units.Increment_Last;
73 Units.Table (Units.Last) :=
74 (Unit_File_Name => File_Name (S),
75 Unit_Name => No_Unit_Name,
76 Expected_Unit => No_Unit_Name,
77 Source_Index => S,
78 Cunit => Empty,
79 Cunit_Entity => Empty,
80 Dependency_Num => 0,
81 Dynamic_Elab => False,
82 Fatal_Error => False,
83 Generate_Code => False,
84 Has_Allocator => False,
85 Has_RACW => False,
86 Is_Compiler_Unit => False,
87 Ident_String => Empty,
88 Loading => False,
89 Main_Priority => -1,
90 Main_CPU => -1,
91 Munit_Index => 0,
92 Serial_Number => 0,
93 Version => 0,
94 Error_Location => No_Location,
95 OA_Setting => 'O');
96 end Add_Preprocessing_Dependency;
97
98 ------------------------------
99 -- Ensure_System_Dependency --
100 ------------------------------
101
102 procedure Ensure_System_Dependency is
103 System_Uname : Unit_Name_Type;
104 -- Unit name for system spec if needed for dummy entry
105
106 System_Fname : File_Name_Type;
107 -- File name for system spec if needed for dummy entry
108
109 begin
110 -- Nothing to do if we already compiled System
111
112 for Unum in Units.First .. Last_Unit loop
113 if Units.Table (Unum).Source_Index = System_Source_File_Index then
114 return;
115 end if;
116 end loop;
117
118 -- If no entry for system.ads in the units table, then add a entry
119 -- to the units table for system.ads, which will be referenced when
120 -- the ali file is generated. We need this because every unit depends
121 -- on system as a result of Targparm scanning the system.ads file to
122 -- determine the target dependent parameters for the compilation.
123
124 Name_Len := 6;
125 Name_Buffer (1 .. 6) := "system";
126 System_Uname := Name_To_Unit_Name (Name_Enter);
127 System_Fname := File_Name (System_Source_File_Index);
128
129 Units.Increment_Last;
130 Units.Table (Units.Last) := (
131 Unit_File_Name => System_Fname,
132 Unit_Name => System_Uname,
133 Expected_Unit => System_Uname,
134 Source_Index => System_Source_File_Index,
135 Cunit => Empty,
136 Cunit_Entity => Empty,
137 Dependency_Num => 0,
138 Dynamic_Elab => False,
139 Fatal_Error => False,
140 Generate_Code => False,
141 Has_Allocator => False,
142 Has_RACW => False,
143 Is_Compiler_Unit => False,
144 Ident_String => Empty,
145 Loading => False,
146 Main_Priority => -1,
147 Main_CPU => -1,
148 Munit_Index => 0,
149 Serial_Number => 0,
150 Version => 0,
151 Error_Location => No_Location,
152 OA_Setting => 'O');
153
154 -- Parse system.ads so that the checksum is set right
155 -- Style checks are not applied.
156
157 declare
158 Save_Mindex : constant Nat := Multiple_Unit_Index;
159 Save_Style : constant Boolean := Style_Check;
160 begin
161 Multiple_Unit_Index := 0;
162 Style_Check := False;
163 Initialize_Scanner (Units.Last, System_Source_File_Index);
164 Discard_List (Par (Configuration_Pragmas => False));
165 Style_Check := Save_Style;
166 Multiple_Unit_Index := Save_Mindex;
167 end;
168 end Ensure_System_Dependency;
169
170 ---------------
171 -- Write_ALI --
172 ---------------
173
174 procedure Write_ALI (Object : Boolean) is
175
176 ----------------
177 -- Local Data --
178 ----------------
179
180 Last_Unit : constant Unit_Number_Type := Units.Last;
181 -- Record unit number of last unit. We capture this in case we
182 -- have to add a dummy entry to the unit table for package System.
183
184 With_Flags : array (Units.First .. Last_Unit) of Boolean;
185 -- Array of flags to show which units are with'ed
186
187 Elab_Flags : array (Units.First .. Last_Unit) of Boolean;
188 -- Array of flags to show which units have pragma Elaborate set
189
190 Elab_All_Flags : array (Units.First .. Last_Unit) of Boolean;
191 -- Array of flags to show which units have pragma Elaborate All set
192
193 Elab_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
194 -- Array of flags to show which units have Elaborate_Desirable set
195
196 Elab_All_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
197 -- Array of flags to show which units have Elaborate_All_Desirable set
198
199 Sdep_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 2));
200 -- Sorted table of source dependencies. One extra entry in case we
201 -- have to add a dummy entry for System.
202
203 Num_Sdep : Nat := 0;
204 -- Number of active entries in Sdep_Table
205
206 flag_compare_debug : Int;
207 pragma Import (C, flag_compare_debug);
208 -- Import from toplev.c
209
210 -----------------------
211 -- Local Subprograms --
212 -----------------------
213
214 procedure Collect_Withs (Cunit : Node_Id);
215 -- Collect with lines for entries in the context clause of the
216 -- given compilation unit, Cunit.
217
218 procedure Update_Tables_From_ALI_File;
219 -- Given an up to date ALI file (see Up_To_Date_ALI_file_Exists
220 -- function), update tables from the ALI information, including
221 -- specifically the Compilation_Switches table.
222
223 function Up_To_Date_ALI_File_Exists return Boolean;
224 -- If there exists an ALI file that is up to date, then this function
225 -- initializes the tables in the ALI spec to contain information on
226 -- this file (using Scan_ALI) and returns True. If no file exists,
227 -- or the file is not up to date, then False is returned.
228
229 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type);
230 -- Write out the library information for one unit for which code is
231 -- generated (includes unit line and with lines).
232
233 procedure Write_With_Lines;
234 -- Write out with lines collected by calls to Collect_Withs
235
236 -------------------
237 -- Collect_Withs --
238 -------------------
239
240 procedure Collect_Withs (Cunit : Node_Id) is
241 Item : Node_Id;
242 Unum : Unit_Number_Type;
243
244 begin
245 Item := First (Context_Items (Cunit));
246 while Present (Item) loop
247
248 -- Process with clause
249
250 -- Ada 2005 (AI-50217): limited with_clauses do not create
251 -- dependencies, but must be recorded as components of the
252 -- partition, in case there is no regular with_clause for
253 -- the unit anywhere else.
254
255 if Nkind (Item) = N_With_Clause then
256 Unum := Get_Cunit_Unit_Number (Library_Unit (Item));
257 With_Flags (Unum) := True;
258
259 if not Limited_Present (Item) then
260 if Elaborate_Present (Item) then
261 Elab_Flags (Unum) := True;
262 end if;
263
264 if Elaborate_All_Present (Item) then
265 Elab_All_Flags (Unum) := True;
266 end if;
267
268 if Elaborate_All_Desirable (Item) then
269 Elab_All_Des_Flags (Unum) := True;
270 end if;
271
272 if Elaborate_Desirable (Item) then
273 Elab_Des_Flags (Unum) := True;
274 end if;
275
276 else
277 Set_From_With_Type (Cunit_Entity (Unum));
278 end if;
279 end if;
280
281 Next (Item);
282 end loop;
283 end Collect_Withs;
284
285 --------------------------------
286 -- Up_To_Date_ALI_File_Exists --
287 --------------------------------
288
289 function Up_To_Date_ALI_File_Exists return Boolean is
290 Name : File_Name_Type;
291 Text : Text_Buffer_Ptr;
292 Id : Sdep_Id;
293 Sind : Source_File_Index;
294
295 begin
296 Opt.Check_Object_Consistency := True;
297 Read_Library_Info (Name, Text);
298
299 -- Return if we could not find an ALI file
300
301 if Text = null then
302 return False;
303 end if;
304
305 -- Return if ALI file has bad format
306
307 Initialize_ALI;
308
309 if Scan_ALI (Name, Text, False, Err => True) = No_ALI_Id then
310 return False;
311 end if;
312
313 -- If we have an OK ALI file, check if it is up to date
314 -- Note that we assume that the ALI read has all the entries
315 -- we have in our table, plus some additional ones (that can
316 -- come from expansion).
317
318 Id := First_Sdep_Entry;
319 for J in 1 .. Num_Sdep loop
320 Sind := Units.Table (Sdep_Table (J)).Source_Index;
321
322 while Sdep.Table (Id).Sfile /= File_Name (Sind) loop
323 if Id = Sdep.Last then
324 return False;
325 else
326 Id := Id + 1;
327 end if;
328 end loop;
329
330 if Sdep.Table (Id).Stamp /= Time_Stamp (Sind) then
331 return False;
332 end if;
333 end loop;
334
335 return True;
336 end Up_To_Date_ALI_File_Exists;
337
338 ---------------------------------
339 -- Update_Tables_From_ALI_File --
340 ---------------------------------
341
342 procedure Update_Tables_From_ALI_File is
343 begin
344 -- Build Compilation_Switches table
345
346 Compilation_Switches.Init;
347
348 for J in First_Arg_Entry .. Args.Last loop
349 Compilation_Switches.Increment_Last;
350 Compilation_Switches.Table (Compilation_Switches.Last) :=
351 Args.Table (J);
352 end loop;
353 end Update_Tables_From_ALI_File;
354
355 ----------------------------
356 -- Write_Unit_Information --
357 ----------------------------
358
359 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type) is
360 Unode : constant Node_Id := Cunit (Unit_Num);
361 Ukind : constant Node_Kind := Nkind (Unit (Unode));
362 Uent : constant Entity_Id := Cunit_Entity (Unit_Num);
363 Pnode : Node_Id;
364
365 begin
366 Write_Info_Initiate ('U');
367 Write_Info_Char (' ');
368 Write_Info_Name (Unit_Name (Unit_Num));
369 Write_Info_Tab (25);
370 Write_Info_Name (Unit_File_Name (Unit_Num));
371
372 Write_Info_Tab (49);
373 Write_Info_Str (Version_Get (Unit_Num));
374
375 -- Add BD parameter if Elaborate_Body pragma desirable
376
377 if Ekind (Uent) = E_Package
378 and then Elaborate_Body_Desirable (Uent)
379 then
380 Write_Info_Str (" BD");
381 end if;
382
383 -- Add BN parameter if body needed for SAL
384
385 if (Is_Subprogram (Uent)
386 or else Ekind (Uent) = E_Package
387 or else Is_Generic_Unit (Uent))
388 and then Body_Needed_For_SAL (Uent)
389 then
390 Write_Info_Str (" BN");
391 end if;
392
393 if Dynamic_Elab (Unit_Num) then
394 Write_Info_Str (" DE");
395 end if;
396
397 -- Set the Elaborate_Body indication if either an explicit pragma
398 -- was present, or if this is an instantiation.
399
400 if Has_Pragma_Elaborate_Body (Uent)
401 or else (Ukind = N_Package_Declaration
402 and then Is_Generic_Instance (Uent)
403 and then Present (Corresponding_Body (Unit (Unode))))
404 then
405 Write_Info_Str (" EB");
406 end if;
407
408 -- Now see if we should tell the binder that an elaboration entity
409 -- is present, which must be set to true during elaboration.
410 -- We generate the indication if the following condition is met:
411
412 -- If this is a spec ...
413
414 if (Is_Subprogram (Uent)
415 or else
416 Ekind (Uent) = E_Package
417 or else
418 Is_Generic_Unit (Uent))
419
420 -- and an elaboration entity was declared ...
421
422 and then Present (Elaboration_Entity (Uent))
423
424 -- and either the elaboration flag is required ...
425
426 and then
427 (Elaboration_Entity_Required (Uent)
428
429 -- or this unit has elaboration code ...
430
431 or else not Has_No_Elaboration_Code (Unode)
432
433 -- or this unit has a separate body and this
434 -- body has elaboration code.
435
436 or else
437 (Ekind (Uent) = E_Package
438 and then Present (Body_Entity (Uent))
439 and then
440 not Has_No_Elaboration_Code
441 (Parent
442 (Declaration_Node
443 (Body_Entity (Uent))))))
444 then
445 if Convention (Uent) = Convention_CIL then
446
447 -- Special case for generic CIL packages which never have
448 -- elaboration code
449
450 Write_Info_Str (" NE");
451
452 else
453 Write_Info_Str (" EE");
454 end if;
455 end if;
456
457 if Has_No_Elaboration_Code (Unode) then
458 Write_Info_Str (" NE");
459 end if;
460
461 Write_Info_Str (" O");
462 Write_Info_Char (OA_Setting (Unit_Num));
463
464 if Ekind_In (Uent, E_Package, E_Package_Body)
465 and then Present (Finalizer (Uent))
466 then
467 Write_Info_Str (" PF");
468 end if;
469
470 if Is_Preelaborated (Uent) then
471 Write_Info_Str (" PR");
472 end if;
473
474 if Is_Pure (Uent) then
475 Write_Info_Str (" PU");
476 end if;
477
478 if Has_RACW (Unit_Num) then
479 Write_Info_Str (" RA");
480 end if;
481
482 if Is_Remote_Call_Interface (Uent) then
483 Write_Info_Str (" RC");
484 end if;
485
486 if Is_Remote_Types (Uent) then
487 Write_Info_Str (" RT");
488 end if;
489
490 if Is_Shared_Passive (Uent) then
491 Write_Info_Str (" SP");
492 end if;
493
494 if Ukind = N_Subprogram_Declaration
495 or else Ukind = N_Subprogram_Body
496 then
497 Write_Info_Str (" SU");
498
499 elsif Ukind = N_Package_Declaration
500 or else
501 Ukind = N_Package_Body
502 then
503 -- If this is a wrapper package for a subprogram instantiation,
504 -- the user view is the subprogram. Note that in this case the
505 -- ali file contains both the spec and body of the instance.
506
507 if Is_Wrapper_Package (Uent) then
508 Write_Info_Str (" SU");
509 else
510 Write_Info_Str (" PK");
511 end if;
512
513 elsif Ukind = N_Generic_Package_Declaration then
514 Write_Info_Str (" PK");
515
516 end if;
517
518 if Ukind in N_Generic_Declaration
519 or else
520 (Present (Library_Unit (Unode))
521 and then
522 Nkind (Unit (Library_Unit (Unode))) in N_Generic_Declaration)
523 then
524 Write_Info_Str (" GE");
525 end if;
526
527 if not Is_Internal_File_Name (Unit_File_Name (Unit_Num), True) then
528 case Identifier_Casing (Source_Index (Unit_Num)) is
529 when All_Lower_Case => Write_Info_Str (" IL");
530 when All_Upper_Case => Write_Info_Str (" IU");
531 when others => null;
532 end case;
533
534 case Keyword_Casing (Source_Index (Unit_Num)) is
535 when Mixed_Case => Write_Info_Str (" KM");
536 when All_Upper_Case => Write_Info_Str (" KU");
537 when others => null;
538 end case;
539 end if;
540
541 if Initialize_Scalars or else Invalid_Value_Used then
542 Write_Info_Str (" IS");
543 end if;
544
545 Write_Info_EOL;
546
547 -- Generate with lines, first those that are directly with'ed
548
549 for J in With_Flags'Range loop
550 With_Flags (J) := False;
551 Elab_Flags (J) := False;
552 Elab_All_Flags (J) := False;
553 Elab_Des_Flags (J) := False;
554 Elab_All_Des_Flags (J) := False;
555 end loop;
556
557 Collect_Withs (Unode);
558
559 -- For a body, we must also check for any subunits which belong to
560 -- it and which have context clauses of their own, since these
561 -- with'ed units are part of its own elaboration dependencies.
562
563 if Nkind (Unit (Unode)) in N_Unit_Body then
564 for S in Units.First .. Last_Unit loop
565
566 -- We are only interested in subunits.
567 -- For preproc. data and def. files, Cunit is Empty, so
568 -- we need to test that first.
569
570 if Cunit (S) /= Empty
571 and then Nkind (Unit (Cunit (S))) = N_Subunit
572 then
573 Pnode := Library_Unit (Cunit (S));
574
575 -- In gnatc mode, the errors in the subunits will not
576 -- have been recorded, but the analysis of the subunit
577 -- may have failed. There is no information to add to
578 -- ALI file in this case.
579
580 if No (Pnode) then
581 exit;
582 end if;
583
584 -- Find ultimate parent of the subunit
585
586 while Nkind (Unit (Pnode)) = N_Subunit loop
587 Pnode := Library_Unit (Pnode);
588 end loop;
589
590 -- See if it belongs to current unit, and if so, include
591 -- its with_clauses.
592
593 if Pnode = Unode then
594 Collect_Withs (Cunit (S));
595 end if;
596 end if;
597 end loop;
598 end if;
599
600 Write_With_Lines;
601
602 -- Output linker option lines
603
604 for J in 1 .. Linker_Option_Lines.Last loop
605 declare
606 S : Linker_Option_Entry renames Linker_Option_Lines.Table (J);
607 begin
608 if S.Unit = Unit_Num then
609 Write_Info_Initiate ('L');
610 Write_Info_Char (' ');
611 Write_Info_Slit (S.Option);
612 Write_Info_EOL;
613 end if;
614 end;
615 end loop;
616
617 -- Output notes
618
619 for J in 1 .. Notes.Last loop
620 declare
621 N : constant Node_Id := Notes.Table (J).Pragma_Node;
622 L : constant Source_Ptr := Sloc (N);
623 U : constant Unit_Number_Type := Notes.Table (J).Unit;
624 C : Character;
625
626 begin
627 if U = Unit_Num then
628 Write_Info_Initiate ('N');
629 Write_Info_Char (' ');
630
631 case Chars (Pragma_Identifier (N)) is
632 when Name_Annotate =>
633 C := 'A';
634 when Name_Comment =>
635 C := 'C';
636 when Name_Ident =>
637 C := 'I';
638 when Name_Title =>
639 C := 'T';
640 when Name_Subtitle =>
641 C := 'S';
642 when others =>
643 raise Program_Error;
644 end case;
645
646 Write_Info_Char (C);
647 Write_Info_Int (Int (Get_Logical_Line_Number (L)));
648 Write_Info_Char (':');
649 Write_Info_Int (Int (Get_Column_Number (L)));
650
651 declare
652 A : Node_Id;
653
654 begin
655 A := First (Pragma_Argument_Associations (N));
656 while Present (A) loop
657 Write_Info_Char (' ');
658
659 if Chars (A) /= No_Name then
660 Write_Info_Name (Chars (A));
661 Write_Info_Char (':');
662 end if;
663
664 declare
665 Expr : constant Node_Id := Expression (A);
666
667 begin
668 if Nkind (Expr) = N_Identifier then
669 Write_Info_Name (Chars (Expr));
670
671 elsif Nkind (Expr) = N_Integer_Literal
672 and then Is_Static_Expression (Expr)
673 then
674 Write_Info_Uint (Intval (Expr));
675
676 elsif Nkind (Expr) = N_String_Literal
677 and then Is_Static_Expression (Expr)
678 then
679 Write_Info_Slit (Strval (Expr));
680
681 else
682 Write_Info_Str ("<expr>");
683 end if;
684 end;
685
686 Next (A);
687 end loop;
688 end;
689
690 Write_Info_EOL;
691 end if;
692 end;
693 end loop;
694 end Write_Unit_Information;
695
696 ----------------------
697 -- Write_With_Lines --
698 ----------------------
699
700 procedure Write_With_Lines is
701 With_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 1));
702 Num_Withs : Int := 0;
703 Unum : Unit_Number_Type;
704 Cunit : Node_Id;
705 Uname : Unit_Name_Type;
706 Fname : File_Name_Type;
707 Pname : constant Unit_Name_Type :=
708 Get_Parent_Spec_Name (Unit_Name (Main_Unit));
709 Body_Fname : File_Name_Type;
710 Body_Index : Nat;
711
712 procedure Write_With_File_Names
713 (Nam : in out File_Name_Type;
714 Idx : Nat);
715 -- Write source file name Nam and ALI file name for unit index Idx.
716 -- Possibly change Nam to lowercase (generating a new file name).
717
718 --------------------------
719 -- Write_With_File_Name --
720 --------------------------
721
722 procedure Write_With_File_Names
723 (Nam : in out File_Name_Type;
724 Idx : Nat)
725 is
726 begin
727 if not File_Names_Case_Sensitive then
728 Get_Name_String (Nam);
729 To_Lower (Name_Buffer (1 .. Name_Len));
730 Nam := Name_Find;
731 end if;
732
733 Write_Info_Name (Nam);
734 Write_Info_Tab (49);
735 Write_Info_Name (Lib_File_Name (Nam, Idx));
736 end Write_With_File_Names;
737
738 -- Start of processing for Write_With_Lines
739
740 begin
741 -- Loop to build the with table. A with on the main unit itself
742 -- is ignored (AARM 10.2(14a)). Such a with-clause can occur if
743 -- the main unit is a subprogram with no spec, and a subunit of
744 -- it unnecessarily withs the parent.
745
746 for J in Units.First + 1 .. Last_Unit loop
747
748 -- Add element to with table if it is with'ed or if it is the
749 -- parent spec of the main unit (case of main unit is a child
750 -- unit). The latter with is not needed for semantic purposes,
751 -- but is required by the binder for elaboration purposes.
752 -- For preproc. data and def. files, there is no Unit_Name,
753 -- check for that first.
754
755 if Unit_Name (J) /= No_Unit_Name
756 and then (With_Flags (J) or else Unit_Name (J) = Pname)
757 then
758 Num_Withs := Num_Withs + 1;
759 With_Table (Num_Withs) := J;
760 end if;
761 end loop;
762
763 -- Sort and output the table
764
765 Sort (With_Table (1 .. Num_Withs));
766
767 for J in 1 .. Num_Withs loop
768 Unum := With_Table (J);
769 Cunit := Units.Table (Unum).Cunit;
770 Uname := Units.Table (Unum).Unit_Name;
771 Fname := Units.Table (Unum).Unit_File_Name;
772
773 if Ekind (Cunit_Entity (Unum)) = E_Package
774 and then From_With_Type (Cunit_Entity (Unum))
775 then
776 Write_Info_Initiate ('Y');
777 else
778 Write_Info_Initiate ('W');
779 end if;
780
781 Write_Info_Char (' ');
782 Write_Info_Name (Uname);
783
784 -- Now we need to figure out the names of the files that contain
785 -- the with'ed unit. These will usually be the files for the body,
786 -- except in the case of a package that has no body. Note that we
787 -- have a specific exemption here for predefined library generics
788 -- (see comments for Generic_May_Lack_ALI). We do not generate
789 -- dependency upon the ALI file for such units. Older compilers
790 -- used to not support generating code (and ALI) for generics, and
791 -- we want to avoid having different processing (namely, different
792 -- lists of files to be compiled) for different stages of the
793 -- bootstrap.
794
795 if not ((Nkind (Unit (Cunit)) in N_Generic_Declaration
796 or else
797 Nkind (Unit (Cunit)) in N_Generic_Renaming_Declaration)
798 and then Generic_May_Lack_ALI (Fname))
799 then
800 Write_Info_Tab (25);
801
802 if Is_Spec_Name (Uname) then
803 Body_Fname :=
804 Get_File_Name
805 (Get_Body_Name (Uname),
806 Subunit => False, May_Fail => True);
807
808 Body_Index :=
809 Get_Unit_Index
810 (Get_Body_Name (Uname));
811
812 if Body_Fname = No_File then
813 Body_Fname := Get_File_Name (Uname, Subunit => False);
814 Body_Index := Get_Unit_Index (Uname);
815 end if;
816
817 else
818 Body_Fname := Get_File_Name (Uname, Subunit => False);
819 Body_Index := Get_Unit_Index (Uname);
820 end if;
821
822 -- A package is considered to have a body if it requires
823 -- a body or if a body is present in Ada 83 mode.
824
825 if Body_Required (Cunit)
826 or else (Ada_Version = Ada_83
827 and then Full_Source_Name (Body_Fname) /= No_File)
828 then
829 Write_With_File_Names (Body_Fname, Body_Index);
830 else
831 Write_With_File_Names (Fname, Munit_Index (Unum));
832 end if;
833
834 if Ekind (Cunit_Entity (Unum)) = E_Package
835 and then From_With_Type (Cunit_Entity (Unum))
836 then
837 null;
838 else
839 if Elab_Flags (Unum) then
840 Write_Info_Str (" E");
841 end if;
842
843 if Elab_All_Flags (Unum) then
844 Write_Info_Str (" EA");
845 end if;
846
847 if Elab_Des_Flags (Unum) then
848 Write_Info_Str (" ED");
849 end if;
850
851 if Elab_All_Des_Flags (Unum) then
852 Write_Info_Str (" AD");
853 end if;
854 end if;
855 end if;
856
857 Write_Info_EOL;
858 end loop;
859 end Write_With_Lines;
860
861 -- Start of processing for Write_ALI
862
863 begin
864 -- We never write an ALI file if the original operating mode was
865 -- syntax-only (-gnats switch used in compiler invocation line)
866
867 if Original_Operating_Mode = Check_Syntax
868 or flag_compare_debug /= 0
869 then
870 return;
871 end if;
872
873 -- Generation of ALI files may be disabled, e.g. for formal verification
874 -- back-end.
875
876 if Disable_ALI_File then
877 return;
878 end if;
879
880 -- Build sorted source dependency table. We do this right away, because
881 -- it is referenced by Up_To_Date_ALI_File_Exists.
882
883 for Unum in Units.First .. Last_Unit loop
884 if Cunit_Entity (Unum) = Empty
885 or else not From_With_Type (Cunit_Entity (Unum))
886 then
887 Num_Sdep := Num_Sdep + 1;
888 Sdep_Table (Num_Sdep) := Unum;
889 end if;
890 end loop;
891
892 -- Sort the table so that the D lines are in order
893
894 Lib.Sort (Sdep_Table (1 .. Num_Sdep));
895
896 -- If we are not generating code, and there is an up to date ALI file
897 -- file accessible, read it, and acquire the compilation arguments from
898 -- this file.
899
900 if Operating_Mode /= Generate_Code then
901 if Up_To_Date_ALI_File_Exists then
902 Update_Tables_From_ALI_File;
903 return;
904 end if;
905 end if;
906
907 -- Otherwise acquire compilation arguments and prepare to write
908 -- out a new ali file.
909
910 Create_Output_Library_Info;
911
912 -- Output version line
913
914 Write_Info_Initiate ('V');
915 Write_Info_Str (" """);
916 Write_Info_Str (Verbose_Library_Version);
917 Write_Info_Char ('"');
918
919 Write_Info_EOL;
920
921 -- Output main program line if this is acceptable main program
922
923 Output_Main_Program_Line : declare
924 U : Node_Id := Unit (Units.Table (Main_Unit).Cunit);
925 S : Node_Id;
926
927 procedure M_Parameters;
928 -- Output parameters for main program line
929
930 ------------------
931 -- M_Parameters --
932 ------------------
933
934 procedure M_Parameters is
935 begin
936 if Main_Priority (Main_Unit) /= Default_Main_Priority then
937 Write_Info_Char (' ');
938 Write_Info_Nat (Main_Priority (Main_Unit));
939 end if;
940
941 if Opt.Time_Slice_Set then
942 Write_Info_Str (" T=");
943 Write_Info_Nat (Opt.Time_Slice_Value);
944 end if;
945
946 if Has_Allocator (Main_Unit) then
947 Write_Info_Str (" AB");
948 end if;
949
950 if Main_CPU (Main_Unit) /= Default_Main_CPU then
951 Write_Info_Str (" C=");
952 Write_Info_Nat (Main_CPU (Main_Unit));
953 end if;
954
955 Write_Info_Str (" W=");
956 Write_Info_Char
957 (WC_Encoding_Letters (Wide_Character_Encoding_Method));
958
959 Write_Info_EOL;
960 end M_Parameters;
961
962 -- Start of processing for Output_Main_Program_Line
963
964 begin
965 if Nkind (U) = N_Subprogram_Body
966 or else
967 (Nkind (U) = N_Package_Body
968 and then
969 Nkind (Original_Node (U)) in N_Subprogram_Instantiation)
970 then
971 -- If the unit is a subprogram instance, the entity for the
972 -- subprogram is the alias of the visible entity, which is the
973 -- related instance of the wrapper package. We retrieve the
974 -- subprogram declaration of the desired entity.
975
976 if Nkind (U) = N_Package_Body then
977 U := Parent (Parent (
978 Alias (Related_Instance (Defining_Unit_Name
979 (Specification (Unit (Library_Unit (Parent (U)))))))));
980 end if;
981
982 S := Specification (U);
983
984 if No (Parameter_Specifications (S)) then
985 if Nkind (S) = N_Procedure_Specification then
986 Write_Info_Initiate ('M');
987 Write_Info_Str (" P");
988 M_Parameters;
989
990 else
991 declare
992 Nam : Node_Id := Defining_Unit_Name (S);
993
994 begin
995 -- If it is a child unit, get its simple name
996
997 if Nkind (Nam) = N_Defining_Program_Unit_Name then
998 Nam := Defining_Identifier (Nam);
999 end if;
1000
1001 if Is_Integer_Type (Etype (Nam)) then
1002 Write_Info_Initiate ('M');
1003 Write_Info_Str (" F");
1004 M_Parameters;
1005 end if;
1006 end;
1007 end if;
1008 end if;
1009 end if;
1010 end Output_Main_Program_Line;
1011
1012 -- Write command argument ('A') lines
1013
1014 for A in 1 .. Compilation_Switches.Last loop
1015 Write_Info_Initiate ('A');
1016 Write_Info_Char (' ');
1017 Write_Info_Str (Compilation_Switches.Table (A).all);
1018 Write_Info_Terminate;
1019 end loop;
1020
1021 -- Output parameters ('P') line
1022
1023 Write_Info_Initiate ('P');
1024
1025 if Compilation_Errors then
1026 Write_Info_Str (" CE");
1027 end if;
1028
1029 if Opt.Detect_Blocking then
1030 Write_Info_Str (" DB");
1031 end if;
1032
1033 if Opt.Float_Format /= ' ' then
1034 Write_Info_Str (" F");
1035
1036 if Opt.Float_Format = 'I' then
1037 Write_Info_Char ('I');
1038
1039 elsif Opt.Float_Format_Long = 'D' then
1040 Write_Info_Char ('D');
1041
1042 else
1043 Write_Info_Char ('G');
1044 end if;
1045 end if;
1046
1047 if Tasking_Used
1048 and then not Is_Predefined_File_Name (Unit_File_Name (Main_Unit))
1049 then
1050 if Locking_Policy /= ' ' then
1051 Write_Info_Str (" L");
1052 Write_Info_Char (Locking_Policy);
1053 end if;
1054
1055 if Queuing_Policy /= ' ' then
1056 Write_Info_Str (" Q");
1057 Write_Info_Char (Queuing_Policy);
1058 end if;
1059
1060 if Task_Dispatching_Policy /= ' ' then
1061 Write_Info_Str (" T");
1062 Write_Info_Char (Task_Dispatching_Policy);
1063 Write_Info_Char (' ');
1064 end if;
1065 end if;
1066
1067 if not Object then
1068 Write_Info_Str (" NO");
1069 end if;
1070
1071 if No_Run_Time_Mode then
1072 Write_Info_Str (" NR");
1073 end if;
1074
1075 if Normalize_Scalars then
1076 Write_Info_Str (" NS");
1077 end if;
1078
1079 if Sec_Stack_Used then
1080 Write_Info_Str (" SS");
1081 end if;
1082
1083 if Unreserve_All_Interrupts then
1084 Write_Info_Str (" UA");
1085 end if;
1086
1087 if Exception_Mechanism = Back_End_Exceptions then
1088 Write_Info_Str (" ZX");
1089 end if;
1090
1091 Write_Info_EOL;
1092
1093 -- Before outputting the restrictions line, update the setting of
1094 -- the No_Elaboration_Code flag. Violations of this restriction
1095 -- cannot be detected until after the backend has been called since
1096 -- it is the backend that sets this flag. We have to check all units
1097 -- for which we have generated code
1098
1099 for Unit in Units.First .. Last_Unit loop
1100 if Units.Table (Unit).Generate_Code
1101 or else Unit = Main_Unit
1102 then
1103 if not Has_No_Elaboration_Code (Cunit (Unit)) then
1104 Main_Restrictions.Violated (No_Elaboration_Code) := True;
1105 end if;
1106 end if;
1107 end loop;
1108
1109 -- Output first restrictions line
1110
1111 Write_Info_Initiate ('R');
1112 Write_Info_Char (' ');
1113
1114 -- First the information for the boolean restrictions
1115
1116 for R in All_Boolean_Restrictions loop
1117 if Main_Restrictions.Set (R)
1118 and then not Restriction_Warnings (R)
1119 then
1120 Write_Info_Char ('r');
1121 elsif Main_Restrictions.Violated (R) then
1122 Write_Info_Char ('v');
1123 else
1124 Write_Info_Char ('n');
1125 end if;
1126 end loop;
1127
1128 -- And now the information for the parameter restrictions
1129
1130 for RP in All_Parameter_Restrictions loop
1131 if Main_Restrictions.Set (RP)
1132 and then not Restriction_Warnings (RP)
1133 then
1134 Write_Info_Char ('r');
1135 Write_Info_Nat (Nat (Main_Restrictions.Value (RP)));
1136 else
1137 Write_Info_Char ('n');
1138 end if;
1139
1140 if not Main_Restrictions.Violated (RP)
1141 or else RP not in Checked_Parameter_Restrictions
1142 then
1143 Write_Info_Char ('n');
1144 else
1145 Write_Info_Char ('v');
1146 Write_Info_Nat (Nat (Main_Restrictions.Count (RP)));
1147
1148 if Main_Restrictions.Unknown (RP) then
1149 Write_Info_Char ('+');
1150 end if;
1151 end if;
1152 end loop;
1153
1154 Write_Info_EOL;
1155
1156 -- Output R lines for No_Dependence entries
1157
1158 for J in No_Dependence.First .. No_Dependence.Last loop
1159 if In_Extended_Main_Source_Unit (No_Dependence.Table (J).Unit)
1160 and then not No_Dependence.Table (J).Warn
1161 then
1162 Write_Info_Initiate ('R');
1163 Write_Info_Char (' ');
1164 Write_Unit_Name (No_Dependence.Table (J).Unit);
1165 Write_Info_EOL;
1166 end if;
1167 end loop;
1168
1169 -- Output interrupt state lines
1170
1171 for J in Interrupt_States.First .. Interrupt_States.Last loop
1172 Write_Info_Initiate ('I');
1173 Write_Info_Char (' ');
1174 Write_Info_Nat (Interrupt_States.Table (J).Interrupt_Number);
1175 Write_Info_Char (' ');
1176 Write_Info_Char (Interrupt_States.Table (J).Interrupt_State);
1177 Write_Info_Char (' ');
1178 Write_Info_Nat
1179 (Nat (Get_Logical_Line_Number
1180 (Interrupt_States.Table (J).Pragma_Loc)));
1181 Write_Info_EOL;
1182 end loop;
1183
1184 -- Output priority specific dispatching lines
1185
1186 for J in Specific_Dispatching.First .. Specific_Dispatching.Last loop
1187 Write_Info_Initiate ('S');
1188 Write_Info_Char (' ');
1189 Write_Info_Char (Specific_Dispatching.Table (J).Dispatching_Policy);
1190 Write_Info_Char (' ');
1191 Write_Info_Nat (Specific_Dispatching.Table (J).First_Priority);
1192 Write_Info_Char (' ');
1193 Write_Info_Nat (Specific_Dispatching.Table (J).Last_Priority);
1194 Write_Info_Char (' ');
1195 Write_Info_Nat
1196 (Nat (Get_Logical_Line_Number
1197 (Specific_Dispatching.Table (J).Pragma_Loc)));
1198 Write_Info_EOL;
1199 end loop;
1200
1201 -- Loop through file table to output information for all units for which
1202 -- we have generated code, as marked by the Generate_Code flag.
1203
1204 for Unit in Units.First .. Last_Unit loop
1205 if Units.Table (Unit).Generate_Code
1206 or else Unit = Main_Unit
1207 then
1208 Write_Info_EOL; -- blank line
1209 Write_Unit_Information (Unit);
1210 end if;
1211 end loop;
1212
1213 Write_Info_EOL; -- blank line
1214
1215 -- Output external version reference lines
1216
1217 for J in 1 .. Version_Ref.Last loop
1218 Write_Info_Initiate ('E');
1219 Write_Info_Char (' ');
1220
1221 for K in 1 .. String_Length (Version_Ref.Table (J)) loop
1222 Write_Info_Char_Code (Get_String_Char (Version_Ref.Table (J), K));
1223 end loop;
1224
1225 Write_Info_EOL;
1226 end loop;
1227
1228 -- Prepare to output the source dependency lines
1229
1230 declare
1231 Unum : Unit_Number_Type;
1232 -- Number of unit being output
1233
1234 Sind : Source_File_Index;
1235 -- Index of corresponding source file
1236
1237 Fname : File_Name_Type;
1238
1239 begin
1240 for J in 1 .. Num_Sdep loop
1241 Unum := Sdep_Table (J);
1242 Units.Table (Unum).Dependency_Num := J;
1243 Sind := Units.Table (Unum).Source_Index;
1244
1245 Write_Info_Initiate ('D');
1246 Write_Info_Char (' ');
1247
1248 -- Normal case of a unit entry with a source index
1249
1250 if Sind /= No_Source_File then
1251 Fname := File_Name (Sind);
1252
1253 -- Ensure that on platforms where the file names are not
1254 -- case sensitive, the recorded file name is in lower case.
1255
1256 if not File_Names_Case_Sensitive then
1257 Get_Name_String (Fname);
1258 To_Lower (Name_Buffer (1 .. Name_Len));
1259 Fname := Name_Find;
1260 end if;
1261
1262 Write_Info_Name (Fname);
1263 Write_Info_Tab (25);
1264 Write_Info_Str (String (Time_Stamp (Sind)));
1265 Write_Info_Char (' ');
1266 Write_Info_Str (Get_Hex_String (Source_Checksum (Sind)));
1267
1268 -- If subunit, add unit name, omitting the %b at the end
1269
1270 if Present (Cunit (Unum))
1271 and then Nkind (Unit (Cunit (Unum))) = N_Subunit
1272 then
1273 Get_Decoded_Name_String (Unit_Name (Unum));
1274 Write_Info_Char (' ');
1275 Write_Info_Str (Name_Buffer (1 .. Name_Len - 2));
1276 end if;
1277
1278 -- If Source_Reference pragma used output information
1279
1280 if Num_SRef_Pragmas (Sind) > 0 then
1281 Write_Info_Char (' ');
1282
1283 if Num_SRef_Pragmas (Sind) = 1 then
1284 Write_Info_Nat (Int (First_Mapped_Line (Sind)));
1285 else
1286 Write_Info_Nat (0);
1287 end if;
1288
1289 Write_Info_Char (':');
1290 Write_Info_Name (Reference_Name (Sind));
1291 end if;
1292
1293 -- Case where there is no source index (happens for missing
1294 -- files). In this case we write a dummy time stamp.
1295
1296 else
1297 Write_Info_Name (Unit_File_Name (Unum));
1298 Write_Info_Tab (25);
1299 Write_Info_Str (String (Dummy_Time_Stamp));
1300 Write_Info_Char (' ');
1301 Write_Info_Str (Get_Hex_String (0));
1302 end if;
1303
1304 Write_Info_EOL;
1305 end loop;
1306 end;
1307
1308 -- Output cross-references
1309
1310 if Opt.Xref_Active then
1311 Output_References;
1312 end if;
1313
1314 -- Output SCO information if present
1315
1316 if Generate_SCO then
1317 SCO_Output;
1318 end if;
1319
1320 -- Output Alfa information if needed
1321
1322 if Opt.Xref_Active and then Alfa_Mode then
1323 Collect_Alfa (Sdep_Table => Sdep_Table, Num_Sdep => Num_Sdep);
1324 Output_Alfa;
1325 end if;
1326
1327 -- Output final blank line and we are done. This final blank line is
1328 -- probably junk, but we don't feel like making an incompatible change!
1329
1330 Write_Info_Terminate;
1331 Close_Output_Library_Info;
1332 end Write_ALI;
1333
1334 ---------------------
1335 -- Write_Unit_Name --
1336 ---------------------
1337
1338 procedure Write_Unit_Name (N : Node_Id) is
1339 begin
1340 if Nkind (N) = N_Identifier then
1341 Write_Info_Name (Chars (N));
1342
1343 else
1344 pragma Assert (Nkind (N) = N_Selected_Component);
1345 Write_Unit_Name (Prefix (N));
1346 Write_Info_Char ('.');
1347 Write_Unit_Name (Selector_Name (N));
1348 end if;
1349 end Write_Unit_Name;
1350
1351 end Lib.Writ;