PR c++/11808
[official-gcc.git] / gcc / ada / switch-b.adb
blob08ad273293266aa2038368cfec1e1b404d7ea375
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S W I T C H - B --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2001-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 -- 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 Debug; use Debug;
28 with Osint; use Osint;
29 with Opt; use Opt;
31 with System.WCh_Con; use System.WCh_Con;
33 package body Switch.B is
35 --------------------------
36 -- Scan_Binder_Switches --
37 --------------------------
39 procedure Scan_Binder_Switches (Switch_Chars : String) is
40 Ptr : Integer := Switch_Chars'First;
41 Max : Integer := Switch_Chars'Last;
42 C : Character := ' ';
44 begin
45 -- Skip past the initial character (must be the switch character)
47 if Ptr = Max then
48 raise Bad_Switch;
49 else
50 Ptr := Ptr + 1;
51 end if;
53 -- A little check, "gnat" at the start of a switch is not allowed
54 -- except for the compiler
56 if Switch_Chars'Last >= Ptr + 3
57 and then Switch_Chars (Ptr .. Ptr + 3) = "gnat"
58 then
59 Osint.Fail ("invalid switch: """, Switch_Chars, """"
60 & " (gnat not needed here)");
62 end if;
64 -- Loop to scan through switches given in switch string
66 while Ptr <= Max loop
67 C := Switch_Chars (Ptr);
69 case C is
71 -- Processing for A switch
73 when 'A' =>
74 Ptr := Ptr + 1;
76 Ada_Bind_File := True;
78 -- Processing for b switch
80 when 'b' =>
81 Ptr := Ptr + 1;
82 Brief_Output := True;
84 -- Processing for c switch
86 when 'c' =>
87 Ptr := Ptr + 1;
89 Check_Only := True;
91 -- Processing for C switch
93 when 'C' =>
94 Ptr := Ptr + 1;
96 Ada_Bind_File := False;
98 -- Processing for d switch
100 when 'd' =>
102 -- Note: for the debug switch, the remaining characters in this
103 -- switch field must all be debug flags, since all valid switch
104 -- characters are also valid debug characters. This switch is not
105 -- documented on purpose because it is only used by the
106 -- implementors.
108 -- Loop to scan out debug flags
110 while Ptr < Max loop
111 Ptr := Ptr + 1;
112 C := Switch_Chars (Ptr);
113 exit when C = ASCII.NUL or else C = '/' or else C = '-';
115 if C in '1' .. '9' or else
116 C in 'a' .. 'z' or else
117 C in 'A' .. 'Z'
118 then
119 Set_Debug_Flag (C);
120 else
121 raise Bad_Switch;
122 end if;
123 end loop;
125 -- Make sure Zero_Cost_Exceptions is set if gnatdX set. This
126 -- is for backwards compatibility with old versions and usage.
128 if Debug_Flag_XX then
129 Zero_Cost_Exceptions_Set := True;
130 Zero_Cost_Exceptions_Val := True;
131 end if;
133 return;
135 -- Processing for e switch
137 when 'e' =>
138 Ptr := Ptr + 1;
139 Elab_Dependency_Output := True;
141 -- Processing for E switch
143 when 'E' =>
144 Ptr := Ptr + 1;
145 Exception_Tracebacks := True;
147 -- Processing for f switch
149 when 'f' =>
150 Ptr := Ptr + 1;
151 Force_RM_Elaboration_Order := True;
153 -- Processing for g switch
155 when 'g' =>
156 Ptr := Ptr + 1;
158 if Ptr <= Max then
159 C := Switch_Chars (Ptr);
161 if C in '0' .. '3' then
162 Debugger_Level :=
163 Character'Pos
164 (Switch_Chars (Ptr)) - Character'Pos ('0');
165 Ptr := Ptr + 1;
166 end if;
168 else
169 Debugger_Level := 2;
170 end if;
172 -- Processing for h switch
174 when 'h' =>
175 Ptr := Ptr + 1;
176 Usage_Requested := True;
178 -- Processing for i switch
180 when 'i' =>
181 if Ptr = Max then
182 raise Bad_Switch;
183 end if;
185 Ptr := Ptr + 1;
186 C := Switch_Chars (Ptr);
188 if C in '1' .. '5'
189 or else C = '8'
190 or else C = 'p'
191 or else C = 'f'
192 or else C = 'n'
193 or else C = 'w'
194 then
195 Identifier_Character_Set := C;
196 Ptr := Ptr + 1;
197 else
198 raise Bad_Switch;
199 end if;
201 -- Processing for K switch
203 when 'K' =>
204 Ptr := Ptr + 1;
205 Output_Linker_Option_List := True;
207 -- Processing for l switch
209 when 'l' =>
210 Ptr := Ptr + 1;
211 Elab_Order_Output := True;
213 -- Processing for m switch
215 when 'm' =>
216 Ptr := Ptr + 1;
217 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Errors);
219 -- Processing for n switch
221 when 'n' =>
222 Ptr := Ptr + 1;
223 Bind_Main_Program := False;
225 -- Note: The -L option of the binder also implies -n, so
226 -- any change here must also be reflected in the processing
227 -- for -L that is found in Gnatbind.Scan_Bind_Arg.
229 -- Processing for o switch
231 when 'o' =>
232 Ptr := Ptr + 1;
234 if Output_File_Name_Present then
235 raise Too_Many_Output_Files;
237 else
238 Output_File_Name_Present := True;
239 end if;
241 -- Processing for O switch
243 when 'O' =>
244 Ptr := Ptr + 1;
245 Output_Object_List := True;
247 -- Processing for p switch
249 when 'p' =>
250 Ptr := Ptr + 1;
251 Pessimistic_Elab_Order := True;
253 -- Processing for q switch
255 when 'q' =>
256 Ptr := Ptr + 1;
257 Quiet_Output := True;
259 -- Processing for r switch
261 when 'r' =>
262 Ptr := Ptr + 1;
263 List_Restrictions := True;
265 -- Processing for s switch
267 when 's' =>
268 Ptr := Ptr + 1;
269 All_Sources := True;
270 Check_Source_Files := True;
272 -- Processing for t switch
274 when 't' =>
275 Ptr := Ptr + 1;
276 Tolerate_Consistency_Errors := True;
278 -- Processing for T switch
280 when 'T' =>
281 Ptr := Ptr + 1;
282 Time_Slice_Set := True;
283 Scan_Nat (Switch_Chars, Max, Ptr, Time_Slice_Value);
285 -- Processing for v switch
287 when 'v' =>
288 Ptr := Ptr + 1;
289 Verbose_Mode := True;
291 -- Processing for w switch
293 when 'w' =>
295 -- For the binder we only allow suppress/error cases
297 Ptr := Ptr + 1;
299 case Switch_Chars (Ptr) is
301 when 'e' =>
302 Warning_Mode := Treat_As_Error;
304 when 's' =>
305 Warning_Mode := Suppress;
307 when others =>
308 raise Bad_Switch;
309 end case;
311 Ptr := Ptr + 1;
313 -- Processing for W switch
315 when 'W' =>
316 Ptr := Ptr + 1;
318 for J in WC_Encoding_Method loop
319 if Switch_Chars (Ptr) = WC_Encoding_Letters (J) then
320 Wide_Character_Encoding_Method := J;
321 exit;
323 elsif J = WC_Encoding_Method'Last then
324 raise Bad_Switch;
325 end if;
326 end loop;
328 Upper_Half_Encoding :=
329 Wide_Character_Encoding_Method in
330 WC_Upper_Half_Encoding_Method;
332 Ptr := Ptr + 1;
334 -- Processing for x switch
336 when 'x' =>
337 Ptr := Ptr + 1;
338 All_Sources := False;
339 Check_Source_Files := False;
341 -- Processing for z switch
343 when 'z' =>
344 Ptr := Ptr + 1;
345 No_Main_Subprogram := True;
347 -- Ignore extra switch character
349 when '/' =>
350 Ptr := Ptr + 1;
352 -- Ignore '-' extra switch caracter, only if it isn't followed by
353 -- 'RTS'. If it is, then we must process the 'RTS' switch
355 when '-' =>
357 if Ptr + 3 <= Max and then
358 Switch_Chars (Ptr + 1 .. Ptr + 3) = "RTS"
359 then
360 Ptr := Ptr + 1;
362 if Switch_Chars (Ptr + 3) /= '=' or else
363 (Switch_Chars (Ptr + 3) = '='
364 and then Ptr + 4 > Max)
365 then
366 Osint.Fail ("missing path for --RTS");
367 else
369 -- valid --RTS switch
370 Opt.No_Stdinc := True;
371 Opt.RTS_Switch := True;
373 declare
374 Src_Path_Name : String_Ptr := Get_RTS_Search_Dir
375 (Switch_Chars (Ptr + 4 .. Switch_Chars'Last), Include);
376 Lib_Path_Name : String_Ptr := Get_RTS_Search_Dir
377 (Switch_Chars (Ptr + 4 .. Switch_Chars'Last), Objects);
378 begin
379 if Src_Path_Name /= null and then
380 Lib_Path_Name /= null
381 then
382 Add_Search_Dirs (Src_Path_Name, Include);
383 Add_Search_Dirs (Lib_Path_Name, Objects);
384 -- we can exit as there can not be another switch
385 -- after --RTS
386 exit;
387 elsif Src_Path_Name = null
388 and Lib_Path_Name = null then
389 Osint.Fail ("RTS path not valid: missing " &
390 "adainclude and adalib directories");
391 elsif Src_Path_Name = null then
392 Osint.Fail ("RTS path not valid: missing " &
393 "adainclude directory");
394 elsif Lib_Path_Name = null then
395 Osint.Fail ("RTS path not valid: missing " &
396 "adalib directory");
397 end if;
398 end;
399 end if;
401 else
402 Ptr := Ptr + 1;
403 end if;
405 -- Anything else is an error (illegal switch character)
407 when others =>
408 raise Bad_Switch;
409 end case;
410 end loop;
412 exception
413 when Bad_Switch =>
414 Osint.Fail ("invalid switch: ", (1 => C));
416 when Bad_Switch_Value =>
417 Osint.Fail ("numeric value too big for switch: ", (1 => C));
419 when Missing_Switch_Value =>
420 Osint.Fail ("missing numeric value for switch: ", (1 => C));
422 when Too_Many_Output_Files =>
423 Osint.Fail ("duplicate -o switch");
424 end Scan_Binder_Switches;
426 end Switch.B;