1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
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
;
37 with Osint
; use Osint
;
38 with Osint
.L
; use Osint
.L
;
39 with Output
; use Output
;
40 with Rident
; use Rident
;
43 with Targparm
; use Targparm
;
44 with Types
; use Types
;
46 with GNAT
.Case_Util
; use GNAT
.Case_Util
;
49 pragma Ident
(Gnat_Static_Version_String
);
51 Gpr_Project_Path
: constant String := "GPR_PROJECT_PATH";
52 Ada_Project_Path
: constant String := "ADA_PROJECT_PATH";
53 -- Names of the env. variables that contains path name(s) of directories
54 -- where project files may reside. If GPR_PROJECT_PATH is defined, its
55 -- value is used, otherwise ADA_PROJECT_PATH is used, if defined.
57 -- NOTE : The following string may be used by other tools, such as GPS. So
58 -- it can only be modified if these other uses are checked and coordinated.
60 Project_Search_Path
: constant String := "Project Search Path:";
61 -- Label displayed in verbose mode before the directories in the project
62 -- search path. Do not modify without checking NOTE above.
64 No_Project_Default_Dir
: constant String := "-";
66 Max_Column
: constant := 80;
68 No_Obj
: aliased String := "<no_obj>";
71 OK
, -- matching timestamp
72 Checksum_OK
, -- only matching checksum
73 Not_Found
, -- file not found on source PATH
74 Not_Same
, -- neither checksum nor timestamp matching
75 Not_First_On_PATH
); -- matching file hidden by Not_Same file on path
78 type Dir_Ref
is access Dir_Data
;
80 type Dir_Data
is record
81 Value
: String_Access
;
86 First_Source_Dir
: Dir_Ref
;
87 Last_Source_Dir
: Dir_Ref
;
88 -- The list of source directories from the command line.
89 -- These directories are added using Osint.Add_Src_Search_Dir
90 -- after those of the GNAT Project File, if any.
92 First_Lib_Dir
: Dir_Ref
;
93 Last_Lib_Dir
: Dir_Ref
;
94 -- The list of object directories from the command line.
95 -- These directories are added using Osint.Add_Lib_Search_Dir
96 -- after those of the GNAT Project File, if any.
98 Main_File
: File_Name_Type
;
99 Ali_File
: File_Name_Type
;
100 Text
: Text_Buffer_Ptr
;
103 Too_Long
: Boolean := False;
104 -- When True, lines are too long for multi-column output and each
105 -- item of information is on a different line.
107 Selective_Output
: Boolean := False;
108 Print_Usage
: Boolean := False;
109 Print_Unit
: Boolean := True;
110 Print_Source
: Boolean := True;
111 Print_Object
: Boolean := True;
112 -- Flags controlling the form of the output
114 Dependable
: Boolean := False; -- flag -d
115 Also_Predef
: Boolean := False;
117 Very_Verbose_Mode
: Boolean := False; -- flag -V
119 Unit_Start
: Integer;
121 Source_Start
: Integer;
122 Source_End
: Integer;
123 Object_Start
: Integer;
124 Object_End
: Integer;
125 -- Various column starts and ends
127 Spaces
: constant String (1 .. Max_Column
) := (others => ' ');
129 RTS_Specified
: String_Access
:= null;
130 -- Used to detect multiple use of --RTS= switch
132 -----------------------
133 -- Local Subprograms --
134 -----------------------
136 procedure Add_Lib_Dir
(Dir
: String);
137 -- Add an object directory in the list First_Lib_Dir-Last_Lib_Dir
139 procedure Add_Source_Dir
(Dir
: String);
140 -- Add a source directory in the list First_Source_Dir-Last_Source_Dir
142 procedure Find_General_Layout
;
143 -- Determine the structure of the output (multi columns or not, etc)
145 procedure Find_Status
146 (FS
: in out File_Name_Type
;
147 Stamp
: Time_Stamp_Type
;
149 Status
: out File_Status
);
150 -- Determine the file status (Status) of the file represented by FS
151 -- with the expected Stamp and checksum given as argument. FS will be
152 -- updated to the full file name if available.
154 function Corresponding_Sdep_Entry
(A
: ALI_Id
; U
: Unit_Id
) return Sdep_Id
;
155 -- Give the Sdep entry corresponding to the unit U in ali record A
157 procedure Output_Object
(O
: File_Name_Type
);
158 -- Print out the name of the object when requested
160 procedure Output_Source
(Sdep_I
: Sdep_Id
);
161 -- Print out the name and status of the source corresponding to this
164 procedure Output_Status
(FS
: File_Status
; Verbose
: Boolean);
165 -- Print out FS either in a coded form if verbose is false or in an
166 -- expanded form otherwise.
168 procedure Output_Unit
(ALI
: ALI_Id
; U_Id
: Unit_Id
);
169 -- Print out information on the unit when requested
171 procedure Reset_Print
;
172 -- Reset Print flags properly when selective output is chosen
174 procedure Scan_Ls_Arg
(Argv
: String);
175 -- Scan and process lser specific arguments. Argv is a single argument
178 -- Print usage message
180 function Image
(Restriction
: Restriction_Id
) return String;
181 -- Returns the capitalized image of Restriction
183 ---------------------------------------
184 -- GLADE specific output subprograms --
185 ---------------------------------------
189 -- Any modification to this subunit requires a synchronization
190 -- with the GLADE implementation.
192 procedure Output_ALI
(A
: ALI_Id
);
193 procedure Output_No_ALI
(Afile
: File_Name_Type
);
201 procedure Add_Lib_Dir
(Dir
: String) is
203 if First_Lib_Dir
= null then
206 (Value => new String'(Dir
),
208 Last_Lib_Dir
:= First_Lib_Dir
;
213 (Value => new String'(Dir
),
215 Last_Lib_Dir
:= Last_Lib_Dir
.Next
;
223 procedure Add_Source_Dir
(Dir
: String) is
225 if First_Source_Dir
= null then
228 (Value => new String'(Dir
),
230 Last_Source_Dir
:= First_Source_Dir
;
233 Last_Source_Dir
.Next
:=
235 (Value => new String'(Dir
),
237 Last_Source_Dir
:= Last_Source_Dir
.Next
;
241 ------------------------------
242 -- Corresponding_Sdep_Entry --
243 ------------------------------
245 function Corresponding_Sdep_Entry
247 U
: Unit_Id
) return Sdep_Id
250 for D
in ALIs
.Table
(A
).First_Sdep
.. ALIs
.Table
(A
).Last_Sdep
loop
251 if Sdep
.Table
(D
).Sfile
= Units
.Table
(U
).Sfile
then
256 Error_Msg_Name_1
:= Units
.Table
(U
).Uname
;
257 Error_Msg_Name_2
:= ALIs
.Table
(A
).Afile
;
259 Error_Msg
("wrong ALI format, can't find dependency line for & in %");
260 Exit_Program
(E_Fatal
);
261 end Corresponding_Sdep_Entry
;
263 -------------------------
264 -- Find_General_Layout --
265 -------------------------
267 procedure Find_General_Layout
is
268 Max_Unit_Length
: Integer := 11;
269 Max_Src_Length
: Integer := 11;
270 Max_Obj_Length
: Integer := 11;
276 -- Compute maximum of each column
278 for Id
in ALIs
.First
.. ALIs
.Last
loop
279 Get_Name_String
(Units
.Table
(ALIs
.Table
(Id
).First_Unit
).Uname
);
280 if Also_Predef
or else not Is_Internal_Unit
then
284 Max_Unit_Length
:= Integer'Max (Max_Unit_Length
, Len
);
288 FS
:= Full_Source_Name
(ALIs
.Table
(Id
).Sfile
);
291 Get_Name_String
(ALIs
.Table
(Id
).Sfile
);
292 Name_Len
:= Name_Len
+ 13;
294 Get_Name_String
(FS
);
297 Max_Src_Length
:= Integer'Max (Max_Src_Length
, Name_Len
+ 1);
301 if ALIs
.Table
(Id
).No_Object
then
303 Integer'Max (Max_Obj_Length
, No_Obj
'Length);
305 Get_Name_String
(ALIs
.Table
(Id
).Ofile_Full_Name
);
306 Max_Obj_Length
:= Integer'Max (Max_Obj_Length
, Name_Len
+ 1);
312 -- Verify is output is not wider than maximum number of columns
317 (Max_Unit_Length
+ Max_Src_Length
+ Max_Obj_Length
) > Max_Column
;
319 -- Set start and end of columns
322 Object_End
:= Object_Start
- 1;
325 Object_End
:= Object_Start
+ Max_Obj_Length
;
328 Unit_Start
:= Object_End
+ 1;
329 Unit_End
:= Unit_Start
- 1;
332 Unit_End
:= Unit_Start
+ Max_Unit_Length
;
335 Source_Start
:= Unit_End
+ 1;
337 if Source_Start
> Spaces
'Last then
338 Source_Start
:= Spaces
'Last;
341 Source_End
:= Source_Start
- 1;
344 Source_End
:= Source_Start
+ Max_Src_Length
;
346 end Find_General_Layout
;
352 procedure Find_Status
353 (FS
: in out File_Name_Type
;
354 Stamp
: Time_Stamp_Type
;
356 Status
: out File_Status
)
358 Tmp1
: File_Name_Type
;
359 Tmp2
: File_Name_Type
;
362 Tmp1
:= Full_Source_Name
(FS
);
364 if Tmp1
= No_File
then
367 elsif File_Stamp
(Tmp1
) = Stamp
then
371 elsif Checksums_Match
(Get_File_Checksum
(FS
), Checksum
) then
373 Status
:= Checksum_OK
;
376 Tmp2
:= Matching_Full_Source_Name
(FS
, Stamp
);
378 if Tmp2
= No_File
then
383 Status
:= Not_First_On_PATH
;
393 package body GLADE
is
396 N_Indents
: Natural := 0;
427 Image
: constant array (Token_Type
) of String_Access
:=
428 (T_No_ALI
=> new String'("No_ALI"),
429 T_ALI => new String'("ALI"),
430 T_Unit
=> new String'("Unit"),
431 T_With => new String'("With"),
432 T_Source
=> new String'("Source"),
433 T_Afile => new String'("Afile"),
434 T_Ofile
=> new String'("Ofile"),
435 T_Sfile => new String'("Sfile"),
436 T_Name
=> new String'("Name"),
437 T_Main => new String'("Main"),
438 T_Kind
=> new String'("Kind"),
439 T_Flags => new String'("Flags"),
440 T_Preelaborated
=> new String'("Preelaborated"),
441 T_Pure => new String'("Pure"),
442 T_Has_RACW
=> new String'("Has_RACW"),
443 T_Remote_Types => new String'("Remote_Types"),
444 T_Shared_Passive
=> new String'("Shared_Passive"),
445 T_RCI => new String'("RCI"),
446 T_Predefined
=> new String'("Predefined"),
447 T_Internal => new String'("Internal"),
448 T_Is_Generic
=> new String'("Is_Generic"),
449 T_Procedure => new String'("procedure"),
450 T_Function
=> new String'("function"),
451 T_Package => new String'("package"),
452 T_Subprogram
=> new String'("subprogram"),
453 T_Spec => new String'("spec"),
454 T_Body
=> new String'("body"));
456 procedure Output_Name (N : Name_Id);
457 -- Remove any encoding info (%b and %s) and output N
459 procedure Output_Afile (A : File_Name_Type);
460 procedure Output_Ofile (O : File_Name_Type);
461 procedure Output_Sfile (S : File_Name_Type);
462 -- Output various names. Check that the name is different from
463 -- no name. Otherwise, skip the output.
465 procedure Output_Token (T : Token_Type);
466 -- Output token using a specific format. That is several
469 -- T_No_ALI .. T_With : <token> & " =>" & NL
470 -- T_Source .. T_Kind : <token> & " => "
471 -- T_Flags : <token> & " =>"
472 -- T_Preelab .. T_Body : " " & <token>
474 procedure Output_Sdep (S : Sdep_Id);
475 procedure Output_Unit (U : Unit_Id);
476 procedure Output_With (W : With_Id);
477 -- Output this entry as a global section (like ALIs)
483 procedure Output_Afile (A : File_Name_Type) is
486 Output_Token (T_Afile);
496 procedure Output_ALI (A : ALI_Id) is
498 Output_Token (T_ALI);
499 N_Indents := N_Indents + 1;
501 Output_Afile (ALIs.Table (A).Afile);
502 Output_Ofile (ALIs.Table (A).Ofile_Full_Name);
503 Output_Sfile (ALIs.Table (A).Sfile);
507 if ALIs.Table (A).Main_Program /= None then
508 Output_Token (T_Main);
510 if ALIs.Table (A).Main_Program = Proc then
511 Output_Token (T_Procedure);
513 Output_Token (T_Function);
521 for U in ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit loop
527 for S in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
531 N_Indents := N_Indents - 1;
538 procedure Output_No_ALI (Afile : File_Name_Type) is
540 Output_Token (T_No_ALI);
541 N_Indents := N_Indents + 1;
542 Output_Afile (Afile);
543 N_Indents := N_Indents - 1;
550 procedure Output_Name (N : Name_Id) is
552 -- Remove any encoding info (%s or %b)
557 and then Name_Buffer (Name_Len - 1) = '%'
559 Name_Len := Name_Len - 2;
562 Output_Token (T_Name);
563 Write_Str (Name_Buffer (1 .. Name_Len));
571 procedure Output_Ofile (O : File_Name_Type) is
574 Output_Token (T_Ofile);
584 procedure Output_Sdep (S : Sdep_Id) is
586 Output_Token (T_Source);
587 Write_Name (Sdep.Table (S).Sfile);
595 procedure Output_Sfile (S : File_Name_Type) is
596 FS : File_Name_Type := S;
599 if FS /= No_File then
601 -- We want to output the full source name
603 FS := Full_Source_Name (FS);
605 -- There is no full source name. This occurs for instance when a
606 -- withed unit has a spec file but no body file. This situation
607 -- is not a problem for GLADE since the unit may be located on
608 -- a partition we do not want to build. However, we need to
609 -- locate the spec file and to find its full source name.
610 -- Replace the body file name with the spec file name used to
611 -- compile the current unit when possible.
617 and then Name_Buffer (Name_Len - 3 .. Name_Len) = ".adb"
619 Name_Buffer (Name_Len) := 's
';
620 FS := Full_Source_Name (Name_Find);
625 if FS /= No_File then
626 Output_Token (T_Sfile);
636 procedure Output_Token (T : Token_Type) is
638 if T in T_No_ALI .. T_Flags then
639 for J in 1 .. N_Indents loop
643 Write_Str (Image (T).all);
645 for J in Image (T)'Length .. 12 loop
651 if T in T_No_ALI .. T_With then
653 elsif T in T_Source .. T_Name then
657 elsif T in T_Preelaborated .. T_Body then
658 if T in T_Preelaborated .. T_Is_Generic then
660 Output_Token (T_Flags);
663 N_Flags := N_Flags + 1;
667 Write_Str (Image (T).all);
670 Write_Str (Image (T).all);
678 procedure Output_Unit (U : Unit_Id) is
680 Output_Token (T_Unit);
681 N_Indents := N_Indents + 1;
685 Output_Name (Units.Table (U).Uname);
689 Output_Token (T_Kind);
691 if Units.Table (U).Unit_Kind = 'p
' then
692 Output_Token (T_Package);
694 Output_Token (T_Subprogram);
697 if Name_Buffer (Name_Len) = 's
' then
698 Output_Token (T_Spec);
700 Output_Token (T_Body);
705 -- Output source file name
707 Output_Sfile (Units.Table (U).Sfile);
713 if Units.Table (U).Preelab then
714 Output_Token (T_Preelaborated);
717 if Units.Table (U).Pure then
718 Output_Token (T_Pure);
721 if Units.Table (U).Has_RACW then
722 Output_Token (T_Has_RACW);
725 if Units.Table (U).Remote_Types then
726 Output_Token (T_Remote_Types);
729 if Units.Table (U).Shared_Passive then
730 Output_Token (T_Shared_Passive);
733 if Units.Table (U).RCI then
734 Output_Token (T_RCI);
737 if Units.Table (U).Predefined then
738 Output_Token (T_Predefined);
741 if Units.Table (U).Internal then
742 Output_Token (T_Internal);
745 if Units.Table (U).Is_Generic then
746 Output_Token (T_Is_Generic);
755 for W in Units.Table (U).First_With .. Units.Table (U).Last_With loop
759 N_Indents := N_Indents - 1;
766 procedure Output_With (W : With_Id) is
768 Output_Token (T_With);
769 N_Indents := N_Indents + 1;
771 Output_Name (Withs.Table (W).Uname);
775 Output_Token (T_Kind);
777 if Name_Buffer (Name_Len) = 's
' then
778 Output_Token (T_Spec);
780 Output_Token (T_Body);
785 Output_Afile (Withs.Table (W).Afile);
786 Output_Sfile (Withs.Table (W).Sfile);
788 N_Indents := N_Indents - 1;
797 function Image (Restriction : Restriction_Id) return String is
798 Result : String := Restriction'Img;
799 Skip : Boolean := True;
802 for J in Result'Range loop
805 Result (J) := To_Upper (Result (J));
807 elsif Result (J) = '_
' then
811 Result (J) := To_Lower (Result (J));
822 procedure Output_Object (O : File_Name_Type) is
823 Object_Name : String_Access;
829 Object_Name := To_Host_File_Spec (Name_Buffer (1 .. Name_Len));
831 Object_Name := No_Obj'Unchecked_Access;
834 Write_Str (Object_Name.all);
836 if Print_Source or else Print_Unit then
842 (Object_Start + Object_Name'Length .. Object_End));
852 procedure Output_Source (Sdep_I : Sdep_Id) is
853 Stamp : constant Time_Stamp_Type := Sdep.Table (Sdep_I).Stamp;
854 Checksum : constant Word := Sdep.Table (Sdep_I).Checksum;
855 FS : File_Name_Type := Sdep.Table (Sdep_I).Sfile;
856 Status : File_Status;
857 Object_Name : String_Access;
861 Find_Status (FS, Stamp, Checksum, Status);
862 Get_Name_String (FS);
864 Object_Name := To_Host_File_Spec (Name_Buffer (1 .. Name_Len));
867 Write_Str (" Source => ");
868 Write_Str (Object_Name.all);
872 (Spaces (Source_Start + Object_Name'Length .. Source_End));
875 Output_Status (Status, Verbose => True);
880 if not Selective_Output then
881 Output_Status (Status, Verbose => False);
884 Write_Str (Object_Name.all);
893 procedure Output_Status (FS : File_Status; Verbose : Boolean) is
898 Write_Str (" unchanged");
901 Write_Str (" slightly modified");
904 Write_Str (" file not found");
907 Write_Str (" modified");
909 when Not_First_On_PATH =>
910 Write_Str (" unchanged version not first on PATH");
927 when Not_First_On_PATH =>
937 procedure Output_Unit (ALI : ALI_Id; U_Id : Unit_Id) is
939 U : Unit_Record renames Units.Table (U_Id);
943 Get_Name_String (U.Uname);
944 Kind := Name_Buffer (Name_Len);
945 Name_Len := Name_Len - 2;
947 if not Verbose_Mode then
948 Write_Str (Name_Buffer (1 .. Name_Len));
951 Write_Str ("Unit => ");
953 Write_Str (" Name => ");
954 Write_Str (Name_Buffer (1 .. Name_Len));
956 Write_Str (" Kind => ");
958 if Units.Table (U_Id).Unit_Kind = 'p
' then
959 Write_Str ("package ");
961 Write_Str ("subprogram ");
985 U.Body_Needed_For_SAL or
989 Write_Str (" Flags =>");
992 Write_Str (" Preelaborable");
996 Write_Str (" No_Elab_Code");
1000 Write_Str (" Pure");
1003 if U.Dynamic_Elab then
1004 Write_Str (" Dynamic_Elab");
1008 Write_Str (" Has_RACW");
1011 if U.Remote_Types then
1012 Write_Str (" Remote_Types");
1015 if U.Shared_Passive then
1016 Write_Str (" Shared_Passive");
1023 if U.Predefined then
1024 Write_Str (" Predefined");
1028 Write_Str (" Internal");
1031 if U.Is_Generic then
1032 Write_Str (" Is_Generic");
1035 if U.Init_Scalars then
1036 Write_Str (" Init_Scalars");
1039 if U.SAL_Interface then
1040 Write_Str (" SAL_Interface");
1043 if U.Body_Needed_For_SAL then
1044 Write_Str (" Body_Needed_For_SAL");
1047 if U.Elaborate_Body then
1048 Write_Str (" Elaborate Body");
1051 if U.Remote_Types then
1052 Write_Str (" Remote_Types");
1055 if U.Shared_Passive then
1056 Write_Str (" Shared_Passive");
1059 if U.Predefined then
1060 Write_Str (" Predefined");
1066 Restrictions : constant Restrictions_Info :=
1067 ALIs.Table (ALI).Restrictions;
1070 -- If the source was compiled with pragmas Restrictions,
1071 -- Display these restrictions.
1073 if Restrictions.Set /= (All_Restrictions => False) then
1075 Write_Str (" pragma Restrictions =>");
1077 -- For boolean restrictions, just display the name of the
1078 -- restriction; for valued restrictions, also display the
1079 -- restriction value.
1081 for Restriction in All_Restrictions loop
1082 if Restrictions.Set (Restriction) then
1085 Write_Str (Image (Restriction));
1087 if Restriction in All_Parameter_Restrictions then
1089 Write_Str (Restrictions.Value (Restriction)'Img);
1095 -- If the unit violates some Restrictions, display the list of
1096 -- these restrictions.
1098 if Restrictions.Violated /= (All_Restrictions => False) then
1100 Write_Str (" Restrictions violated =>");
1102 -- For boolean restrictions, just display the name of the
1103 -- restriction; for valued restrictions, also display the
1104 -- restriction value.
1106 for Restriction in All_Restrictions loop
1107 if Restrictions.Violated (Restriction) then
1110 Write_Str (Image (Restriction));
1112 if Restriction in All_Parameter_Restrictions then
1113 if Restrictions.Count (Restriction) > 0 then
1116 if Restrictions.Unknown (Restriction) then
1117 Write_Str (" at least");
1120 Write_Str (Restrictions.Count (Restriction)'Img);
1129 if Print_Source then
1134 Write_Str (Spaces (Unit_Start + Name_Len + 1 .. Unit_End));
1144 procedure Reset_Print is
1146 if not Selective_Output then
1147 Selective_Output := True;
1148 Print_Source := False;
1149 Print_Object := False;
1150 Print_Unit := False;
1158 procedure Scan_Ls_Arg (Argv : String) is
1159 FD : File_Descriptor;
1163 pragma Assert (Argv'First = 1);
1165 if Argv'Length = 0 then
1169 if Argv (1) = '-' then
1170 if Argv'Length = 1 then
1171 Fail ("switch character cannot be followed by a blank");
1173 -- Processing for -I-
1175 elsif Argv (2 .. Argv'Last) = "I-" then
1176 Opt.Look_In_Primary_Dir := False;
1178 -- Forbid -?- or -??- where ? is any character
1180 elsif (Argv'Length = 3 and then Argv (3) = '-')
1181 or else (Argv'Length = 4 and then Argv (4) = '-')
1183 Fail ("Trailing ""-"" at the end of ", Argv, " forbidden.");
1185 -- Processing for -Idir
1187 elsif Argv (2) = 'I
' then
1188 Add_Source_Dir (Argv (3 .. Argv'Last));
1189 Add_Lib_Dir (Argv (3 .. Argv'Last));
1191 -- Processing for -aIdir (to gcc this is like a -I switch)
1193 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
1194 Add_Source_Dir (Argv (4 .. Argv'Last));
1196 -- Processing for -aOdir
1198 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
1199 Add_Lib_Dir (Argv (4 .. Argv'Last));
1201 -- Processing for -aLdir (to gnatbind this is like a -aO switch)
1203 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
1204 Add_Lib_Dir (Argv (4 .. Argv'Last));
1206 -- Processing for -nostdinc
1208 elsif Argv (2 .. Argv'Last) = "nostdinc" then
1209 Opt.No_Stdinc := True;
1211 -- Processing for one character switches
1213 elsif Argv'Length = 2 then
1215 when 'a
' => Also_Predef := True;
1216 when 'h
' => Print_Usage := True;
1217 when 'u
' => Reset_Print; Print_Unit := True;
1218 when 's
' => Reset_Print; Print_Source := True;
1219 when 'o
' => Reset_Print; Print_Object := True;
1220 when 'v
' => Verbose_Mode := True;
1221 when 'd
' => Dependable := True;
1222 when 'V
' => Very_Verbose_Mode := True;
1224 when others => null;
1227 -- Processing for -files=file
1229 elsif Argv'Length > 7 and then Argv (1 .. 7) = "-files=" then
1230 FD := Open_Read (Argv (8 .. Argv'Last), GNAT.OS_Lib.Text);
1232 if FD = Invalid_FD then
1233 Osint.Fail ("could not find text file """ &
1234 Argv (8 .. Argv'Last) & '"');
1237 Len := Integer (File_Length (FD));
1240 Buffer : String (1 .. Len + 1);
1241 Index : Positive := 1;
1247 Len := Read (FD, Buffer (1)'Address, Len);
1248 Buffer (Buffer'Last) := ASCII.NUL;
1251 -- Scan the file line by line
1253 while Index < Buffer'Last loop
1255 -- Find the end of line
1259 while Last <= Buffer'Last
1260 and then Buffer (Last) /= ASCII.LF
1261 and then Buffer (Last) /= ASCII.CR
1266 -- Ignore empty lines
1268 if Last > Index then
1269 Add_File (Buffer (Index .. Last - 1));
1274 -- Find the beginning of the next line
1276 while Buffer (Index) = ASCII.CR or else
1277 Buffer (Index) = ASCII.LF
1284 -- Processing for --RTS=path
1286 elsif Argv'Length >= 5 and then Argv (1 .. 5) = "--RTS" then
1287 if Argv
'Length <= 6 or else Argv
(6) /= '='then
1288 Osint
.Fail
("missing path for --RTS");
1291 -- Check that it is the first time we see this switch or, if
1292 -- it is not the first time, the same path is specified.
1294 if RTS_Specified
= null then
1295 RTS_Specified
:= new String'(Argv (7 .. Argv'Last));
1297 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
1298 Osint.Fail ("--RTS cannot be specified multiple times");
1301 -- Valid --RTS switch
1303 Opt.No_Stdinc := True;
1304 Opt.RTS_Switch := True;
1307 Src_Path_Name : constant String_Ptr :=
1310 (Argv (7 .. Argv'Last), Include));
1311 Lib_Path_Name : constant String_Ptr :=
1314 (Argv (7 .. Argv'Last), Objects));
1317 if Src_Path_Name /= null
1318 and then Lib_Path_Name /= null
1320 Add_Search_Dirs (Src_Path_Name, Include);
1321 Add_Search_Dirs (Lib_Path_Name, Objects);
1323 elsif Src_Path_Name = null
1324 and then Lib_Path_Name = null
1326 Osint.Fail ("RTS path not valid: missing " &
1327 "adainclude and adalib directories");
1329 elsif Src_Path_Name = null then
1330 Osint.Fail ("RTS path not valid: missing " &
1331 "adainclude directory");
1333 elsif Lib_Path_Name = null then
1334 Osint.Fail ("RTS path not valid: missing " &
1335 "adalib directory");
1341 -- If not a switch, it must be a file name
1356 Write_Str ("Usage: ");
1357 Osint.Write_Program_Name;
1358 Write_Str (" switches [list of object files]");
1364 Write_Str ("switches:");
1369 Write_Str (" -a also output relevant predefined units");
1374 Write_Str (" -u output only relevant unit names");
1379 Write_Str (" -h output this help message");
1384 Write_Str (" -s output only relevant source names");
1389 Write_Str (" -o output only relevant object names");
1394 Write_Str (" -d output sources on which specified units " &
1400 Write_Str (" -v verbose output, full path and unit " &
1407 Write_Str (" -files=fil files are listed in text file 'fil
'");
1410 -- Line for -aI switch
1412 Write_Str (" -aIdir specify source files search path");
1415 -- Line for -aO switch
1417 Write_Str (" -aOdir specify object files search path");
1420 -- Line for -I switch
1422 Write_Str (" -Idir like -aIdir -aOdir");
1425 -- Line for -I- switch
1427 Write_Str (" -I- do not look for sources & object files");
1428 Write_Str (" in the default directory");
1431 -- Line for -nostdinc
1433 Write_Str (" -nostdinc do not look for source files");
1434 Write_Str (" in the system default directory");
1439 Write_Str (" --RTS=dir specify the default source and object search"
1443 -- File Status explanation
1446 Write_Str (" file status can be:");
1449 for ST in File_Status loop
1451 Output_Status (ST, Verbose => False);
1452 Write_Str (" ==> ");
1453 Output_Status (ST, Verbose => True);
1458 -- Start of processing for Gnatls
1461 -- Initialize standard packages
1467 -- Loop to scan out arguments
1470 Scan_Args : while Next_Arg < Arg_Count loop
1472 Next_Argv : String (1 .. Len_Arg (Next_Arg));
1474 Fill_Arg (Next_Argv'Address, Next_Arg);
1475 Scan_Ls_Arg (Next_Argv);
1478 Next_Arg := Next_Arg + 1;
1481 -- Add the source and object directories specified on the
1482 -- command line, if any, to the searched directories.
1484 while First_Source_Dir /= null loop
1485 Add_Src_Search_Dir (First_Source_Dir.Value.all);
1486 First_Source_Dir := First_Source_Dir.Next;
1489 while First_Lib_Dir /= null loop
1490 Add_Lib_Search_Dir (First_Lib_Dir.Value.all);
1491 First_Lib_Dir := First_Lib_Dir.Next;
1494 -- Finally, add the default directories and obtain target parameters
1496 Osint.Add_Default_Search_Dirs;
1498 if Verbose_Mode then
1499 Targparm.Get_Target_Parameters;
1502 Write_Str ("GNATLS ");
1503 Write_Str (Gnat_Version_String);
1505 Write_Str ("Copyright 1997-" &
1507 ", Free Software Foundation, Inc.");
1510 Write_Str ("Source Search Path:");
1513 for J in 1 .. Nb_Dir_In_Src_Search_Path loop
1516 if Dir_In_Src_Search_Path (J)'Length = 0 then
1517 Write_Str ("<Current_Directory>");
1519 Write_Str (To_Host_Dir_Spec
1520 (Dir_In_Src_Search_Path (J).all, True).all);
1528 Write_Str ("Object Search Path:");
1531 for J in 1 .. Nb_Dir_In_Obj_Search_Path loop
1534 if Dir_In_Obj_Search_Path (J)'Length = 0 then
1535 Write_Str ("<Current_Directory>");
1537 Write_Str (To_Host_Dir_Spec
1538 (Dir_In_Obj_Search_Path (J).all, True).all);
1546 Write_Str (Project_Search_Path);
1548 Write_Str (" <Current_Directory>");
1552 Project_Path : String_Access := Getenv (Gpr_Project_Path);
1554 Lib : constant String :=
1555 Directory_Separator & "lib" & Directory_Separator;
1560 Add_Default_Dir : Boolean := True;
1563 -- If there is a project path, display each directory in the path
1565 if Project_Path.all = "" then
1566 Project_Path := Getenv (Ada_Project_Path);
1569 if Project_Path.all /= "" then
1570 First := Project_Path'First;
1572 while First <= Project_Path'Last
1573 and then (Project_Path (First) = Path_Separator)
1578 exit when First > Project_Path'Last;
1581 while Last < Project_Path'Last
1582 and then Project_Path (Last + 1) /= Path_Separator
1587 -- If the directory is No_Default_Project_Dir, set
1588 -- Add_Default_Dir to False.
1590 if Project_Path (First .. Last) = No_Project_Default_Dir then
1591 Add_Default_Dir := False;
1593 elsif First /= Last or else Project_Path (First) /= '.' then
1595 -- If the directory is ".", skip it as it is the current
1596 -- directory and it is already the first directory in the
1602 (Project_Path (First .. Last), True).all);
1610 -- Add the default dir, except if "-" was one of the "directories"
1611 -- specified in ADA_PROJECT_DIR.
1613 if Add_Default_Dir then
1615 Add_Str_To_Name_Buffer (Sdefault.Search_Dir_Prefix.all);
1617 -- On Windows, make sure that all directory separators are '\
'
1619 if Directory_Separator /= '/' then
1620 for J in 1 .. Name_Len loop
1621 if Name_Buffer (J) = '/' then
1622 Name_Buffer (J) := Directory_Separator;
1627 -- Find the sequence "/lib/"
1629 while Name_Len >= Lib'Length
1630 and then Name_Buffer (Name_Len - 4 .. Name_Len) /= Lib
1632 Name_Len := Name_Len - 1;
1635 -- If the sequence "/lib"/ was found, display the default
1636 -- directory <prefix>/lib/gnat/.
1638 if Name_Len >= 5 then
1639 Name_Buffer (Name_Len + 1 .. Name_Len + 4) := "gnat";
1640 Name_Buffer (Name_Len + 5) := Directory_Separator;
1641 Name_Len := Name_Len + 5;
1643 (To_Host_Dir_Spec (Name_Buffer (1 .. Name_Len), True).all);
1651 -- Output usage information when requested
1657 if not More_Lib_Files then
1658 if not Print_Usage and then not Verbose_Mode then
1662 Exit_Program (E_Fatal);
1666 Initialize_ALI_Source;
1668 -- Print out all library for which no ALI files can be located
1670 while More_Lib_Files loop
1671 Main_File := Next_Main_Lib_File;
1672 Ali_File := Full_Lib_File_Name (Lib_File_Name (Main_File));
1674 if Ali_File = No_File then
1675 if Very_Verbose_Mode then
1676 GLADE.Output_No_ALI (Lib_File_Name (Main_File));
1679 Write_Str ("Can't find library info for ");
1680 Get_Name_String (Main_File);
1681 Write_Char ('"'); -- "
1682 Write_Str
(Name_Buffer
(1 .. Name_Len
));
1683 Write_Char
('"'); -- "
1688 Ali_File
:= Strip_Directory
(Ali_File
);
1690 if Get_Name_Table_Info
(Ali_File
) = 0 then
1691 Text
:= Read_Library_Info
(Ali_File
, True);
1695 pragma Unreferenced
(Discard
);
1703 Ignore_Errors
=> True);
1711 if Very_Verbose_Mode
then
1712 for A
in ALIs
.First
.. ALIs
.Last
loop
1713 GLADE
.Output_ALI
(A
);
1719 Find_General_Layout
;
1721 for Id
in ALIs
.First
.. ALIs
.Last
loop
1726 Get_Name_String
(Units
.Table
(ALIs
.Table
(Id
).First_Unit
).Uname
);
1728 if Also_Predef
or else not Is_Internal_Unit
then
1729 if ALIs
.Table
(Id
).No_Object
then
1730 Output_Object
(No_File
);
1732 Output_Object
(ALIs
.Table
(Id
).Ofile_Full_Name
);
1735 -- In verbose mode print all main units in the ALI file, otherwise
1736 -- just print the first one to ease columnwise printout
1738 if Verbose_Mode
then
1739 Last_U
:= ALIs
.Table
(Id
).Last_Unit
;
1741 Last_U
:= ALIs
.Table
(Id
).First_Unit
;
1744 for U
in ALIs
.Table
(Id
).First_Unit
.. Last_U
loop
1745 if U
/= ALIs
.Table
(Id
).First_Unit
1746 and then Selective_Output
1752 Output_Unit
(Id
, U
);
1754 -- Output source now, unless if it will be done as part of
1755 -- outputing dependencies.
1757 if not (Dependable
and then Print_Source
) then
1758 Output_Source
(Corresponding_Sdep_Entry
(Id
, U
));
1762 -- Print out list of units on which this unit depends (D lines)
1764 if Dependable
and then Print_Source
then
1765 if Verbose_Mode
then
1766 Write_Str
("depends upon");
1774 ALIs
.Table
(Id
).First_Sdep
.. ALIs
.Table
(Id
).Last_Sdep
1777 or else not Is_Internal_File_Name
(Sdep
.Table
(D
).Sfile
)
1779 if Verbose_Mode
then
1789 Write_Str
(Spaces
(1 .. Source_Start
- 2));
1802 -- All done. Set proper exit status
1805 Exit_Program
(E_Success
);