Remove some compile time warnings about duplicate definitions.
[official-gcc.git] / gcc / ada / lib-writ.adb
bloba7039f8390fff7114200dab8e6631d2d80b3305e
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- L I B . W R I T --
6 -- --
7 -- B o d y --
8 -- --
9 -- $Revision: 1.160 $
10 -- --
11 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
12 -- --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
23 -- --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
26 -- --
27 ------------------------------------------------------------------------------
29 with ALI; use ALI;
30 with Atree; use Atree;
31 with Casing; use Casing;
32 with Einfo; use Einfo;
33 with Errout; use Errout;
34 with Fname; use Fname;
35 with Fname.UF; use Fname.UF;
36 with Lib.Util; use Lib.Util;
37 with Lib.Xref; use Lib.Xref;
38 with Namet; use Namet;
39 with Nlists; use Nlists;
40 with Gnatvsn; use Gnatvsn;
41 with Opt; use Opt;
42 with Osint; use Osint;
43 with Par;
44 with Restrict; use Restrict;
45 with Scn; use Scn;
46 with Sinfo; use Sinfo;
47 with Sinput; use Sinput;
48 with Stringt; use Stringt;
49 with Targparm; use Targparm;
50 with Uname; use Uname;
52 with System.WCh_Con; use System.WCh_Con;
54 package body Lib.Writ is
56 ------------------------------
57 -- Ensure_System_Dependency --
58 ------------------------------
60 procedure Ensure_System_Dependency is
61 Discard : List_Id;
63 System_Uname : Unit_Name_Type;
64 -- Unit name for system spec if needed for dummy entry
66 System_Fname : File_Name_Type;
67 -- File name for system spec if needed for dummy entry
69 begin
70 -- Nothing to do if we already compiled System
72 for Unum in Units.First .. Last_Unit loop
73 if Units.Table (Unum).Source_Index = System_Source_File_Index then
74 return;
75 end if;
76 end loop;
78 -- If no entry for system.ads in the units table, then add a entry
79 -- to the units table for system.ads, which will be referenced when
80 -- the ali file is generated. We need this because every unit depends
81 -- on system as a result of Targparm scanning the system.ads file to
82 -- determine the target dependent parameters for the compilation.
84 Name_Len := 6;
85 Name_Buffer (1 .. 6) := "system";
86 System_Uname := Name_To_Unit_Name (Name_Enter);
87 System_Fname := File_Name (System_Source_File_Index);
89 Units.Increment_Last;
90 Units.Table (Units.Last) := (
91 Unit_File_Name => System_Fname,
92 Unit_Name => System_Uname,
93 Expected_Unit => System_Uname,
94 Source_Index => System_Source_File_Index,
95 Cunit => Empty,
96 Cunit_Entity => Empty,
97 Dependency_Num => 0,
98 Dependent_Unit => True,
99 Dynamic_Elab => False,
100 Fatal_Error => False,
101 Generate_Code => False,
102 Has_RACW => False,
103 Ident_String => Empty,
104 Loading => False,
105 Main_Priority => -1,
106 Serial_Number => 0,
107 Version => 0,
108 Error_Location => No_Location);
110 -- Parse system.ads so that the checksum is set right
112 Initialize_Scanner (Units.Last, System_Source_File_Index);
113 Discard := Par (Configuration_Pragmas => False);
114 end Ensure_System_Dependency;
116 ---------------
117 -- Write_ALI --
118 ---------------
120 procedure Write_ALI (Object : Boolean) is
122 ----------------
123 -- Local Data --
124 ----------------
126 Last_Unit : constant Unit_Number_Type := Units.Last;
127 -- Record unit number of last unit. We capture this in case we
128 -- have to add a dummy entry to the unit table for package System.
130 With_Flags : array (Units.First .. Last_Unit) of Boolean;
131 -- Array of flags to show which units are with'ed
133 Elab_Flags : array (Units.First .. Last_Unit) of Boolean;
134 -- Array of flags to show which units have pragma Elaborate set
136 Elab_All_Flags : array (Units.First .. Last_Unit) of Boolean;
137 -- Array of flags to show which units have pragma Elaborate All set
139 Elab_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
140 -- Array of flags to show which units have Elaborate_All_Desirable set
142 Sdep_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 2));
143 -- Sorted table of source dependencies. One extra entry in case we
144 -- have to add a dummy entry for System.
146 Num_Sdep : Nat := 0;
147 -- Number of active entries in Sdep_Table
149 -----------------------
150 -- Local Subprograms --
151 -----------------------
153 procedure Collect_Withs (Cunit : Node_Id);
154 -- Collect with lines for entries in the context clause of the
155 -- given compilation unit, Cunit.
157 procedure Update_Tables_From_ALI_File;
158 -- Given an up to date ALI file (see Up_To_Date_ALI_file_Exists
159 -- function), update tables from the ALI information, including
160 -- specifically the Compilation_Switches table.
162 function Up_To_Date_ALI_File_Exists return Boolean;
163 -- If there exists an ALI file that is up to date, then this function
164 -- initializes the tables in the ALI spec to contain information on
165 -- this file (using Scan_ALI) and returns True. If no file exists,
166 -- or the file is not up to date, then False is returned.
168 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type);
169 -- Write out the library information for one unit for which code is
170 -- generated (includes unit line and with lines).
172 procedure Write_With_Lines;
173 -- Write out with lines collected by calls to Collect_Withs
175 -------------------
176 -- Collect_Withs --
177 -------------------
179 procedure Collect_Withs (Cunit : Node_Id) is
180 Item : Node_Id;
181 Unum : Unit_Number_Type;
183 begin
184 Item := First (Context_Items (Cunit));
185 while Present (Item) loop
187 if Nkind (Item) = N_With_Clause then
188 Unum := Get_Cunit_Unit_Number (Library_Unit (Item));
189 With_Flags (Unum) := True;
191 if Elaborate_Present (Item) then
192 Elab_Flags (Unum) := True;
193 end if;
195 if Elaborate_All_Present (Item) then
196 Elab_All_Flags (Unum) := True;
197 end if;
199 if Elaborate_All_Desirable (Cunit_Entity (Unum)) then
200 Elab_Des_Flags (Unum) := True;
201 end if;
202 end if;
204 Next (Item);
205 end loop;
206 end Collect_Withs;
208 --------------------------------
209 -- Up_To_Date_ALI_File_Exists --
210 --------------------------------
212 function Up_To_Date_ALI_File_Exists return Boolean is
213 Name : File_Name_Type;
214 Text : Text_Buffer_Ptr;
215 Id : Sdep_Id;
216 Sind : Source_File_Index;
218 begin
219 Opt.Check_Object_Consistency := True;
220 Read_Library_Info (Name, Text);
222 -- Return if we could not find an ALI file
224 if Text = null then
225 return False;
226 end if;
228 -- Return if ALI file has bad format
230 Initialize_ALI;
232 if Scan_ALI (Name, Text, False, Err => True) = No_ALI_Id then
233 return False;
234 end if;
236 -- If we have an OK ALI file, check if it is up to date
237 -- Note that we assume that the ALI read has all the entries
238 -- we have in our table, plus some additional ones (that can
239 -- come from expansion).
241 Id := First_Sdep_Entry;
242 for J in 1 .. Num_Sdep loop
243 Sind := Units.Table (Sdep_Table (J)).Source_Index;
245 while Sdep.Table (Id).Sfile /= File_Name (Sind) loop
246 if Id = Sdep.Last then
247 return False;
248 else
249 Id := Id + 1;
250 end if;
251 end loop;
253 if Sdep.Table (Id).Stamp /= Time_Stamp (Sind) then
254 return False;
255 end if;
256 end loop;
258 return True;
259 end Up_To_Date_ALI_File_Exists;
261 ---------------------------------
262 -- Update_Tables_From_ALI_File --
263 ---------------------------------
265 procedure Update_Tables_From_ALI_File is
266 begin
267 -- Build Compilation_Switches table
269 Compilation_Switches.Init;
271 for J in First_Arg_Entry .. Args.Last loop
272 Compilation_Switches.Increment_Last;
273 Compilation_Switches.Table (Compilation_Switches.Last) :=
274 Args.Table (J);
275 end loop;
276 end Update_Tables_From_ALI_File;
278 ----------------------------
279 -- Write_Unit_Information --
280 ----------------------------
282 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type) is
283 Unode : constant Node_Id := Cunit (Unit_Num);
284 Ukind : constant Node_Kind := Nkind (Unit (Unode));
285 Uent : constant Entity_Id := Cunit_Entity (Unit_Num);
286 Pnode : Node_Id;
288 begin
289 Write_Info_Initiate ('U');
290 Write_Info_Char (' ');
291 Write_Info_Name (Unit_Name (Unit_Num));
292 Write_Info_Tab (25);
293 Write_Info_Name (Unit_File_Name (Unit_Num));
295 Write_Info_Tab (49);
296 Write_Info_Str (Version_Get (Unit_Num));
298 if Dynamic_Elab (Unit_Num) then
299 Write_Info_Str (" DE");
300 end if;
302 -- We set the Elaborate_Body indication if either an explicit pragma
303 -- was present, or if this is an instantiation. RM 12.3(20) requires
304 -- that the body be immediately elaborated after the spec. We would
305 -- normally do that anyway, but the EB we generate here ensures that
306 -- this gets done even when we use the -p gnatbind switch.
308 if Has_Pragma_Elaborate_Body (Uent)
309 or else (Ukind = N_Package_Declaration
310 and then Is_Generic_Instance (Uent)
311 and then Present (Corresponding_Body (Unit (Unode))))
312 then
313 Write_Info_Str (" EB");
314 end if;
316 -- Now see if we should tell the binder that an elaboration entity
317 -- is present, which must be reset to true during elaboration. We
318 -- generate the indication if the following condition is met:
320 -- If this is a spec ...
322 if (Is_Subprogram (Uent)
323 or else
324 Ekind (Uent) = E_Package
325 or else
326 Is_Generic_Unit (Uent))
328 -- and an elaboration entity was declared ...
330 and then Present (Elaboration_Entity (Uent))
332 -- and either the elaboration flag is required ...
334 and then
335 (Elaboration_Entity_Required (Uent)
337 -- or this unit has elaboration code ...
339 or else not Has_No_Elaboration_Code (Unode)
341 -- or this unit has a separate body and this
342 -- body has elaboration code.
344 or else
345 (Ekind (Uent) = E_Package
346 and then Present (Body_Entity (Uent))
347 and then
348 not Has_No_Elaboration_Code
349 (Parent
350 (Declaration_Node
351 (Body_Entity (Uent))))))
352 then
353 Write_Info_Str (" EE");
354 end if;
356 if Has_No_Elaboration_Code (Unode) then
357 Write_Info_Str (" NE");
358 end if;
360 if Is_Preelaborated (Uent) then
361 Write_Info_Str (" PR");
362 end if;
364 if Is_Pure (Uent) then
365 Write_Info_Str (" PU");
366 end if;
368 if Has_RACW (Unit_Num) then
369 Write_Info_Str (" RA");
370 end if;
372 if Is_Remote_Call_Interface (Uent) then
373 Write_Info_Str (" RC");
374 end if;
376 if Is_Remote_Types (Uent) then
377 Write_Info_Str (" RT");
378 end if;
380 if Is_Shared_Passive (Uent) then
381 Write_Info_Str (" SP");
382 end if;
384 if Ukind = N_Subprogram_Declaration
385 or else Ukind = N_Subprogram_Body
386 then
387 Write_Info_Str (" SU");
389 elsif Ukind = N_Package_Declaration
390 or else
391 Ukind = N_Package_Body
392 then
393 -- If this is a wrapper package for a subprogram instantiation,
394 -- the user view is the subprogram. Note that in this case the
395 -- ali file contains both the spec and body of the instance.
397 if Is_Wrapper_Package (Uent) then
398 Write_Info_Str (" SU");
399 else
400 Write_Info_Str (" PK");
401 end if;
403 elsif Ukind = N_Generic_Package_Declaration then
404 Write_Info_Str (" PK");
406 end if;
408 if Ukind in N_Generic_Declaration
409 or else
410 (Present (Library_Unit (Unode))
411 and then
412 Nkind (Unit (Library_Unit (Unode))) in N_Generic_Declaration)
413 then
414 Write_Info_Str (" GE");
415 end if;
417 if not Is_Internal_File_Name (Unit_File_Name (Unit_Num), True) then
418 case Identifier_Casing (Source_Index (Unit_Num)) is
419 when All_Lower_Case => Write_Info_Str (" IL");
420 when All_Upper_Case => Write_Info_Str (" IU");
421 when others => null;
422 end case;
424 case Keyword_Casing (Source_Index (Unit_Num)) is
425 when Mixed_Case => Write_Info_Str (" KM");
426 when All_Upper_Case => Write_Info_Str (" KU");
427 when others => null;
428 end case;
429 end if;
431 if Initialize_Scalars then
432 Write_Info_Str (" IS");
433 end if;
435 Write_Info_EOL;
437 -- Generate with lines, first those that are directly with'ed
439 for J in With_Flags'Range loop
440 With_Flags (J) := False;
441 Elab_Flags (J) := False;
442 Elab_All_Flags (J) := False;
443 Elab_Des_Flags (J) := False;
444 end loop;
446 Collect_Withs (Unode);
448 -- For a body, we must also check for any subunits which belong to
449 -- it and which have context clauses of their own, since these
450 -- with'ed units are part of its own elaboration dependencies.
452 if Nkind (Unit (Unode)) in N_Unit_Body then
453 for S in Units.First .. Last_Unit loop
455 -- We are only interested in subunits
457 if Nkind (Unit (Cunit (S))) = N_Subunit then
458 Pnode := Library_Unit (Cunit (S));
460 -- In gnatc mode, the errors in the subunits will not
461 -- have been recorded, but the analysis of the subunit
462 -- may have failed. There is no information to add to
463 -- ALI file in this case.
465 if No (Pnode) then
466 exit;
467 end if;
469 -- Find ultimate parent of the subunit
471 while Nkind (Unit (Pnode)) = N_Subunit loop
472 Pnode := Library_Unit (Pnode);
473 end loop;
475 -- See if it belongs to current unit, and if so, include
476 -- its with_clauses.
478 if Pnode = Unode then
479 Collect_Withs (Cunit (S));
480 end if;
481 end if;
482 end loop;
483 end if;
485 Write_With_Lines;
486 end Write_Unit_Information;
488 ----------------------
489 -- Write_With_Lines --
490 ----------------------
492 procedure Write_With_Lines is
493 With_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 1));
494 Num_Withs : Int := 0;
495 Unum : Unit_Number_Type;
496 Cunit : Node_Id;
497 Cunite : Entity_Id;
498 Uname : Unit_Name_Type;
499 Fname : File_Name_Type;
500 Pname : constant Unit_Name_Type :=
501 Get_Parent_Spec_Name (Unit_Name (Main_Unit));
502 Body_Fname : File_Name_Type;
504 begin
505 -- Loop to build the with table. A with on the main unit itself
506 -- is ignored (AARM 10.2(14a)). Such a with-clause can occur if
507 -- the main unit is a subprogram with no spec, and a subunit of
508 -- it unecessarily withs the parent.
510 for J in Units.First + 1 .. Last_Unit loop
512 -- Add element to with table if it is with'ed or if it is the
513 -- parent spec of the main unit (case of main unit is a child
514 -- unit). The latter with is not needed for semantic purposes,
515 -- but is required by the binder for elaboration purposes.
517 if (With_Flags (J) or else Unit_Name (J) = Pname)
518 and then Units.Table (J).Dependent_Unit
519 then
520 Num_Withs := Num_Withs + 1;
521 With_Table (Num_Withs) := J;
522 end if;
523 end loop;
525 -- Sort and output the table
527 Sort (With_Table (1 .. Num_Withs));
529 for J in 1 .. Num_Withs loop
530 Unum := With_Table (J);
531 Cunit := Units.Table (Unum).Cunit;
532 Cunite := Units.Table (Unum).Cunit_Entity;
533 Uname := Units.Table (Unum).Unit_Name;
534 Fname := Units.Table (Unum).Unit_File_Name;
536 Write_Info_Initiate ('W');
537 Write_Info_Char (' ');
538 Write_Info_Name (Uname);
540 -- Now we need to figure out the names of the files that contain
541 -- the with'ed unit. These will usually be the files for the body,
542 -- except in the case of a package that has no body.
544 if (Nkind (Unit (Cunit)) not in N_Generic_Declaration
545 and then
546 Nkind (Unit (Cunit)) not in N_Generic_Renaming_Declaration)
547 or else Generic_Separately_Compiled (Cunite)
548 then
549 Write_Info_Tab (25);
551 if Is_Spec_Name (Uname) then
552 Body_Fname :=
553 Get_File_Name (Get_Body_Name (Uname), Subunit => False);
554 else
555 Body_Fname := Get_File_Name (Uname, Subunit => False);
556 end if;
558 -- A package is considered to have a body if it requires
559 -- a body or if a body is present in Ada 83 mode.
561 if Body_Required (Cunit)
562 or else (Ada_83
563 and then Full_Source_Name (Body_Fname) /= No_File)
564 then
565 Write_Info_Name (Body_Fname);
566 Write_Info_Tab (49);
567 Write_Info_Name (Lib_File_Name (Body_Fname));
568 else
569 Write_Info_Name (Fname);
570 Write_Info_Tab (49);
571 Write_Info_Name (Lib_File_Name (Fname));
572 end if;
574 if Elab_Flags (Unum) then
575 Write_Info_Str (" E");
576 end if;
578 if Elab_All_Flags (Unum) then
579 Write_Info_Str (" EA");
580 end if;
582 if Elab_Des_Flags (Unum) then
583 Write_Info_Str (" ED");
584 end if;
585 end if;
587 Write_Info_EOL;
588 end loop;
589 end Write_With_Lines;
591 -- Start of processing for Writ_ALI
593 begin
594 -- Build sorted source dependency table. We do this right away,
595 -- because it is referenced by Up_To_Date_ALI_File_Exists.
597 for Unum in Units.First .. Last_Unit loop
598 Num_Sdep := Num_Sdep + 1;
599 Sdep_Table (Num_Sdep) := Unum;
600 end loop;
602 -- Sort the table so that the D lines are in order
604 Lib.Sort (Sdep_Table (1 .. Num_Sdep));
606 -- If we are not generating code, and there is an up to date
607 -- ali file accessible, read it, and acquire the compilation
608 -- arguments from this file.
610 if Operating_Mode /= Generate_Code then
611 if Up_To_Date_ALI_File_Exists then
612 Update_Tables_From_ALI_File;
613 return;
614 end if;
615 end if;
617 -- Otherwise acquire compilation arguments and prepare to write
618 -- out a new ali file.
620 Create_Output_Library_Info;
622 -- Output version line
624 Write_Info_Initiate ('V');
625 Write_Info_Str (" """);
626 Write_Info_Str (Library_Version);
627 Write_Info_Char ('"');
629 Write_Info_EOL;
631 -- Output main program line if this is acceptable main program
633 declare
634 U : Node_Id := Unit (Units.Table (Main_Unit).Cunit);
635 S : Node_Id;
637 procedure M_Parameters;
638 -- Output parameters for main program line
640 procedure M_Parameters is
641 begin
642 if Main_Priority (Main_Unit) /= Default_Main_Priority then
643 Write_Info_Char (' ');
644 Write_Info_Nat (Main_Priority (Main_Unit));
645 end if;
647 if Opt.Time_Slice_Set then
648 Write_Info_Str (" T=");
649 Write_Info_Nat (Opt.Time_Slice_Value);
650 end if;
652 Write_Info_Str (" W=");
653 Write_Info_Char
654 (WC_Encoding_Letters (Wide_Character_Encoding_Method));
656 Write_Info_EOL;
657 end M_Parameters;
659 begin
660 if Nkind (U) = N_Subprogram_Body
661 or else (Nkind (U) = N_Package_Body
662 and then
663 (Nkind (Original_Node (U)) = N_Function_Instantiation
664 or else
665 Nkind (Original_Node (U)) =
666 N_Procedure_Instantiation))
667 then
668 -- If the unit is a subprogram instance, the entity for the
669 -- subprogram is the alias of the visible entity, which is the
670 -- related instance of the wrapper package. We retrieve the
671 -- subprogram declaration of the desired entity.
673 if Nkind (U) = N_Package_Body then
674 U := Parent (Parent (
675 Alias (Related_Instance (Defining_Unit_Name
676 (Specification (Unit (Library_Unit (Parent (U)))))))));
677 end if;
679 S := Specification (U);
681 if not Present (Parameter_Specifications (S)) then
682 if Nkind (S) = N_Procedure_Specification then
683 Write_Info_Initiate ('M');
684 Write_Info_Str (" P");
685 M_Parameters;
687 else
688 declare
689 Nam : Node_Id := Defining_Unit_Name (S);
691 begin
692 -- If it is a child unit, get its simple name.
694 if Nkind (Nam) = N_Defining_Program_Unit_Name then
695 Nam := Defining_Identifier (Nam);
696 end if;
698 if Is_Integer_Type (Etype (Nam)) then
699 Write_Info_Initiate ('M');
700 Write_Info_Str (" F");
701 M_Parameters;
702 end if;
703 end;
704 end if;
705 end if;
706 end if;
707 end;
709 -- Write command argmument ('A') lines
711 for A in 1 .. Compilation_Switches.Last loop
712 Write_Info_Initiate ('A');
713 Write_Info_Char (' ');
714 Write_Info_Str (Compilation_Switches.Table (A).all);
715 Write_Info_Terminate;
716 end loop;
718 -- Output parameters ('P') line
720 Write_Info_Initiate ('P');
722 if Compilation_Errors then
723 Write_Info_Str (" CE");
724 end if;
726 if Opt.Float_Format /= ' ' then
727 Write_Info_Str (" F");
729 if Opt.Float_Format = 'I' then
730 Write_Info_Char ('I');
732 elsif Opt.Float_Format_Long = 'D' then
733 Write_Info_Char ('D');
735 else
736 Write_Info_Char ('G');
737 end if;
738 end if;
740 if Tasking_Used
741 and then not Is_Predefined_File_Name (Unit_File_Name (Main_Unit))
742 then
743 if Locking_Policy /= ' ' then
744 Write_Info_Str (" L");
745 Write_Info_Char (Locking_Policy);
746 end if;
748 if Queuing_Policy /= ' ' then
749 Write_Info_Str (" Q");
750 Write_Info_Char (Queuing_Policy);
751 end if;
753 if Task_Dispatching_Policy /= ' ' then
754 Write_Info_Str (" T");
755 Write_Info_Char (Task_Dispatching_Policy);
756 Write_Info_Char (' ');
757 end if;
758 end if;
760 if not Object then
761 Write_Info_Str (" NO");
762 end if;
764 if No_Run_Time then
765 Write_Info_Str (" NR");
766 end if;
768 if Normalize_Scalars then
769 Write_Info_Str (" NS");
770 end if;
772 if Unreserve_All_Interrupts then
773 Write_Info_Str (" UA");
774 end if;
776 if ZCX_By_Default_On_Target then
777 if Unit_Exception_Table_Present then
778 Write_Info_Str (" UX");
779 end if;
781 Write_Info_Str (" ZX");
782 end if;
784 Write_Info_EOL;
786 -- Output restrictions line
788 Write_Info_Initiate ('R');
789 Write_Info_Char (' ');
791 for J in Partition_Restrictions loop
792 if Main_Restrictions (J) then
793 Write_Info_Char ('r');
794 elsif Violations (J) then
795 Write_Info_Char ('v');
796 else
797 Write_Info_Char ('n');
798 end if;
799 end loop;
801 Write_Info_EOL;
803 -- Loop through file table to output information for all units for which
804 -- we have generated code, as marked by the Generate_Code flag.
806 for Unit in Units.First .. Last_Unit loop
807 if Units.Table (Unit).Generate_Code
808 or else Unit = Main_Unit
809 then
810 Write_Info_EOL; -- blank line
811 Write_Unit_Information (Unit);
812 end if;
813 end loop;
815 Write_Info_EOL; -- blank line
817 -- Output linker option lines
819 for J in 1 .. Linker_Option_Lines.Last loop
820 declare
821 S : constant String_Id := Linker_Option_Lines.Table (J);
822 C : Character;
824 begin
825 Write_Info_Initiate ('L');
826 Write_Info_Str (" """);
828 for J in 1 .. String_Length (S) loop
829 C := Get_Character (Get_String_Char (S, J));
831 if C in Character'Val (16#20#) .. Character'Val (16#7E#)
832 and then C /= '{'
833 then
834 Write_Info_Char (C);
836 if C = '"' then
837 Write_Info_Char (C);
838 end if;
840 else
841 declare
842 Hex : array (0 .. 15) of Character := "0123456789ABCDEF";
844 begin
845 Write_Info_Char ('{');
846 Write_Info_Char (Hex (Character'Pos (C) / 16));
847 Write_Info_Char (Hex (Character'Pos (C) mod 16));
848 Write_Info_Char ('}');
849 end;
850 end if;
851 end loop;
853 Write_Info_Char ('"');
854 Write_Info_EOL;
855 end;
856 end loop;
858 -- Output external version reference lines
860 for J in 1 .. Version_Ref.Last loop
861 Write_Info_Initiate ('E');
862 Write_Info_Char (' ');
864 for K in 1 .. String_Length (Version_Ref.Table (J)) loop
865 Write_Info_Char_Code (Get_String_Char (Version_Ref.Table (J), K));
866 end loop;
868 Write_Info_EOL;
869 end loop;
871 -- Prepare to output the source dependency lines
873 declare
874 Unum : Unit_Number_Type;
875 -- Number of unit being output
877 Sind : Source_File_Index;
878 -- Index of corresponding source file
880 begin
881 for J in 1 .. Num_Sdep loop
882 Unum := Sdep_Table (J);
883 Sind := Units.Table (Unum).Source_Index;
885 -- Error defence, ignore entries with no source index
887 if Sind /= No_Source_File then
888 Units.Table (Unum).Dependency_Num := J;
890 if Units.Table (Unum).Dependent_Unit then
891 Write_Info_Initiate ('D');
892 Write_Info_Char (' ');
893 Write_Info_Name (File_Name (Sind));
894 Write_Info_Tab (25);
895 Write_Info_Str (String (Time_Stamp (Sind)));
896 Write_Info_Char (' ');
897 Write_Info_Str (Get_Hex_String (Source_Checksum (Sind)));
899 -- If subunit, add unit name, omitting the %b at the end
901 if Present (Cunit (Unum))
902 and then Nkind (Unit (Cunit (Unum))) = N_Subunit
903 then
904 Get_Decoded_Name_String (Unit_Name (Unum));
905 Write_Info_Char (' ');
906 Write_Info_Str (Name_Buffer (1 .. Name_Len - 2));
907 end if;
909 -- If Source_Reference pragma used output information
911 if Num_SRef_Pragmas (Sind) > 0 then
912 Write_Info_Char (' ');
914 if Num_SRef_Pragmas (Sind) = 1 then
915 Write_Info_Nat (Int (First_Mapped_Line (Sind)));
916 else
917 Write_Info_Nat (0);
918 end if;
920 Write_Info_Char (':');
921 Write_Info_Name (Reference_Name (Sind));
922 end if;
924 Write_Info_EOL;
925 end if;
926 end if;
927 end loop;
928 end;
930 Output_References;
931 Write_Info_Terminate;
932 Close_Output_Library_Info;
934 end Write_ALI;
936 end Lib.Writ;