testsuite: 32 bit AIX 2 byte wchar
[official-gcc.git] / gcc / ada / lib-writ.adb
blob23b6266bb415550bcc28d278f3d3dddd04576995
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-2023, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with 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 Einfo.Entities; use Einfo.Entities;
32 with Einfo.Utils; use Einfo.Utils;
33 with Elists; use Elists;
34 with Errout; use Errout;
35 with Fname; use Fname;
36 with Fname.UF; use Fname.UF;
37 with Lib.Util; use Lib.Util;
38 with Lib.Xref; use Lib.Xref;
39 with Nlists; use Nlists;
40 with Gnatvsn; use Gnatvsn;
41 with GNAT_CUDA; use GNAT_CUDA;
42 with Opt; use Opt;
43 with Osint; use Osint;
44 with Osint.C; use Osint.C;
45 with Output; use Output;
46 with Par;
47 with Par_SCO; use Par_SCO;
48 with Restrict; use Restrict;
49 with Rident; use Rident;
50 with Stand; use Stand;
51 with Scn; use Scn;
52 with Sem_Eval; use Sem_Eval;
53 with Sem_Util; use Sem_Util;
54 with Sinfo; use Sinfo;
55 with Sinfo.Nodes; use Sinfo.Nodes;
56 with Sinfo.Utils; use Sinfo.Utils;
57 with Sinput; use Sinput;
58 with Snames; use Snames;
59 with Stringt; use Stringt;
60 with Tbuild; use Tbuild;
61 with Uname; use Uname;
63 with System.Case_Util; use System.Case_Util;
64 with System.WCh_Con; use System.WCh_Con;
66 package body Lib.Writ is
68 -----------------------
69 -- Local subprograms --
70 -----------------------
72 function Present (N_Id : Name_Id) return Boolean;
73 pragma Inline (Present);
74 -- Determine whether a name with id N_Id exists
76 procedure Write_Invocation_Construct (IC_Id : Invocation_Construct_Id);
77 pragma Inline (Write_Invocation_Construct);
78 -- Write invocation construct IC_Id to the ALI file
80 procedure Write_Invocation_Graph;
81 pragma Inline (Write_Invocation_Graph);
82 -- Write out the invocation graph
84 procedure Write_Invocation_Graph_Attributes;
85 pragma Inline (Write_Invocation_Graph_Attributes);
86 -- Write out the attributes of the invocation graph
88 procedure Write_Invocation_Relation (IR_Id : Invocation_Relation_Id);
89 pragma Inline (Write_Invocation_Relation);
90 -- Write invocation relation IR_Id to the ALI file
92 procedure Write_Invocation_Signature (IS_Id : Invocation_Signature_Id);
93 pragma Inline (Write_Invocation_Signature);
94 -- Write invocation signature IS_Id to the ALI file
96 procedure Write_Unit_Name (N : Node_Id);
97 -- Used to write out the unit name for R (pragma Restriction) lines
98 -- for uses of Restriction (No_Dependence => unit-name).
100 ----------------------------------
101 -- Add_Preprocessing_Dependency --
102 ----------------------------------
104 procedure Add_Preprocessing_Dependency (S : Source_File_Index) is
105 begin
106 Units.Increment_Last;
107 Units.Table (Units.Last) :=
108 (Unit_File_Name => File_Name (S),
109 Unit_Name => No_Unit_Name,
110 Expected_Unit => No_Unit_Name,
111 Source_Index => S,
112 Cunit => Empty,
113 Cunit_Entity => Empty,
114 Dependency_Num => 0,
115 Dynamic_Elab => False,
116 Fatal_Error => None,
117 Generate_Code => False,
118 Has_RACW => False,
119 Filler => False,
120 Ident_String => Empty,
121 Is_Predefined_Renaming => False,
122 Is_Internal_Unit => False,
123 Is_Predefined_Unit => False,
124 Filler2 => False,
125 Loading => False,
126 Main_Priority => -1,
127 Main_CPU => -1,
128 Munit_Index => 0,
129 No_Elab_Code_All => False,
130 Primary_Stack_Count => 0,
131 Sec_Stack_Count => 0,
132 Serial_Number => 0,
133 Version => 0,
134 Error_Location => No_Location,
135 OA_Setting => 'O');
136 end Add_Preprocessing_Dependency;
138 ------------------------------
139 -- Ensure_System_Dependency --
140 ------------------------------
142 procedure Ensure_System_Dependency is
143 System_Uname : constant Unit_Name_Type :=
144 Name_To_Unit_Name (Name_System);
145 -- Unit name for system spec if needed for dummy entry
147 System_Fname : File_Name_Type;
148 -- File name for system spec if needed for dummy entry
150 begin
151 -- Nothing to do if we already compiled System
153 if Is_Loaded (System_Uname) then
154 return;
155 end if;
157 -- If no entry for system.ads in the units table, then add a entry
158 -- to the units table for system.ads, which will be referenced when
159 -- the ali file is generated. We need this because every unit depends
160 -- on system as a result of Targparm scanning the system.ads file to
161 -- determine the target dependent parameters for the compilation.
163 System_Fname := File_Name (System_Source_File_Index);
165 Units.Increment_Last;
166 Units.Table (Units.Last) :=
167 (Unit_File_Name => System_Fname,
168 Unit_Name => System_Uname,
169 Expected_Unit => System_Uname,
170 Source_Index => System_Source_File_Index,
171 Cunit => Empty,
172 Cunit_Entity => Empty,
173 Dependency_Num => 0,
174 Dynamic_Elab => False,
175 Fatal_Error => None,
176 Generate_Code => False,
177 Has_RACW => False,
178 Filler => False,
179 Ident_String => Empty,
180 Is_Predefined_Renaming => False,
181 Is_Internal_Unit => True,
182 Is_Predefined_Unit => True,
183 Filler2 => False,
184 Loading => False,
185 Main_Priority => -1,
186 Main_CPU => -1,
187 Munit_Index => 0,
188 No_Elab_Code_All => False,
189 Primary_Stack_Count => 0,
190 Sec_Stack_Count => 0,
191 Serial_Number => 0,
192 Version => 0,
193 Error_Location => No_Location,
194 OA_Setting => 'O');
195 Init_Unit_Name (Units.Last, System_Uname);
197 -- Parse system.ads so that the checksum is set right. Style checks are
198 -- not applied. The Ekind is set to ensure that this reference is always
199 -- present in the ali file.
201 declare
202 Save_Mindex : constant Nat := Multiple_Unit_Index;
203 Save_Style : constant Boolean := Style_Check;
204 begin
205 Multiple_Unit_Index := 0;
206 Style_Check := False;
207 Initialize_Scanner (Units.Last, System_Source_File_Index);
208 Discard_List (Par (Configuration_Pragmas => False));
209 Mutate_Ekind (Cunit_Entity (Units.Last), E_Package);
210 Set_Scope (Cunit_Entity (Units.Last), Standard_Standard);
211 Style_Check := Save_Style;
212 Multiple_Unit_Index := Save_Mindex;
213 end;
214 end Ensure_System_Dependency;
216 -------------
217 -- Present --
218 -------------
220 function Present (N_Id : Name_Id) return Boolean is
221 begin
222 return N_Id /= No_Name;
223 end Present;
225 ---------------
226 -- Write_ALI --
227 ---------------
229 procedure Write_ALI (Object : Boolean) is
231 ----------------
232 -- Local Data --
233 ----------------
235 Last_Unit : constant Unit_Number_Type := Units.Last;
236 -- Record unit number of last unit. We capture this in case we
237 -- have to add a dummy entry to the unit table for package System.
239 With_Flags : array (Units.First .. Last_Unit) of Boolean;
240 -- Array of flags to show which units are with'ed
242 Elab_Flags : array (Units.First .. Last_Unit) of Boolean;
243 -- Array of flags to show which units have pragma Elaborate set
245 Elab_All_Flags : array (Units.First .. Last_Unit) of Boolean;
246 -- Array of flags to show which units have pragma Elaborate All set
248 Elab_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
249 -- Array of flags to show which units have Elaborate_Desirable set
251 Elab_All_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
252 -- Array of flags to show which units have Elaborate_All_Desirable set
254 type Yes_No is (Unknown, Yes, No);
255 Has_Implicit_With : array (Units.First .. Last_Unit) of Yes_No;
256 -- Indicates if an implicit with has been given for the unit. Yes if
257 -- certainly present, No if certainly absent, Unknown if not known.
259 Sdep_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 2));
260 -- Sorted table of source dependencies. One extra entry in case we
261 -- have to add a dummy entry for System.
263 Num_Sdep : Nat := 0;
264 -- Number of active entries in Sdep_Table
266 -----------------------
267 -- Local Subprograms --
268 -----------------------
270 procedure Collect_Withs (Cunit : Node_Id);
271 -- Collect with lines for entries in the context clause of the given
272 -- compilation unit, Cunit.
274 procedure Output_CUDA_Symbols (Unit_Num : Unit_Number_Type);
275 -- Output CUDA symbols, so that the rest of the toolchain may know what
276 -- symbols need registering with the CUDA runtime.
278 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type);
279 -- Write out the library information for one unit for which code is
280 -- generated (includes unit line and with lines).
282 procedure Write_With_Lines;
283 -- Write out with lines collected by calls to Collect_Withs
285 -------------------
286 -- Collect_Withs --
287 -------------------
289 procedure Collect_Withs (Cunit : Node_Id) is
290 function Is_Implicit_With_Clause (Clause : Node_Id) return Boolean;
291 pragma Inline (Is_Implicit_With_Clause);
292 -- Determine whether a with clause denoted by Clause is implicit
294 -----------------------------
295 -- Is_Implicit_With_Clause --
296 -----------------------------
298 function Is_Implicit_With_Clause (Clause : Node_Id) return Boolean is
299 begin
300 -- With clauses created for ancestor units are marked as internal,
301 -- however, they emulate the semantics in Ada RM 10.1.2 (6/2),
302 -- where
304 -- with A.B;
306 -- is almost equivalent to
308 -- with A;
309 -- with A.B;
311 -- For ALI encoding purposes, they are considered to be explicit.
312 -- Note that the clauses cannot be marked as explicit because they
313 -- will be subjected to various checks related to with clauses and
314 -- possibly cause false positives.
316 if Parent_With (Clause) then
317 return False;
319 else
320 return Implicit_With (Clause);
321 end if;
322 end Is_Implicit_With_Clause;
324 -- Local variables
326 Item : Node_Id;
327 Unum : Unit_Number_Type;
329 -- Start of processing for Collect_Withs
331 begin
332 Item := First (Context_Items (Cunit));
333 while Present (Item) loop
335 -- Process with clause
337 -- Ada 2005 (AI-50217): limited with_clauses do not create
338 -- dependencies, but must be recorded as components of the
339 -- partition, in case there is no regular with_clause for
340 -- the unit anywhere else.
342 if Nkind (Item) = N_With_Clause then
343 Unum := Get_Cunit_Unit_Number (Library_Unit (Item));
344 With_Flags (Unum) := True;
346 if not Limited_Present (Item) then
347 if Elaborate_Present (Item) then
348 Elab_Flags (Unum) := True;
349 end if;
351 if Elaborate_All_Present (Item) then
352 Elab_All_Flags (Unum) := True;
353 end if;
355 if Elaborate_All_Desirable (Item) then
356 Elab_All_Des_Flags (Unum) := True;
357 end if;
359 if Elaborate_Desirable (Item) then
360 Elab_Des_Flags (Unum) := True;
361 end if;
363 else
364 Set_From_Limited_With (Cunit_Entity (Unum));
365 end if;
367 if Is_Implicit_With_Clause (Item) then
369 -- A previous explicit with clause withs the unit. Retain
370 -- this classification, as it reflects the source relations
371 -- between units.
373 if Has_Implicit_With (Unum) = No then
374 null;
376 -- Otherwise this is either the first time any clause withs
377 -- the unit, or the unit is already implicitly withed.
379 else
380 Has_Implicit_With (Unum) := Yes;
381 end if;
383 -- Otherwise the current with clause is explicit. Such clauses
384 -- take precedence over existing implicit clauses because they
385 -- reflect the source relations between unit.
387 else
388 Has_Implicit_With (Unum) := No;
389 end if;
390 end if;
392 Next (Item);
393 end loop;
394 end Collect_Withs;
396 -------------------------
397 -- Output_CUDA_Symbols --
398 -------------------------
400 procedure Output_CUDA_Symbols (Unit_Num : Unit_Number_Type) is
401 Unit_Id : constant Node_Id := Unit (Cunit (Unit_Num));
402 Spec_Id : Node_Id;
403 Kernels : Elist_Id;
404 Kernel_Elm : Elmt_Id;
405 Kernel : Entity_Id;
406 begin
407 if not Enable_CUDA_Expansion
408 or else Nkind (Unit_Id) = N_Null_Statement
409 then
410 return;
411 end if;
412 Spec_Id := (if Nkind (Unit_Id) = N_Package_Body
413 then Corresponding_Spec (Unit_Id)
414 else Defining_Unit_Name (Specification (Unit_Id)));
415 Kernels := Get_CUDA_Kernels (Spec_Id);
416 if No (Kernels) then
417 return;
418 end if;
420 Kernel_Elm := First_Elmt (Kernels);
421 while Present (Kernel_Elm) loop
422 Kernel := Node (Kernel_Elm);
424 Write_Info_Initiate ('K');
425 Write_Info_Char (' ');
426 Write_Info_Name (Chars (Kernel));
427 Write_Info_Terminate;
428 Next_Elmt (Kernel_Elm);
429 end loop;
431 end Output_CUDA_Symbols;
433 ----------------------------
434 -- Write_Unit_Information --
435 ----------------------------
437 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type) is
438 Unode : constant Node_Id := Cunit (Unit_Num);
439 Ukind : constant Node_Kind := Nkind (Unit (Unode));
440 Uent : constant Entity_Id := Cunit_Entity (Unit_Num);
441 Pnode : Node_Id;
443 begin
444 Write_Info_Initiate ('U');
445 Write_Info_Char (' ');
446 Write_Info_Name (Unit_Name (Unit_Num));
447 Write_Info_Tab (25);
448 Write_Info_Name (Unit_File_Name (Unit_Num));
450 Write_Info_Tab (49);
451 Write_Info_Str (Version_Get (Unit_Num));
453 -- Add BD parameter if Elaborate_Body pragma desirable
455 if Ekind (Uent) = E_Package
456 and then Elaborate_Body_Desirable (Uent)
457 then
458 Write_Info_Str (" BD");
459 end if;
461 -- Add BN parameter if body needed for SAL
463 if (Is_Subprogram (Uent)
464 or else Ekind (Uent) = E_Package
465 or else Is_Generic_Unit (Uent))
466 and then Body_Needed_For_SAL (Uent)
467 then
468 Write_Info_Str (" BN");
469 end if;
471 if Dynamic_Elab (Unit_Num) then
472 Write_Info_Str (" DE");
473 end if;
475 -- Set the Elaborate_Body indication if either an explicit pragma
476 -- was present, or if this is an instantiation.
478 if Has_Pragma_Elaborate_Body (Uent)
479 or else (Ukind = N_Package_Declaration
480 and then Is_Generic_Instance (Uent)
481 and then Present (Corresponding_Body (Unit (Unode))))
482 then
483 Write_Info_Str (" EB");
484 end if;
486 -- Now see if we should tell the binder that an elaboration entity
487 -- is present, which must be set to true during elaboration.
488 -- We generate the indication if the following condition is met:
490 -- If this is a spec ...
492 if (Is_Subprogram (Uent)
493 or else Ekind (Uent) = E_Package
494 or else Is_Generic_Unit (Uent))
496 -- and an elaboration entity was declared ...
498 and then Present (Elaboration_Entity (Uent))
500 -- and either the elaboration flag is required ...
502 and then (Elaboration_Entity_Required (Uent)
504 -- or this unit has elaboration code ...
506 or else not Has_No_Elaboration_Code (Unode)
508 -- or this unit has a separate body and this
509 -- body has elaboration code.
511 or else
512 (Ekind (Uent) = E_Package
513 and then Present (Body_Entity (Uent))
514 and then
515 not Has_No_Elaboration_Code
516 (Parent (Declaration_Node (Body_Entity (Uent))))))
517 then
518 Write_Info_Str (" EE");
519 end if;
521 if Has_No_Elaboration_Code (Unode) then
522 Write_Info_Str (" NE");
523 end if;
525 Write_Info_Str (" O");
526 Write_Info_Char (OA_Setting (Unit_Num));
528 -- For a package instance with a body that is a library unit, the two
529 -- compilation units share Cunit_Entity so we cannot rely on Uent.
531 if Ukind in N_Package_Declaration | N_Package_Body then
532 declare
533 E : constant Entity_Id := Defining_Entity (Unit (Unode));
535 begin
536 if Ekind (E) in E_Package | E_Package_Body
537 and then Present (Finalizer (E))
538 then
539 Write_Info_Str (" PF");
540 end if;
541 end;
542 end if;
544 if Is_Preelaborated (Uent) then
545 Write_Info_Str (" PR");
546 end if;
548 if Is_Pure (Uent) then
549 Write_Info_Str (" PU");
550 end if;
552 if Has_RACW (Unit_Num) then
553 Write_Info_Str (" RA");
554 end if;
556 if Is_Remote_Call_Interface (Uent) then
557 Write_Info_Str (" RC");
558 end if;
560 if Is_Remote_Types (Uent) then
561 Write_Info_Str (" RT");
562 end if;
564 if Serious_Errors_Detected /= 0 then
565 Write_Info_Str (" SE");
566 end if;
568 if Is_Shared_Passive (Uent) then
569 Write_Info_Str (" SP");
570 end if;
572 if Ukind = N_Subprogram_Declaration
573 or else Ukind = N_Subprogram_Body
574 then
575 Write_Info_Str (" SU");
577 elsif Ukind = N_Package_Declaration
578 or else
579 Ukind = N_Package_Body
580 then
581 -- If this is a wrapper package for a subprogram instantiation,
582 -- the user view is the subprogram. Note that in this case the
583 -- ali file contains both the spec and body of the instance.
585 if Is_Wrapper_Package (Uent) then
586 Write_Info_Str (" SU");
587 else
588 Write_Info_Str (" PK");
589 end if;
591 elsif Ukind = N_Generic_Package_Declaration then
592 Write_Info_Str (" PK");
594 end if;
596 if Ukind in N_Generic_Declaration
597 or else
598 (Present (Library_Unit (Unode))
599 and then
600 Nkind (Unit (Library_Unit (Unode))) in N_Generic_Declaration)
601 then
602 Write_Info_Str (" GE");
603 end if;
605 if not Is_Internal_Unit (Unit_Num) then
606 case Identifier_Casing (Source_Index (Unit_Num)) is
607 when All_Lower_Case => Write_Info_Str (" IL");
608 when All_Upper_Case => Write_Info_Str (" IU");
609 when others => null;
610 end case;
612 case Keyword_Casing (Source_Index (Unit_Num)) is
613 when Mixed_Case => Write_Info_Str (" KM");
614 when All_Upper_Case => Write_Info_Str (" KU");
615 when others => null;
616 end case;
617 end if;
619 if Initialize_Scalars or else Invalid_Value_Used then
620 Write_Info_Str (" IS");
621 end if;
623 Write_Info_EOL;
625 -- Generate with lines, first those that are directly with'ed
627 for J in With_Flags'Range loop
628 With_Flags (J) := False;
629 Elab_Flags (J) := False;
630 Elab_All_Flags (J) := False;
631 Elab_Des_Flags (J) := False;
632 Elab_All_Des_Flags (J) := False;
633 Has_Implicit_With (J) := Unknown;
634 end loop;
636 Collect_Withs (Unode);
638 -- For a body, we must also check for any subunits which belong to
639 -- it and which have context clauses of their own, since these
640 -- with'ed units are part of its own elaboration dependencies.
642 if Nkind (Unit (Unode)) in N_Unit_Body then
643 for S in Units.First .. Last_Unit loop
645 -- We are only interested in subunits. For preproc. data and
646 -- def. files, Cunit is Empty, so we need to test that first.
648 if Cunit (S) /= Empty
649 and then Nkind (Unit (Cunit (S))) = N_Subunit
650 then
651 Pnode := Library_Unit (Cunit (S));
653 -- In gnatc mode, the errors in the subunits will not have
654 -- been recorded, but the analysis of the subunit may have
655 -- failed. There is no information to add to ALI file in
656 -- this case.
658 if No (Pnode) then
659 exit;
660 end if;
662 -- Find ultimate parent of the subunit
664 while Nkind (Unit (Pnode)) = N_Subunit loop
665 Pnode := Library_Unit (Pnode);
666 end loop;
668 -- See if it belongs to current unit, and if so, include
669 -- its with_clauses.
671 if Pnode = Unode then
672 Collect_Withs (Cunit (S));
673 end if;
674 end if;
675 end loop;
676 end if;
678 Write_With_Lines;
680 -- Generate task stack lines
682 if Primary_Stack_Count (Unit_Num) > 0
683 or else Sec_Stack_Count (Unit_Num) > 0
684 then
685 Write_Info_Initiate ('T');
686 Write_Info_Char (' ');
687 Write_Info_Int (Primary_Stack_Count (Unit_Num));
688 Write_Info_Char (' ');
689 Write_Info_Int (Sec_Stack_Count (Unit_Num));
690 Write_Info_EOL;
691 end if;
693 -- Generate the linker option lines
695 for J in 1 .. Linker_Option_Lines.Last loop
697 -- Pragma Linker_Options is not allowed in predefined generic
698 -- units. This is because they won't be read, due to the fact that
699 -- with lines for generic units lack the file name and lib name
700 -- parameters (see Lib_Writ spec for an explanation).
702 if Is_Generic_Unit (Cunit_Entity (Main_Unit))
703 and then Is_Predefined_Unit (Current_Sem_Unit)
704 and then Linker_Option_Lines.Table (J).Unit = Unit_Num
705 then
706 Set_Standard_Error;
707 Write_Line
708 ("linker options not allowed in predefined generic unit");
709 raise Unrecoverable_Error;
710 end if;
712 -- Output one linker option line
714 declare
715 S : Linker_Option_Entry renames Linker_Option_Lines.Table (J);
716 begin
717 if S.Unit = Unit_Num then
718 Write_Info_Initiate ('L');
719 Write_Info_Char (' ');
720 Write_Info_Slit (S.Option);
721 Write_Info_EOL;
722 end if;
723 end;
724 end loop;
726 -- Output notes
728 for J in 1 .. Notes.Last loop
729 declare
730 N : constant Node_Id := Notes.Table (J);
731 L : constant Source_Ptr := Sloc (N);
732 U : constant Unit_Number_Type :=
733 Unit (Get_Source_File_Index (L));
734 C : Character;
736 Note_Unit : Unit_Number_Type;
737 -- The unit in whose U section this note must be emitted:
738 -- notes for subunits are emitted along with the main unit;
739 -- all other notes are emitted as part of the enclosing
740 -- compilation unit.
742 begin
743 if U /= No_Unit and then Nkind (Unit (Cunit (U))) = N_Subunit
744 then
745 Note_Unit := Main_Unit;
746 else
747 Note_Unit := U;
748 end if;
750 -- No action needed for pragmas removed by the expander (for
751 -- example, pragmas of ignored ghost entities).
753 if Nkind (N) = N_Null_Statement then
754 pragma Assert (Nkind (Original_Node (N)) = N_Pragma);
755 null;
757 elsif Note_Unit = Unit_Num then
758 Write_Info_Initiate ('N');
759 Write_Info_Char (' ');
761 case Pragma_Name (N) is
762 when Name_Annotate | Name_GNAT_Annotate =>
763 C := 'A';
764 when Name_Comment =>
765 C := 'C';
766 when Name_Ident =>
767 C := 'I';
768 when Name_Title =>
769 C := 'T';
770 when Name_Subtitle =>
771 C := 'S';
772 when others =>
773 raise Program_Error;
774 end case;
776 Write_Info_Char (C);
777 Write_Info_Int (Int (Get_Logical_Line_Number (L)));
778 Write_Info_Char (':');
779 Write_Info_Int (Int (Get_Column_Number (L)));
781 -- Indicate source file of annotation if different from
782 -- compilation unit source file (case of annotation coming
783 -- from a separate).
785 if Get_Source_File_Index (L) /= Source_Index (Unit_Num) then
786 Write_Info_Char (':');
787 Write_Info_Name (File_Name (Get_Source_File_Index (L)));
788 end if;
790 declare
791 A : Node_Id;
793 begin
794 A := First (Pragma_Argument_Associations (N));
795 while Present (A) loop
796 Write_Info_Char (' ');
798 if Chars (A) /= No_Name then
799 Write_Info_Name (Chars (A));
800 Write_Info_Char (':');
801 end if;
803 declare
804 Expr : constant Node_Id := Expression (A);
806 begin
807 if Nkind (Expr) = N_Identifier then
808 Write_Info_Name (Chars (Expr));
810 elsif Nkind (Expr) = N_Integer_Literal
811 and then Is_OK_Static_Expression (Expr)
812 then
813 Write_Info_Uint (Intval (Expr));
815 elsif Nkind (Expr) = N_String_Literal
816 and then Is_OK_Static_Expression (Expr)
817 then
818 Write_Info_Slit (Strval (Expr));
820 else
821 Write_Info_Str ("<expr>");
822 end if;
823 end;
825 Next (A);
826 end loop;
827 end;
829 Write_Info_EOL;
830 end if;
831 end;
832 end loop;
833 end Write_Unit_Information;
835 ----------------------
836 -- Write_With_Lines --
837 ----------------------
839 procedure Write_With_Lines is
840 Pname : constant Unit_Name_Type :=
841 Get_Parent_Spec_Name (Unit_Name (Main_Unit));
842 Body_Fname : File_Name_Type;
843 Body_Index : Nat;
844 Cunit : Node_Id;
845 Fname : File_Name_Type;
846 Num_Withs : Int := 0;
847 Unum : Unit_Number_Type;
848 Uname : Unit_Name_Type;
849 With_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 1));
851 procedure Write_With_File_Names
852 (Nam : in out File_Name_Type;
853 Idx : Nat);
854 -- Write source file name Nam and ALI file name for unit index Idx.
855 -- Possibly change Nam to lowercase (generating a new file name).
857 ---------------------------
858 -- Write_With_File_Names --
859 ---------------------------
861 procedure Write_With_File_Names
862 (Nam : in out File_Name_Type;
863 Idx : Nat)
865 begin
866 if not File_Names_Case_Sensitive then
867 Get_Name_String (Nam);
868 To_Lower (Name_Buffer (1 .. Name_Len));
869 Nam := Name_Find;
870 end if;
872 Write_Info_Name (Nam);
873 Write_Info_Tab (49);
874 Write_Info_Name (Lib_File_Name (Nam, Idx));
875 end Write_With_File_Names;
877 -- Start of processing for Write_With_Lines
879 begin
880 -- Loop to build the with table. A with on the main unit itself
881 -- is ignored (AARM 10.2(14a)). Such a with-clause can occur if
882 -- the main unit is a subprogram with no spec, and a subunit of
883 -- it unnecessarily withs the parent.
885 for J in Units.First + 1 .. Last_Unit loop
887 -- Add element to with table if it is with'ed or if it is the
888 -- parent spec of the main unit (case of main unit is a child
889 -- unit). The latter with is not needed for semantic purposes,
890 -- but is required by the binder for elaboration purposes. For
891 -- preprocessing data and definition files, there is no Unit_Name,
892 -- check for that first.
894 if Present (Unit_Name (J))
895 and then (With_Flags (J) or else Unit_Name (J) = Pname)
896 then
897 Num_Withs := Num_Withs + 1;
898 With_Table (Num_Withs) := J;
899 end if;
900 end loop;
902 -- Sort and output the table
904 Sort (With_Table (1 .. Num_Withs));
906 for J in 1 .. Num_Withs loop
907 Unum := With_Table (J);
909 -- Do not generate a with line for an ignored Ghost unit because
910 -- the unit does not have an ALI file.
912 if Is_Ignored_Ghost_Entity (Cunit_Entity (Unum)) then
913 goto Next_With_Line;
914 end if;
916 Cunit := Units.Table (Unum).Cunit;
917 Uname := Units.Table (Unum).Unit_Name;
918 Fname := Units.Table (Unum).Unit_File_Name;
920 -- Limited with clauses must be processed first because they are
921 -- the most specific among the three kinds.
923 if Ekind (Cunit_Entity (Unum)) = E_Package
924 and then From_Limited_With (Cunit_Entity (Unum))
925 then
926 Write_Info_Initiate ('Y');
928 elsif Has_Implicit_With (Unum) = Yes then
929 Write_Info_Initiate ('Z');
931 else
932 Write_Info_Initiate ('W');
933 end if;
935 Write_Info_Char (' ');
936 Write_Info_Name (Uname);
938 -- Now we need to figure out the names of the files that contain
939 -- the with'ed unit. These will usually be the files for the body,
940 -- except in the case of a package that has no body. Note that we
941 -- have a specific exemption here for predefined library generics
942 -- (see comments for Generic_May_Lack_ALI). We do not generate
943 -- dependency upon the ALI file for such units. Older compilers
944 -- used to not support generating code (and ALI) for generics, and
945 -- we want to avoid having different processing (namely, different
946 -- lists of files to be compiled) for different stages of the
947 -- bootstrap.
949 if not ((Nkind (Unit (Cunit)) in N_Generic_Declaration
950 or else
951 Nkind (Unit (Cunit)) in N_Generic_Renaming_Declaration)
952 and then Generic_May_Lack_ALI (Unum))
954 -- In SPARK mode, always generate the dependencies on ALI
955 -- files, which are required to compute frame conditions
956 -- of subprograms.
958 or else GNATprove_Mode
959 then
960 Write_Info_Tab (25);
962 if Is_Spec_Name (Uname) then
963 Body_Fname :=
964 Get_File_Name
965 (Uname => Get_Body_Name (Uname),
966 Subunit => False,
967 May_Fail => True);
969 Body_Index := Get_Unit_Index (Get_Body_Name (Uname));
971 if Body_Fname = No_File then
972 Body_Fname := Get_File_Name (Uname, Subunit => False);
973 Body_Index := Get_Unit_Index (Uname);
974 end if;
975 else
976 Body_Fname := Get_File_Name (Uname, Subunit => False);
977 Body_Index := Get_Unit_Index (Uname);
978 end if;
980 -- A package is considered to have a body if it requires
981 -- a body or if a body is present in Ada 83 mode.
983 if Body_Required (Cunit)
984 or else (Ada_Version = Ada_83
985 and then Full_Source_Name (Body_Fname) /= No_File)
986 then
987 Write_With_File_Names (Body_Fname, Body_Index);
988 else
989 Write_With_File_Names (Fname, Munit_Index (Unum));
990 end if;
992 if Ekind (Cunit_Entity (Unum)) = E_Package
993 and then From_Limited_With (Cunit_Entity (Unum))
994 then
995 null;
996 else
997 if Elab_Flags (Unum) then
998 Write_Info_Str (" E");
999 end if;
1001 if Elab_All_Flags (Unum) then
1002 Write_Info_Str (" EA");
1003 end if;
1005 if Elab_Des_Flags (Unum) then
1006 Write_Info_Str (" ED");
1007 end if;
1009 if Elab_All_Des_Flags (Unum) then
1010 Write_Info_Str (" AD");
1011 end if;
1012 end if;
1013 end if;
1015 Write_Info_EOL;
1017 <<Next_With_Line>>
1018 null;
1019 end loop;
1021 -- Finally generate the special lines for cases of Restriction_Set
1022 -- with No_Dependence and no restriction present.
1024 declare
1025 Unam : Unit_Name_Type;
1027 begin
1028 for J in Restriction_Set_Dependences.First ..
1029 Restriction_Set_Dependences.Last
1030 loop
1031 Unam := Restriction_Set_Dependences.Table (J);
1033 -- Don't need an entry if already in the unit table
1035 for U in 0 .. Last_Unit loop
1036 if Unit_Name (U) = Unam then
1037 goto Next_Restriction_Set;
1038 end if;
1039 end loop;
1041 -- Otherwise generate the entry
1043 Write_Info_Initiate ('W');
1044 Write_Info_Char (' ');
1045 Write_Info_Name (Unam);
1046 Write_Info_EOL;
1048 <<Next_Restriction_Set>>
1049 null;
1050 end loop;
1051 end;
1052 end Write_With_Lines;
1054 -- Start of processing for Write_ALI
1056 begin
1057 -- We never write an ALI file if the original operating mode was
1058 -- syntax-only (-gnats switch used in compiler invocation line).
1060 if Original_Operating_Mode = Check_Syntax then
1061 return;
1062 end if;
1064 -- Generation of ALI files may be disabled, e.g. for formal verification
1065 -- back-end.
1067 if Disable_ALI_File then
1068 return;
1069 end if;
1071 -- Build sorted source dependency table
1073 for Unum in Units.First .. Last_Unit loop
1074 if Cunit_Entity (Unum) = Empty
1075 or else not From_Limited_With (Cunit_Entity (Unum))
1076 then
1077 -- Units that are not analyzed need not appear in the dependency
1078 -- list. These units are either units appearing in limited_with
1079 -- clauses of other units, or units loaded for inlining that end
1080 -- up not inlined by a later decision of the inlining code, to
1081 -- prevent circularities. We want to exclude these files from the
1082 -- list of dependencies, so that the dependency number of other
1083 -- is correctly set, as that number is used by cross-reference
1084 -- tools to relate entity information to the unit in which they
1085 -- are declared.
1087 if Present (Cunit_Entity (Unum))
1088 and then Ekind (Cunit_Entity (Unum)) = E_Void
1089 and then Nkind (Unit (Cunit (Unum))) /= N_Subunit
1090 and then Serious_Errors_Detected = 0
1091 then
1092 null;
1094 else
1095 Num_Sdep := Num_Sdep + 1;
1096 Sdep_Table (Num_Sdep) := Unum;
1097 end if;
1098 end if;
1099 end loop;
1101 -- Sort the table so that the D lines are in order
1103 Lib.Sort (Sdep_Table (1 .. Num_Sdep));
1105 -- Acquire compilation arguments and prepare to write out a new ali
1106 -- file.
1108 Create_Output_Library_Info;
1110 -- Output version line
1112 Write_Info_Initiate ('V');
1113 Write_Info_Str (" """);
1114 Write_Info_Str (Verbose_Library_Version);
1115 Write_Info_Char ('"');
1117 Write_Info_EOL;
1119 -- Output main program line if this is acceptable main program
1121 Output_Main_Program_Line : declare
1122 U : Node_Id := Unit (Units.Table (Main_Unit).Cunit);
1123 S : Node_Id;
1125 procedure M_Parameters;
1126 -- Output parameters for main program line
1128 ------------------
1129 -- M_Parameters --
1130 ------------------
1132 procedure M_Parameters is
1133 begin
1134 if Main_Priority (Main_Unit) /= Default_Main_Priority then
1135 Write_Info_Char (' ');
1136 Write_Info_Nat (Main_Priority (Main_Unit));
1137 end if;
1139 if Opt.Time_Slice_Set then
1140 Write_Info_Str (" T=");
1141 Write_Info_Nat (Opt.Time_Slice_Value);
1142 end if;
1144 if Main_CPU (Main_Unit) /= Default_Main_CPU then
1145 Write_Info_Str (" C=");
1146 Write_Info_Nat (Main_CPU (Main_Unit));
1147 end if;
1149 Write_Info_Str (" W=");
1150 Write_Info_Char
1151 (WC_Encoding_Letters (Wide_Character_Encoding_Method));
1153 Write_Info_EOL;
1154 end M_Parameters;
1156 -- Start of processing for Output_Main_Program_Line
1158 begin
1159 if Nkind (U) = N_Subprogram_Body
1160 or else
1161 (Nkind (U) = N_Package_Body
1162 and then
1163 Nkind (Original_Node (U)) in N_Subprogram_Instantiation)
1164 then
1165 -- If the unit is a subprogram instance, the entity for the
1166 -- subprogram is the alias of the visible entity, which is the
1167 -- related instance of the wrapper package. We retrieve the
1168 -- subprogram declaration of the desired entity.
1170 if Nkind (U) = N_Package_Body then
1171 U := Parent (Parent (
1172 Alias (Related_Instance (Defining_Unit_Name
1173 (Specification (Unit (Library_Unit (Parent (U)))))))));
1174 end if;
1176 S := Specification (U);
1178 -- A generic subprogram is never a main program
1180 if Nkind (U) = N_Subprogram_Body
1181 and then Present (Corresponding_Spec (U))
1182 and then Is_Generic_Subprogram (Corresponding_Spec (U))
1183 then
1184 null;
1186 elsif No (Parameter_Specifications (S)) then
1187 if Nkind (S) = N_Procedure_Specification then
1188 Write_Info_Initiate ('M');
1189 Write_Info_Str (" P");
1190 M_Parameters;
1192 else
1193 declare
1194 Nam : Node_Id := Defining_Unit_Name (S);
1196 begin
1197 -- If it is a child unit, get its simple name
1199 if Nkind (Nam) = N_Defining_Program_Unit_Name then
1200 Nam := Defining_Identifier (Nam);
1201 end if;
1203 if Is_Integer_Type (Etype (Nam)) then
1204 Write_Info_Initiate ('M');
1205 Write_Info_Str (" F");
1206 M_Parameters;
1207 end if;
1208 end;
1209 end if;
1210 end if;
1211 end if;
1212 end Output_Main_Program_Line;
1214 -- Write command argument ('A') lines
1216 for A in 1 .. Compilation_Switches.Last loop
1217 Write_Info_Initiate ('A');
1218 Write_Info_Char (' ');
1219 Write_Info_Str (Compilation_Switches.Table (A).all);
1220 Write_Info_Terminate;
1221 end loop;
1223 -- Output CUDA Kernel lines
1225 for Unit in Units.First .. Last_Unit loop
1226 if Present (Cunit (Unit)) then
1227 Output_CUDA_Symbols (Unit);
1228 end if;
1229 end loop;
1231 -- Output parameters ('P') line
1233 Write_Info_Initiate ('P');
1235 if Compilation_Errors then
1236 Write_Info_Str (" CE");
1237 end if;
1239 if Opt.Detect_Blocking then
1240 Write_Info_Str (" DB");
1241 end if;
1243 if Tasking_Used and then not Is_Predefined_Unit (Main_Unit) then
1244 if Locking_Policy /= ' ' then
1245 Write_Info_Str (" L");
1246 Write_Info_Char (Locking_Policy);
1247 end if;
1249 if Queuing_Policy /= ' ' then
1250 Write_Info_Str (" Q");
1251 Write_Info_Char (Queuing_Policy);
1252 end if;
1254 if Task_Dispatching_Policy /= ' ' then
1255 Write_Info_Str (" T");
1256 Write_Info_Char (Task_Dispatching_Policy);
1257 Write_Info_Char (' ');
1258 end if;
1259 end if;
1261 if GNATprove_Mode then
1262 Write_Info_Str (" GP");
1263 end if;
1265 if Partition_Elaboration_Policy /= ' ' then
1266 Write_Info_Str (" E");
1267 Write_Info_Char (Partition_Elaboration_Policy);
1268 end if;
1270 if No_Component_Reordering_Config then
1271 Write_Info_Str (" NC");
1272 end if;
1274 if not Object then
1275 Write_Info_Str (" NO");
1276 end if;
1278 if No_Run_Time_Mode then
1279 Write_Info_Str (" NR");
1280 end if;
1282 if Normalize_Scalars then
1283 Write_Info_Str (" NS");
1284 end if;
1286 if Default_SSO_Config /= ' ' then
1287 Write_Info_Str (" O");
1288 Write_Info_Char (Default_SSO_Config);
1289 end if;
1291 if Sec_Stack_Used then
1292 Write_Info_Str (" SS");
1293 end if;
1295 if Unreserve_All_Interrupts then
1296 Write_Info_Str (" UA");
1297 end if;
1299 if ZCX_Exceptions then
1300 Write_Info_Str (" ZX");
1301 end if;
1303 Write_Info_EOL;
1305 -- Before outputting the restrictions line, update the setting of
1306 -- the No_Elaboration_Code flag. Violations of this restriction
1307 -- cannot be detected until after the backend has been called since
1308 -- it is the backend that sets this flag. We have to check all units
1309 -- for which we have generated code
1311 for Unit in Units.First .. Last_Unit loop
1312 if Units.Table (Unit).Generate_Code then
1313 if not Has_No_Elaboration_Code (Cunit (Unit)) then
1314 Main_Restrictions.Violated (No_Elaboration_Code) := True;
1315 exit;
1316 end if;
1317 end if;
1318 end loop;
1320 -- Positional case (only if debug flag -gnatd.R is set)
1322 if Debug_Flag_Dot_RR then
1324 -- Output first restrictions line
1326 Write_Info_Initiate ('R');
1327 Write_Info_Char (' ');
1329 -- First the information for the boolean restrictions
1331 for R in All_Boolean_Restrictions loop
1332 if Main_Restrictions.Set (R)
1333 and then not Restriction_Warnings (R)
1334 then
1335 Write_Info_Char ('r');
1336 elsif Main_Restrictions.Violated (R) then
1337 Write_Info_Char ('v');
1338 else
1339 Write_Info_Char ('n');
1340 end if;
1341 end loop;
1343 -- And now the information for the parameter restrictions
1345 for RP in All_Parameter_Restrictions loop
1346 if Main_Restrictions.Set (RP)
1347 and then not Restriction_Warnings (RP)
1348 then
1349 Write_Info_Char ('r');
1350 Write_Info_Nat (Nat (Main_Restrictions.Value (RP)));
1351 else
1352 Write_Info_Char ('n');
1353 end if;
1355 if not Main_Restrictions.Violated (RP)
1356 or else RP not in Checked_Parameter_Restrictions
1357 then
1358 Write_Info_Char ('n');
1359 else
1360 Write_Info_Char ('v');
1361 Write_Info_Nat (Nat (Main_Restrictions.Count (RP)));
1363 if Main_Restrictions.Unknown (RP) then
1364 Write_Info_Char ('+');
1365 end if;
1366 end if;
1367 end loop;
1369 Write_Info_EOL;
1371 -- Named case (if debug flag -gnatd.R is not set)
1373 else
1374 declare
1375 C : Character;
1377 begin
1378 -- Write RN header line with preceding blank line
1380 Write_Info_EOL;
1381 Write_Info_Initiate ('R');
1382 Write_Info_Char ('N');
1383 Write_Info_EOL;
1385 -- First the lines for the boolean restrictions
1387 for R in All_Boolean_Restrictions loop
1388 if Main_Restrictions.Set (R)
1389 and then not Restriction_Warnings (R)
1390 then
1391 C := 'R';
1392 elsif Main_Restrictions.Violated (R) then
1393 C := 'V';
1394 else
1395 goto Continue;
1396 end if;
1398 Write_Info_Initiate ('R');
1399 Write_Info_Char (C);
1400 Write_Info_Char (' ');
1401 Write_Info_Str (All_Boolean_Restrictions'Image (R));
1402 Write_Info_EOL;
1404 <<Continue>>
1405 null;
1406 end loop;
1407 end;
1409 -- And now the lines for the parameter restrictions
1411 for RP in All_Parameter_Restrictions loop
1412 if Main_Restrictions.Set (RP)
1413 and then not Restriction_Warnings (RP)
1414 then
1415 Write_Info_Initiate ('R');
1416 Write_Info_Str ("R ");
1417 Write_Info_Str (All_Parameter_Restrictions'Image (RP));
1418 Write_Info_Char ('=');
1419 Write_Info_Nat (Nat (Main_Restrictions.Value (RP)));
1420 Write_Info_EOL;
1421 end if;
1423 if not Main_Restrictions.Violated (RP)
1424 or else RP not in Checked_Parameter_Restrictions
1425 then
1426 null;
1427 else
1428 Write_Info_Initiate ('R');
1429 Write_Info_Str ("V ");
1430 Write_Info_Str (All_Parameter_Restrictions'Image (RP));
1431 Write_Info_Char ('=');
1432 Write_Info_Nat (Nat (Main_Restrictions.Count (RP)));
1434 if Main_Restrictions.Unknown (RP) then
1435 Write_Info_Char ('+');
1436 end if;
1438 Write_Info_EOL;
1439 end if;
1440 end loop;
1441 end if;
1443 -- Output R lines for No_Dependence entries
1445 for J in No_Dependences.First .. No_Dependences.Last loop
1446 if In_Extended_Main_Source_Unit (No_Dependences.Table (J).Unit)
1447 and then not No_Dependences.Table (J).Warn
1448 then
1449 Write_Info_Initiate ('R');
1450 Write_Info_Char (' ');
1451 Write_Unit_Name (No_Dependences.Table (J).Unit);
1452 Write_Info_EOL;
1453 end if;
1454 end loop;
1456 -- Output interrupt state lines
1458 for J in Interrupt_States.First .. Interrupt_States.Last loop
1459 Write_Info_Initiate ('I');
1460 Write_Info_Char (' ');
1461 Write_Info_Nat (Interrupt_States.Table (J).Interrupt_Number);
1462 Write_Info_Char (' ');
1463 Write_Info_Char (Interrupt_States.Table (J).Interrupt_State);
1464 Write_Info_Char (' ');
1465 Write_Info_Nat
1466 (Nat (Get_Logical_Line_Number
1467 (Interrupt_States.Table (J).Pragma_Loc)));
1468 Write_Info_EOL;
1469 end loop;
1471 -- Output priority specific dispatching lines
1473 for J in Specific_Dispatching.First .. Specific_Dispatching.Last loop
1474 Write_Info_Initiate ('S');
1475 Write_Info_Char (' ');
1476 Write_Info_Char (Specific_Dispatching.Table (J).Dispatching_Policy);
1477 Write_Info_Char (' ');
1478 Write_Info_Nat (Specific_Dispatching.Table (J).First_Priority);
1479 Write_Info_Char (' ');
1480 Write_Info_Nat (Specific_Dispatching.Table (J).Last_Priority);
1481 Write_Info_Char (' ');
1482 Write_Info_Nat
1483 (Nat (Get_Logical_Line_Number
1484 (Specific_Dispatching.Table (J).Pragma_Loc)));
1485 Write_Info_EOL;
1486 end loop;
1488 -- Loop through file table to output information for all units for which
1489 -- we have generated code, as marked by the Generate_Code flag.
1491 for Unit in Units.First .. Last_Unit loop
1492 if Units.Table (Unit).Generate_Code
1493 or else Unit = Main_Unit
1494 then
1495 Write_Info_EOL; -- blank line
1496 Write_Unit_Information (Unit);
1497 end if;
1498 end loop;
1500 Write_Info_EOL; -- blank line
1502 -- Output external version reference lines
1504 for J in 1 .. Version_Ref.Last loop
1505 Write_Info_Initiate ('E');
1506 Write_Info_Char (' ');
1508 for K in 1 .. String_Length (Version_Ref.Table (J)) loop
1509 Write_Info_Char_Code (Get_String_Char (Version_Ref.Table (J), K));
1510 end loop;
1512 Write_Info_EOL;
1513 end loop;
1515 -- Prepare to output the source dependency lines
1517 declare
1518 Unum : Unit_Number_Type;
1519 -- Number of unit being output
1521 Sind : Source_File_Index;
1522 -- Index of corresponding source file
1524 Fname : File_Name_Type;
1526 begin
1527 for J in 1 .. Num_Sdep loop
1528 Unum := Sdep_Table (J);
1529 Units.Table (Unum).Dependency_Num := J;
1530 Sind := Source_Index (Unum);
1532 Write_Info_Initiate ('D');
1533 Write_Info_Char (' ');
1535 -- Normal case of a unit entry with a source index
1537 if Sind > No_Source_File then
1539 if Config_Files_Store_Basename then
1540 Fname := Strip_Directory (File_Name (Sind));
1541 else
1542 Fname := File_Name (Sind);
1543 end if;
1545 -- Ensure that on platforms where the file names are not
1546 -- case sensitive, the recorded file name is in lower case.
1548 if not File_Names_Case_Sensitive then
1549 Get_Name_String (Fname);
1550 To_Lower (Name_Buffer (1 .. Name_Len));
1551 Fname := Name_Find;
1552 end if;
1554 Write_Info_Name_May_Be_Quoted (Fname);
1555 Write_Info_Tab (25);
1556 Write_Info_Str (String (Time_Stamp (Sind)));
1557 Write_Info_Char (' ');
1558 Write_Info_Str (Get_Hex_String (Source_Checksum (Sind)));
1560 -- If the dependency comes from a limited_with clause, record
1561 -- limited_checksum. This is disabled until full checksum
1562 -- changes are checked.
1564 -- if Present (Cunit_Entity (Unum))
1565 -- and then From_Limited_With (Cunit_Entity (Unum))
1566 -- then
1567 -- Write_Info_Char (' ');
1568 -- Write_Info_Char ('Y');
1569 -- Write_Info_Str (Get_Hex_String (Limited_Chk_Sum (Sind)));
1570 -- end if;
1572 -- If subunit, add unit name, omitting the %b at the end
1574 if Present (Cunit (Unum)) then
1575 Get_Decoded_Name_String (Unit_Name (Unum));
1576 Write_Info_Char (' ');
1578 if Nkind (Unit (Cunit (Unum))) = N_Subunit then
1579 Write_Info_Str (Name_Buffer (1 .. Name_Len - 2));
1580 else
1581 Write_Info_Str (Name_Buffer (1 .. Name_Len));
1582 end if;
1583 end if;
1585 -- If Source_Reference pragma used, output information
1587 if Num_SRef_Pragmas (Sind) > 0 then
1588 Write_Info_Char (' ');
1590 if Num_SRef_Pragmas (Sind) = 1 then
1591 Write_Info_Nat (Int (First_Mapped_Line (Sind)));
1592 else
1593 Write_Info_Nat (0);
1594 end if;
1596 Write_Info_Char (':');
1597 Write_Info_Name (Reference_Name (Sind));
1598 end if;
1600 -- Case where there is no source index (happens for missing
1601 -- files). In this case we write a dummy time stamp.
1603 else
1604 Write_Info_Name (Unit_File_Name (Unum));
1605 Write_Info_Tab (25);
1606 Write_Info_Str (String (Dummy_Time_Stamp));
1607 Write_Info_Char (' ');
1608 Write_Info_Str (Get_Hex_String (0));
1609 end if;
1611 Write_Info_EOL;
1612 end loop;
1613 end;
1615 -- Output the invocation graph
1617 Write_Invocation_Graph;
1619 -- Output cross-references
1621 if Opt.Xref_Active then
1622 Output_References;
1623 end if;
1625 -- Output SCO information if present
1627 if Generate_SCO then
1628 SCO_Record_Filtered;
1629 SCO_Output;
1630 end if;
1632 -- Output final blank line and we are done. This final blank line is
1633 -- probably junk, but we don't feel like making an incompatible change.
1635 Write_Info_Terminate;
1636 Close_Output_Library_Info;
1637 end Write_ALI;
1639 --------------------------------
1640 -- Write_Invocation_Construct --
1641 --------------------------------
1643 procedure Write_Invocation_Construct (IC_Id : Invocation_Construct_Id) is
1644 begin
1645 -- G header
1647 Write_Info_Initiate ('G');
1648 Write_Info_Char (' ');
1650 -- line-kind
1652 Write_Info_Char
1653 (Invocation_Graph_Line_Kind_To_Code (Invocation_Construct_Line));
1654 Write_Info_Char (' ');
1656 -- construct-kind
1658 Write_Info_Char (Invocation_Construct_Kind_To_Code (Kind (IC_Id)));
1659 Write_Info_Char (' ');
1661 -- construct-spec-placement
1663 Write_Info_Char
1664 (Declaration_Placement_Kind_To_Code (Spec_Placement (IC_Id)));
1665 Write_Info_Char (' ');
1667 -- construct-body-placement
1669 Write_Info_Char
1670 (Declaration_Placement_Kind_To_Code (Body_Placement (IC_Id)));
1671 Write_Info_Char (' ');
1673 -- construct-signature
1675 Write_Invocation_Signature (Signature (IC_Id));
1676 Write_Info_EOL;
1677 end Write_Invocation_Construct;
1679 ---------------------------------------
1680 -- Write_Invocation_Graph_Attributes --
1681 ---------------------------------------
1683 procedure Write_Invocation_Graph_Attributes is
1684 begin
1685 -- G header
1687 Write_Info_Initiate ('G');
1688 Write_Info_Char (' ');
1690 -- line-kind
1692 Write_Info_Char
1693 (Invocation_Graph_Line_Kind_To_Code
1694 (Invocation_Graph_Attributes_Line));
1695 Write_Info_Char (' ');
1697 -- encoding-kind
1699 Write_Info_Char
1700 (Invocation_Graph_Encoding_Kind_To_Code (Invocation_Graph_Encoding));
1701 Write_Info_EOL;
1702 end Write_Invocation_Graph_Attributes;
1704 ----------------------------
1705 -- Write_Invocation_Graph --
1706 ----------------------------
1708 procedure Write_Invocation_Graph is
1709 begin
1710 Write_Invocation_Graph_Attributes;
1712 -- First write out all invocation constructs declared within the current
1713 -- unit. This ensures that when this invocation is read, the invocation
1714 -- constructs are materialized before they are referenced by invocation
1715 -- relations.
1717 For_Each_Invocation_Construct (Write_Invocation_Construct'Access);
1719 -- Write out all invocation relations that originate from invocation
1720 -- constructs delared in the current unit.
1722 For_Each_Invocation_Relation (Write_Invocation_Relation'Access);
1723 end Write_Invocation_Graph;
1725 -------------------------------
1726 -- Write_Invocation_Relation --
1727 -------------------------------
1729 procedure Write_Invocation_Relation (IR_Id : Invocation_Relation_Id) is
1730 begin
1731 -- G header
1733 Write_Info_Initiate ('G');
1734 Write_Info_Char (' ');
1736 -- line-kind
1738 Write_Info_Char
1739 (Invocation_Graph_Line_Kind_To_Code (Invocation_Relation_Line));
1740 Write_Info_Char (' ');
1742 -- relation-kind
1744 Write_Info_Char (Invocation_Kind_To_Code (Kind (IR_Id)));
1745 Write_Info_Char (' ');
1747 -- (extra-name | "none")
1749 if Present (Extra (IR_Id)) then
1750 Write_Info_Name (Extra (IR_Id));
1751 else
1752 Write_Info_Str ("none");
1753 end if;
1755 Write_Info_Char (' ');
1757 -- invoker-signature
1759 Write_Invocation_Signature (Invoker (IR_Id));
1760 Write_Info_Char (' ');
1762 -- target-signature
1764 Write_Invocation_Signature (Target (IR_Id));
1766 Write_Info_EOL;
1767 end Write_Invocation_Relation;
1769 --------------------------------
1770 -- Write_Invocation_Signature --
1771 --------------------------------
1773 procedure Write_Invocation_Signature (IS_Id : Invocation_Signature_Id) is
1774 begin
1775 -- [
1777 Write_Info_Char ('[');
1779 -- name
1781 Write_Info_Name (Name (IS_Id));
1782 Write_Info_Char (' ');
1784 -- scope
1786 Write_Info_Name (IS_Scope (IS_Id));
1787 Write_Info_Char (' ');
1789 -- line
1791 Write_Info_Nat (Line (IS_Id));
1792 Write_Info_Char (' ');
1794 -- column
1796 Write_Info_Nat (Column (IS_Id));
1797 Write_Info_Char (' ');
1799 -- (locations | "none")
1801 if Present (Locations (IS_Id)) then
1802 Write_Info_Name (Locations (IS_Id));
1803 else
1804 Write_Info_Str ("none");
1805 end if;
1807 -- ]
1809 Write_Info_Char (']');
1810 end Write_Invocation_Signature;
1812 ---------------------
1813 -- Write_Unit_Name --
1814 ---------------------
1816 procedure Write_Unit_Name (N : Node_Id) is
1817 begin
1818 if Nkind (N) = N_Identifier then
1819 Write_Info_Name (Chars (N));
1821 else
1822 pragma Assert (Nkind (N) = N_Selected_Component);
1823 Write_Unit_Name (Prefix (N));
1824 Write_Info_Char ('.');
1825 Write_Unit_Name (Selector_Name (N));
1826 end if;
1827 end Write_Unit_Name;
1829 end Lib.Writ;