2004-12-07 Eric Christopher <echristo@redhat.com>
[official-gcc.git] / gcc / ada / gnatls.adb
bloba2dd0a1ac49fcf7bba45a54a88a48557b5dc8a8c
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- G N A T L S --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2004 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 with ALI; use ALI;
28 with ALI.Util; use ALI.Util;
29 with Binderr; use Binderr;
30 with Butil; use Butil;
31 with Csets; use Csets;
32 with Fname; use Fname;
33 with Gnatvsn; use Gnatvsn;
34 with GNAT.OS_Lib; use GNAT.OS_Lib;
35 with Namet; use Namet;
36 with Opt; use Opt;
37 with Osint; use Osint;
38 with Osint.L; use Osint.L;
39 with Output; use Output;
40 with Rident; use Rident;
41 with Snames;
42 with Targparm; use Targparm;
43 with Types; use Types;
45 with GNAT.Case_Util; use GNAT.Case_Util;
47 procedure Gnatls is
48 pragma Ident (Gnat_Static_Version_String);
50 Max_Column : constant := 80;
52 No_Obj : aliased String := "<no_obj>";
54 type File_Status is (
55 OK, -- matching timestamp
56 Checksum_OK, -- only matching checksum
57 Not_Found, -- file not found on source PATH
58 Not_Same, -- neither checksum nor timestamp matching
59 Not_First_On_PATH); -- matching file hidden by Not_Same file on path
61 type Dir_Data;
62 type Dir_Ref is access Dir_Data;
64 type Dir_Data is record
65 Value : String_Access;
66 Next : Dir_Ref;
67 end record;
68 -- ??? comment needed
70 First_Source_Dir : Dir_Ref;
71 Last_Source_Dir : Dir_Ref;
72 -- The list of source directories from the command line.
73 -- These directories are added using Osint.Add_Src_Search_Dir
74 -- after those of the GNAT Project File, if any.
76 First_Lib_Dir : Dir_Ref;
77 Last_Lib_Dir : Dir_Ref;
78 -- The list of object directories from the command line.
79 -- These directories are added using Osint.Add_Lib_Search_Dir
80 -- after those of the GNAT Project File, if any.
82 Main_File : File_Name_Type;
83 Ali_File : File_Name_Type;
84 Text : Text_Buffer_Ptr;
85 Next_Arg : Positive;
87 Too_Long : Boolean := False;
88 -- When True, lines are too long for multi-column output and each
89 -- item of information is on a different line.
91 Selective_Output : Boolean := False;
92 Print_Usage : Boolean := False;
93 Print_Unit : Boolean := True;
94 Print_Source : Boolean := True;
95 Print_Object : Boolean := True;
96 -- Flags controlling the form of the output
98 Dependable : Boolean := False; -- flag -d
99 Also_Predef : Boolean := False;
101 Very_Verbose_Mode : Boolean := False; -- flag -V
103 Unit_Start : Integer;
104 Unit_End : Integer;
105 Source_Start : Integer;
106 Source_End : Integer;
107 Object_Start : Integer;
108 Object_End : Integer;
109 -- Various column starts and ends
111 Spaces : constant String (1 .. Max_Column) := (others => ' ');
113 RTS_Specified : String_Access := null;
114 -- Used to detect multiple use of --RTS= switch
116 -----------------------
117 -- Local Subprograms --
118 -----------------------
120 procedure Add_Lib_Dir (Dir : String);
121 -- Add an object directory in the list First_Lib_Dir-Last_Lib_Dir
123 procedure Add_Source_Dir (Dir : String);
124 -- Add a source directory in the list First_Source_Dir-Last_Source_Dir
126 procedure Find_General_Layout;
127 -- Determine the structure of the output (multi columns or not, etc)
129 procedure Find_Status
130 (FS : in out File_Name_Type;
131 Stamp : Time_Stamp_Type;
132 Checksum : Word;
133 Status : out File_Status);
134 -- Determine the file status (Status) of the file represented by FS
135 -- with the expected Stamp and checksum given as argument. FS will be
136 -- updated to the full file name if available.
138 function Corresponding_Sdep_Entry (A : ALI_Id; U : Unit_Id) return Sdep_Id;
139 -- Give the Sdep entry corresponding to the unit U in ali record A
141 procedure Output_Object (O : File_Name_Type);
142 -- Print out the name of the object when requested
144 procedure Output_Source (Sdep_I : Sdep_Id);
145 -- Print out the name and status of the source corresponding to this
146 -- sdep entry.
148 procedure Output_Status (FS : File_Status; Verbose : Boolean);
149 -- Print out FS either in a coded form if verbose is false or in an
150 -- expanded form otherwise.
152 procedure Output_Unit (ALI : ALI_Id; U_Id : Unit_Id);
153 -- Print out information on the unit when requested
155 procedure Reset_Print;
156 -- Reset Print flags properly when selective output is chosen
158 procedure Scan_Ls_Arg (Argv : String);
159 -- Scan and process lser specific arguments. Argv is a single argument
161 procedure Usage;
162 -- Print usage message
164 function Image (Restriction : Restriction_Id) return String;
165 -- Returns the capitalized image of Restriction
167 ---------------------------------------
168 -- GLADE specific output subprograms --
169 ---------------------------------------
171 package GLADE is
173 -- Any modification to this subunit requires a synchronization
174 -- with the GLADE implementation.
176 procedure Output_ALI (A : ALI_Id);
177 procedure Output_No_ALI (Afile : File_Name_Type);
179 end GLADE;
181 -----------------
182 -- Add_Lib_Dir --
183 -----------------
185 procedure Add_Lib_Dir (Dir : String) is
186 begin
187 if First_Lib_Dir = null then
188 First_Lib_Dir :=
189 new Dir_Data'
190 (Value => new String'(Dir),
191 Next => null);
192 Last_Lib_Dir := First_Lib_Dir;
194 else
195 Last_Lib_Dir.Next :=
196 new Dir_Data'
197 (Value => new String'(Dir),
198 Next => null);
199 Last_Lib_Dir := Last_Lib_Dir.Next;
200 end if;
201 end Add_Lib_Dir;
203 -- -----------------
204 -- Add_Source_Dir --
205 --------------------
207 procedure Add_Source_Dir (Dir : String) is
208 begin
209 if First_Source_Dir = null then
210 First_Source_Dir :=
211 new Dir_Data'
212 (Value => new String'(Dir),
213 Next => null);
214 Last_Source_Dir := First_Source_Dir;
216 else
217 Last_Source_Dir.Next :=
218 new Dir_Data'
219 (Value => new String'(Dir),
220 Next => null);
221 Last_Source_Dir := Last_Source_Dir.Next;
222 end if;
223 end Add_Source_Dir;
225 ------------------------------
226 -- Corresponding_Sdep_Entry --
227 ------------------------------
229 function Corresponding_Sdep_Entry
230 (A : ALI_Id;
231 U : Unit_Id) return Sdep_Id
233 begin
234 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
235 if Sdep.Table (D).Sfile = Units.Table (U).Sfile then
236 return D;
237 end if;
238 end loop;
240 Error_Msg_Name_1 := Units.Table (U).Uname;
241 Error_Msg_Name_2 := ALIs.Table (A).Afile;
242 Write_Eol;
243 Error_Msg ("wrong ALI format, can't find dependency line for & in %");
244 Exit_Program (E_Fatal);
245 end Corresponding_Sdep_Entry;
247 -------------------------
248 -- Find_General_Layout --
249 -------------------------
251 procedure Find_General_Layout is
252 Max_Unit_Length : Integer := 11;
253 Max_Src_Length : Integer := 11;
254 Max_Obj_Length : Integer := 11;
256 Len : Integer;
257 FS : File_Name_Type;
259 begin
260 -- Compute maximum of each column
262 for Id in ALIs.First .. ALIs.Last loop
263 Get_Name_String (Units.Table (ALIs.Table (Id).First_Unit).Uname);
264 if Also_Predef or else not Is_Internal_Unit then
266 if Print_Unit then
267 Len := Name_Len - 1;
268 Max_Unit_Length := Integer'Max (Max_Unit_Length, Len);
269 end if;
271 if Print_Source then
272 FS := Full_Source_Name (ALIs.Table (Id).Sfile);
274 if FS = No_File then
275 Get_Name_String (ALIs.Table (Id).Sfile);
276 Name_Len := Name_Len + 13;
277 else
278 Get_Name_String (FS);
279 end if;
281 Max_Src_Length := Integer'Max (Max_Src_Length, Name_Len + 1);
282 end if;
284 if Print_Object then
285 if ALIs.Table (Id).No_Object then
286 Max_Obj_Length :=
287 Integer'Max (Max_Obj_Length, No_Obj'Length);
288 else
289 Get_Name_String (ALIs.Table (Id).Ofile_Full_Name);
290 Max_Obj_Length := Integer'Max (Max_Obj_Length, Name_Len + 1);
291 end if;
292 end if;
293 end if;
294 end loop;
296 -- Verify is output is not wider than maximum number of columns
298 Too_Long :=
299 Verbose_Mode
300 or else
301 (Max_Unit_Length + Max_Src_Length + Max_Obj_Length) > Max_Column;
303 -- Set start and end of columns
305 Object_Start := 1;
306 Object_End := Object_Start - 1;
308 if Print_Object then
309 Object_End := Object_Start + Max_Obj_Length;
310 end if;
312 Unit_Start := Object_End + 1;
313 Unit_End := Unit_Start - 1;
315 if Print_Unit then
316 Unit_End := Unit_Start + Max_Unit_Length;
317 end if;
319 Source_Start := Unit_End + 1;
321 if Source_Start > Spaces'Last then
322 Source_Start := Spaces'Last;
323 end if;
325 Source_End := Source_Start - 1;
327 if Print_Source then
328 Source_End := Source_Start + Max_Src_Length;
329 end if;
330 end Find_General_Layout;
332 -----------------
333 -- Find_Status --
334 -----------------
336 procedure Find_Status
337 (FS : in out File_Name_Type;
338 Stamp : Time_Stamp_Type;
339 Checksum : Word;
340 Status : out File_Status)
342 Tmp1 : File_Name_Type;
343 Tmp2 : File_Name_Type;
345 begin
346 Tmp1 := Full_Source_Name (FS);
348 if Tmp1 = No_File then
349 Status := Not_Found;
351 elsif File_Stamp (Tmp1) = Stamp then
352 FS := Tmp1;
353 Status := OK;
355 elsif Checksums_Match (Get_File_Checksum (FS), Checksum) then
356 FS := Tmp1;
357 Status := Checksum_OK;
359 else
360 Tmp2 := Matching_Full_Source_Name (FS, Stamp);
362 if Tmp2 = No_File then
363 Status := Not_Same;
364 FS := Tmp1;
366 else
367 Status := Not_First_On_PATH;
368 FS := Tmp2;
369 end if;
370 end if;
371 end Find_Status;
373 -----------
374 -- GLADE --
375 -----------
377 package body GLADE is
379 N_Flags : Natural;
380 N_Indents : Natural := 0;
382 type Token_Type is
383 (T_No_ALI,
384 T_ALI,
385 T_Unit,
386 T_With,
387 T_Source,
388 T_Afile,
389 T_Ofile,
390 T_Sfile,
391 T_Name,
392 T_Main,
393 T_Kind,
394 T_Flags,
395 T_Preelaborated,
396 T_Pure,
397 T_Has_RACW,
398 T_Remote_Types,
399 T_Shared_Passive,
400 T_RCI,
401 T_Predefined,
402 T_Internal,
403 T_Is_Generic,
404 T_Procedure,
405 T_Function,
406 T_Package,
407 T_Subprogram,
408 T_Spec,
409 T_Body);
411 Image : constant array (Token_Type) of String_Access :=
412 (T_No_ALI => new String'("No_ALI"),
413 T_ALI => new String'("ALI"),
414 T_Unit => new String'("Unit"),
415 T_With => new String'("With"),
416 T_Source => new String'("Source"),
417 T_Afile => new String'("Afile"),
418 T_Ofile => new String'("Ofile"),
419 T_Sfile => new String'("Sfile"),
420 T_Name => new String'("Name"),
421 T_Main => new String'("Main"),
422 T_Kind => new String'("Kind"),
423 T_Flags => new String'("Flags"),
424 T_Preelaborated => new String'("Preelaborated"),
425 T_Pure => new String'("Pure"),
426 T_Has_RACW => new String'("Has_RACW"),
427 T_Remote_Types => new String'("Remote_Types"),
428 T_Shared_Passive => new String'("Shared_Passive"),
429 T_RCI => new String'("RCI"),
430 T_Predefined => new String'("Predefined"),
431 T_Internal => new String'("Internal"),
432 T_Is_Generic => new String'("Is_Generic"),
433 T_Procedure => new String'("procedure"),
434 T_Function => new String'("function"),
435 T_Package => new String'("package"),
436 T_Subprogram => new String'("subprogram"),
437 T_Spec => new String'("spec"),
438 T_Body => new String'("body"));
440 procedure Output_Name (N : Name_Id);
441 -- Remove any encoding info (%b and %s) and output N
443 procedure Output_Afile (A : File_Name_Type);
444 procedure Output_Ofile (O : File_Name_Type);
445 procedure Output_Sfile (S : File_Name_Type);
446 -- Output various names. Check that the name is different from
447 -- no name. Otherwise, skip the output.
449 procedure Output_Token (T : Token_Type);
450 -- Output token using a specific format. That is several
451 -- indentations and:
453 -- T_No_ALI .. T_With : <token> & " =>" & NL
454 -- T_Source .. T_Kind : <token> & " => "
455 -- T_Flags : <token> & " =>"
456 -- T_Preelab .. T_Body : " " & <token>
458 procedure Output_Sdep (S : Sdep_Id);
459 procedure Output_Unit (U : Unit_Id);
460 procedure Output_With (W : With_Id);
461 -- Output this entry as a global section (like ALIs)
463 ------------------
464 -- Output_Afile --
465 ------------------
467 procedure Output_Afile (A : File_Name_Type) is
468 begin
469 if A /= No_File then
470 Output_Token (T_Afile);
471 Write_Name (A);
472 Write_Eol;
473 end if;
474 end Output_Afile;
476 ----------------
477 -- Output_ALI --
478 ----------------
480 procedure Output_ALI (A : ALI_Id) is
481 begin
482 Output_Token (T_ALI);
483 N_Indents := N_Indents + 1;
485 Output_Afile (ALIs.Table (A).Afile);
486 Output_Ofile (ALIs.Table (A).Ofile_Full_Name);
487 Output_Sfile (ALIs.Table (A).Sfile);
489 -- Output Main
491 if ALIs.Table (A).Main_Program /= None then
492 Output_Token (T_Main);
494 if ALIs.Table (A).Main_Program = Proc then
495 Output_Token (T_Procedure);
496 else
497 Output_Token (T_Function);
498 end if;
500 Write_Eol;
501 end if;
503 -- Output Units
505 for U in ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit loop
506 Output_Unit (U);
507 end loop;
509 -- Output Sdeps
511 for S in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
512 Output_Sdep (S);
513 end loop;
515 N_Indents := N_Indents - 1;
516 end Output_ALI;
518 -------------------
519 -- Output_No_ALI --
520 -------------------
522 procedure Output_No_ALI (Afile : File_Name_Type) is
523 begin
524 Output_Token (T_No_ALI);
525 N_Indents := N_Indents + 1;
526 Output_Afile (Afile);
527 N_Indents := N_Indents - 1;
528 end Output_No_ALI;
530 -----------------
531 -- Output_Name --
532 -----------------
534 procedure Output_Name (N : Name_Id) is
535 begin
536 -- Remove any encoding info (%s or %b)
538 Get_Name_String (N);
539 if Name_Len > 2
540 and then Name_Buffer (Name_Len - 1) = '%'
541 then
542 Name_Len := Name_Len - 2;
543 end if;
545 Output_Token (T_Name);
546 Write_Str (Name_Buffer (1 .. Name_Len));
547 Write_Eol;
548 end Output_Name;
550 ------------------
551 -- Output_Ofile --
552 ------------------
554 procedure Output_Ofile (O : File_Name_Type) is
555 begin
556 if O /= No_File then
557 Output_Token (T_Ofile);
558 Write_Name (O);
559 Write_Eol;
560 end if;
561 end Output_Ofile;
563 -----------------
564 -- Output_Sdep --
565 -----------------
567 procedure Output_Sdep (S : Sdep_Id) is
568 begin
569 Output_Token (T_Source);
570 Write_Name (Sdep.Table (S).Sfile);
571 Write_Eol;
572 end Output_Sdep;
574 ------------------
575 -- Output_Sfile --
576 ------------------
578 procedure Output_Sfile (S : File_Name_Type) is
579 FS : File_Name_Type := S;
581 begin
582 if FS /= No_File then
584 -- We want to output the full source name
586 FS := Full_Source_Name (FS);
588 -- There is no full source name. This occurs for instance when a
589 -- withed unit has a spec file but no body file. This situation
590 -- is not a problem for GLADE since the unit may be located on
591 -- a partition we do not want to build. However, we need to
592 -- locate the spec file and to find its full source name.
593 -- Replace the body file name with the spec file name used to
594 -- compile the current unit when possible.
596 if FS = No_File then
597 Get_Name_String (S);
599 if Name_Len > 4
600 and then Name_Buffer (Name_Len - 3 .. Name_Len) = ".adb"
601 then
602 Name_Buffer (Name_Len) := 's';
603 FS := Full_Source_Name (Name_Find);
604 end if;
605 end if;
606 end if;
608 if FS /= No_File then
609 Output_Token (T_Sfile);
610 Write_Name (FS);
611 Write_Eol;
612 end if;
613 end Output_Sfile;
615 ------------------
616 -- Output_Token --
617 ------------------
619 procedure Output_Token (T : Token_Type) is
620 begin
621 if T in T_No_ALI .. T_Flags then
622 for J in 1 .. N_Indents loop
623 Write_Str (" ");
624 end loop;
626 Write_Str (Image (T).all);
628 for J in Image (T)'Length .. 12 loop
629 Write_Char (' ');
630 end loop;
632 Write_Str ("=>");
634 if T in T_No_ALI .. T_With then
635 Write_Eol;
636 elsif T in T_Source .. T_Name then
637 Write_Char (' ');
638 end if;
640 elsif T in T_Preelaborated .. T_Body then
641 if T in T_Preelaborated .. T_Is_Generic then
642 if N_Flags = 0 then
643 Output_Token (T_Flags);
644 end if;
646 N_Flags := N_Flags + 1;
647 end if;
649 Write_Char (' ');
650 Write_Str (Image (T).all);
652 else
653 Write_Str (Image (T).all);
654 end if;
655 end Output_Token;
657 -----------------
658 -- Output_Unit --
659 -----------------
661 procedure Output_Unit (U : Unit_Id) is
662 begin
663 Output_Token (T_Unit);
664 N_Indents := N_Indents + 1;
666 -- Output Name
668 Output_Name (Units.Table (U).Uname);
670 -- Output Kind
672 Output_Token (T_Kind);
674 if Units.Table (U).Unit_Kind = 'p' then
675 Output_Token (T_Package);
676 else
677 Output_Token (T_Subprogram);
678 end if;
680 if Name_Buffer (Name_Len) = 's' then
681 Output_Token (T_Spec);
682 else
683 Output_Token (T_Body);
684 end if;
686 Write_Eol;
688 -- Output source file name
690 Output_Sfile (Units.Table (U).Sfile);
692 -- Output Flags
694 N_Flags := 0;
696 if Units.Table (U).Preelab then
697 Output_Token (T_Preelaborated);
698 end if;
700 if Units.Table (U).Pure then
701 Output_Token (T_Pure);
702 end if;
704 if Units.Table (U).Has_RACW then
705 Output_Token (T_Has_RACW);
706 end if;
708 if Units.Table (U).Remote_Types then
709 Output_Token (T_Remote_Types);
710 end if;
712 if Units.Table (U).Shared_Passive then
713 Output_Token (T_Shared_Passive);
714 end if;
716 if Units.Table (U).RCI then
717 Output_Token (T_RCI);
718 end if;
720 if Units.Table (U).Predefined then
721 Output_Token (T_Predefined);
722 end if;
724 if Units.Table (U).Internal then
725 Output_Token (T_Internal);
726 end if;
728 if Units.Table (U).Is_Generic then
729 Output_Token (T_Is_Generic);
730 end if;
732 if N_Flags > 0 then
733 Write_Eol;
734 end if;
736 -- Output Withs
738 for W in Units.Table (U).First_With .. Units.Table (U).Last_With loop
739 Output_With (W);
740 end loop;
742 N_Indents := N_Indents - 1;
743 end Output_Unit;
745 -----------------
746 -- Output_With --
747 -----------------
749 procedure Output_With (W : With_Id) is
750 begin
751 Output_Token (T_With);
752 N_Indents := N_Indents + 1;
754 Output_Name (Withs.Table (W).Uname);
756 -- Output Kind
758 Output_Token (T_Kind);
760 if Name_Buffer (Name_Len) = 's' then
761 Output_Token (T_Spec);
762 else
763 Output_Token (T_Body);
764 end if;
766 Write_Eol;
768 Output_Afile (Withs.Table (W).Afile);
769 Output_Sfile (Withs.Table (W).Sfile);
771 N_Indents := N_Indents - 1;
772 end Output_With;
774 end GLADE;
776 -----------
777 -- Image --
778 -----------
780 function Image (Restriction : Restriction_Id) return String is
781 Result : String := Restriction'Img;
782 Skip : Boolean := True;
784 begin
785 for J in Result'Range loop
786 if Skip then
787 Skip := False;
788 Result (J) := To_Upper (Result (J));
790 elsif Result (J) = '_' then
791 Skip := True;
793 else
794 Result (J) := To_Lower (Result (J));
795 end if;
796 end loop;
798 return Result;
799 end Image;
801 -------------------
802 -- Output_Object --
803 -------------------
805 procedure Output_Object (O : File_Name_Type) is
806 Object_Name : String_Access;
808 begin
809 if Print_Object then
810 if O /= No_File then
811 Get_Name_String (O);
812 Object_Name := To_Host_File_Spec (Name_Buffer (1 .. Name_Len));
813 else
814 Object_Name := No_Obj'Unchecked_Access;
815 end if;
817 Write_Str (Object_Name.all);
819 if Print_Source or else Print_Unit then
820 if Too_Long then
821 Write_Eol;
822 Write_Str (" ");
823 else
824 Write_Str (Spaces
825 (Object_Start + Object_Name'Length .. Object_End));
826 end if;
827 end if;
828 end if;
829 end Output_Object;
831 -------------------
832 -- Output_Source --
833 -------------------
835 procedure Output_Source (Sdep_I : Sdep_Id) is
836 Stamp : constant Time_Stamp_Type := Sdep.Table (Sdep_I).Stamp;
837 Checksum : constant Word := Sdep.Table (Sdep_I).Checksum;
838 FS : File_Name_Type := Sdep.Table (Sdep_I).Sfile;
839 Status : File_Status;
840 Object_Name : String_Access;
842 begin
843 if Print_Source then
844 Find_Status (FS, Stamp, Checksum, Status);
845 Get_Name_String (FS);
847 Object_Name := To_Host_File_Spec (Name_Buffer (1 .. Name_Len));
849 if Verbose_Mode then
850 Write_Str (" Source => ");
851 Write_Str (Object_Name.all);
853 if not Too_Long then
854 Write_Str
855 (Spaces (Source_Start + Object_Name'Length .. Source_End));
856 end if;
858 Output_Status (Status, Verbose => True);
859 Write_Eol;
860 Write_Str (" ");
862 else
863 if not Selective_Output then
864 Output_Status (Status, Verbose => False);
865 end if;
867 Write_Str (Object_Name.all);
868 end if;
869 end if;
870 end Output_Source;
872 -------------------
873 -- Output_Status --
874 -------------------
876 procedure Output_Status (FS : File_Status; Verbose : Boolean) is
877 begin
878 if Verbose then
879 case FS is
880 when OK =>
881 Write_Str (" unchanged");
883 when Checksum_OK =>
884 Write_Str (" slightly modified");
886 when Not_Found =>
887 Write_Str (" file not found");
889 when Not_Same =>
890 Write_Str (" modified");
892 when Not_First_On_PATH =>
893 Write_Str (" unchanged version not first on PATH");
894 end case;
896 else
897 case FS is
898 when OK =>
899 Write_Str (" OK ");
901 when Checksum_OK =>
902 Write_Str (" MOK ");
904 when Not_Found =>
905 Write_Str (" ??? ");
907 when Not_Same =>
908 Write_Str (" DIF ");
910 when Not_First_On_PATH =>
911 Write_Str (" HID ");
912 end case;
913 end if;
914 end Output_Status;
916 -----------------
917 -- Output_Unit --
918 -----------------
920 procedure Output_Unit (ALI : ALI_Id; U_Id : Unit_Id) is
921 Kind : Character;
922 U : Unit_Record renames Units.Table (U_Id);
924 begin
925 if Print_Unit then
926 Get_Name_String (U.Uname);
927 Kind := Name_Buffer (Name_Len);
928 Name_Len := Name_Len - 2;
930 if not Verbose_Mode then
931 Write_Str (Name_Buffer (1 .. Name_Len));
933 else
934 Write_Str ("Unit => ");
935 Write_Eol;
936 Write_Str (" Name => ");
937 Write_Str (Name_Buffer (1 .. Name_Len));
938 Write_Eol;
939 Write_Str (" Kind => ");
941 if Units.Table (U_Id).Unit_Kind = 'p' then
942 Write_Str ("package ");
943 else
944 Write_Str ("subprogram ");
945 end if;
947 if Kind = 's' then
948 Write_Str ("spec");
949 else
950 Write_Str ("body");
951 end if;
952 end if;
954 if Verbose_Mode then
955 if U.Preelab or
956 U.No_Elab or
957 U.Pure or
958 U.Dynamic_Elab or
959 U.Has_RACW or
960 U.Remote_Types or
961 U.Shared_Passive or
962 U.RCI or
963 U.Predefined or
964 U.Internal or
965 U.Is_Generic or
966 U.Init_Scalars or
967 U.Interface or
968 U.Body_Needed_For_SAL or
969 U.Elaborate_Body
970 then
971 Write_Eol;
972 Write_Str (" Flags =>");
974 if U.Preelab then
975 Write_Str (" Preelaborable");
976 end if;
978 if U.No_Elab then
979 Write_Str (" No_Elab_Code");
980 end if;
982 if U.Pure then
983 Write_Str (" Pure");
984 end if;
986 if U.Dynamic_Elab then
987 Write_Str (" Dynamic_Elab");
988 end if;
990 if U.Has_RACW then
991 Write_Str (" Has_RACW");
992 end if;
994 if U.Remote_Types then
995 Write_Str (" Remote_Types");
996 end if;
998 if U.Shared_Passive then
999 Write_Str (" Shared_Passive");
1000 end if;
1002 if U.RCI then
1003 Write_Str (" RCI");
1004 end if;
1006 if U.Predefined then
1007 Write_Str (" Predefined");
1008 end if;
1010 if U.Internal then
1011 Write_Str (" Internal");
1012 end if;
1014 if U.Is_Generic then
1015 Write_Str (" Is_Generic");
1016 end if;
1018 if U.Init_Scalars then
1019 Write_Str (" Init_Scalars");
1020 end if;
1022 if U.Interface then
1023 Write_Str (" Interface");
1024 end if;
1026 if U.Body_Needed_For_SAL then
1027 Write_Str (" Body_Needed_For_SAL");
1028 end if;
1030 if U.Elaborate_Body then
1031 Write_Str (" Elaborate Body");
1032 end if;
1034 if U.Remote_Types then
1035 Write_Str (" Remote_Types");
1036 end if;
1038 if U.Shared_Passive then
1039 Write_Str (" Shared_Passive");
1040 end if;
1042 if U.Predefined then
1043 Write_Str (" Predefined");
1044 end if;
1046 end if;
1048 declare
1049 Restrictions : constant Restrictions_Info :=
1050 ALIs.Table (ALI).Restrictions;
1052 begin
1053 -- If the source was compiled with pragmas Restrictions,
1054 -- Display these restrictions.
1056 if Restrictions.Set /= (All_Restrictions => False) then
1057 Write_Eol;
1058 Write_Str (" pragma Restrictions =>");
1060 -- For boolean restrictions, just display the name of the
1061 -- restriction; for valued restrictions, also display the
1062 -- restriction value.
1064 for Restriction in All_Restrictions loop
1065 if Restrictions.Set (Restriction) then
1066 Write_Eol;
1067 Write_Str (" ");
1068 Write_Str (Image (Restriction));
1070 if Restriction in All_Parameter_Restrictions then
1071 Write_Str (" =>");
1072 Write_Str (Restrictions.Value (Restriction)'Img);
1073 end if;
1074 end if;
1075 end loop;
1076 end if;
1078 -- If the unit violates some Restrictions, display the list of
1079 -- these restrictions.
1081 if Restrictions.Violated /= (All_Restrictions => False) then
1082 Write_Eol;
1083 Write_Str (" Restrictions violated =>");
1085 -- For boolean restrictions, just display the name of the
1086 -- restriction; for valued restrictions, also display the
1087 -- restriction value.
1089 for Restriction in All_Restrictions loop
1090 if Restrictions.Violated (Restriction) then
1091 Write_Eol;
1092 Write_Str (" ");
1093 Write_Str (Image (Restriction));
1095 if Restriction in All_Parameter_Restrictions then
1096 if Restrictions.Count (Restriction) > 0 then
1097 Write_Str (" =>");
1099 if Restrictions.Unknown (Restriction) then
1100 Write_Str (" at least");
1101 end if;
1103 Write_Str (Restrictions.Count (Restriction)'Img);
1104 end if;
1105 end if;
1106 end if;
1107 end loop;
1108 end if;
1109 end;
1110 end if;
1112 if Print_Source then
1113 if Too_Long then
1114 Write_Eol;
1115 Write_Str (" ");
1116 else
1117 Write_Str (Spaces (Unit_Start + Name_Len + 1 .. Unit_End));
1118 end if;
1119 end if;
1120 end if;
1121 end Output_Unit;
1123 -----------------
1124 -- Reset_Print --
1125 -----------------
1127 procedure Reset_Print is
1128 begin
1129 if not Selective_Output then
1130 Selective_Output := True;
1131 Print_Source := False;
1132 Print_Object := False;
1133 Print_Unit := False;
1134 end if;
1135 end Reset_Print;
1137 -------------------
1138 -- Scan_Ls_Arg --
1139 -------------------
1141 procedure Scan_Ls_Arg (Argv : String) is
1142 FD : File_Descriptor;
1143 Len : Integer;
1145 begin
1146 pragma Assert (Argv'First = 1);
1148 if Argv'Length = 0 then
1149 return;
1150 end if;
1152 if Argv (1) = '-' then
1153 if Argv'Length = 1 then
1154 Fail ("switch character cannot be followed by a blank");
1156 -- Processing for -I-
1158 elsif Argv (2 .. Argv'Last) = "I-" then
1159 Opt.Look_In_Primary_Dir := False;
1161 -- Forbid -?- or -??- where ? is any character
1163 elsif (Argv'Length = 3 and then Argv (3) = '-')
1164 or else (Argv'Length = 4 and then Argv (4) = '-')
1165 then
1166 Fail ("Trailing ""-"" at the end of ", Argv, " forbidden.");
1168 -- Processing for -Idir
1170 elsif Argv (2) = 'I' then
1171 Add_Source_Dir (Argv (3 .. Argv'Last));
1172 Add_Lib_Dir (Argv (3 .. Argv'Last));
1174 -- Processing for -aIdir (to gcc this is like a -I switch)
1176 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
1177 Add_Source_Dir (Argv (4 .. Argv'Last));
1179 -- Processing for -aOdir
1181 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
1182 Add_Lib_Dir (Argv (4 .. Argv'Last));
1184 -- Processing for -aLdir (to gnatbind this is like a -aO switch)
1186 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
1187 Add_Lib_Dir (Argv (4 .. Argv'Last));
1189 -- Processing for -nostdinc
1191 elsif Argv (2 .. Argv'Last) = "nostdinc" then
1192 Opt.No_Stdinc := True;
1194 -- Processing for one character switches
1196 elsif Argv'Length = 2 then
1197 case Argv (2) is
1198 when 'a' => Also_Predef := True;
1199 when 'h' => Print_Usage := True;
1200 when 'u' => Reset_Print; Print_Unit := True;
1201 when 's' => Reset_Print; Print_Source := True;
1202 when 'o' => Reset_Print; Print_Object := True;
1203 when 'v' => Verbose_Mode := True;
1204 when 'd' => Dependable := True;
1205 when 'V' => Very_Verbose_Mode := True;
1207 when others => null;
1208 end case;
1210 -- Processing for -files=file
1212 elsif Argv'Length > 7 and then Argv (1 .. 7) = "-files=" then
1213 FD := Open_Read (Argv (8 .. Argv'Last), GNAT.OS_Lib.Text);
1215 if FD = Invalid_FD then
1216 Osint.Fail ("could not find text file """ &
1217 Argv (8 .. Argv'Last) & '"');
1218 end if;
1220 Len := Integer (File_Length (FD));
1222 declare
1223 Buffer : String (1 .. Len + 1);
1224 Index : Positive := 1;
1225 Last : Positive;
1227 begin
1228 -- Read the file
1230 Len := Read (FD, Buffer (1)'Address, Len);
1231 Buffer (Buffer'Last) := ASCII.NUL;
1232 Close (FD);
1234 -- Scan the file line by line
1236 while Index < Buffer'Last loop
1237 -- Find the end of line
1239 Last := Index;
1241 while Last <= Buffer'Last
1242 and then Buffer (Last) /= ASCII.LF
1243 and then Buffer (Last) /= ASCII.CR
1244 loop
1245 Last := Last + 1;
1246 end loop;
1248 -- Ignore empty lines
1250 if Last > Index then
1251 Add_File (Buffer (Index .. Last - 1));
1252 end if;
1254 Index := Last;
1256 -- Find the beginning of the next line
1258 while Buffer (Index) = ASCII.CR or else
1259 Buffer (Index) = ASCII.LF
1260 loop
1261 Index := Index + 1;
1262 end loop;
1263 end loop;
1264 end;
1266 -- Processing for --RTS=path
1268 elsif Argv'Length >= 5 and then Argv (1 .. 5) = "--RTS" then
1269 if Argv'Length <= 6 or else Argv (6) /= '='then
1270 Osint.Fail ("missing path for --RTS");
1272 else
1273 -- Check that it is the first time we see this switch or, if
1274 -- it is not the first time, the same path is specified.
1276 if RTS_Specified = null then
1277 RTS_Specified := new String'(Argv (7 .. Argv'Last));
1279 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
1280 Osint.Fail ("--RTS cannot be specified multiple times");
1281 end if;
1283 -- Valid --RTS switch
1285 Opt.No_Stdinc := True;
1286 Opt.RTS_Switch := True;
1288 declare
1289 Src_Path_Name : constant String_Ptr :=
1290 String_Ptr
1291 (Get_RTS_Search_Dir
1292 (Argv (7 .. Argv'Last), Include));
1293 Lib_Path_Name : constant String_Ptr :=
1294 String_Ptr
1295 (Get_RTS_Search_Dir
1296 (Argv (7 .. Argv'Last), Objects));
1298 begin
1299 if Src_Path_Name /= null
1300 and then Lib_Path_Name /= null
1301 then
1302 Add_Search_Dirs (Src_Path_Name, Include);
1303 Add_Search_Dirs (Lib_Path_Name, Objects);
1305 elsif Src_Path_Name = null
1306 and then Lib_Path_Name = null
1307 then
1308 Osint.Fail ("RTS path not valid: missing " &
1309 "adainclude and adalib directories");
1311 elsif Src_Path_Name = null then
1312 Osint.Fail ("RTS path not valid: missing " &
1313 "adainclude directory");
1315 elsif Lib_Path_Name = null then
1316 Osint.Fail ("RTS path not valid: missing " &
1317 "adalib directory");
1318 end if;
1319 end;
1320 end if;
1321 end if;
1323 -- If not a switch, it must be a file name
1325 else
1326 Add_File (Argv);
1327 end if;
1328 end Scan_Ls_Arg;
1330 -----------
1331 -- Usage --
1332 -----------
1334 procedure Usage is
1335 begin
1336 -- Usage line
1338 Write_Str ("Usage: ");
1339 Osint.Write_Program_Name;
1340 Write_Str (" switches [list of object files]");
1341 Write_Eol;
1342 Write_Eol;
1344 -- GNATLS switches
1346 Write_Str ("switches:");
1347 Write_Eol;
1349 -- Line for -a
1351 Write_Str (" -a also output relevant predefined units");
1352 Write_Eol;
1354 -- Line for -u
1356 Write_Str (" -u output only relevant unit names");
1357 Write_Eol;
1359 -- Line for -h
1361 Write_Str (" -h output this help message");
1362 Write_Eol;
1364 -- Line for -s
1366 Write_Str (" -s output only relevant source names");
1367 Write_Eol;
1369 -- Line for -o
1371 Write_Str (" -o output only relevant object names");
1372 Write_Eol;
1374 -- Line for -d
1376 Write_Str (" -d output sources on which specified units " &
1377 "depend");
1378 Write_Eol;
1380 -- Line for -v
1382 Write_Str (" -v verbose output, full path and unit " &
1383 "information");
1384 Write_Eol;
1385 Write_Eol;
1387 -- Line for -files=
1389 Write_Str (" -files=fil files are listed in text file 'fil'");
1390 Write_Eol;
1392 -- Line for -aI switch
1394 Write_Str (" -aIdir specify source files search path");
1395 Write_Eol;
1397 -- Line for -aO switch
1399 Write_Str (" -aOdir specify object files search path");
1400 Write_Eol;
1402 -- Line for -I switch
1404 Write_Str (" -Idir like -aIdir -aOdir");
1405 Write_Eol;
1407 -- Line for -I- switch
1409 Write_Str (" -I- do not look for sources & object files");
1410 Write_Str (" in the default directory");
1411 Write_Eol;
1413 -- Line for -nostdinc
1415 Write_Str (" -nostdinc do not look for source files");
1416 Write_Str (" in the system default directory");
1417 Write_Eol;
1419 -- Line for --RTS
1421 Write_Str (" --RTS=dir specify the default source and object search"
1422 & " path");
1423 Write_Eol;
1425 -- File Status explanation
1427 Write_Eol;
1428 Write_Str (" file status can be:");
1429 Write_Eol;
1431 for ST in File_Status loop
1432 Write_Str (" ");
1433 Output_Status (ST, Verbose => False);
1434 Write_Str (" ==> ");
1435 Output_Status (ST, Verbose => True);
1436 Write_Eol;
1437 end loop;
1439 end Usage;
1441 -- Start of processing for Gnatls
1443 begin
1444 -- Initialize standard packages
1446 Namet.Initialize;
1447 Csets.Initialize;
1448 Snames.Initialize;
1450 -- Loop to scan out arguments
1452 Next_Arg := 1;
1453 Scan_Args : while Next_Arg < Arg_Count loop
1454 declare
1455 Next_Argv : String (1 .. Len_Arg (Next_Arg));
1456 begin
1457 Fill_Arg (Next_Argv'Address, Next_Arg);
1458 Scan_Ls_Arg (Next_Argv);
1459 end;
1461 Next_Arg := Next_Arg + 1;
1462 end loop Scan_Args;
1464 -- Add the source and object directories specified on the
1465 -- command line, if any, to the searched directories.
1467 while First_Source_Dir /= null loop
1468 Add_Src_Search_Dir (First_Source_Dir.Value.all);
1469 First_Source_Dir := First_Source_Dir.Next;
1470 end loop;
1472 while First_Lib_Dir /= null loop
1473 Add_Lib_Search_Dir (First_Lib_Dir.Value.all);
1474 First_Lib_Dir := First_Lib_Dir.Next;
1475 end loop;
1477 -- Finally, add the default directories and obtain target parameters
1479 Osint.Add_Default_Search_Dirs;
1481 if Verbose_Mode then
1482 Targparm.Get_Target_Parameters;
1484 Write_Eol;
1485 Write_Str ("GNATLS ");
1486 Write_Str (Gnat_Version_String);
1487 Write_Eol;
1488 Write_Str ("Copyright 1997-2004 Free Software Foundation, Inc.");
1489 Write_Eol;
1490 Write_Eol;
1491 Write_Str ("Source Search Path:");
1492 Write_Eol;
1494 for J in 1 .. Nb_Dir_In_Src_Search_Path loop
1495 Write_Str (" ");
1497 if Dir_In_Src_Search_Path (J)'Length = 0 then
1498 Write_Str ("<Current_Directory>");
1499 else
1500 Write_Str (To_Host_Dir_Spec
1501 (Dir_In_Src_Search_Path (J).all, True).all);
1502 end if;
1504 Write_Eol;
1505 end loop;
1507 Write_Eol;
1508 Write_Eol;
1509 Write_Str ("Object Search Path:");
1510 Write_Eol;
1512 for J in 1 .. Nb_Dir_In_Obj_Search_Path loop
1513 Write_Str (" ");
1515 if Dir_In_Obj_Search_Path (J)'Length = 0 then
1516 Write_Str ("<Current_Directory>");
1517 else
1518 Write_Str (To_Host_Dir_Spec
1519 (Dir_In_Obj_Search_Path (J).all, True).all);
1520 end if;
1522 Write_Eol;
1523 end loop;
1525 Write_Eol;
1526 end if;
1528 -- Output usage information when requested
1530 if Print_Usage then
1531 Usage;
1532 end if;
1534 if not More_Lib_Files then
1535 if not Print_Usage and then not Verbose_Mode then
1536 Usage;
1537 end if;
1539 Exit_Program (E_Fatal);
1540 end if;
1542 Initialize_ALI;
1543 Initialize_ALI_Source;
1545 -- Print out all library for which no ALI files can be located
1547 while More_Lib_Files loop
1548 Main_File := Next_Main_Lib_File;
1549 Ali_File := Full_Lib_File_Name (Lib_File_Name (Main_File));
1551 if Ali_File = No_File then
1552 if Very_Verbose_Mode then
1553 GLADE.Output_No_ALI (Lib_File_Name (Main_File));
1555 else
1556 Write_Str ("Can't find library info for ");
1557 Get_Name_String (Main_File);
1558 Write_Char ('"'); -- "
1559 Write_Str (Name_Buffer (1 .. Name_Len));
1560 Write_Char ('"'); -- "
1561 Write_Eol;
1562 end if;
1564 else
1565 Ali_File := Strip_Directory (Ali_File);
1567 if Get_Name_Table_Info (Ali_File) = 0 then
1568 Text := Read_Library_Info (Ali_File, True);
1570 declare
1571 Discard : ALI_Id;
1572 pragma Unreferenced (Discard);
1573 begin
1574 Discard :=
1575 Scan_ALI
1576 (Ali_File,
1577 Text,
1578 Ignore_ED => False,
1579 Err => False,
1580 Ignore_Errors => True);
1581 end;
1583 Free (Text);
1584 end if;
1585 end if;
1586 end loop;
1588 if Very_Verbose_Mode then
1589 for A in ALIs.First .. ALIs.Last loop
1590 GLADE.Output_ALI (A);
1591 end loop;
1593 return;
1594 end if;
1596 Find_General_Layout;
1598 for Id in ALIs.First .. ALIs.Last loop
1599 declare
1600 Last_U : Unit_Id;
1602 begin
1603 Get_Name_String (Units.Table (ALIs.Table (Id).First_Unit).Uname);
1605 if Also_Predef or else not Is_Internal_Unit then
1606 if ALIs.Table (Id).No_Object then
1607 Output_Object (No_File);
1608 else
1609 Output_Object (ALIs.Table (Id).Ofile_Full_Name);
1610 end if;
1612 -- In verbose mode print all main units in the ALI file, otherwise
1613 -- just print the first one to ease columnwise printout
1615 if Verbose_Mode then
1616 Last_U := ALIs.Table (Id).Last_Unit;
1617 else
1618 Last_U := ALIs.Table (Id).First_Unit;
1619 end if;
1621 for U in ALIs.Table (Id).First_Unit .. Last_U loop
1622 if U /= ALIs.Table (Id).First_Unit
1623 and then Selective_Output
1624 and then Print_Unit
1625 then
1626 Write_Eol;
1627 end if;
1629 Output_Unit (Id, U);
1631 -- Output source now, unless if it will be done as part of
1632 -- outputing dependencies.
1634 if not (Dependable and then Print_Source) then
1635 Output_Source (Corresponding_Sdep_Entry (Id, U));
1636 end if;
1637 end loop;
1639 -- Print out list of units on which this unit depends (D lines)
1641 if Dependable and then Print_Source then
1642 if Verbose_Mode then
1643 Write_Str ("depends upon");
1644 Write_Eol;
1645 Write_Str (" ");
1647 else
1648 Write_Eol;
1649 end if;
1651 for D in
1652 ALIs.Table (Id).First_Sdep .. ALIs.Table (Id).Last_Sdep
1653 loop
1654 if Also_Predef
1655 or else not Is_Internal_File_Name (Sdep.Table (D).Sfile)
1656 then
1657 if Verbose_Mode then
1658 Write_Str (" ");
1659 Output_Source (D);
1661 elsif Too_Long then
1662 Write_Str (" ");
1663 Output_Source (D);
1664 Write_Eol;
1666 else
1667 Write_Str (Spaces (1 .. Source_Start - 2));
1668 Output_Source (D);
1669 Write_Eol;
1670 end if;
1671 end if;
1672 end loop;
1673 end if;
1675 Write_Eol;
1676 end if;
1677 end;
1678 end loop;
1680 -- All done. Set proper exit status
1682 Namet.Finalize;
1683 Exit_Program (E_Success);
1684 end Gnatls;