* config/xtensa/xtensa.h (GO_IF_MODE_DEPENDENT_ADDRESS): Treat
[official-gcc.git] / gcc / ada / gnatxref.adb
blobf72bdb02ca38053a4bf2ae304d965fb9f5700d2c
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- G N A T X R E F --
6 -- --
7 -- B o d y --
8 -- --
9 -- --
10 -- Copyright (C) 1998-2002 Free Software Foundation, Inc. --
11 -- --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
22 -- --
23 -- GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com). --
24 -- --
25 ------------------------------------------------------------------------------
27 with Xr_Tabls; use Xr_Tabls;
28 with Xref_Lib; use Xref_Lib;
29 with Osint; use Osint;
30 with Types; use Types;
32 with Gnatvsn;
33 with Opt;
35 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
36 with Ada.Text_IO; use Ada.Text_IO;
37 with GNAT.Command_Line; use GNAT.Command_Line;
39 procedure Gnatxref is
41 Search_Unused : Boolean := False;
42 Local_Symbols : Boolean := True;
43 Prj_File : File_Name_String;
44 Prj_File_Length : Natural := 0;
45 Usage_Error : exception;
46 Full_Path_Name : Boolean := False;
47 Vi_Mode : Boolean := False;
48 Read_Only : Boolean := False;
49 Have_File : Boolean := False;
50 Der_Info : Boolean := False;
52 procedure Parse_Cmd_Line;
53 -- Parse every switch on the command line
55 procedure Write_Usage;
56 -- Print a small help page for program usage
58 --------------------
59 -- Parse_Cmd_Line --
60 --------------------
62 procedure Parse_Cmd_Line is
63 begin
64 loop
65 case
66 GNAT.Command_Line.Getopt
67 ("a aI: aO: d f g h I: nostdinc nostdlib p: u v -RTS=")
69 when ASCII.NUL =>
70 exit;
72 when 'a' =>
73 if GNAT.Command_Line.Full_Switch = "a" then
74 Read_Only := True;
76 elsif GNAT.Command_Line.Full_Switch = "aI" then
77 Osint.Add_Src_Search_Dir (GNAT.Command_Line.Parameter);
79 else
80 Osint.Add_Lib_Search_Dir (GNAT.Command_Line.Parameter);
81 end if;
83 when 'd' =>
84 Der_Info := True;
86 when 'f' =>
87 Full_Path_Name := True;
89 when 'g' =>
90 Local_Symbols := False;
92 when 'h' =>
93 Write_Usage;
95 when 'I' =>
96 Osint.Add_Src_Search_Dir (GNAT.Command_Line.Parameter);
97 Osint.Add_Lib_Search_Dir (GNAT.Command_Line.Parameter);
99 when 'n' =>
100 if GNAT.Command_Line.Full_Switch = "nostdinc" then
101 Opt.No_Stdinc := True;
102 elsif GNAT.Command_Line.Full_Switch = "nostlib" then
103 Opt.No_Stdlib := True;
104 end if;
106 when 'p' =>
107 declare
108 S : constant String := GNAT.Command_Line.Parameter;
110 begin
111 Prj_File_Length := S'Length;
112 Prj_File (1 .. Prj_File_Length) := S;
113 end;
115 when 'u' =>
116 Search_Unused := True;
117 Vi_Mode := False;
119 when 'v' =>
120 Vi_Mode := True;
121 Search_Unused := False;
123 -- The only switch starting with -- recognized is --RTS
125 when '-' =>
126 Opt.No_Stdinc := True;
127 Opt.RTS_Switch := True;
129 declare
130 Src_Path_Name : String_Ptr :=
131 Get_RTS_Search_Dir
132 (GNAT.Command_Line.Parameter, Include);
134 Lib_Path_Name : String_Ptr :=
135 Get_RTS_Search_Dir
136 (GNAT.Command_Line.Parameter, Objects);
138 begin
139 if Src_Path_Name /= null and then Lib_Path_Name /= null then
140 Add_Search_Dirs (Src_Path_Name, Include);
141 Add_Search_Dirs (Lib_Path_Name, Objects);
143 elsif Src_Path_Name = null and then Lib_Path_Name = null then
144 Osint.Fail ("RTS path not valid: missing " &
145 "adainclude and adalib directories");
147 elsif Src_Path_Name = null then
148 Osint.Fail ("RTS path not valid: missing " &
149 "adainclude directory");
151 elsif Lib_Path_Name = null then
152 Osint.Fail ("RTS path not valid: missing " &
153 "adalib directory");
154 end if;
155 end;
157 when others =>
158 Write_Usage;
159 end case;
160 end loop;
162 -- Get the other arguments
164 loop
165 declare
166 S : constant String := GNAT.Command_Line.Get_Argument;
168 begin
169 exit when S'Length = 0;
171 if Ada.Strings.Fixed.Index (S, ":") /= 0 then
172 Ada.Text_IO.Put_Line
173 ("Only file names are allowed on the command line");
174 Write_Usage;
175 end if;
177 Add_Xref_File (S);
178 Have_File := True;
179 end;
180 end loop;
182 exception
183 when GNAT.Command_Line.Invalid_Switch =>
184 Ada.Text_IO.Put_Line ("Invalid switch : "
185 & GNAT.Command_Line.Full_Switch);
186 Write_Usage;
188 when GNAT.Command_Line.Invalid_Parameter =>
189 Ada.Text_IO.Put_Line ("Parameter missing for : "
190 & GNAT.Command_Line.Full_Switch);
191 Write_Usage;
192 end Parse_Cmd_Line;
194 -----------------
195 -- Write_Usage --
196 -----------------
198 procedure Write_Usage is
199 use Ada.Text_IO;
201 begin
202 Put_Line ("GNATXREF " & Gnatvsn.Gnat_Version_String
203 & " Copyright 1998-2002, Ada Core Technologies Inc.");
204 Put_Line ("Usage: gnatxref [switches] file1 file2 ...");
205 New_Line;
206 Put_Line (" file ... list of source files to xref, " &
207 "including with'ed units");
208 New_Line;
209 Put_Line ("gnatxref switches:");
210 Put_Line (" -a Consider all files, even when the ali file is"
211 & " readonly");
212 Put_Line (" -aIdir Specify source files search path");
213 Put_Line (" -aOdir Specify library/object files search path");
214 Put_Line (" -d Output derived type information");
215 Put_Line (" -f Output full path name");
216 Put_Line (" -g Output information only for global symbols");
217 Put_Line (" -Idir Like -aIdir -aOdir");
218 Put_Line (" -nostdinc Don't look for sources in the system default"
219 & " directory");
220 Put_Line (" -nostdlib Don't look for library files in the system"
221 & " default directory");
222 Put_Line (" --RTS=dir specify the default source and object search"
223 & " path");
224 Put_Line (" -p file Use file as the default project file");
225 Put_Line (" -u List unused entities");
226 Put_Line (" -v Print a 'tags' file for vi");
227 New_Line;
229 raise Usage_Error;
230 end Write_Usage;
232 begin
233 Parse_Cmd_Line;
235 if not Have_File then
236 Write_Usage;
237 end if;
239 Xr_Tabls.Set_Default_Match (True);
241 -- Find the project file
243 if Prj_File_Length = 0 then
244 Xr_Tabls.Create_Project_File
245 (Default_Project_File (Osint.To_Host_Dir_Spec (".", False).all));
246 else
247 Xr_Tabls.Create_Project_File (Prj_File (1 .. Prj_File_Length));
248 end if;
250 -- Fill up the table
252 Search_Xref (Local_Symbols, Read_Only, Der_Info);
254 if Search_Unused then
255 Print_Unused (Full_Path_Name);
256 elsif Vi_Mode then
257 Print_Vi (Full_Path_Name);
258 else
259 Print_Xref (Full_Path_Name);
260 end if;
262 exception
263 when Usage_Error =>
264 null;
265 end Gnatxref;