OSDN Git Service

* tree.def (RTL_EXPR): Remove.
[pf3gnuchains/gcc-fork.git] / gcc / ada / switch-c.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             S W I T C H - C                              --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 2001-2004 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 GNAT.OS_Lib; use GNAT.OS_Lib;
28
29 with Debug;    use Debug;
30 with Lib;      use Lib;
31 with Osint;    use Osint;
32 with Opt;      use Opt;
33 with Prepcomp; use Prepcomp;
34 with Types;    use Types;
35 with Validsw;  use Validsw;
36 with Stylesw;  use Stylesw;
37
38 with System.WCh_Con; use System.WCh_Con;
39
40 package body Switch.C is
41
42    RTS_Specified : String_Access := null;
43    --  Used to detect multiple use of --RTS= flag
44
45    -----------------------------
46    -- Scan_Front_End_Switches --
47    -----------------------------
48
49    procedure Scan_Front_End_Switches (Switch_Chars : String) is
50       Switch_Starts_With_Gnat : Boolean;
51       --  True if first four switch characters are "gnat"
52
53       First_Switch : Boolean := True;
54       --  False for all but first switch
55
56       Ptr : Integer := Switch_Chars'First;
57       Max : constant Integer := Switch_Chars'Last;
58       C   : Character := ' ';
59       Dot : Boolean;
60
61       Store_Switch : Boolean  := True;
62       First_Char   : Integer  := Ptr;
63       Storing      : String   := Switch_Chars;
64       First_Stored : Positive := Ptr + 1;
65       --  The above need comments ???
66
67    begin
68       --  Skip past the initial character (must be the switch character)
69
70       if Ptr = Max then
71          raise Bad_Switch;
72       else
73          Ptr := Ptr + 1;
74       end if;
75
76       --  Remove "gnat" from the switch, if present
77
78       Switch_Starts_With_Gnat :=
79         Ptr + 3 <= Max and then Switch_Chars (Ptr .. Ptr + 3) = "gnat";
80
81       if Switch_Starts_With_Gnat then
82          Ptr := Ptr + 4;
83          First_Stored := Ptr;
84       end if;
85
86       --  Loop to scan through switches given in switch string
87
88       while Ptr <= Max loop
89          Store_Switch := True;
90          First_Char := Ptr;
91          C := Switch_Chars (Ptr);
92
93          --  Processing for a switch
94
95          case Switch_Starts_With_Gnat is
96
97             when False =>
98
99             --  There are few front-end switches that
100             --  do not start with -gnat: -I, --RTS
101
102                if Switch_Chars (Ptr) = 'I' then
103                   Store_Switch := False;
104
105                   Ptr := Ptr + 1;
106
107                   if Ptr > Max then
108                      raise Bad_Switch;
109                   end if;
110
111                   --  Find out whether this is a -I- or regular -Ixxx switch
112
113                   if Ptr = Max and then Switch_Chars (Ptr) = '-' then
114                      Look_In_Primary_Dir := False;
115
116                   else
117                      Add_Src_Search_Dir (Switch_Chars (Ptr .. Max));
118                   end if;
119
120                   Ptr := Max + 1;
121
122                --  Processing of the --RTS switch. --RTS has been modified by
123                --  gcc and is now of the form -fRTS
124
125                elsif Ptr + 3 <= Max
126                  and then Switch_Chars (Ptr .. Ptr + 3) = "fRTS"
127                then
128                   Ptr := Ptr + 1;
129
130                   if Ptr + 4 > Max
131                     or else Switch_Chars (Ptr + 3) /= '='
132                   then
133                      Osint.Fail ("missing path for --RTS");
134                   else
135                      --  Check that this is the first time --RTS is specified
136                      --  or if it is not the first time, the same path has
137                      --  been specified.
138
139                      if RTS_Specified = null then
140                         RTS_Specified :=
141                           new String'(Switch_Chars (Ptr + 4 .. Max));
142
143                      elsif
144                        RTS_Specified.all /= Switch_Chars (Ptr + 4 .. Max)
145                      then
146                         Osint.Fail
147                           ("--RTS cannot be specified multiple times");
148                      end if;
149
150                      --  Valid --RTS switch
151
152                      Opt.No_Stdinc := True;
153                      Opt.RTS_Switch := True;
154
155                      RTS_Src_Path_Name := Get_RTS_Search_Dir
156                                             (Switch_Chars (Ptr + 4 .. Max),
157                                              Include);
158                      RTS_Lib_Path_Name := Get_RTS_Search_Dir
159                                             (Switch_Chars (Ptr + 4 .. Max),
160                                              Objects);
161
162                      if RTS_Src_Path_Name /= null and then
163                         RTS_Lib_Path_Name /= null
164                      then
165                         Ptr := Max + 1;
166
167                      elsif RTS_Src_Path_Name = null and then
168                            RTS_Lib_Path_Name = null
169                      then
170                         Osint.Fail ("RTS path not valid: missing " &
171                                     "adainclude and adalib directories");
172
173                      elsif RTS_Src_Path_Name = null then
174                         Osint.Fail ("RTS path not valid: missing " &
175                                     "adainclude directory");
176
177                      elsif RTS_Lib_Path_Name = null then
178                         Osint.Fail ("RTS path not valid: missing " &
179                                     "adalib directory");
180                      end if;
181                   end if;
182                else
183                   raise Bad_Switch;
184                end if;
185
186          when True =>
187
188             --  Process -gnat* options
189
190             case C is
191
192             when 'a' =>
193                Ptr := Ptr + 1;
194                Assertions_Enabled := True;
195
196             --  Processing for A switch
197
198             when 'A' =>
199                Ptr := Ptr + 1;
200                Config_File := False;
201
202             --  Processing for b switch
203
204             when 'b' =>
205                Ptr := Ptr + 1;
206                Brief_Output := True;
207
208             --  Processing for c switch
209
210             when 'c' =>
211                if not First_Switch then
212                   Osint.Fail
213                     ("-gnatc must be first if combined with other switches");
214                end if;
215
216                Ptr := Ptr + 1;
217                Operating_Mode := Check_Semantics;
218
219                if Tree_Output then
220                   ASIS_Mode := True;
221                end if;
222
223             --  Processing for d switch
224
225             when 'd' =>
226                Store_Switch := False;
227                Storing (First_Stored) := 'd';
228                Dot := False;
229
230                --  Note: for the debug switch, the remaining characters in this
231                --  switch field must all be debug flags, since all valid switch
232                --  characters are also valid debug characters.
233
234                --  Loop to scan out debug flags
235
236                while Ptr < Max loop
237                   Ptr := Ptr + 1;
238                   C := Switch_Chars (Ptr);
239                   exit when C = ASCII.NUL or else C = '/' or else C = '-';
240
241                   if C in '1' .. '9' or else
242                      C in 'a' .. 'z' or else
243                      C in 'A' .. 'Z'
244                   then
245                      if Dot then
246                         Set_Dotted_Debug_Flag (C);
247                         Storing (First_Stored + 1) := '.';
248                         Storing (First_Stored + 2) := C;
249                         Store_Compilation_Switch
250                           (Storing (Storing'First .. First_Stored + 2));
251                         Dot := False;
252
253                      else
254                         Set_Debug_Flag (C);
255                         Storing (First_Stored + 1) := C;
256                         Store_Compilation_Switch
257                           (Storing (Storing'First .. First_Stored + 1));
258                      end if;
259
260                   elsif C = '.' then
261                      Dot := True;
262
263                   else
264                      raise Bad_Switch;
265                   end if;
266                end loop;
267
268                --  Make sure Zero_Cost_Exceptions is set if gnatdX set. This
269                --  is for backwards compatibility with old versions and usage.
270
271                if Debug_Flag_XX then
272                   Zero_Cost_Exceptions_Set := True;
273                   Zero_Cost_Exceptions_Val := True;
274                end if;
275
276                return;
277
278             --  Processing for D switch
279
280             when 'D' =>
281                Ptr := Ptr + 1;
282
283                --  Note: -gnatD also sets -gnatx (to turn off cross-reference
284                --  generation in the ali file) since otherwise this generation
285                --  gets confused by the "wrong" Sloc values put in the tree.
286
287                Debug_Generated_Code := True;
288                Xref_Active := False;
289                Set_Debug_Flag ('g');
290
291             --  -gnate? (extended switches)
292
293             when 'e' =>
294                Ptr := Ptr + 1;
295
296                --  The -gnate? switches are all double character switches
297                --  so we must always have a character after the e.
298
299                if Ptr > Max then
300                   raise Bad_Switch;
301                end if;
302
303                case Switch_Chars (Ptr) is
304
305                   --  -gnatec (configuration pragmas)
306
307                   when 'c' =>
308                      Store_Switch := False;
309                      Ptr := Ptr + 1;
310
311                      --  There may be an equal sign between -gnatec and
312                      --  the path name of the config file.
313
314                      if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
315                         Ptr := Ptr + 1;
316                      end if;
317
318                      if Ptr > Max then
319                         raise Bad_Switch;
320                      end if;
321
322                      declare
323                         Config_File_Name : constant String_Access :=
324                                              new String'
325                                                   (Switch_Chars (Ptr .. Max));
326
327                      begin
328                         if Config_File_Names = null then
329                            Config_File_Names :=
330                              new String_List'(1 => Config_File_Name);
331
332                         else
333                            declare
334                               New_Names : constant String_List_Access :=
335                                             new String_List
336                                               (1 ..
337                                                Config_File_Names'Length + 1);
338
339                            begin
340                               for Index in Config_File_Names'Range loop
341                                  New_Names (Index) :=
342                                    Config_File_Names (Index);
343                                  Config_File_Names (Index) := null;
344                               end loop;
345
346                               New_Names (New_Names'Last) := Config_File_Name;
347                               Free (Config_File_Names);
348                               Config_File_Names := New_Names;
349                            end;
350                         end if;
351                      end;
352
353                      return;
354
355                   --  -gnateD switch (symbol definition)
356
357                   when 'D' =>
358                      Store_Switch := False;
359                      Ptr := Ptr + 1;
360
361                      if Ptr > Max then
362                         raise Bad_Switch;
363                      end if;
364
365                      Add_Symbol_Definition (Switch_Chars (Ptr .. Max));
366
367                      --  Store the switch
368
369                      Storing (First_Stored .. First_Stored + 1) := "eD";
370                      Storing
371                        (First_Stored + 2 .. First_Stored + Max - Ptr + 2) :=
372                        Switch_Chars (Ptr .. Max);
373                      Store_Compilation_Switch (Storing
374                               (Storing'First .. First_Stored + Max - Ptr + 2));
375                      return;
376
377                   --  -gnatef (full source path for brief error messages)
378
379                   when 'f' =>
380                      Store_Switch := False;
381                      Ptr := Ptr + 1;
382                      Full_Path_Name_For_Brief_Errors := True;
383                      return;
384
385                   --  -gnateI (index of unit in multi-unit source)
386
387                   when 'I' =>
388                      Ptr := Ptr + 1;
389                      Scan_Pos (Switch_Chars, Max, Ptr, Multiple_Unit_Index);
390
391                   --  -gnatem (mapping file)
392
393                   when 'm' =>
394                      Store_Switch := False;
395                      Ptr := Ptr + 1;
396
397                      --  There may be an equal sign between -gnatem and
398                      --  the path name of the mapping file.
399
400                      if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
401                         Ptr := Ptr + 1;
402                      end if;
403
404                      if Ptr > Max then
405                         raise Bad_Switch;
406                      end if;
407
408                      Mapping_File_Name :=
409                        new String'(Switch_Chars (Ptr .. Max));
410                      return;
411
412                   --  -gnatep (preprocessing data file)
413
414                   when 'p' =>
415                      Store_Switch := False;
416                      Ptr := Ptr + 1;
417
418                      --  There may be an equal sign between -gnatep and
419                      --  the path name of the mapping file.
420
421                      if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
422                         Ptr := Ptr + 1;
423                      end if;
424
425                      if Ptr > Max then
426                         raise Bad_Switch;
427                      end if;
428
429                      Preprocessing_Data_File :=
430                        new String'(Switch_Chars (Ptr .. Max));
431
432                      --  Store the switch.
433                      --  Because we may store a longer switch (we normalize
434                      --  to -gnatep=), use a local variable.
435
436                      declare
437                         To_Store : String
438                           (1 .. Preprocessing_Data_File'Length + 8);
439
440                      begin
441                         To_Store (1 .. 8) := "-gnatep=";
442                         To_Store (9 .. Preprocessing_Data_File'Length + 8) :=
443                           Preprocessing_Data_File.all;
444                         Store_Compilation_Switch (To_Store);
445                      end;
446
447                   return;
448
449                   when 'z' =>
450                      Store_Switch := False;
451                      Disable_Switch_Storing;
452                      Ptr := Ptr + 1;
453
454                   --  All other -gnate? switches are unassigned
455
456                   when others =>
457                      raise Bad_Switch;
458                end case;
459
460             --  -gnatE (dynamic elaboration checks)
461
462             when 'E' =>
463                Ptr := Ptr + 1;
464                Dynamic_Elaboration_Checks := True;
465
466             --  -gnatf (full error messages)
467
468             when 'f' =>
469                Ptr := Ptr + 1;
470                All_Errors_Mode := True;
471
472             --  Processing for F switch
473
474             when 'F' =>
475                Ptr := Ptr + 1;
476                External_Name_Exp_Casing := Uppercase;
477                External_Name_Imp_Casing := Uppercase;
478
479             --  Processing for g switch
480
481             when 'g' =>
482                Ptr := Ptr + 1;
483                GNAT_Mode := True;
484                Identifier_Character_Set := 'n';
485                System_Extend_Unit := Empty;
486                Warning_Mode := Treat_As_Error;
487
488                --  Set default warnings (basically -gnatwa)
489
490                Check_Unreferenced           := True;
491                Check_Unreferenced_Formals   := True;
492                Check_Withs                  := True;
493                Constant_Condition_Warnings  := True;
494                Implementation_Unit_Warnings := True;
495                Ineffective_Inline_Warnings  := True;
496                Warn_On_Constant             := True;
497                Warn_On_Export_Import        := True;
498                Warn_On_Modified_Unread      := True;
499                Warn_On_No_Value_Assigned    := True;
500                Warn_On_Obsolescent_Feature  := True;
501                Warn_On_Redundant_Constructs := True;
502                Warn_On_Unchecked_Conversion := True;
503                Warn_On_Unrecognized_Pragma  := True;
504
505                Set_Default_Style_Check_Options;
506
507             --  Processing for G switch
508
509             when 'G' =>
510                Ptr := Ptr + 1;
511                Print_Generated_Code := True;
512
513             --  Processing for h switch
514
515             when 'h' =>
516                Ptr := Ptr + 1;
517                Usage_Requested := True;
518
519             --  Processing for H switch
520
521             when 'H' =>
522                Ptr := Ptr + 1;
523                HLO_Active := True;
524
525             --  Processing for i switch
526
527             when 'i' =>
528                if Ptr = Max then
529                   raise Bad_Switch;
530                end if;
531
532                Ptr := Ptr + 1;
533                C := Switch_Chars (Ptr);
534
535                if C in '1' .. '5'
536                  or else C = '8'
537                  or else C = '9'
538                  or else C = 'p'
539                  or else C = 'f'
540                  or else C = 'n'
541                  or else C = 'w'
542                then
543                   Identifier_Character_Set := C;
544                   Ptr := Ptr + 1;
545
546                else
547                   raise Bad_Switch;
548                end if;
549
550             --  Processing for k switch
551
552             when 'k' =>
553                Ptr := Ptr + 1;
554                Scan_Pos (Switch_Chars, Max, Ptr, Maximum_File_Name_Length);
555
556             --  Processing for l switch
557
558             when 'l' =>
559                Ptr := Ptr + 1;
560                Full_List := True;
561
562             --  Processing for L switch
563
564             when 'L' =>
565                Ptr := Ptr + 1;
566                Zero_Cost_Exceptions_Set := True;
567                Zero_Cost_Exceptions_Val := False;
568
569             --  Processing for m switch
570
571             when 'm' =>
572                Ptr := Ptr + 1;
573                Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Errors);
574
575             --  Processing for n switch
576
577             when 'n' =>
578                Ptr := Ptr + 1;
579                Inline_Active := True;
580
581             --  Processing for N switch
582
583             when 'N' =>
584                Ptr := Ptr + 1;
585                Inline_Active := True;
586                Front_End_Inlining := True;
587
588             --  Processing for o switch
589
590             when 'o' =>
591                Ptr := Ptr + 1;
592                Suppress_Options (Overflow_Check) := False;
593                Opt.Enable_Overflow_Checks := True;
594
595             --  Processing for O switch
596
597             when 'O' =>
598                Store_Switch := False;
599                Ptr := Ptr + 1;
600                Output_File_Name_Present := True;
601
602             --  Processing for p switch
603
604             when 'p' =>
605                Ptr := Ptr + 1;
606                Suppress_Options           := (others => True);
607                Validity_Checks_On         := False;
608                Opt.Suppress_Checks        := True;
609                Opt.Enable_Overflow_Checks := False;
610
611             --  Processing for P switch
612
613             when 'P' =>
614                Ptr := Ptr + 1;
615                Polling_Required := True;
616
617             --  Processing for q switch
618
619             when 'q' =>
620                Ptr := Ptr + 1;
621                Try_Semantics := True;
622
623             --  Processing for q switch
624
625             when 'Q' =>
626                Ptr := Ptr + 1;
627                Force_ALI_Tree_File := True;
628                Try_Semantics := True;
629
630             --  Processing for R switch
631
632             when 'R' =>
633                Ptr := Ptr + 1;
634                Back_Annotate_Rep_Info := True;
635                List_Representation_Info := 1;
636
637                while Ptr <= Max loop
638                   C := Switch_Chars (Ptr);
639
640                   if C in '1' .. '3' then
641                      List_Representation_Info :=
642                        Character'Pos (C) - Character'Pos ('0');
643
644                   elsif Switch_Chars (Ptr) = 's' then
645                      List_Representation_Info_To_File := True;
646
647                   elsif Switch_Chars (Ptr) = 'm' then
648                      List_Representation_Info_Mechanisms := True;
649
650                   else
651                      raise Bad_Switch;
652                   end if;
653
654                   Ptr := Ptr + 1;
655                end loop;
656
657             --  Processing for s switch
658
659             when 's' =>
660                if not First_Switch then
661                   Osint.Fail
662                     ("-gnats must be first if combined with other switches");
663                end if;
664
665                Ptr := Ptr + 1;
666                Operating_Mode := Check_Syntax;
667
668             --  Processing for S switch
669
670             when 'S' =>
671                Print_Standard := True;
672                Ptr := Ptr + 1;
673
674             --  Processing for t switch
675
676             when 't' =>
677                Ptr := Ptr + 1;
678                Tree_Output := True;
679
680                if Operating_Mode = Check_Semantics then
681                   ASIS_Mode := True;
682                end if;
683
684                Back_Annotate_Rep_Info := True;
685
686             --  Processing for T switch
687
688             when 'T' =>
689                Ptr := Ptr + 1;
690                Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor);
691
692             --  Processing for u switch
693
694             when 'u' =>
695                Ptr := Ptr + 1;
696                List_Units := True;
697
698             --  Processing for U switch
699
700             when 'U' =>
701                Ptr := Ptr + 1;
702                Unique_Error_Tag := True;
703
704             --  Processing for v switch
705
706             when 'v' =>
707                Ptr := Ptr + 1;
708                Verbose_Mode := True;
709
710             --  Processing for V switch
711
712             when 'V' =>
713                Store_Switch := False;
714                Storing (First_Stored) := 'V';
715                Ptr := Ptr + 1;
716
717                if Ptr > Max then
718                   raise Bad_Switch;
719
720                else
721                   declare
722                      OK  : Boolean;
723
724                   begin
725                      Set_Validity_Check_Options
726                        (Switch_Chars (Ptr .. Max), OK, Ptr);
727
728                      if not OK then
729                         raise Bad_Switch;
730                      end if;
731
732                      for Index in First_Char + 1 .. Max loop
733                         Storing (First_Stored + 1) :=
734                           Switch_Chars (Index);
735                         Store_Compilation_Switch
736                           (Storing (Storing'First .. First_Stored + 1));
737                      end loop;
738                   end;
739                end if;
740
741                Ptr := Max + 1;
742
743             --  Processing for w switch
744
745             when 'w' =>
746                Store_Switch := False;
747                Storing (First_Stored) := 'w';
748                Ptr := Ptr + 1;
749
750                if Ptr > Max then
751                   raise Bad_Switch;
752                end if;
753
754                while Ptr <= Max loop
755                   C := Switch_Chars (Ptr);
756
757                   case C is
758                      when 'a' =>
759                         Check_Unreferenced              := True;
760                         Check_Unreferenced_Formals      := True;
761                         Check_Withs                     := True;
762                         Constant_Condition_Warnings     := True;
763                         Implementation_Unit_Warnings    := True;
764                         Ineffective_Inline_Warnings     := True;
765                         Warn_On_Constant                := True;
766                         Warn_On_Export_Import           := True;
767                         Warn_On_Modified_Unread         := True;
768                         Warn_On_No_Value_Assigned       := True;
769                         Warn_On_Obsolescent_Feature     := True;
770                         Warn_On_Redundant_Constructs    := True;
771                         Warn_On_Unchecked_Conversion    := True;
772                         Warn_On_Unrecognized_Pragma     := True;
773
774                      when 'A' =>
775                         Check_Unreferenced              := False;
776                         Check_Unreferenced_Formals      := False;
777                         Check_Withs                     := False;
778                         Constant_Condition_Warnings     := False;
779                         Elab_Warnings                   := False;
780                         Implementation_Unit_Warnings    := False;
781                         Ineffective_Inline_Warnings     := False;
782                         Warn_On_Constant                := False;
783                         Warn_On_Dereference             := False;
784                         Warn_On_Export_Import           := False;
785                         Warn_On_Hiding                  := False;
786                         Warn_On_Modified_Unread         := False;
787                         Warn_On_No_Value_Assigned       := False;
788                         Warn_On_Obsolescent_Feature     := False;
789                         Warn_On_Redundant_Constructs    := False;
790                         Warn_On_Unchecked_Conversion    := False;
791                         Warn_On_Unrecognized_Pragma     := False;
792
793                      when 'c' =>
794                         Constant_Condition_Warnings     := True;
795
796                      when 'C' =>
797                         Constant_Condition_Warnings     := False;
798
799                      when 'd' =>
800                         Warn_On_Dereference             := True;
801
802                      when 'D' =>
803                         Warn_On_Dereference             := False;
804
805                      when 'e' =>
806                         Warning_Mode                    := Treat_As_Error;
807
808                      when 'f' =>
809                         Check_Unreferenced_Formals      := True;
810
811                      when 'F' =>
812                         Check_Unreferenced_Formals      := False;
813
814                      when 'g' =>
815                         Warn_On_Unrecognized_Pragma     := True;
816
817                      when 'G' =>
818                         Warn_On_Unrecognized_Pragma     := False;
819
820                      when 'h' =>
821                         Warn_On_Hiding                  := True;
822
823                      when 'H' =>
824                         Warn_On_Hiding                  := False;
825
826                      when 'i' =>
827                         Implementation_Unit_Warnings    := True;
828
829                      when 'I' =>
830                         Implementation_Unit_Warnings    := False;
831
832                      when 'j' =>
833                         Warn_On_Obsolescent_Feature     := True;
834
835                      when 'J' =>
836                         Warn_On_Obsolescent_Feature     := False;
837
838                      when 'k' =>
839                         Warn_On_Constant                := True;
840
841                      when 'K' =>
842                         Warn_On_Constant                := False;
843
844                      when 'l' =>
845                         Elab_Warnings                   := True;
846
847                      when 'L' =>
848                         Elab_Warnings                   := False;
849
850                      when 'm' =>
851                         Warn_On_Modified_Unread         := True;
852
853                      when 'M' =>
854                         Warn_On_Modified_Unread         := False;
855
856                      when 'n' =>
857                         Warning_Mode                    := Normal;
858
859                      when 'o' =>
860                         Address_Clause_Overlay_Warnings := True;
861
862                      when 'O' =>
863                         Address_Clause_Overlay_Warnings := False;
864
865                      when 'p' =>
866                         Ineffective_Inline_Warnings     := True;
867
868                      when 'P' =>
869                         Ineffective_Inline_Warnings     := False;
870
871                      when 'r' =>
872                         Warn_On_Redundant_Constructs    := True;
873
874                      when 'R' =>
875                         Warn_On_Redundant_Constructs    := False;
876
877                      when 's' =>
878                         Warning_Mode                    := Suppress;
879
880                      when 'u' =>
881                         Check_Unreferenced              := True;
882                         Check_Withs                     := True;
883                         Check_Unreferenced_Formals      := True;
884
885                      when 'U' =>
886                         Check_Unreferenced              := False;
887                         Check_Withs                     := False;
888                         Check_Unreferenced_Formals      := False;
889
890                      when 'v' =>
891                         Warn_On_No_Value_Assigned       := True;
892
893                      when 'V' =>
894                         Warn_On_No_Value_Assigned       := False;
895
896                      when 'x' =>
897                         Warn_On_Export_Import           := True;
898
899                      when 'X' =>
900                         Warn_On_Export_Import           := False;
901
902                      when 'z' =>
903                         Warn_On_Unchecked_Conversion    := True;
904
905                      when 'Z' =>
906                         Warn_On_Unchecked_Conversion    := False;
907
908                         --  Allow and ignore 'w' so that the old
909                         --  format (e.g. -gnatwuwl) will work.
910
911                      when 'w' =>
912                         null;
913
914                      when others =>
915                         raise Bad_Switch;
916                   end case;
917
918                   if C /= 'w' then
919                      Storing (First_Stored + 1) := C;
920                      Store_Compilation_Switch
921                        (Storing (Storing'First .. First_Stored + 1));
922                   end if;
923
924                   Ptr := Ptr + 1;
925                end loop;
926
927                return;
928
929             --  Processing for W switch
930
931             when 'W' =>
932                Ptr := Ptr + 1;
933
934                if Ptr > Max then
935                   raise Bad_Switch;
936                end if;
937
938                for J in WC_Encoding_Method loop
939                   if Switch_Chars (Ptr) = WC_Encoding_Letters (J) then
940                      Wide_Character_Encoding_Method := J;
941                      exit;
942
943                   elsif J = WC_Encoding_Method'Last then
944                      raise Bad_Switch;
945                   end if;
946                end loop;
947
948                Upper_Half_Encoding :=
949                  Wide_Character_Encoding_Method in
950                  WC_Upper_Half_Encoding_Method;
951
952                Ptr := Ptr + 1;
953
954             --  Processing for x switch
955
956             when 'x' =>
957                Ptr := Ptr + 1;
958                Xref_Active := False;
959
960             --  Processing for X switch
961
962             when 'X' =>
963                Ptr := Ptr + 1;
964                Extensions_Allowed := True;
965                Ada_Version := Ada_Version_Type'Last;
966
967             --  Processing for y switch
968
969             when 'y' =>
970                Ptr := Ptr + 1;
971
972                if Ptr > Max then
973                   Set_Default_Style_Check_Options;
974
975                else
976                   Store_Switch := False;
977                   Storing (First_Stored) := 'y';
978
979                   declare
980                      OK  : Boolean;
981                      Last_Stored : Integer;
982
983                   begin
984                      Set_Style_Check_Options
985                        (Switch_Chars (Ptr .. Max), OK, Ptr);
986
987                      if not OK then
988                         raise Bad_Switch;
989                      end if;
990
991                      Ptr := First_Char + 1;
992
993                      while Ptr <= Max loop
994                         Last_Stored := First_Stored + 1;
995                         Storing (Last_Stored) := Switch_Chars (Ptr);
996
997                         if Switch_Chars (Ptr) = 'M' then
998                            loop
999                               Ptr := Ptr + 1;
1000                               exit when Ptr > Max
1001                                 or else Switch_Chars (Ptr) not in '0' .. '9';
1002                               Last_Stored := Last_Stored + 1;
1003                               Storing (Last_Stored) := Switch_Chars (Ptr);
1004                            end loop;
1005
1006                         else
1007                            Ptr := Ptr + 1;
1008                         end if;
1009
1010                         Store_Compilation_Switch
1011                           (Storing (Storing'First .. Last_Stored));
1012                      end loop;
1013                   end;
1014                end if;
1015
1016             --  Processing for z switch
1017
1018             when 'z' =>
1019                Ptr := Ptr + 1;
1020
1021                --  Allowed for compiler only if this is the only
1022                --  -z switch, we do not allow multiple occurrences
1023
1024                if Distribution_Stub_Mode = No_Stubs then
1025                   case Switch_Chars (Ptr) is
1026                      when 'r' =>
1027                         Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
1028
1029                      when 'c' =>
1030                         Distribution_Stub_Mode := Generate_Caller_Stub_Body;
1031
1032                      when others =>
1033                         raise Bad_Switch;
1034                   end case;
1035
1036                   Ptr := Ptr + 1;
1037
1038                end if;
1039
1040             --  Processing for Z switch
1041
1042             when 'Z' =>
1043                Ptr := Ptr + 1;
1044                Zero_Cost_Exceptions_Set := True;
1045                Zero_Cost_Exceptions_Val := True;
1046
1047             --  Processing for 83 switch
1048
1049             when '8' =>
1050                if Ptr = Max then
1051                   raise Bad_Switch;
1052                end if;
1053
1054                Ptr := Ptr + 1;
1055
1056                if Switch_Chars (Ptr) /= '3' then
1057                   raise Bad_Switch;
1058                else
1059                   Ptr := Ptr + 1;
1060                   Ada_Version := Ada_83;
1061                end if;
1062
1063             --  Processing for 95 switch
1064
1065             when '9' =>
1066                if Ptr = Max then
1067                   raise Bad_Switch;
1068                end if;
1069
1070                Ptr := Ptr + 1;
1071
1072                if Switch_Chars (Ptr) /= '5' then
1073                   raise Bad_Switch;
1074                else
1075                   Ptr := Ptr + 1;
1076                   Ada_Version := Ada_95;
1077                end if;
1078
1079             --  Processing for 05 switch
1080
1081             when '0' =>
1082                if Ptr = Max then
1083                   raise Bad_Switch;
1084                end if;
1085
1086                Ptr := Ptr + 1;
1087
1088                if Switch_Chars (Ptr) /= '5' then
1089                   raise Bad_Switch;
1090                else
1091                   Ptr := Ptr + 1;
1092                   Ada_Version := Ada_05;
1093                end if;
1094
1095             --  Ignore extra switch character
1096
1097             when '/' | '-' =>
1098                Ptr := Ptr + 1;
1099
1100             --  Anything else is an error (illegal switch character)
1101
1102             when others =>
1103                raise Bad_Switch;
1104             end case;
1105          end case;
1106
1107          if Store_Switch then
1108             Storing (First_Stored .. First_Stored + Ptr - First_Char - 1) :=
1109               Switch_Chars (First_Char .. Ptr - 1);
1110             Store_Compilation_Switch
1111               (Storing (Storing'First .. First_Stored + Ptr - First_Char - 1));
1112          end if;
1113
1114          First_Switch := False;
1115       end loop;
1116
1117    exception
1118       when Bad_Switch =>
1119          Osint.Fail ("invalid switch: ", (1 => C));
1120
1121       when Bad_Switch_Value =>
1122          Osint.Fail ("numeric value out of range for switch: ", (1 => C));
1123
1124       when Missing_Switch_Value =>
1125          Osint.Fail ("missing numeric value for switch: ", (1 => C));
1126
1127    end Scan_Front_End_Switches;
1128
1129 end Switch.C;