f035b45e913315d76b2588a3f801b1a1bfaa7512
[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-2018, 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 Debug; use Debug;
30 with Einfo; use Einfo;
31 with Errout; use Errout;
32 with Fname; use Fname;
33 with Fname.UF; use Fname.UF;
34 with Lib.Util; use Lib.Util;
35 with Lib.Xref; use Lib.Xref;
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 Output; use Output;
42 with Par;
43 with Par_SCO; use Par_SCO;
44 with Restrict; use Restrict;
45 with Rident; use Rident;
46 with Stand; use Stand;
47 with Scn; use Scn;
48 with Sem_Eval; use Sem_Eval;
49 with Sinfo; use Sinfo;
50 with Sinput; use Sinput;
51 with Snames; use Snames;
52 with Stringt; use Stringt;
53 with Tbuild; use Tbuild;
54 with Uname; use Uname;
55
56 with System.Case_Util; use System.Case_Util;
57 with System.WCh_Con; use System.WCh_Con;
58
59 package body Lib.Writ is
60
61 -----------------------
62 -- Local Subprograms --
63 -----------------------
64
65 procedure Write_Unit_Name (N : Node_Id);
66 -- Used to write out the unit name for R (pragma Restriction) lines
67 -- for uses of Restriction (No_Dependence => unit-name).
68
69 ----------------------------------
70 -- Add_Preprocessing_Dependency --
71 ----------------------------------
72
73 procedure Add_Preprocessing_Dependency (S : Source_File_Index) is
74 begin
75 Units.Increment_Last;
76 Units.Table (Units.Last) :=
77 (Unit_File_Name => File_Name (S),
78 Unit_Name => No_Unit_Name,
79 Expected_Unit => No_Unit_Name,
80 Source_Index => S,
81 Cunit => Empty,
82 Cunit_Entity => Empty,
83 Dependency_Num => 0,
84 Dynamic_Elab => False,
85 Fatal_Error => None,
86 Generate_Code => False,
87 Has_RACW => False,
88 Filler => False,
89 Ident_String => Empty,
90 Is_Predefined_Renaming => False,
91 Is_Internal_Unit => False,
92 Is_Predefined_Unit => False,
93 Filler2 => False,
94 Loading => False,
95 Main_Priority => -1,
96 Main_CPU => -1,
97 Munit_Index => 0,
98 No_Elab_Code_All => False,
99 Primary_Stack_Count => 0,
100 Sec_Stack_Count => 0,
101 Serial_Number => 0,
102 Version => 0,
103 Error_Location => No_Location,
104 OA_Setting => 'O');
105 end Add_Preprocessing_Dependency;
106
107 ------------------------------
108 -- Ensure_System_Dependency --
109 ------------------------------
110
111 procedure Ensure_System_Dependency is
112 System_Uname : Unit_Name_Type;
113 -- Unit name for system spec if needed for dummy entry
114
115 System_Fname : File_Name_Type;
116 -- File name for system spec if needed for dummy entry
117
118 begin
119 -- Nothing to do if we already compiled System
120
121 for Unum in Units.First .. Last_Unit loop
122 if Units.Table (Unum).Source_Index = System_Source_File_Index then
123 return;
124 end if;
125 end loop;
126
127 -- If no entry for system.ads in the units table, then add a entry
128 -- to the units table for system.ads, which will be referenced when
129 -- the ali file is generated. We need this because every unit depends
130 -- on system as a result of Targparm scanning the system.ads file to
131 -- determine the target dependent parameters for the compilation.
132
133 Name_Len := 6;
134 Name_Buffer (1 .. 6) := "system";
135 System_Uname := Name_To_Unit_Name (Name_Enter);
136 System_Fname := File_Name (System_Source_File_Index);
137
138 Units.Increment_Last;
139 Units.Table (Units.Last) :=
140 (Unit_File_Name => System_Fname,
141 Unit_Name => System_Uname,
142 Expected_Unit => System_Uname,
143 Source_Index => System_Source_File_Index,
144 Cunit => Empty,
145 Cunit_Entity => Empty,
146 Dependency_Num => 0,
147 Dynamic_Elab => False,
148 Fatal_Error => None,
149 Generate_Code => False,
150 Has_RACW => False,
151 Filler => False,
152 Ident_String => Empty,
153 Is_Predefined_Renaming => False,
154 Is_Internal_Unit => True,
155 Is_Predefined_Unit => True,
156 Filler2 => False,
157 Loading => False,
158 Main_Priority => -1,
159 Main_CPU => -1,
160 Munit_Index => 0,
161 No_Elab_Code_All => False,
162 Primary_Stack_Count => 0,
163 Sec_Stack_Count => 0,
164 Serial_Number => 0,
165 Version => 0,
166 Error_Location => No_Location,
167 OA_Setting => 'O');
168
169 -- Parse system.ads so that the checksum is set right. Style checks are
170 -- not applied. The Ekind is set to ensure that this reference is always
171 -- present in the ali file.
172
173 declare
174 Save_Mindex : constant Nat := Multiple_Unit_Index;
175 Save_Style : constant Boolean := Style_Check;
176 begin
177 Multiple_Unit_Index := 0;
178 Style_Check := False;
179 Initialize_Scanner (Units.Last, System_Source_File_Index);
180 Discard_List (Par (Configuration_Pragmas => False));
181 Set_Ekind (Cunit_Entity (Units.Last), E_Package);
182 Set_Scope (Cunit_Entity (Units.Last), Standard_Standard);
183 Style_Check := Save_Style;
184 Multiple_Unit_Index := Save_Mindex;
185 end;
186 end Ensure_System_Dependency;
187
188 ---------------
189 -- Write_ALI --
190 ---------------
191
192 procedure Write_ALI (Object : Boolean) is
193
194 ----------------
195 -- Local Data --
196 ----------------
197
198 Last_Unit : constant Unit_Number_Type := Units.Last;
199 -- Record unit number of last unit. We capture this in case we
200 -- have to add a dummy entry to the unit table for package System.
201
202 With_Flags : array (Units.First .. Last_Unit) of Boolean;
203 -- Array of flags to show which units are with'ed
204
205 Elab_Flags : array (Units.First .. Last_Unit) of Boolean;
206 -- Array of flags to show which units have pragma Elaborate set
207
208 Elab_All_Flags : array (Units.First .. Last_Unit) of Boolean;
209 -- Array of flags to show which units have pragma Elaborate All set
210
211 Elab_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
212 -- Array of flags to show which units have Elaborate_Desirable set
213
214 Elab_All_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
215 -- Array of flags to show which units have Elaborate_All_Desirable set
216
217 type Yes_No is (Unknown, Yes, No);
218 Has_Implicit_With : array (Units.First .. Last_Unit) of Yes_No;
219 -- Indicates if an implicit with has been given for the unit. Yes if
220 -- certainly present, No if certainly absent, Unknown if not known.
221
222 Sdep_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 2));
223 -- Sorted table of source dependencies. One extra entry in case we
224 -- have to add a dummy entry for System.
225
226 Num_Sdep : Nat := 0;
227 -- Number of active entries in Sdep_Table
228
229 flag_compare_debug : Int;
230 pragma Import (C, flag_compare_debug);
231 -- Import from toplev.c
232
233 -----------------------
234 -- Local Subprograms --
235 -----------------------
236
237 procedure Collect_Withs (Cunit : Node_Id);
238 -- Collect with lines for entries in the context clause of the given
239 -- compilation unit, Cunit.
240
241 procedure Update_Tables_From_ALI_File;
242 -- Given an up to date ALI file (see Up_To_Date_ALI_file_Exists
243 -- function), update tables from the ALI information, including
244 -- specifically the Compilation_Switches table.
245
246 function Up_To_Date_ALI_File_Exists return Boolean;
247 -- If there exists an ALI file that is up to date, then this function
248 -- initializes the tables in the ALI spec to contain information on
249 -- this file (using Scan_ALI) and returns True. If no file exists,
250 -- or the file is not up to date, then False is returned.
251
252 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type);
253 -- Write out the library information for one unit for which code is
254 -- generated (includes unit line and with lines).
255
256 procedure Write_With_Lines;
257 -- Write out with lines collected by calls to Collect_Withs
258
259 -------------------
260 -- Collect_Withs --
261 -------------------
262
263 procedure Collect_Withs (Cunit : Node_Id) is
264 function Is_Implicit_With_Clause (Clause : Node_Id) return Boolean;
265 pragma Inline (Is_Implicit_With_Clause);
266 -- Determine whether a with clause denoted by Clause is implicit
267
268 -----------------------------
269 -- Is_Implicit_With_Clause --
270 -----------------------------
271
272 function Is_Implicit_With_Clause (Clause : Node_Id) return Boolean is
273 begin
274 -- With clauses created for ancestor units are marked as internal,
275 -- however, they emulate the semantics in Ada RM 10.1.2 (6/2),
276 -- where
277 --
278 -- with A.B;
279 --
280 -- is almost equivalent to
281 --
282 -- with A;
283 -- with A.B;
284 --
285 -- For ALI encoding purposes, they are considered to be explicit.
286 -- Note that the clauses cannot be marked as explicit because they
287 -- will be subjected to various checks related to with clauses and
288 -- possibly cause false positives.
289
290 if Parent_With (Clause) then
291 return False;
292
293 else
294 return Implicit_With (Clause);
295 end if;
296 end Is_Implicit_With_Clause;
297
298 -- Local variables
299
300 Item : Node_Id;
301 Unum : Unit_Number_Type;
302
303 -- Start of processing for Collect_Withs
304
305 begin
306 Item := First (Context_Items (Cunit));
307 while Present (Item) loop
308
309 -- Process with clause
310
311 -- Ada 2005 (AI-50217): limited with_clauses do not create
312 -- dependencies, but must be recorded as components of the
313 -- partition, in case there is no regular with_clause for
314 -- the unit anywhere else.
315
316 if Nkind (Item) = N_With_Clause then
317 Unum := Get_Cunit_Unit_Number (Library_Unit (Item));
318 With_Flags (Unum) := True;
319
320 if not Limited_Present (Item) then
321 if Elaborate_Present (Item) then
322 Elab_Flags (Unum) := True;
323 end if;
324
325 if Elaborate_All_Present (Item) then
326 Elab_All_Flags (Unum) := True;
327 end if;
328
329 if Elaborate_All_Desirable (Item) then
330 Elab_All_Des_Flags (Unum) := True;
331 end if;
332
333 if Elaborate_Desirable (Item) then
334 Elab_Des_Flags (Unum) := True;
335 end if;
336
337 else
338 Set_From_Limited_With (Cunit_Entity (Unum));
339 end if;
340
341 if Is_Implicit_With_Clause (Item) then
342
343 -- A previous explicit with clause withs the unit. Retain
344 -- this classification, as it reflects the source relations
345 -- between units.
346
347 if Has_Implicit_With (Unum) = No then
348 null;
349
350 -- Otherwise this is either the first time any clause withs
351 -- the unit, or the unit is already implicitly withed.
352
353 else
354 Has_Implicit_With (Unum) := Yes;
355 end if;
356
357 -- Otherwise the current with clause is explicit. Such clauses
358 -- take precedence over existing implicit clauses because they
359 -- reflect the source relations between unit.
360
361 else
362 Has_Implicit_With (Unum) := No;
363 end if;
364 end if;
365
366 Next (Item);
367 end loop;
368 end Collect_Withs;
369
370 --------------------------------
371 -- Up_To_Date_ALI_File_Exists --
372 --------------------------------
373
374 function Up_To_Date_ALI_File_Exists return Boolean is
375 Name : File_Name_Type;
376 Text : Text_Buffer_Ptr;
377 Id : Sdep_Id;
378 Sind : Source_File_Index;
379
380 begin
381 Opt.Check_Object_Consistency := True;
382 Read_Library_Info (Name, Text);
383
384 -- Return if we could not find an ALI file
385
386 if Text = null then
387 return False;
388 end if;
389
390 -- Return if ALI file has bad format
391
392 Initialize_ALI;
393
394 if Scan_ALI (Name, Text, False, Err => True) = No_ALI_Id then
395 return False;
396 end if;
397
398 -- If we have an OK ALI file, check if it is up to date
399 -- Note that we assume that the ALI read has all the entries
400 -- we have in our table, plus some additional ones (that can
401 -- come from expansion).
402
403 Id := First_Sdep_Entry;
404 for J in 1 .. Num_Sdep loop
405 Sind := Units.Table (Sdep_Table (J)).Source_Index;
406
407 while Sdep.Table (Id).Sfile /= File_Name (Sind) loop
408 if Id = Sdep.Last then
409 return False;
410 else
411 Id := Id + 1;
412 end if;
413 end loop;
414
415 if Sdep.Table (Id).Stamp /= Time_Stamp (Sind) then
416 return False;
417 end if;
418 end loop;
419
420 return True;
421 end Up_To_Date_ALI_File_Exists;
422
423 ---------------------------------
424 -- Update_Tables_From_ALI_File --
425 ---------------------------------
426
427 procedure Update_Tables_From_ALI_File is
428 begin
429 -- Build Compilation_Switches table
430
431 Compilation_Switches.Init;
432
433 for J in First_Arg_Entry .. Args.Last loop
434 Compilation_Switches.Increment_Last;
435 Compilation_Switches.Table (Compilation_Switches.Last) :=
436 Args.Table (J);
437 end loop;
438 end Update_Tables_From_ALI_File;
439
440 ----------------------------
441 -- Write_Unit_Information --
442 ----------------------------
443
444 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type) is
445 Unode : constant Node_Id := Cunit (Unit_Num);
446 Ukind : constant Node_Kind := Nkind (Unit (Unode));
447 Uent : constant Entity_Id := Cunit_Entity (Unit_Num);
448 Pnode : Node_Id;
449
450 begin
451 Write_Info_Initiate ('U');
452 Write_Info_Char (' ');
453 Write_Info_Name (Unit_Name (Unit_Num));
454 Write_Info_Tab (25);
455 Write_Info_Name (Unit_File_Name (Unit_Num));
456
457 Write_Info_Tab (49);
458 Write_Info_Str (Version_Get (Unit_Num));
459
460 -- Add BD parameter if Elaborate_Body pragma desirable
461
462 if Ekind (Uent) = E_Package
463 and then Elaborate_Body_Desirable (Uent)
464 then
465 Write_Info_Str (" BD");
466 end if;
467
468 -- Add BN parameter if body needed for SAL
469
470 if (Is_Subprogram (Uent)
471 or else Ekind (Uent) = E_Package
472 or else Is_Generic_Unit (Uent))
473 and then Body_Needed_For_SAL (Uent)
474 then
475 Write_Info_Str (" BN");
476 end if;
477
478 if Dynamic_Elab (Unit_Num) then
479 Write_Info_Str (" DE");
480 end if;
481
482 -- Set the Elaborate_Body indication if either an explicit pragma
483 -- was present, or if this is an instantiation.
484
485 if Has_Pragma_Elaborate_Body (Uent)
486 or else (Ukind = N_Package_Declaration
487 and then Is_Generic_Instance (Uent)
488 and then Present (Corresponding_Body (Unit (Unode))))
489 then
490 Write_Info_Str (" EB");
491 end if;
492
493 -- Now see if we should tell the binder that an elaboration entity
494 -- is present, which must be set to true during elaboration.
495 -- We generate the indication if the following condition is met:
496
497 -- If this is a spec ...
498
499 if (Is_Subprogram (Uent)
500 or else Ekind (Uent) = E_Package
501 or else Is_Generic_Unit (Uent))
502
503 -- and an elaboration entity was declared ...
504
505 and then Present (Elaboration_Entity (Uent))
506
507 -- and either the elaboration flag is required ...
508
509 and then (Elaboration_Entity_Required (Uent)
510
511 -- or this unit has elaboration code ...
512
513 or else not Has_No_Elaboration_Code (Unode)
514
515 -- or this unit has a separate body and this
516 -- body has elaboration code.
517
518 or else
519 (Ekind (Uent) = E_Package
520 and then Present (Body_Entity (Uent))
521 and then
522 not Has_No_Elaboration_Code
523 (Parent (Declaration_Node (Body_Entity (Uent))))))
524 then
525 Write_Info_Str (" EE");
526 end if;
527
528 if Has_No_Elaboration_Code (Unode) then
529 Write_Info_Str (" NE");
530 end if;
531
532 Write_Info_Str (" O");
533 Write_Info_Char (OA_Setting (Unit_Num));
534
535 if Ekind_In (Uent, E_Package, E_Package_Body)
536 and then Present (Finalizer (Uent))
537 then
538 Write_Info_Str (" PF");
539 end if;
540
541 if Is_Preelaborated (Uent) then
542 Write_Info_Str (" PR");
543 end if;
544
545 if Is_Pure (Uent) then
546 Write_Info_Str (" PU");
547 end if;
548
549 if Has_RACW (Unit_Num) then
550 Write_Info_Str (" RA");
551 end if;
552
553 if Is_Remote_Call_Interface (Uent) then
554 Write_Info_Str (" RC");
555 end if;
556
557 if Is_Remote_Types (Uent) then
558 Write_Info_Str (" RT");
559 end if;
560
561 if Serious_Errors_Detected /= 0 then
562 Write_Info_Str (" SE");
563 end if;
564
565 if Is_Shared_Passive (Uent) then
566 Write_Info_Str (" SP");
567 end if;
568
569 if Ukind = N_Subprogram_Declaration
570 or else Ukind = N_Subprogram_Body
571 then
572 Write_Info_Str (" SU");
573
574 elsif Ukind = N_Package_Declaration
575 or else
576 Ukind = N_Package_Body
577 then
578 -- If this is a wrapper package for a subprogram instantiation,
579 -- the user view is the subprogram. Note that in this case the
580 -- ali file contains both the spec and body of the instance.
581
582 if Is_Wrapper_Package (Uent) then
583 Write_Info_Str (" SU");
584 else
585 Write_Info_Str (" PK");
586 end if;
587
588 elsif Ukind = N_Generic_Package_Declaration then
589 Write_Info_Str (" PK");
590
591 end if;
592
593 if Ukind in N_Generic_Declaration
594 or else
595 (Present (Library_Unit (Unode))
596 and then
597 Nkind (Unit (Library_Unit (Unode))) in N_Generic_Declaration)
598 then
599 Write_Info_Str (" GE");
600 end if;
601
602 if not Is_Internal_Unit (Unit_Num) then
603 case Identifier_Casing (Source_Index (Unit_Num)) is
604 when All_Lower_Case => Write_Info_Str (" IL");
605 when All_Upper_Case => Write_Info_Str (" IU");
606 when others => null;
607 end case;
608
609 case Keyword_Casing (Source_Index (Unit_Num)) is
610 when Mixed_Case => Write_Info_Str (" KM");
611 when All_Upper_Case => Write_Info_Str (" KU");
612 when others => null;
613 end case;
614 end if;
615
616 if Initialize_Scalars or else Invalid_Value_Used then
617 Write_Info_Str (" IS");
618 end if;
619
620 Write_Info_EOL;
621
622 -- Generate with lines, first those that are directly with'ed
623
624 for J in With_Flags'Range loop
625 With_Flags (J) := False;
626 Elab_Flags (J) := False;
627 Elab_All_Flags (J) := False;
628 Elab_Des_Flags (J) := False;
629 Elab_All_Des_Flags (J) := False;
630 Has_Implicit_With (J) := Unknown;
631 end loop;
632
633 Collect_Withs (Unode);
634
635 -- For a body, we must also check for any subunits which belong to
636 -- it and which have context clauses of their own, since these
637 -- with'ed units are part of its own elaboration dependencies.
638
639 if Nkind (Unit (Unode)) in N_Unit_Body then
640 for S in Units.First .. Last_Unit loop
641
642 -- We are only interested in subunits. For preproc. data and
643 -- def. files, Cunit is Empty, so we need to test that first.
644
645 if Cunit (S) /= Empty
646 and then Nkind (Unit (Cunit (S))) = N_Subunit
647 then
648 Pnode := Library_Unit (Cunit (S));
649
650 -- In gnatc mode, the errors in the subunits will not have
651 -- been recorded, but the analysis of the subunit may have
652 -- failed. There is no information to add to ALI file in
653 -- this case.
654
655 if No (Pnode) then
656 exit;
657 end if;
658
659 -- Find ultimate parent of the subunit
660
661 while Nkind (Unit (Pnode)) = N_Subunit loop
662 Pnode := Library_Unit (Pnode);
663 end loop;
664
665 -- See if it belongs to current unit, and if so, include
666 -- its with_clauses.
667
668 if Pnode = Unode then
669 Collect_Withs (Cunit (S));
670 end if;
671 end if;
672 end loop;
673 end if;
674
675 Write_With_Lines;
676
677 -- Generate task stack lines
678
679 if Primary_Stack_Count (Unit_Num) > 0
680 or else Sec_Stack_Count (Unit_Num) > 0
681 then
682 Write_Info_Initiate ('T');
683 Write_Info_Char (' ');
684 Write_Info_Int (Primary_Stack_Count (Unit_Num));
685 Write_Info_Char (' ');
686 Write_Info_Int (Sec_Stack_Count (Unit_Num));
687 Write_Info_EOL;
688 end if;
689
690 -- Generate the linker option lines
691
692 for J in 1 .. Linker_Option_Lines.Last loop
693
694 -- Pragma Linker_Options is not allowed in predefined generic
695 -- units. This is because they won't be read, due to the fact that
696 -- with lines for generic units lack the file name and lib name
697 -- parameters (see Lib_Writ spec for an explanation).
698
699 if Is_Generic_Unit (Cunit_Entity (Main_Unit))
700 and then Is_Predefined_Unit (Current_Sem_Unit)
701 and then Linker_Option_Lines.Table (J).Unit = Unit_Num
702 then
703 Set_Standard_Error;
704 Write_Line
705 ("linker options not allowed in predefined generic unit");
706 raise Unrecoverable_Error;
707 end if;
708
709 -- Output one linker option line
710
711 declare
712 S : Linker_Option_Entry renames Linker_Option_Lines.Table (J);
713 begin
714 if S.Unit = Unit_Num then
715 Write_Info_Initiate ('L');
716 Write_Info_Char (' ');
717 Write_Info_Slit (S.Option);
718 Write_Info_EOL;
719 end if;
720 end;
721 end loop;
722
723 -- Output notes
724
725 for J in 1 .. Notes.Last loop
726 declare
727 N : constant Node_Id := Notes.Table (J);
728 L : constant Source_Ptr := Sloc (N);
729 U : constant Unit_Number_Type :=
730 Unit (Get_Source_File_Index (L));
731 C : Character;
732
733 Note_Unit : Unit_Number_Type;
734 -- The unit in whose U section this note must be emitted:
735 -- notes for subunits are emitted along with the main unit;
736 -- all other notes are emitted as part of the enclosing
737 -- compilation unit.
738
739 begin
740 if U /= No_Unit and then Nkind (Unit (Cunit (U))) = N_Subunit
741 then
742 Note_Unit := Main_Unit;
743 else
744 Note_Unit := U;
745 end if;
746
747 -- No action needed for pragmas removed by the expander (for
748 -- example, pragmas of ignored ghost entities).
749
750 if Nkind (N) = N_Null_Statement then
751 pragma Assert (Nkind (Original_Node (N)) = N_Pragma);
752 null;
753
754 elsif Note_Unit = Unit_Num then
755 Write_Info_Initiate ('N');
756 Write_Info_Char (' ');
757
758 case Pragma_Name (N) is
759 when Name_Annotate =>
760 C := 'A';
761 when Name_Comment =>
762 C := 'C';
763 when Name_Ident =>
764 C := 'I';
765 when Name_Title =>
766 C := 'T';
767 when Name_Subtitle =>
768 C := 'S';
769 when others =>
770 raise Program_Error;
771 end case;
772
773 Write_Info_Char (C);
774 Write_Info_Int (Int (Get_Logical_Line_Number (L)));
775 Write_Info_Char (':');
776 Write_Info_Int (Int (Get_Column_Number (L)));
777
778 -- Indicate source file of annotation if different from
779 -- compilation unit source file (case of annotation coming
780 -- from a separate).
781
782 if Get_Source_File_Index (L) /= Source_Index (Unit_Num) then
783 Write_Info_Char (':');
784 Write_Info_Name (File_Name (Get_Source_File_Index (L)));
785 end if;
786
787 declare
788 A : Node_Id;
789
790 begin
791 A := First (Pragma_Argument_Associations (N));
792 while Present (A) loop
793 Write_Info_Char (' ');
794
795 if Chars (A) /= No_Name then
796 Write_Info_Name (Chars (A));
797 Write_Info_Char (':');
798 end if;
799
800 declare
801 Expr : constant Node_Id := Expression (A);
802
803 begin
804 if Nkind (Expr) = N_Identifier then
805 Write_Info_Name (Chars (Expr));
806
807 elsif Nkind (Expr) = N_Integer_Literal
808 and then Is_OK_Static_Expression (Expr)
809 then
810 Write_Info_Uint (Intval (Expr));
811
812 elsif Nkind (Expr) = N_String_Literal
813 and then Is_OK_Static_Expression (Expr)
814 then
815 Write_Info_Slit (Strval (Expr));
816
817 else
818 Write_Info_Str ("<expr>");
819 end if;
820 end;
821
822 Next (A);
823 end loop;
824 end;
825
826 Write_Info_EOL;
827 end if;
828 end;
829 end loop;
830 end Write_Unit_Information;
831
832 ----------------------
833 -- Write_With_Lines --
834 ----------------------
835
836 procedure Write_With_Lines is
837 Pname : constant Unit_Name_Type :=
838 Get_Parent_Spec_Name (Unit_Name (Main_Unit));
839 Body_Fname : File_Name_Type;
840 Body_Index : Nat;
841 Cunit : Node_Id;
842 Fname : File_Name_Type;
843 Num_Withs : Int := 0;
844 Unum : Unit_Number_Type;
845 Uname : Unit_Name_Type;
846 With_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 1));
847
848 procedure Write_With_File_Names
849 (Nam : in out File_Name_Type;
850 Idx : Nat);
851 -- Write source file name Nam and ALI file name for unit index Idx.
852 -- Possibly change Nam to lowercase (generating a new file name).
853
854 ---------------------------
855 -- Write_With_File_Names --
856 ---------------------------
857
858 procedure Write_With_File_Names
859 (Nam : in out File_Name_Type;
860 Idx : Nat)
861 is
862 begin
863 if not File_Names_Case_Sensitive then
864 Get_Name_String (Nam);
865 To_Lower (Name_Buffer (1 .. Name_Len));
866 Nam := Name_Find;
867 end if;
868
869 Write_Info_Name (Nam);
870 Write_Info_Tab (49);
871 Write_Info_Name (Lib_File_Name (Nam, Idx));
872 end Write_With_File_Names;
873
874 -- Start of processing for Write_With_Lines
875
876 begin
877 -- Loop to build the with table. A with on the main unit itself
878 -- is ignored (AARM 10.2(14a)). Such a with-clause can occur if
879 -- the main unit is a subprogram with no spec, and a subunit of
880 -- it unnecessarily withs the parent.
881
882 for J in Units.First + 1 .. Last_Unit loop
883
884 -- Add element to with table if it is with'ed or if it is the
885 -- parent spec of the main unit (case of main unit is a child
886 -- unit). The latter with is not needed for semantic purposes,
887 -- but is required by the binder for elaboration purposes. For
888 -- preprocessing data and definition files, there is no Unit_Name,
889 -- check for that first.
890
891 if Unit_Name (J) /= No_Unit_Name
892 and then (With_Flags (J) or else Unit_Name (J) = Pname)
893 then
894 Num_Withs := Num_Withs + 1;
895 With_Table (Num_Withs) := J;
896 end if;
897 end loop;
898
899 -- Sort and output the table
900
901 Sort (With_Table (1 .. Num_Withs));
902
903 for J in 1 .. Num_Withs loop
904 Unum := With_Table (J);
905
906 -- Do not generate a with line for an ignored Ghost unit because
907 -- the unit does not have an ALI file.
908
909 if Is_Ignored_Ghost_Entity (Cunit_Entity (Unum)) then
910 goto Next_With_Line;
911 end if;
912
913 Cunit := Units.Table (Unum).Cunit;
914 Uname := Units.Table (Unum).Unit_Name;
915 Fname := Units.Table (Unum).Unit_File_Name;
916
917 -- Limited with clauses must be processed first because they are
918 -- the most specific among the three kinds.
919
920 if Ekind (Cunit_Entity (Unum)) = E_Package
921 and then From_Limited_With (Cunit_Entity (Unum))
922 then
923 Write_Info_Initiate ('Y');
924
925 elsif Has_Implicit_With (Unum) = Yes then
926 Write_Info_Initiate ('Z');
927
928 else
929 Write_Info_Initiate ('W');
930 end if;
931
932 Write_Info_Char (' ');
933 Write_Info_Name (Uname);
934
935 -- Now we need to figure out the names of the files that contain
936 -- the with'ed unit. These will usually be the files for the body,
937 -- except in the case of a package that has no body. Note that we
938 -- have a specific exemption here for predefined library generics
939 -- (see comments for Generic_May_Lack_ALI). We do not generate
940 -- dependency upon the ALI file for such units. Older compilers
941 -- used to not support generating code (and ALI) for generics, and
942 -- we want to avoid having different processing (namely, different
943 -- lists of files to be compiled) for different stages of the
944 -- bootstrap.
945
946 if not ((Nkind (Unit (Cunit)) in N_Generic_Declaration
947 or else
948 Nkind (Unit (Cunit)) in N_Generic_Renaming_Declaration)
949 and then Generic_May_Lack_ALI (Unum))
950
951 -- In SPARK mode, always generate the dependencies on ALI
952 -- files, which are required to compute frame conditions
953 -- of subprograms.
954
955 or else GNATprove_Mode
956 then
957 Write_Info_Tab (25);
958
959 if Is_Spec_Name (Uname) then
960
961 -- In GNATprove mode we must write the spec of a unit which
962 -- requires a body if that body is not found. This will
963 -- allow partial analysis on incomplete sources. Also, in
964 -- the case of a unit that is a remote call interface, the
965 -- bodies of packages may not exist but still may form a
966 -- valid program - so we handle that here as well.
967
968 if GNATprove_Mode
969 or else Is_Remote_Call_Interface (Cunit_Entity (Unum))
970 then
971 Body_Fname :=
972 Get_File_Name
973 (Uname => Get_Body_Name (Uname),
974 Subunit => False,
975 May_Fail => True);
976
977 Body_Index := Get_Unit_Index (Get_Body_Name (Uname));
978
979 if Body_Fname = No_File then
980 Body_Fname := Get_File_Name (Uname, Subunit => False);
981 Body_Index := Get_Unit_Index (Uname);
982 end if;
983
984 -- In the normal path we don't allow failure in fetching the
985 -- name of the desired body unit so that it may be properly
986 -- referenced in the output ali - even if it is missing.
987
988 else
989 Body_Fname :=
990 Get_File_Name
991 (Uname => Get_Body_Name (Uname),
992 Subunit => False,
993 May_Fail => False);
994
995 Body_Index := Get_Unit_Index (Get_Body_Name (Uname));
996 end if;
997 else
998 Body_Fname := Get_File_Name (Uname, Subunit => False);
999 Body_Index := Get_Unit_Index (Uname);
1000 end if;
1001
1002 -- A package is considered to have a body if it requires
1003 -- a body or if a body is present in Ada 83 mode.
1004
1005 if Body_Required (Cunit)
1006 or else (Ada_Version = Ada_83
1007 and then Full_Source_Name (Body_Fname) /= No_File)
1008 then
1009 Write_With_File_Names (Body_Fname, Body_Index);
1010 else
1011 Write_With_File_Names (Fname, Munit_Index (Unum));
1012 end if;
1013
1014 if Ekind (Cunit_Entity (Unum)) = E_Package
1015 and then From_Limited_With (Cunit_Entity (Unum))
1016 then
1017 null;
1018 else
1019 if Elab_Flags (Unum) then
1020 Write_Info_Str (" E");
1021 end if;
1022
1023 if Elab_All_Flags (Unum) then
1024 Write_Info_Str (" EA");
1025 end if;
1026
1027 if Elab_Des_Flags (Unum) then
1028 Write_Info_Str (" ED");
1029 end if;
1030
1031 if Elab_All_Des_Flags (Unum) then
1032 Write_Info_Str (" AD");
1033 end if;
1034 end if;
1035 end if;
1036
1037 Write_Info_EOL;
1038
1039 <<Next_With_Line>>
1040 null;
1041 end loop;
1042
1043 -- Finally generate the special lines for cases of Restriction_Set
1044 -- with No_Dependence and no restriction present.
1045
1046 declare
1047 Unam : Unit_Name_Type;
1048
1049 begin
1050 for J in Restriction_Set_Dependences.First ..
1051 Restriction_Set_Dependences.Last
1052 loop
1053 Unam := Restriction_Set_Dependences.Table (J);
1054
1055 -- Don't need an entry if already in the unit table
1056
1057 for U in 0 .. Last_Unit loop
1058 if Unit_Name (U) = Unam then
1059 goto Next_Restriction_Set;
1060 end if;
1061 end loop;
1062
1063 -- Otherwise generate the entry
1064
1065 Write_Info_Initiate ('W');
1066 Write_Info_Char (' ');
1067 Write_Info_Name (Unam);
1068 Write_Info_EOL;
1069
1070 <<Next_Restriction_Set>>
1071 null;
1072 end loop;
1073 end;
1074 end Write_With_Lines;
1075
1076 -- Start of processing for Write_ALI
1077
1078 begin
1079 -- We never write an ALI file if the original operating mode was
1080 -- syntax-only (-gnats switch used in compiler invocation line)
1081
1082 if Original_Operating_Mode = Check_Syntax
1083 or flag_compare_debug /= 0
1084 then
1085 return;
1086 end if;
1087
1088 -- Generation of ALI files may be disabled, e.g. for formal verification
1089 -- back-end.
1090
1091 if Disable_ALI_File then
1092 return;
1093 end if;
1094
1095 -- Build sorted source dependency table. We do this right away, because
1096 -- it is referenced by Up_To_Date_ALI_File_Exists.
1097
1098 for Unum in Units.First .. Last_Unit loop
1099 if Cunit_Entity (Unum) = Empty
1100 or else not From_Limited_With (Cunit_Entity (Unum))
1101 then
1102 -- Units that are not analyzed need not appear in the dependency
1103 -- list. These units are either units appearing in limited_with
1104 -- clauses of other units, or units loaded for inlining that end
1105 -- up not inlined by a later decision of the inlining code, to
1106 -- prevent circularities. We want to exclude these files from the
1107 -- list of dependencies, so that the dependency number of other
1108 -- is correctly set, as that number is used by cross-reference
1109 -- tools to relate entity information to the unit in which they
1110 -- are declared.
1111
1112 if Present (Cunit_Entity (Unum))
1113 and then Ekind (Cunit_Entity (Unum)) = E_Void
1114 and then Nkind (Unit (Cunit (Unum))) /= N_Subunit
1115 and then Serious_Errors_Detected = 0
1116 then
1117 null;
1118
1119 else
1120 Num_Sdep := Num_Sdep + 1;
1121 Sdep_Table (Num_Sdep) := Unum;
1122 end if;
1123 end if;
1124 end loop;
1125
1126 -- Sort the table so that the D lines are in order
1127
1128 Lib.Sort (Sdep_Table (1 .. Num_Sdep));
1129
1130 -- If we are not generating code, and there is an up to date ALI file
1131 -- file accessible, read it, and acquire the compilation arguments from
1132 -- this file. In GNATprove mode, always generate the ALI file, which
1133 -- contains a special section for formal verification.
1134
1135 if Operating_Mode /= Generate_Code and then not GNATprove_Mode then
1136 if Up_To_Date_ALI_File_Exists then
1137 Update_Tables_From_ALI_File;
1138 return;
1139 end if;
1140 end if;
1141
1142 -- Otherwise acquire compilation arguments and prepare to write out a
1143 -- new ali file.
1144
1145 Create_Output_Library_Info;
1146
1147 -- Output version line
1148
1149 Write_Info_Initiate ('V');
1150 Write_Info_Str (" """);
1151 Write_Info_Str (Verbose_Library_Version);
1152 Write_Info_Char ('"');
1153
1154 Write_Info_EOL;
1155
1156 -- Output main program line if this is acceptable main program
1157
1158 Output_Main_Program_Line : declare
1159 U : Node_Id := Unit (Units.Table (Main_Unit).Cunit);
1160 S : Node_Id;
1161
1162 procedure M_Parameters;
1163 -- Output parameters for main program line
1164
1165 ------------------
1166 -- M_Parameters --
1167 ------------------
1168
1169 procedure M_Parameters is
1170 begin
1171 if Main_Priority (Main_Unit) /= Default_Main_Priority then
1172 Write_Info_Char (' ');
1173 Write_Info_Nat (Main_Priority (Main_Unit));
1174 end if;
1175
1176 if Opt.Time_Slice_Set then
1177 Write_Info_Str (" T=");
1178 Write_Info_Nat (Opt.Time_Slice_Value);
1179 end if;
1180
1181 if Main_CPU (Main_Unit) /= Default_Main_CPU then
1182 Write_Info_Str (" C=");
1183 Write_Info_Nat (Main_CPU (Main_Unit));
1184 end if;
1185
1186 Write_Info_Str (" W=");
1187 Write_Info_Char
1188 (WC_Encoding_Letters (Wide_Character_Encoding_Method));
1189
1190 Write_Info_EOL;
1191 end M_Parameters;
1192
1193 -- Start of processing for Output_Main_Program_Line
1194
1195 begin
1196 if Nkind (U) = N_Subprogram_Body
1197 or else
1198 (Nkind (U) = N_Package_Body
1199 and then
1200 Nkind (Original_Node (U)) in N_Subprogram_Instantiation)
1201 then
1202 -- If the unit is a subprogram instance, the entity for the
1203 -- subprogram is the alias of the visible entity, which is the
1204 -- related instance of the wrapper package. We retrieve the
1205 -- subprogram declaration of the desired entity.
1206
1207 if Nkind (U) = N_Package_Body then
1208 U := Parent (Parent (
1209 Alias (Related_Instance (Defining_Unit_Name
1210 (Specification (Unit (Library_Unit (Parent (U)))))))));
1211 end if;
1212
1213 S := Specification (U);
1214
1215 -- A generic subprogram is never a main program
1216
1217 if Nkind (U) = N_Subprogram_Body
1218 and then Present (Corresponding_Spec (U))
1219 and then
1220 Ekind_In (Corresponding_Spec (U), E_Generic_Procedure,
1221 E_Generic_Function)
1222 then
1223 null;
1224
1225 elsif No (Parameter_Specifications (S)) then
1226 if Nkind (S) = N_Procedure_Specification then
1227 Write_Info_Initiate ('M');
1228 Write_Info_Str (" P");
1229 M_Parameters;
1230
1231 else
1232 declare
1233 Nam : Node_Id := Defining_Unit_Name (S);
1234
1235 begin
1236 -- If it is a child unit, get its simple name
1237
1238 if Nkind (Nam) = N_Defining_Program_Unit_Name then
1239 Nam := Defining_Identifier (Nam);
1240 end if;
1241
1242 if Is_Integer_Type (Etype (Nam)) then
1243 Write_Info_Initiate ('M');
1244 Write_Info_Str (" F");
1245 M_Parameters;
1246 end if;
1247 end;
1248 end if;
1249 end if;
1250 end if;
1251 end Output_Main_Program_Line;
1252
1253 -- Write command argument ('A') lines
1254
1255 for A in 1 .. Compilation_Switches.Last loop
1256 Write_Info_Initiate ('A');
1257 Write_Info_Char (' ');
1258 Write_Info_Str (Compilation_Switches.Table (A).all);
1259 Write_Info_Terminate;
1260 end loop;
1261
1262 -- Output parameters ('P') line
1263
1264 Write_Info_Initiate ('P');
1265
1266 if Compilation_Errors then
1267 Write_Info_Str (" CE");
1268 end if;
1269
1270 if Opt.Detect_Blocking then
1271 Write_Info_Str (" DB");
1272 end if;
1273
1274 if Tasking_Used and then not Is_Predefined_Unit (Main_Unit) then
1275 if Locking_Policy /= ' ' then
1276 Write_Info_Str (" L");
1277 Write_Info_Char (Locking_Policy);
1278 end if;
1279
1280 if Queuing_Policy /= ' ' then
1281 Write_Info_Str (" Q");
1282 Write_Info_Char (Queuing_Policy);
1283 end if;
1284
1285 if Task_Dispatching_Policy /= ' ' then
1286 Write_Info_Str (" T");
1287 Write_Info_Char (Task_Dispatching_Policy);
1288 Write_Info_Char (' ');
1289 end if;
1290 end if;
1291
1292 if GNATprove_Mode then
1293 Write_Info_Str (" GP");
1294 end if;
1295
1296 if Partition_Elaboration_Policy /= ' ' then
1297 Write_Info_Str (" E");
1298 Write_Info_Char (Partition_Elaboration_Policy);
1299 end if;
1300
1301 if No_Component_Reordering_Config then
1302 Write_Info_Str (" NC");
1303 end if;
1304
1305 if not Object then
1306 Write_Info_Str (" NO");
1307 end if;
1308
1309 if No_Run_Time_Mode then
1310 Write_Info_Str (" NR");
1311 end if;
1312
1313 if Normalize_Scalars then
1314 Write_Info_Str (" NS");
1315 end if;
1316
1317 if Default_SSO_Config /= ' ' then
1318 Write_Info_Str (" O");
1319 Write_Info_Char (Default_SSO_Config);
1320 end if;
1321
1322 if Sec_Stack_Used then
1323 Write_Info_Str (" SS");
1324 end if;
1325
1326 if Unreserve_All_Interrupts then
1327 Write_Info_Str (" UA");
1328 end if;
1329
1330 if Front_End_Exceptions then
1331 Write_Info_Str (" FX");
1332 end if;
1333
1334 if ZCX_Exceptions then
1335 Write_Info_Str (" ZX");
1336 end if;
1337
1338 Write_Info_EOL;
1339
1340 -- Before outputting the restrictions line, update the setting of
1341 -- the No_Elaboration_Code flag. Violations of this restriction
1342 -- cannot be detected until after the backend has been called since
1343 -- it is the backend that sets this flag. We have to check all units
1344 -- for which we have generated code
1345
1346 for Unit in Units.First .. Last_Unit loop
1347 if Units.Table (Unit).Generate_Code or else Unit = Main_Unit then
1348 if not Has_No_Elaboration_Code (Cunit (Unit)) then
1349 Main_Restrictions.Violated (No_Elaboration_Code) := True;
1350 end if;
1351 end if;
1352 end loop;
1353
1354 -- Positional case (only if debug flag -gnatd.R is set)
1355
1356 if Debug_Flag_Dot_RR then
1357
1358 -- Output first restrictions line
1359
1360 Write_Info_Initiate ('R');
1361 Write_Info_Char (' ');
1362
1363 -- First the information for the boolean restrictions
1364
1365 for R in All_Boolean_Restrictions loop
1366 if Main_Restrictions.Set (R)
1367 and then not Restriction_Warnings (R)
1368 then
1369 Write_Info_Char ('r');
1370 elsif Main_Restrictions.Violated (R) then
1371 Write_Info_Char ('v');
1372 else
1373 Write_Info_Char ('n');
1374 end if;
1375 end loop;
1376
1377 -- And now the information for the parameter restrictions
1378
1379 for RP in All_Parameter_Restrictions loop
1380 if Main_Restrictions.Set (RP)
1381 and then not Restriction_Warnings (RP)
1382 then
1383 Write_Info_Char ('r');
1384 Write_Info_Nat (Nat (Main_Restrictions.Value (RP)));
1385 else
1386 Write_Info_Char ('n');
1387 end if;
1388
1389 if not Main_Restrictions.Violated (RP)
1390 or else RP not in Checked_Parameter_Restrictions
1391 then
1392 Write_Info_Char ('n');
1393 else
1394 Write_Info_Char ('v');
1395 Write_Info_Nat (Nat (Main_Restrictions.Count (RP)));
1396
1397 if Main_Restrictions.Unknown (RP) then
1398 Write_Info_Char ('+');
1399 end if;
1400 end if;
1401 end loop;
1402
1403 Write_Info_EOL;
1404
1405 -- Named case (if debug flag -gnatd.R is not set)
1406
1407 else
1408 declare
1409 C : Character;
1410
1411 begin
1412 -- Write RN header line with preceding blank line
1413
1414 Write_Info_EOL;
1415 Write_Info_Initiate ('R');
1416 Write_Info_Char ('N');
1417 Write_Info_EOL;
1418
1419 -- First the lines for the boolean restrictions
1420
1421 for R in All_Boolean_Restrictions loop
1422 if Main_Restrictions.Set (R)
1423 and then not Restriction_Warnings (R)
1424 then
1425 C := 'R';
1426 elsif Main_Restrictions.Violated (R) then
1427 C := 'V';
1428 else
1429 goto Continue;
1430 end if;
1431
1432 Write_Info_Initiate ('R');
1433 Write_Info_Char (C);
1434 Write_Info_Char (' ');
1435 Write_Info_Str (All_Boolean_Restrictions'Image (R));
1436 Write_Info_EOL;
1437
1438 <<Continue>>
1439 null;
1440 end loop;
1441 end;
1442
1443 -- And now the lines for the parameter restrictions
1444
1445 for RP in All_Parameter_Restrictions loop
1446 if Main_Restrictions.Set (RP)
1447 and then not Restriction_Warnings (RP)
1448 then
1449 Write_Info_Initiate ('R');
1450 Write_Info_Str ("R ");
1451 Write_Info_Str (All_Parameter_Restrictions'Image (RP));
1452 Write_Info_Char ('=');
1453 Write_Info_Nat (Nat (Main_Restrictions.Value (RP)));
1454 Write_Info_EOL;
1455 end if;
1456
1457 if not Main_Restrictions.Violated (RP)
1458 or else RP not in Checked_Parameter_Restrictions
1459 then
1460 null;
1461 else
1462 Write_Info_Initiate ('R');
1463 Write_Info_Str ("V ");
1464 Write_Info_Str (All_Parameter_Restrictions'Image (RP));
1465 Write_Info_Char ('=');
1466 Write_Info_Nat (Nat (Main_Restrictions.Count (RP)));
1467
1468 if Main_Restrictions.Unknown (RP) then
1469 Write_Info_Char ('+');
1470 end if;
1471
1472 Write_Info_EOL;
1473 end if;
1474 end loop;
1475 end if;
1476
1477 -- Output R lines for No_Dependence entries
1478
1479 for J in No_Dependences.First .. No_Dependences.Last loop
1480 if In_Extended_Main_Source_Unit (No_Dependences.Table (J).Unit)
1481 and then not No_Dependences.Table (J).Warn
1482 then
1483 Write_Info_Initiate ('R');
1484 Write_Info_Char (' ');
1485 Write_Unit_Name (No_Dependences.Table (J).Unit);
1486 Write_Info_EOL;
1487 end if;
1488 end loop;
1489
1490 -- Output interrupt state lines
1491
1492 for J in Interrupt_States.First .. Interrupt_States.Last loop
1493 Write_Info_Initiate ('I');
1494 Write_Info_Char (' ');
1495 Write_Info_Nat (Interrupt_States.Table (J).Interrupt_Number);
1496 Write_Info_Char (' ');
1497 Write_Info_Char (Interrupt_States.Table (J).Interrupt_State);
1498 Write_Info_Char (' ');
1499 Write_Info_Nat
1500 (Nat (Get_Logical_Line_Number
1501 (Interrupt_States.Table (J).Pragma_Loc)));
1502 Write_Info_EOL;
1503 end loop;
1504
1505 -- Output priority specific dispatching lines
1506
1507 for J in Specific_Dispatching.First .. Specific_Dispatching.Last loop
1508 Write_Info_Initiate ('S');
1509 Write_Info_Char (' ');
1510 Write_Info_Char (Specific_Dispatching.Table (J).Dispatching_Policy);
1511 Write_Info_Char (' ');
1512 Write_Info_Nat (Specific_Dispatching.Table (J).First_Priority);
1513 Write_Info_Char (' ');
1514 Write_Info_Nat (Specific_Dispatching.Table (J).Last_Priority);
1515 Write_Info_Char (' ');
1516 Write_Info_Nat
1517 (Nat (Get_Logical_Line_Number
1518 (Specific_Dispatching.Table (J).Pragma_Loc)));
1519 Write_Info_EOL;
1520 end loop;
1521
1522 -- Loop through file table to output information for all units for which
1523 -- we have generated code, as marked by the Generate_Code flag.
1524
1525 for Unit in Units.First .. Last_Unit loop
1526 if Units.Table (Unit).Generate_Code
1527 or else Unit = Main_Unit
1528 then
1529 Write_Info_EOL; -- blank line
1530 Write_Unit_Information (Unit);
1531 end if;
1532 end loop;
1533
1534 Write_Info_EOL; -- blank line
1535
1536 -- Output external version reference lines
1537
1538 for J in 1 .. Version_Ref.Last loop
1539 Write_Info_Initiate ('E');
1540 Write_Info_Char (' ');
1541
1542 for K in 1 .. String_Length (Version_Ref.Table (J)) loop
1543 Write_Info_Char_Code (Get_String_Char (Version_Ref.Table (J), K));
1544 end loop;
1545
1546 Write_Info_EOL;
1547 end loop;
1548
1549 -- Prepare to output the source dependency lines
1550
1551 declare
1552 Unum : Unit_Number_Type;
1553 -- Number of unit being output
1554
1555 Sind : Source_File_Index;
1556 -- Index of corresponding source file
1557
1558 Fname : File_Name_Type;
1559
1560 begin
1561 for J in 1 .. Num_Sdep loop
1562 Unum := Sdep_Table (J);
1563 Units.Table (Unum).Dependency_Num := J;
1564 Sind := Units.Table (Unum).Source_Index;
1565
1566 Write_Info_Initiate ('D');
1567 Write_Info_Char (' ');
1568
1569 -- Normal case of a unit entry with a source index
1570
1571 if Sind > No_Source_File then
1572 -- We never want directory information in ALI files
1573 -- ???But back out this change temporarily until
1574 -- gprbuild is fixed.
1575
1576 if False then
1577 Fname := Strip_Directory (File_Name (Sind));
1578 else
1579 Fname := File_Name (Sind);
1580 end if;
1581
1582 -- Ensure that on platforms where the file names are not
1583 -- case sensitive, the recorded file name is in lower case.
1584
1585 if not File_Names_Case_Sensitive then
1586 Get_Name_String (Fname);
1587 To_Lower (Name_Buffer (1 .. Name_Len));
1588 Fname := Name_Find;
1589 end if;
1590
1591 Write_Info_Name_May_Be_Quoted (Fname);
1592 Write_Info_Tab (25);
1593 Write_Info_Str (String (Time_Stamp (Sind)));
1594 Write_Info_Char (' ');
1595 Write_Info_Str (Get_Hex_String (Source_Checksum (Sind)));
1596
1597 -- If the dependency comes from a limited_with clause, record
1598 -- limited_checksum. This is disabled until full checksum
1599 -- changes are checked.
1600
1601 -- if Present (Cunit_Entity (Unum))
1602 -- and then From_Limited_With (Cunit_Entity (Unum))
1603 -- then
1604 -- Write_Info_Char (' ');
1605 -- Write_Info_Char ('Y');
1606 -- Write_Info_Str (Get_Hex_String (Limited_Chk_Sum (Sind)));
1607 -- end if;
1608
1609 -- If subunit, add unit name, omitting the %b at the end
1610
1611 if Present (Cunit (Unum)) then
1612 Get_Decoded_Name_String (Unit_Name (Unum));
1613 Write_Info_Char (' ');
1614
1615 if Nkind (Unit (Cunit (Unum))) = N_Subunit then
1616 Write_Info_Str (Name_Buffer (1 .. Name_Len - 2));
1617 else
1618 Write_Info_Str (Name_Buffer (1 .. Name_Len));
1619 end if;
1620 end if;
1621
1622 -- If Source_Reference pragma used, output information
1623
1624 if Num_SRef_Pragmas (Sind) > 0 then
1625 Write_Info_Char (' ');
1626
1627 if Num_SRef_Pragmas (Sind) = 1 then
1628 Write_Info_Nat (Int (First_Mapped_Line (Sind)));
1629 else
1630 Write_Info_Nat (0);
1631 end if;
1632
1633 Write_Info_Char (':');
1634 Write_Info_Name (Reference_Name (Sind));
1635 end if;
1636
1637 -- Case where there is no source index (happens for missing
1638 -- files). In this case we write a dummy time stamp.
1639
1640 else
1641 Write_Info_Name (Unit_File_Name (Unum));
1642 Write_Info_Tab (25);
1643 Write_Info_Str (String (Dummy_Time_Stamp));
1644 Write_Info_Char (' ');
1645 Write_Info_Str (Get_Hex_String (0));
1646 end if;
1647
1648 Write_Info_EOL;
1649 end loop;
1650 end;
1651
1652 -- Output cross-references
1653
1654 if Opt.Xref_Active then
1655 Output_References;
1656 end if;
1657
1658 -- Output SCO information if present
1659
1660 if Generate_SCO then
1661 SCO_Record_Filtered;
1662 SCO_Output;
1663 end if;
1664
1665 -- Output final blank line and we are done. This final blank line is
1666 -- probably junk, but we don't feel like making an incompatible change.
1667
1668 Write_Info_Terminate;
1669 Close_Output_Library_Info;
1670 end Write_ALI;
1671
1672 ---------------------
1673 -- Write_Unit_Name --
1674 ---------------------
1675
1676 procedure Write_Unit_Name (N : Node_Id) is
1677 begin
1678 if Nkind (N) = N_Identifier then
1679 Write_Info_Name (Chars (N));
1680
1681 else
1682 pragma Assert (Nkind (N) = N_Selected_Component);
1683 Write_Unit_Name (Prefix (N));
1684 Write_Info_Char ('.');
1685 Write_Unit_Name (Selector_Name (N));
1686 end if;
1687 end Write_Unit_Name;
1688
1689 end Lib.Writ;