OSDN Git Service

* 1aexcept.adb, 1aexcept.ads, 1ic.ads, 1ssecsta.adb,
[pf3gnuchains/gcc-fork.git] / gcc / ada / switch-b.adb
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 ------------------------------------------------------------------------------
26
27 with Debug;    use Debug;
28 with Osint;    use Osint;
29 with Opt;      use Opt;
30
31 with System.WCh_Con; use System.WCh_Con;
32
33 package body Switch.B is
34
35    --------------------------
36    -- Scan_Binder_Switches --
37    --------------------------
38
39    procedure Scan_Binder_Switches (Switch_Chars : String) is
40       Ptr : Integer := Switch_Chars'First;
41       Max : Integer := Switch_Chars'Last;
42       C   : Character := ' ';
43
44    begin
45       --  Skip past the initial character (must be the switch character)
46
47       if Ptr = Max then
48          raise Bad_Switch;
49       else
50          Ptr := Ptr + 1;
51       end if;
52
53       --  A little check, "gnat" at the start of a switch is not allowed
54       --  except for the compiler
55
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)");
61
62       end if;
63
64       --  Loop to scan through switches given in switch string
65
66       while Ptr <= Max loop
67          C := Switch_Chars (Ptr);
68
69          case C is
70
71          --  Processing for A switch
72
73          when 'A' =>
74             Ptr := Ptr + 1;
75
76             Ada_Bind_File := True;
77
78          --  Processing for b switch
79
80          when 'b' =>
81             Ptr := Ptr + 1;
82             Brief_Output := True;
83
84          --  Processing for c switch
85
86          when 'c' =>
87             Ptr := Ptr + 1;
88
89             Check_Only := True;
90
91          --  Processing for C switch
92
93          when 'C' =>
94             Ptr := Ptr + 1;
95
96             Ada_Bind_File := False;
97
98          --  Processing for d switch
99
100          when 'd' =>
101
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.
107
108             --  Loop to scan out debug flags
109
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 = '-';
114
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;
124
125             --  Make sure Zero_Cost_Exceptions is set if gnatdX set. This
126             --  is for backwards compatibility with old versions and usage.
127
128             if Debug_Flag_XX then
129                Zero_Cost_Exceptions_Set := True;
130                Zero_Cost_Exceptions_Val := True;
131             end if;
132
133             return;
134
135          --  Processing for e switch
136
137          when 'e' =>
138             Ptr := Ptr + 1;
139             Elab_Dependency_Output := True;
140
141          --  Processing for E switch
142
143          when 'E' =>
144             Ptr := Ptr + 1;
145             Exception_Tracebacks := True;
146
147          --  Processing for f switch
148
149          when 'f' =>
150             Ptr := Ptr + 1;
151             Force_RM_Elaboration_Order := True;
152
153          --  Processing for g switch
154
155          when 'g' =>
156             Ptr := Ptr + 1;
157
158             if Ptr <= Max then
159                C := Switch_Chars (Ptr);
160
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;
167
168             else
169                Debugger_Level := 2;
170             end if;
171
172          --  Processing for h switch
173
174          when 'h' =>
175             Ptr := Ptr + 1;
176             Usage_Requested := True;
177
178          --  Processing for i switch
179
180          when 'i' =>
181             if Ptr = Max then
182                raise Bad_Switch;
183             end if;
184
185             Ptr := Ptr + 1;
186             C := Switch_Chars (Ptr);
187
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;
200
201          --  Processing for K switch
202
203          when 'K' =>
204             Ptr := Ptr + 1;
205             Output_Linker_Option_List := True;
206
207          --  Processing for l switch
208
209          when 'l' =>
210             Ptr := Ptr + 1;
211             Elab_Order_Output := True;
212
213          --  Processing for m switch
214
215          when 'm' =>
216             Ptr := Ptr + 1;
217             Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Errors);
218
219          --  Processing for n switch
220
221          when 'n' =>
222             Ptr := Ptr + 1;
223             Bind_Main_Program := False;
224
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.
228
229          --  Processing for o switch
230
231          when 'o' =>
232             Ptr := Ptr + 1;
233
234             if Output_File_Name_Present then
235                raise Too_Many_Output_Files;
236
237             else
238                Output_File_Name_Present := True;
239             end if;
240
241          --  Processing for O switch
242
243          when 'O' =>
244             Ptr := Ptr + 1;
245             Output_Object_List := True;
246
247          --  Processing for p switch
248
249          when 'p' =>
250             Ptr := Ptr + 1;
251             Pessimistic_Elab_Order := True;
252
253          --  Processing for q switch
254
255          when 'q' =>
256             Ptr := Ptr + 1;
257             Quiet_Output := True;
258
259          --  Processing for r switch
260
261          when 'r' =>
262             Ptr := Ptr + 1;
263             List_Restrictions := True;
264
265          --  Processing for s switch
266
267          when 's' =>
268             Ptr := Ptr + 1;
269             All_Sources := True;
270             Check_Source_Files := True;
271
272          --  Processing for t switch
273
274          when 't' =>
275             Ptr := Ptr + 1;
276             Tolerate_Consistency_Errors := True;
277
278          --  Processing for T switch
279
280          when 'T' =>
281             Ptr := Ptr + 1;
282             Time_Slice_Set := True;
283             Scan_Nat (Switch_Chars, Max, Ptr, Time_Slice_Value);
284
285          --  Processing for v switch
286
287          when 'v' =>
288             Ptr := Ptr + 1;
289             Verbose_Mode := True;
290
291          --  Processing for w switch
292
293          when 'w' =>
294
295             --  For the binder we only allow suppress/error cases
296
297             Ptr := Ptr + 1;
298
299             case Switch_Chars (Ptr) is
300
301                when 'e' =>
302                   Warning_Mode  := Treat_As_Error;
303
304                when 's' =>
305                   Warning_Mode  := Suppress;
306
307                when others =>
308                   raise Bad_Switch;
309             end case;
310
311             Ptr := Ptr + 1;
312
313          --  Processing for W switch
314
315          when 'W' =>
316             Ptr := Ptr + 1;
317
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;
322
323                elsif J = WC_Encoding_Method'Last then
324                   raise Bad_Switch;
325                end if;
326             end loop;
327
328             Upper_Half_Encoding :=
329               Wide_Character_Encoding_Method in
330                 WC_Upper_Half_Encoding_Method;
331
332             Ptr := Ptr + 1;
333
334          --  Processing for x switch
335
336          when 'x' =>
337             Ptr := Ptr + 1;
338             All_Sources := False;
339             Check_Source_Files := False;
340
341          --  Processing for z switch
342
343          when 'z' =>
344             Ptr := Ptr + 1;
345             No_Main_Subprogram := True;
346
347          --  Ignore extra switch character
348
349          when '/'  =>
350             Ptr := Ptr + 1;
351
352          --  Ignore '-' extra switch caracter, only if it isn't followed by
353          --  'RTS'. If it is, then we must process the 'RTS' switch
354
355          when '-' =>
356
357             if Ptr + 3 <= Max and then
358               Switch_Chars (Ptr + 1 .. Ptr + 3) = "RTS"
359             then
360                Ptr := Ptr + 1;
361
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
368
369                   --  valid --RTS switch
370                   Opt.No_Stdinc := True;
371                   Opt.RTS_Switch := True;
372
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;
400
401             else
402                Ptr := Ptr + 1;
403             end if;
404
405          --  Anything else is an error (illegal switch character)
406
407          when others =>
408             raise Bad_Switch;
409          end case;
410       end loop;
411
412    exception
413       when Bad_Switch =>
414          Osint.Fail ("invalid switch: ", (1 => C));
415
416       when Bad_Switch_Value =>
417          Osint.Fail ("numeric value too big for switch: ", (1 => C));
418
419       when Missing_Switch_Value =>
420          Osint.Fail ("missing numeric value for switch: ", (1 => C));
421
422       when Too_Many_Output_Files =>
423          Osint.Fail ("duplicate -o switch");
424    end Scan_Binder_Switches;
425
426 end Switch.B;