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