* config/arm/elf.h (ASM_OUTPUT_ALIGNED_COMMON): Remove definition.
[official-gcc.git] / gcc / ada / gnatxref.adb
blob3f688738fcb71f74c6220e36d1b6d439598f8ed8
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- G N A T X R E F --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1998-2002 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 ------------------------------------------------------------------------------
24 with Xr_Tabls; use Xr_Tabls;
25 with Xref_Lib; use Xref_Lib;
26 with Osint; use Osint;
27 with Types; use Types;
29 with Gnatvsn;
30 with Opt;
32 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
33 with Ada.Text_IO; use Ada.Text_IO;
34 with GNAT.Command_Line; use GNAT.Command_Line;
36 procedure Gnatxref is
38 Search_Unused : Boolean := False;
39 Local_Symbols : Boolean := True;
40 Prj_File : File_Name_String;
41 Prj_File_Length : Natural := 0;
42 Usage_Error : exception;
43 Full_Path_Name : Boolean := False;
44 Vi_Mode : Boolean := False;
45 Read_Only : Boolean := False;
46 Have_File : Boolean := False;
47 Der_Info : Boolean := False;
49 procedure Parse_Cmd_Line;
50 -- Parse every switch on the command line
52 procedure Write_Usage;
53 -- Print a small help page for program usage
55 --------------------
56 -- Parse_Cmd_Line --
57 --------------------
59 procedure Parse_Cmd_Line is
60 begin
61 loop
62 case
63 GNAT.Command_Line.Getopt
64 ("a aI: aO: d f g h I: nostdinc nostdlib p: u v -RTS=")
66 when ASCII.NUL =>
67 exit;
69 when 'a' =>
70 if GNAT.Command_Line.Full_Switch = "a" then
71 Read_Only := True;
73 elsif GNAT.Command_Line.Full_Switch = "aI" then
74 Osint.Add_Src_Search_Dir (GNAT.Command_Line.Parameter);
76 else
77 Osint.Add_Lib_Search_Dir (GNAT.Command_Line.Parameter);
78 end if;
80 when 'd' =>
81 Der_Info := True;
83 when 'f' =>
84 Full_Path_Name := True;
86 when 'g' =>
87 Local_Symbols := False;
89 when 'h' =>
90 Write_Usage;
92 when 'I' =>
93 Osint.Add_Src_Search_Dir (GNAT.Command_Line.Parameter);
94 Osint.Add_Lib_Search_Dir (GNAT.Command_Line.Parameter);
96 when 'n' =>
97 if GNAT.Command_Line.Full_Switch = "nostdinc" then
98 Opt.No_Stdinc := True;
99 elsif GNAT.Command_Line.Full_Switch = "nostlib" then
100 Opt.No_Stdlib := True;
101 end if;
103 when 'p' =>
104 declare
105 S : constant String := GNAT.Command_Line.Parameter;
107 begin
108 Prj_File_Length := S'Length;
109 Prj_File (1 .. Prj_File_Length) := S;
110 end;
112 when 'u' =>
113 Search_Unused := True;
114 Vi_Mode := False;
116 when 'v' =>
117 Vi_Mode := True;
118 Search_Unused := False;
120 -- The only switch starting with -- recognized is --RTS
122 when '-' =>
123 Opt.No_Stdinc := True;
124 Opt.RTS_Switch := True;
126 declare
127 Src_Path_Name : String_Ptr :=
128 Get_RTS_Search_Dir
129 (GNAT.Command_Line.Parameter, Include);
131 Lib_Path_Name : String_Ptr :=
132 Get_RTS_Search_Dir
133 (GNAT.Command_Line.Parameter, Objects);
135 begin
136 if Src_Path_Name /= null and then Lib_Path_Name /= null then
137 Add_Search_Dirs (Src_Path_Name, Include);
138 Add_Search_Dirs (Lib_Path_Name, Objects);
140 elsif Src_Path_Name = null and then Lib_Path_Name = null then
141 Osint.Fail ("RTS path not valid: missing " &
142 "adainclude and adalib directories");
144 elsif Src_Path_Name = null then
145 Osint.Fail ("RTS path not valid: missing " &
146 "adainclude directory");
148 elsif Lib_Path_Name = null then
149 Osint.Fail ("RTS path not valid: missing " &
150 "adalib directory");
151 end if;
152 end;
154 when others =>
155 Write_Usage;
156 end case;
157 end loop;
159 -- Get the other arguments
161 loop
162 declare
163 S : constant String := GNAT.Command_Line.Get_Argument;
165 begin
166 exit when S'Length = 0;
168 if Ada.Strings.Fixed.Index (S, ":") /= 0 then
169 Ada.Text_IO.Put_Line
170 ("Only file names are allowed on the command line");
171 Write_Usage;
172 end if;
174 Add_Xref_File (S);
175 Have_File := True;
176 end;
177 end loop;
179 exception
180 when GNAT.Command_Line.Invalid_Switch =>
181 Ada.Text_IO.Put_Line ("Invalid switch : "
182 & GNAT.Command_Line.Full_Switch);
183 Write_Usage;
185 when GNAT.Command_Line.Invalid_Parameter =>
186 Ada.Text_IO.Put_Line ("Parameter missing for : "
187 & GNAT.Command_Line.Full_Switch);
188 Write_Usage;
189 end Parse_Cmd_Line;
191 -----------------
192 -- Write_Usage --
193 -----------------
195 procedure Write_Usage is
196 use Ada.Text_IO;
198 begin
199 Put_Line ("GNATXREF " & Gnatvsn.Gnat_Version_String
200 & " Copyright 1998-2002, Ada Core Technologies Inc.");
201 Put_Line ("Usage: gnatxref [switches] file1 file2 ...");
202 New_Line;
203 Put_Line (" file ... list of source files to xref, " &
204 "including with'ed units");
205 New_Line;
206 Put_Line ("gnatxref switches:");
207 Put_Line (" -a Consider all files, even when the ali file is"
208 & " readonly");
209 Put_Line (" -aIdir Specify source files search path");
210 Put_Line (" -aOdir Specify library/object files search path");
211 Put_Line (" -d Output derived type information");
212 Put_Line (" -f Output full path name");
213 Put_Line (" -g Output information only for global symbols");
214 Put_Line (" -Idir Like -aIdir -aOdir");
215 Put_Line (" -nostdinc Don't look for sources in the system default"
216 & " directory");
217 Put_Line (" -nostdlib Don't look for library files in the system"
218 & " default directory");
219 Put_Line (" --RTS=dir specify the default source and object search"
220 & " path");
221 Put_Line (" -p file Use file as the default project file");
222 Put_Line (" -u List unused entities");
223 Put_Line (" -v Print a 'tags' file for vi");
224 New_Line;
226 raise Usage_Error;
227 end Write_Usage;
229 begin
230 Parse_Cmd_Line;
232 if not Have_File then
233 Write_Usage;
234 end if;
236 Xr_Tabls.Set_Default_Match (True);
238 -- Find the project file
240 if Prj_File_Length = 0 then
241 Xr_Tabls.Create_Project_File
242 (Default_Project_File (Osint.To_Host_Dir_Spec (".", False).all));
243 else
244 Xr_Tabls.Create_Project_File (Prj_File (1 .. Prj_File_Length));
245 end if;
247 -- Fill up the table
249 Search_Xref (Local_Symbols, Read_Only, Der_Info);
251 if Search_Unused then
252 Print_Unused (Full_Path_Name);
253 elsif Vi_Mode then
254 Print_Vi (Full_Path_Name);
255 else
256 Print_Xref (Full_Path_Name);
257 end if;
259 exception
260 when Usage_Error =>
261 null;
262 end Gnatxref;