OSDN Git Service

PR bootstrap/11932
[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-2003 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                   --  -gnatem (mapping file)
386
387                   when 'm' =>
388                      Store_Switch := False;
389                      Ptr := Ptr + 1;
390
391                      --  There may be an equal sign between -gnatem and
392                      --  the path name of the mapping file.
393
394                      if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
395                         Ptr := Ptr + 1;
396                      end if;
397
398                      if Ptr > Max then
399                         raise Bad_Switch;
400                      end if;
401
402                      Mapping_File_Name :=
403                        new String'(Switch_Chars (Ptr .. Max));
404                      return;
405
406                   --  -gnatep (preprocessing data file)
407
408                   when 'p' =>
409                      Store_Switch := False;
410                      Ptr := Ptr + 1;
411
412                      --  There may be an equal sign between -gnatep and
413                      --  the path name of the mapping file.
414
415                      if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
416                         Ptr := Ptr + 1;
417                      end if;
418
419                      if Ptr > Max then
420                         raise Bad_Switch;
421                      end if;
422
423                      Preprocessing_Data_File :=
424                        new String'(Switch_Chars (Ptr .. Max));
425
426                      --  Store the switch.
427                      --  Because we may store a longer switch (we normalize
428                      --  to -gnatep=), use a local variable.
429
430                      declare
431                         To_Store : String
432                           (1 .. Preprocessing_Data_File'Length + 8);
433
434                      begin
435                         To_Store (1 .. 8) := "-gnatep=";
436                         To_Store (9 .. Preprocessing_Data_File'Length + 8) :=
437                           Preprocessing_Data_File.all;
438                         Store_Compilation_Switch (To_Store);
439                      end;
440
441                   return;
442
443                   --  All other -gnate? switches are unassigned
444
445                   when others =>
446                      raise Bad_Switch;
447                end case;
448
449             --  -gnatE (dynamic elaboration checks)
450
451             when 'E' =>
452                Ptr := Ptr + 1;
453                Dynamic_Elaboration_Checks := True;
454
455             --  -gnatf (full error messages)
456
457             when 'f' =>
458                Ptr := Ptr + 1;
459                All_Errors_Mode := True;
460
461             --  Processing for F switch
462
463             when 'F' =>
464                Ptr := Ptr + 1;
465                External_Name_Exp_Casing := Uppercase;
466                External_Name_Imp_Casing := Uppercase;
467
468             --  Processing for g switch
469
470             when 'g' =>
471                Ptr := Ptr + 1;
472                GNAT_Mode := True;
473                Identifier_Character_Set := 'n';
474                System_Extend_Unit := Empty;
475                Warning_Mode := Treat_As_Error;
476
477                --  Set default warnings (basically -gnatwa)
478
479                Check_Unreferenced           := True;
480                Check_Unreferenced_Formals   := True;
481                Check_Withs                  := True;
482                Constant_Condition_Warnings  := True;
483                Implementation_Unit_Warnings := True;
484                Ineffective_Inline_Warnings  := True;
485                Warn_On_Constant             := True;
486                Warn_On_Export_Import        := True;
487                Warn_On_Modified_Unread      := True;
488                Warn_On_No_Value_Assigned    := True;
489                Warn_On_Obsolescent_Feature  := True;
490                Warn_On_Redundant_Constructs := True;
491                Warn_On_Unchecked_Conversion := True;
492                Warn_On_Unrecognized_Pragma  := True;
493
494                Set_Default_Style_Check_Options;
495
496             --  Processing for G switch
497
498             when 'G' =>
499                Ptr := Ptr + 1;
500                Print_Generated_Code := True;
501
502             --  Processing for h switch
503
504             when 'h' =>
505                Ptr := Ptr + 1;
506                Usage_Requested := True;
507
508             --  Processing for H switch
509
510             when 'H' =>
511                Ptr := Ptr + 1;
512                HLO_Active := True;
513
514             --  Processing for i switch
515
516             when 'i' =>
517                if Ptr = Max then
518                   raise Bad_Switch;
519                end if;
520
521                Ptr := Ptr + 1;
522                C := Switch_Chars (Ptr);
523
524                if C in '1' .. '5'
525                  or else C = '8'
526                  or else C = '9'
527                  or else C = 'p'
528                  or else C = 'f'
529                  or else C = 'n'
530                  or else C = 'w'
531                then
532                   Identifier_Character_Set := C;
533                   Ptr := Ptr + 1;
534
535                else
536                   raise Bad_Switch;
537                end if;
538
539             --  Processing for k switch
540
541             when 'k' =>
542                Ptr := Ptr + 1;
543                Scan_Pos (Switch_Chars, Max, Ptr, Maximum_File_Name_Length);
544
545             --  Processing for l switch
546
547             when 'l' =>
548                Ptr := Ptr + 1;
549                Full_List := True;
550
551             --  Processing for L switch
552
553             when 'L' =>
554                Ptr := Ptr + 1;
555                Zero_Cost_Exceptions_Set := True;
556                Zero_Cost_Exceptions_Val := False;
557
558             --  Processing for m switch
559
560             when 'm' =>
561                Ptr := Ptr + 1;
562                Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Errors);
563
564             --  Processing for n switch
565
566             when 'n' =>
567                Ptr := Ptr + 1;
568                Inline_Active := True;
569
570             --  Processing for N switch
571
572             when 'N' =>
573                Ptr := Ptr + 1;
574                Inline_Active := True;
575                Front_End_Inlining := True;
576
577             --  Processing for o switch
578
579             when 'o' =>
580                Ptr := Ptr + 1;
581                Suppress_Options (Overflow_Check) := False;
582                Opt.Enable_Overflow_Checks := True;
583
584             --  Processing for O switch
585
586             when 'O' =>
587                Store_Switch := False;
588                Ptr := Ptr + 1;
589                Output_File_Name_Present := True;
590
591             --  Processing for p switch
592
593             when 'p' =>
594                Ptr := Ptr + 1;
595                Suppress_Options           := (others => True);
596                Validity_Checks_On         := False;
597                Opt.Suppress_Checks        := True;
598                Opt.Enable_Overflow_Checks := False;
599
600             --  Processing for P switch
601
602             when 'P' =>
603                Ptr := Ptr + 1;
604                Polling_Required := True;
605
606             --  Processing for q switch
607
608             when 'q' =>
609                Ptr := Ptr + 1;
610                Try_Semantics := True;
611
612             --  Processing for q switch
613
614             when 'Q' =>
615                Ptr := Ptr + 1;
616                Force_ALI_Tree_File := True;
617                Try_Semantics := True;
618
619             --  Processing for R switch
620
621             when 'R' =>
622                Ptr := Ptr + 1;
623                Back_Annotate_Rep_Info := True;
624                List_Representation_Info := 1;
625
626                while Ptr <= Max loop
627                   C := Switch_Chars (Ptr);
628
629                   if C in '1' .. '3' then
630                      List_Representation_Info :=
631                        Character'Pos (C) - Character'Pos ('0');
632
633                   elsif Switch_Chars (Ptr) = 's' then
634                      List_Representation_Info_To_File := True;
635
636                   elsif Switch_Chars (Ptr) = 'm' then
637                      List_Representation_Info_Mechanisms := True;
638
639                   else
640                      raise Bad_Switch;
641                   end if;
642
643                   Ptr := Ptr + 1;
644                end loop;
645
646             --  Processing for s switch
647
648             when 's' =>
649                if not First_Switch then
650                   Osint.Fail
651                     ("-gnats must be first if combined with other switches");
652                end if;
653
654                Ptr := Ptr + 1;
655                Operating_Mode := Check_Syntax;
656
657             --  Processing for S switch
658
659             when 'S' =>
660                Print_Standard := True;
661                Ptr := Ptr + 1;
662
663             --  Processing for t switch
664
665             when 't' =>
666                Ptr := Ptr + 1;
667                Tree_Output := True;
668
669                if Operating_Mode = Check_Semantics then
670                   ASIS_Mode := True;
671                end if;
672
673                Back_Annotate_Rep_Info := True;
674
675             --  Processing for T switch
676
677             when 'T' =>
678                Ptr := Ptr + 1;
679                Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor);
680
681             --  Processing for u switch
682
683             when 'u' =>
684                Ptr := Ptr + 1;
685                List_Units := True;
686
687             --  Processing for U switch
688
689             when 'U' =>
690                Ptr := Ptr + 1;
691                Unique_Error_Tag := True;
692
693             --  Processing for v switch
694
695             when 'v' =>
696                Ptr := Ptr + 1;
697                Verbose_Mode := True;
698
699             --  Processing for V switch
700
701             when 'V' =>
702                Store_Switch := False;
703                Storing (First_Stored) := 'V';
704                Ptr := Ptr + 1;
705
706                if Ptr > Max then
707                   raise Bad_Switch;
708
709                else
710                   declare
711                      OK  : Boolean;
712
713                   begin
714                      Set_Validity_Check_Options
715                        (Switch_Chars (Ptr .. Max), OK, Ptr);
716
717                      if not OK then
718                         raise Bad_Switch;
719                      end if;
720
721                      for Index in First_Char + 1 .. Max loop
722                         Storing (First_Stored + 1) :=
723                           Switch_Chars (Index);
724                         Store_Compilation_Switch
725                           (Storing (Storing'First .. First_Stored + 1));
726                      end loop;
727                   end;
728                end if;
729
730                Ptr := Max + 1;
731
732             --  Processing for w switch
733
734             when 'w' =>
735                Store_Switch := False;
736                Storing (First_Stored) := 'w';
737                Ptr := Ptr + 1;
738
739                if Ptr > Max then
740                   raise Bad_Switch;
741                end if;
742
743                while Ptr <= Max loop
744                   C := Switch_Chars (Ptr);
745
746                   case C is
747                      when 'a' =>
748                         Check_Unreferenced              := True;
749                         Check_Unreferenced_Formals      := True;
750                         Check_Withs                     := True;
751                         Constant_Condition_Warnings     := True;
752                         Implementation_Unit_Warnings    := True;
753                         Ineffective_Inline_Warnings     := True;
754                         Warn_On_Constant                := True;
755                         Warn_On_Export_Import           := True;
756                         Warn_On_Modified_Unread         := True;
757                         Warn_On_No_Value_Assigned       := True;
758                         Warn_On_Obsolescent_Feature     := True;
759                         Warn_On_Redundant_Constructs    := True;
760                         Warn_On_Unchecked_Conversion    := True;
761                         Warn_On_Unrecognized_Pragma     := True;
762
763                      when 'A' =>
764                         Check_Unreferenced              := False;
765                         Check_Unreferenced_Formals      := False;
766                         Check_Withs                     := False;
767                         Constant_Condition_Warnings     := False;
768                         Elab_Warnings                   := False;
769                         Implementation_Unit_Warnings    := False;
770                         Ineffective_Inline_Warnings     := False;
771                         Warn_On_Constant                := False;
772                         Warn_On_Dereference             := False;
773                         Warn_On_Export_Import           := False;
774                         Warn_On_Hiding                  := False;
775                         Warn_On_Modified_Unread         := False;
776                         Warn_On_No_Value_Assigned       := False;
777                         Warn_On_Obsolescent_Feature     := False;
778                         Warn_On_Redundant_Constructs    := False;
779                         Warn_On_Unchecked_Conversion    := False;
780                         Warn_On_Unrecognized_Pragma     := False;
781
782                      when 'c' =>
783                         Constant_Condition_Warnings     := True;
784
785                      when 'C' =>
786                         Constant_Condition_Warnings     := False;
787
788                      when 'd' =>
789                         Warn_On_Dereference             := True;
790
791                      when 'D' =>
792                         Warn_On_Dereference             := False;
793
794                      when 'e' =>
795                         Warning_Mode                    := Treat_As_Error;
796
797                      when 'f' =>
798                         Check_Unreferenced_Formals      := True;
799
800                      when 'F' =>
801                         Check_Unreferenced_Formals      := False;
802
803                      when 'g' =>
804                         Warn_On_Unrecognized_Pragma     := True;
805
806                      when 'G' =>
807                         Warn_On_Unrecognized_Pragma     := False;
808
809                      when 'h' =>
810                         Warn_On_Hiding                  := True;
811
812                      when 'H' =>
813                         Warn_On_Hiding                  := False;
814
815                      when 'i' =>
816                         Implementation_Unit_Warnings    := True;
817
818                      when 'I' =>
819                         Implementation_Unit_Warnings    := False;
820
821                      when 'j' =>
822                         Warn_On_Obsolescent_Feature     := True;
823
824                      when 'J' =>
825                         Warn_On_Obsolescent_Feature     := False;
826
827                      when 'k' =>
828                         Warn_On_Constant                := True;
829
830                      when 'K' =>
831                         Warn_On_Constant                := False;
832
833                      when 'l' =>
834                         Elab_Warnings                   := True;
835
836                      when 'L' =>
837                         Elab_Warnings                   := False;
838
839                      when 'm' =>
840                         Warn_On_Modified_Unread         := True;
841
842                      when 'M' =>
843                         Warn_On_Modified_Unread         := False;
844
845                      when 'n' =>
846                         Warning_Mode                    := Normal;
847
848                      when 'o' =>
849                         Address_Clause_Overlay_Warnings := True;
850
851                      when 'O' =>
852                         Address_Clause_Overlay_Warnings := False;
853
854                      when 'p' =>
855                         Ineffective_Inline_Warnings     := True;
856
857                      when 'P' =>
858                         Ineffective_Inline_Warnings     := False;
859
860                      when 'r' =>
861                         Warn_On_Redundant_Constructs    := True;
862
863                      when 'R' =>
864                         Warn_On_Redundant_Constructs    := False;
865
866                      when 's' =>
867                         Warning_Mode                    := Suppress;
868
869                      when 'u' =>
870                         Check_Unreferenced              := True;
871                         Check_Withs                     := True;
872                         Check_Unreferenced_Formals      := True;
873
874                      when 'U' =>
875                         Check_Unreferenced              := False;
876                         Check_Withs                     := False;
877                         Check_Unreferenced_Formals      := False;
878
879                      when 'v' =>
880                         Warn_On_No_Value_Assigned       := True;
881
882                      when 'V' =>
883                         Warn_On_No_Value_Assigned       := False;
884
885                      when 'x' =>
886                         Warn_On_Export_Import           := True;
887
888                      when 'X' =>
889                         Warn_On_Export_Import           := False;
890
891                      when 'z' =>
892                         Warn_On_Unchecked_Conversion    := True;
893
894                      when 'Z' =>
895                         Warn_On_Unchecked_Conversion    := False;
896
897                         --  Allow and ignore 'w' so that the old
898                         --  format (e.g. -gnatwuwl) will work.
899
900                      when 'w' =>
901                         null;
902
903                      when others =>
904                         raise Bad_Switch;
905                   end case;
906
907                   if C /= 'w' then
908                      Storing (First_Stored + 1) := C;
909                      Store_Compilation_Switch
910                        (Storing (Storing'First .. First_Stored + 1));
911                   end if;
912
913                   Ptr := Ptr + 1;
914                end loop;
915
916                return;
917
918             --  Processing for W switch
919
920             when 'W' =>
921                Ptr := Ptr + 1;
922
923                if Ptr > Max then
924                   raise Bad_Switch;
925                end if;
926
927                for J in WC_Encoding_Method loop
928                   if Switch_Chars (Ptr) = WC_Encoding_Letters (J) then
929                      Wide_Character_Encoding_Method := J;
930                      exit;
931
932                   elsif J = WC_Encoding_Method'Last then
933                      raise Bad_Switch;
934                   end if;
935                end loop;
936
937                Upper_Half_Encoding :=
938                  Wide_Character_Encoding_Method in
939                  WC_Upper_Half_Encoding_Method;
940
941                Ptr := Ptr + 1;
942
943             --  Processing for x switch
944
945             when 'x' =>
946                Ptr := Ptr + 1;
947                Xref_Active := False;
948
949             --  Processing for X switch
950
951             when 'X' =>
952                Ptr := Ptr + 1;
953                Extensions_Allowed := True;
954
955             --  Processing for y switch
956
957             when 'y' =>
958                Ptr := Ptr + 1;
959
960                if Ptr > Max then
961                   Set_Default_Style_Check_Options;
962
963                else
964                   Store_Switch := False;
965                   Storing (First_Stored) := 'y';
966
967                   declare
968                      OK  : Boolean;
969                      Last_Stored : Integer;
970
971                   begin
972                      Set_Style_Check_Options
973                        (Switch_Chars (Ptr .. Max), OK, Ptr);
974
975                      if not OK then
976                         raise Bad_Switch;
977                      end if;
978
979                      Ptr := First_Char + 1;
980
981                      while Ptr <= Max loop
982                         Last_Stored := First_Stored + 1;
983                         Storing (Last_Stored) := Switch_Chars (Ptr);
984
985                         if Switch_Chars (Ptr) = 'M' then
986                            loop
987                               Ptr := Ptr + 1;
988                               exit when Ptr > Max
989                                 or else Switch_Chars (Ptr) not in '0' .. '9';
990                               Last_Stored := Last_Stored + 1;
991                               Storing (Last_Stored) := Switch_Chars (Ptr);
992                            end loop;
993
994                         else
995                            Ptr := Ptr + 1;
996                         end if;
997
998                         Store_Compilation_Switch
999                           (Storing (Storing'First .. Last_Stored));
1000                      end loop;
1001                   end;
1002                end if;
1003
1004             --  Processing for z switch
1005
1006             when 'z' =>
1007                Ptr := Ptr + 1;
1008
1009                --  Allowed for compiler only if this is the only
1010                --  -z switch, we do not allow multiple occurrences
1011
1012                if Distribution_Stub_Mode = No_Stubs then
1013                   case Switch_Chars (Ptr) is
1014                      when 'r' =>
1015                         Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
1016
1017                      when 'c' =>
1018                         Distribution_Stub_Mode := Generate_Caller_Stub_Body;
1019
1020                      when others =>
1021                         raise Bad_Switch;
1022                   end case;
1023
1024                   Ptr := Ptr + 1;
1025
1026                end if;
1027
1028             --  Processing for Z switch
1029
1030             when 'Z' =>
1031                Ptr := Ptr + 1;
1032                Zero_Cost_Exceptions_Set := True;
1033                Zero_Cost_Exceptions_Val := True;
1034
1035             --  Processing for 83 switch
1036
1037             when '8' =>
1038
1039                if Ptr = Max then
1040                   raise Bad_Switch;
1041                end if;
1042
1043                Ptr := Ptr + 1;
1044
1045                if Switch_Chars (Ptr) /= '3' then
1046                   raise Bad_Switch;
1047                else
1048                   Ptr := Ptr + 1;
1049                   Ada_95 := False;
1050                   Ada_83 := True;
1051                end if;
1052
1053             --  Ignore extra switch character
1054
1055             when '/' | '-' =>
1056                Ptr := Ptr + 1;
1057
1058             --  Anything else is an error (illegal switch character)
1059
1060             when others =>
1061                raise Bad_Switch;
1062             end case;
1063          end case;
1064
1065          if Store_Switch then
1066             Storing (First_Stored .. First_Stored + Ptr - First_Char - 1) :=
1067               Switch_Chars (First_Char .. Ptr - 1);
1068             Store_Compilation_Switch
1069               (Storing (Storing'First .. First_Stored + Ptr - First_Char - 1));
1070          end if;
1071
1072          First_Switch := False;
1073       end loop;
1074
1075    exception
1076       when Bad_Switch =>
1077          Osint.Fail ("invalid switch: ", (1 => C));
1078
1079       when Bad_Switch_Value =>
1080          Osint.Fail ("numeric value out of range for switch: ", (1 => C));
1081
1082       when Missing_Switch_Value =>
1083          Osint.Fail ("missing numeric value for switch: ", (1 => C));
1084
1085    end Scan_Front_End_Switches;
1086
1087 end Switch.C;