OSDN Git Service

PR fortran/23516
[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-2005 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,  51  Franklin  Street,  Fifth  Floor, --
20 -- Boston, MA 02110-1301, 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 Validsw;  use Validsw;
35 with Stylesw;  use Stylesw;
36
37 with System.WCh_Con; use System.WCh_Con;
38
39 package body Switch.C is
40
41    RTS_Specified : String_Access := null;
42    --  Used to detect multiple use of --RTS= flag
43
44    -----------------------------
45    -- Scan_Front_End_Switches --
46    -----------------------------
47
48    procedure Scan_Front_End_Switches (Switch_Chars : String) is
49       Switch_Starts_With_Gnat : Boolean;
50       --  True if first four switch characters are "gnat"
51
52       First_Switch : Boolean := True;
53       --  False for all but first switch
54
55       Ptr : Integer := Switch_Chars'First;
56       Max : constant Integer := Switch_Chars'Last;
57       C   : Character := ' ';
58       Dot : Boolean;
59
60       Store_Switch : Boolean  := True;
61       First_Char   : Integer  := Ptr;
62       Storing      : String   := Switch_Chars;
63       First_Stored : Positive := Ptr + 1;
64       --  The above need comments ???
65
66    begin
67       --  Skip past the initial character (must be the switch character)
68
69       if Ptr = Max then
70          raise Bad_Switch;
71       else
72          Ptr := Ptr + 1;
73       end if;
74
75       --  Remove "gnat" from the switch, if present
76
77       Switch_Starts_With_Gnat :=
78         Ptr + 3 <= Max and then Switch_Chars (Ptr .. Ptr + 3) = "gnat";
79
80       if Switch_Starts_With_Gnat then
81          Ptr := Ptr + 4;
82          First_Stored := Ptr;
83       end if;
84
85       --  Loop to scan through switches given in switch string
86
87       while Ptr <= Max loop
88          Store_Switch := True;
89          First_Char := Ptr;
90          C := Switch_Chars (Ptr);
91
92          --  Processing for a switch
93
94          case Switch_Starts_With_Gnat is
95
96             when False =>
97
98             --  There are few front-end switches that
99             --  do not start with -gnat: -I, --RTS
100
101                if Switch_Chars (Ptr) = 'I' then
102                   Store_Switch := False;
103
104                   Ptr := Ptr + 1;
105
106                   if Ptr > Max then
107                      raise Bad_Switch;
108                   end if;
109
110                   --  Find out whether this is a -I- or regular -Ixxx switch
111
112                   if Ptr = Max and then Switch_Chars (Ptr) = '-' then
113                      Look_In_Primary_Dir := False;
114
115                   else
116                      Add_Src_Search_Dir (Switch_Chars (Ptr .. Max));
117                   end if;
118
119                   Ptr := Max + 1;
120
121                --  Processing of the --RTS switch. --RTS has been modified by
122                --  gcc and is now of the form -fRTS
123
124                elsif Ptr + 3 <= Max
125                  and then Switch_Chars (Ptr .. Ptr + 3) = "fRTS"
126                then
127                   Ptr := Ptr + 1;
128
129                   if Ptr + 4 > Max
130                     or else Switch_Chars (Ptr + 3) /= '='
131                   then
132                      Osint.Fail ("missing path for --RTS");
133                   else
134                      --  Check that this is the first time --RTS is specified
135                      --  or if it is not the first time, the same path has
136                      --  been specified.
137
138                      if RTS_Specified = null then
139                         RTS_Specified :=
140                           new String'(Switch_Chars (Ptr + 4 .. Max));
141
142                      elsif
143                        RTS_Specified.all /= Switch_Chars (Ptr + 4 .. Max)
144                      then
145                         Osint.Fail
146                           ("--RTS cannot be specified multiple times");
147                      end if;
148
149                      --  Valid --RTS switch
150
151                      Opt.No_Stdinc := True;
152                      Opt.RTS_Switch := True;
153
154                      RTS_Src_Path_Name := Get_RTS_Search_Dir
155                                             (Switch_Chars (Ptr + 4 .. Max),
156                                              Include);
157                      RTS_Lib_Path_Name := Get_RTS_Search_Dir
158                                             (Switch_Chars (Ptr + 4 .. Max),
159                                              Objects);
160
161                      if RTS_Src_Path_Name /= null and then
162                         RTS_Lib_Path_Name /= null
163                      then
164                         Ptr := Max + 1;
165
166                      elsif RTS_Src_Path_Name = null and then
167                            RTS_Lib_Path_Name = null
168                      then
169                         Osint.Fail ("RTS path not valid: missing " &
170                                     "adainclude and adalib directories");
171
172                      elsif RTS_Src_Path_Name = null then
173                         Osint.Fail ("RTS path not valid: missing " &
174                                     "adainclude directory");
175
176                      elsif RTS_Lib_Path_Name = null then
177                         Osint.Fail ("RTS path not valid: missing " &
178                                     "adalib directory");
179                      end if;
180                   end if;
181                else
182                   raise Bad_Switch;
183                end if;
184
185          when True =>
186
187             --  Process -gnat* options
188
189             case C is
190
191             when 'a' =>
192                Ptr := Ptr + 1;
193                Assertions_Enabled := True;
194                Debug_Pragmas_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                return;
269
270             --  Processing for D switch
271
272             when 'D' =>
273                Ptr := Ptr + 1;
274
275                --  Note: -gnatD also sets -gnatx (to turn off cross-reference
276                --  generation in the ali file) since otherwise this generation
277                --  gets confused by the "wrong" Sloc values put in the tree.
278
279                Debug_Generated_Code := True;
280                Xref_Active := False;
281                Set_Debug_Flag ('g');
282
283             --  -gnate? (extended switches)
284
285             when 'e' =>
286                Ptr := Ptr + 1;
287
288                --  The -gnate? switches are all double character switches
289                --  so we must always have a character after the e.
290
291                if Ptr > Max then
292                   raise Bad_Switch;
293                end if;
294
295                case Switch_Chars (Ptr) is
296
297                   --  -gnatec (configuration pragmas)
298
299                   when 'c' =>
300                      Store_Switch := False;
301                      Ptr := Ptr + 1;
302
303                      --  There may be an equal sign between -gnatec and
304                      --  the path name of the config file.
305
306                      if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
307                         Ptr := Ptr + 1;
308                      end if;
309
310                      if Ptr > Max then
311                         raise Bad_Switch;
312                      end if;
313
314                      declare
315                         Config_File_Name : constant String_Access :=
316                                              new String'
317                                                   (Switch_Chars (Ptr .. Max));
318
319                      begin
320                         if Config_File_Names = null then
321                            Config_File_Names :=
322                              new String_List'(1 => Config_File_Name);
323
324                         else
325                            declare
326                               New_Names : constant String_List_Access :=
327                                             new String_List
328                                               (1 ..
329                                                Config_File_Names'Length + 1);
330
331                            begin
332                               for Index in Config_File_Names'Range loop
333                                  New_Names (Index) :=
334                                    Config_File_Names (Index);
335                                  Config_File_Names (Index) := null;
336                               end loop;
337
338                               New_Names (New_Names'Last) := Config_File_Name;
339                               Free (Config_File_Names);
340                               Config_File_Names := New_Names;
341                            end;
342                         end if;
343                      end;
344
345                      return;
346
347                   --  -gnateD switch (symbol definition)
348
349                   when 'D' =>
350                      Store_Switch := False;
351                      Ptr := Ptr + 1;
352
353                      if Ptr > Max then
354                         raise Bad_Switch;
355                      end if;
356
357                      Add_Symbol_Definition (Switch_Chars (Ptr .. Max));
358
359                      --  Store the switch
360
361                      Storing (First_Stored .. First_Stored + 1) := "eD";
362                      Storing
363                        (First_Stored + 2 .. First_Stored + Max - Ptr + 2) :=
364                        Switch_Chars (Ptr .. Max);
365                      Store_Compilation_Switch (Storing
366                               (Storing'First .. First_Stored + Max - Ptr + 2));
367                      return;
368
369                   --  -gnatef (full source path for brief error messages)
370
371                   when 'f' =>
372                      Store_Switch := False;
373                      Ptr := Ptr + 1;
374                      Full_Path_Name_For_Brief_Errors := True;
375                      return;
376
377                   --  -gnateI (index of unit in multi-unit source)
378
379                   when 'I' =>
380                      Ptr := Ptr + 1;
381                      Scan_Pos (Switch_Chars, Max, Ptr, Multiple_Unit_Index);
382
383                   --  -gnatem (mapping file)
384
385                   when 'm' =>
386                      Store_Switch := False;
387                      Ptr := Ptr + 1;
388
389                      --  There may be an equal sign between -gnatem and
390                      --  the path name of the mapping file.
391
392                      if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
393                         Ptr := Ptr + 1;
394                      end if;
395
396                      if Ptr > Max then
397                         raise Bad_Switch;
398                      end if;
399
400                      Mapping_File_Name :=
401                        new String'(Switch_Chars (Ptr .. Max));
402                      return;
403
404                   --  -gnatep (preprocessing data file)
405
406                   when 'p' =>
407                      Store_Switch := False;
408                      Ptr := Ptr + 1;
409
410                      --  There may be an equal sign between -gnatep and
411                      --  the path name of the mapping file.
412
413                      if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
414                         Ptr := Ptr + 1;
415                      end if;
416
417                      if Ptr > Max then
418                         raise Bad_Switch;
419                      end if;
420
421                      Preprocessing_Data_File :=
422                        new String'(Switch_Chars (Ptr .. Max));
423
424                      --  Store the switch.
425                      --  Because we may store a longer switch (we normalize
426                      --  to -gnatep=), use a local variable.
427
428                      declare
429                         To_Store : String
430                           (1 .. Preprocessing_Data_File'Length + 8);
431
432                      begin
433                         To_Store (1 .. 8) := "-gnatep=";
434                         To_Store (9 .. Preprocessing_Data_File'Length + 8) :=
435                           Preprocessing_Data_File.all;
436                         Store_Compilation_Switch (To_Store);
437                      end;
438
439                   return;
440
441                   when 'z' =>
442                      Store_Switch := False;
443                      Disable_Switch_Storing;
444                      Ptr := Ptr + 1;
445
446                   --  All other -gnate? switches are unassigned
447
448                   when others =>
449                      raise Bad_Switch;
450                end case;
451
452             --  -gnatE (dynamic elaboration checks)
453
454             when 'E' =>
455                Ptr := Ptr + 1;
456                Dynamic_Elaboration_Checks := True;
457
458             --  -gnatf (full error messages)
459
460             when 'f' =>
461                Ptr := Ptr + 1;
462                All_Errors_Mode := True;
463
464             --  Processing for F switch
465
466             when 'F' =>
467                Ptr := Ptr + 1;
468                External_Name_Exp_Casing := Uppercase;
469                External_Name_Imp_Casing := Uppercase;
470
471             --  Processing for g switch
472
473             when 'g' =>
474                Ptr := Ptr + 1;
475                GNAT_Mode := True;
476                Identifier_Character_Set := 'n';
477                System_Extend_Unit := Empty;
478                Warning_Mode := Treat_As_Error;
479
480                --  Set Ada 2005 mode explicitly. We don't want to rely on the
481                --  implicit setting here, since for example, we want
482                --  Preelaborate_05 treated as Preelaborate
483
484                Ada_Version := Ada_05;
485                Ada_Version_Explicit := Ada_Version;
486
487                --  Set default warnings for -gnatg (same set as -gnatwa)
488
489                Check_Unreferenced           := True;
490                Check_Unreferenced_Formals   := True;
491                Check_Withs                  := True;
492                Constant_Condition_Warnings  := True;
493                Implementation_Unit_Warnings := True;
494                Ineffective_Inline_Warnings  := True;
495                Warn_On_Bad_Fixed_Value      := 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_Style_Check_Options ("3abcdefhiklmnprstu");
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                Osint.Fail
567                  ("-gnatL is no longer supported: consider using --RTS=sjlj");
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_Ada_2005_Compatibility  := True;
766                         Warn_On_Bad_Fixed_Value         := True;
767                         Warn_On_Constant                := True;
768                         Warn_On_Export_Import           := True;
769                         Warn_On_Modified_Unread         := True;
770                         Warn_On_No_Value_Assigned       := True;
771                         Warn_On_Obsolescent_Feature     := True;
772                         Warn_On_Redundant_Constructs    := True;
773                         Warn_On_Unchecked_Conversion    := True;
774                         Warn_On_Unrecognized_Pragma     := True;
775
776                      when 'A' =>
777                         Check_Unreferenced              := False;
778                         Check_Unreferenced_Formals      := False;
779                         Check_Withs                     := False;
780                         Constant_Condition_Warnings     := False;
781                         Elab_Warnings                   := False;
782                         Implementation_Unit_Warnings    := False;
783                         Ineffective_Inline_Warnings     := False;
784                         Warn_On_Ada_2005_Compatibility  := False;
785                         Warn_On_Bad_Fixed_Value         := False;
786                         Warn_On_Constant                := False;
787                         Warn_On_Dereference             := False;
788                         Warn_On_Export_Import           := False;
789                         Warn_On_Hiding                  := False;
790                         Warn_On_Modified_Unread         := False;
791                         Warn_On_No_Value_Assigned       := False;
792                         Warn_On_Obsolescent_Feature     := False;
793                         Warn_On_Redundant_Constructs    := False;
794                         Warn_On_Unchecked_Conversion    := False;
795                         Warn_On_Unrecognized_Pragma     := False;
796
797                      when 'b' =>
798                         Warn_On_Bad_Fixed_Value         := True;
799
800                      when 'B' =>
801                         Warn_On_Bad_Fixed_Value         := False;
802
803                      when 'c' =>
804                         Constant_Condition_Warnings     := True;
805
806                      when 'C' =>
807                         Constant_Condition_Warnings     := False;
808
809                      when 'd' =>
810                         Warn_On_Dereference             := True;
811
812                      when 'D' =>
813                         Warn_On_Dereference             := False;
814
815                      when 'e' =>
816                         Warning_Mode                    := Treat_As_Error;
817
818                      when 'f' =>
819                         Check_Unreferenced_Formals      := True;
820
821                      when 'F' =>
822                         Check_Unreferenced_Formals      := False;
823
824                      when 'g' =>
825                         Warn_On_Unrecognized_Pragma     := True;
826
827                      when 'G' =>
828                         Warn_On_Unrecognized_Pragma     := False;
829
830                      when 'h' =>
831                         Warn_On_Hiding                  := True;
832
833                      when 'H' =>
834                         Warn_On_Hiding                  := False;
835
836                      when 'i' =>
837                         Implementation_Unit_Warnings    := True;
838
839                      when 'I' =>
840                         Implementation_Unit_Warnings    := False;
841
842                      when 'j' =>
843                         Warn_On_Obsolescent_Feature     := True;
844
845                      when 'J' =>
846                         Warn_On_Obsolescent_Feature     := False;
847
848                      when 'k' =>
849                         Warn_On_Constant                := True;
850
851                      when 'K' =>
852                         Warn_On_Constant                := False;
853
854                      when 'l' =>
855                         Elab_Warnings                   := True;
856
857                      when 'L' =>
858                         Elab_Warnings                   := False;
859
860                      when 'm' =>
861                         Warn_On_Modified_Unread         := True;
862
863                      when 'M' =>
864                         Warn_On_Modified_Unread         := False;
865
866                      when 'n' =>
867                         Warning_Mode                    := Normal;
868
869                      when 'o' =>
870                         Address_Clause_Overlay_Warnings := True;
871
872                      when 'O' =>
873                         Address_Clause_Overlay_Warnings := False;
874
875                      when 'p' =>
876                         Ineffective_Inline_Warnings     := True;
877
878                      when 'P' =>
879                         Ineffective_Inline_Warnings     := False;
880
881                      when 'r' =>
882                         Warn_On_Redundant_Constructs    := True;
883
884                      when 'R' =>
885                         Warn_On_Redundant_Constructs    := False;
886
887                      when 's' =>
888                         Warning_Mode                    := Suppress;
889
890                      when 'u' =>
891                         Check_Unreferenced              := True;
892                         Check_Withs                     := True;
893                         Check_Unreferenced_Formals      := True;
894
895                      when 'U' =>
896                         Check_Unreferenced              := False;
897                         Check_Withs                     := False;
898                         Check_Unreferenced_Formals      := False;
899
900                      when 'v' =>
901                         Warn_On_No_Value_Assigned       := True;
902
903                      when 'V' =>
904                         Warn_On_No_Value_Assigned       := False;
905
906                      when 'x' =>
907                         Warn_On_Export_Import           := True;
908
909                      when 'X' =>
910                         Warn_On_Export_Import           := False;
911
912                      when 'y' =>
913                         Warn_On_Ada_2005_Compatibility  := True;
914
915                      when 'Y' =>
916                         Warn_On_Ada_2005_Compatibility  := False;
917
918                      when 'z' =>
919                         Warn_On_Unchecked_Conversion    := True;
920
921                      when 'Z' =>
922                         Warn_On_Unchecked_Conversion    := False;
923
924                         --  Allow and ignore 'w' so that the old
925                         --  format (e.g. -gnatwuwl) will work.
926
927                      when 'w' =>
928                         null;
929
930                      when others =>
931                         raise Bad_Switch;
932                   end case;
933
934                   if C /= 'w' then
935                      Storing (First_Stored + 1) := C;
936                      Store_Compilation_Switch
937                        (Storing (Storing'First .. First_Stored + 1));
938                   end if;
939
940                   Ptr := Ptr + 1;
941                end loop;
942
943                return;
944
945             --  Processing for W switch
946
947             when 'W' =>
948                Ptr := Ptr + 1;
949
950                if Ptr > Max then
951                   raise Bad_Switch;
952                end if;
953
954                for J in WC_Encoding_Method loop
955                   if Switch_Chars (Ptr) = WC_Encoding_Letters (J) then
956                      Wide_Character_Encoding_Method := J;
957                      exit;
958
959                   elsif J = WC_Encoding_Method'Last then
960                      raise Bad_Switch;
961                   end if;
962                end loop;
963
964                Upper_Half_Encoding :=
965                  Wide_Character_Encoding_Method in
966                  WC_Upper_Half_Encoding_Method;
967
968                Ptr := Ptr + 1;
969
970             --  Processing for x switch
971
972             when 'x' =>
973                Ptr := Ptr + 1;
974                Xref_Active := False;
975
976             --  Processing for X switch
977
978             when 'X' =>
979                Ptr := Ptr + 1;
980                Extensions_Allowed := True;
981                Ada_Version := Ada_Version_Type'Last;
982                Ada_Version_Explicit := Ada_Version;
983
984             --  Processing for y switch
985
986             when 'y' =>
987                Ptr := Ptr + 1;
988
989                if Ptr > Max then
990                   Set_Default_Style_Check_Options;
991
992                else
993                   Store_Switch := False;
994                   Storing (First_Stored) := 'y';
995
996                   declare
997                      OK  : Boolean;
998                      Last_Stored : Integer;
999
1000                   begin
1001                      Set_Style_Check_Options
1002                        (Switch_Chars (Ptr .. Max), OK, Ptr);
1003
1004                      if not OK then
1005                         raise Bad_Switch;
1006                      end if;
1007
1008                      Ptr := First_Char + 1;
1009
1010                      while Ptr <= Max loop
1011                         Last_Stored := First_Stored + 1;
1012                         Storing (Last_Stored) := Switch_Chars (Ptr);
1013
1014                         if Switch_Chars (Ptr) = 'M' then
1015                            loop
1016                               Ptr := Ptr + 1;
1017                               exit when Ptr > Max
1018                                 or else Switch_Chars (Ptr) not in '0' .. '9';
1019                               Last_Stored := Last_Stored + 1;
1020                               Storing (Last_Stored) := Switch_Chars (Ptr);
1021                            end loop;
1022
1023                         else
1024                            Ptr := Ptr + 1;
1025                         end if;
1026
1027                         Store_Compilation_Switch
1028                           (Storing (Storing'First .. Last_Stored));
1029                      end loop;
1030                   end;
1031                end if;
1032
1033             --  Processing for z switch
1034
1035             when 'z' =>
1036                Ptr := Ptr + 1;
1037
1038                --  Allowed for compiler only if this is the only
1039                --  -z switch, we do not allow multiple occurrences
1040
1041                if Distribution_Stub_Mode = No_Stubs then
1042                   case Switch_Chars (Ptr) is
1043                      when 'r' =>
1044                         Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
1045
1046                      when 'c' =>
1047                         Distribution_Stub_Mode := Generate_Caller_Stub_Body;
1048
1049                      when others =>
1050                         raise Bad_Switch;
1051                   end case;
1052
1053                   Ptr := Ptr + 1;
1054
1055                end if;
1056
1057             --  Processing for Z switch
1058
1059             when 'Z' =>
1060                Ptr := Ptr + 1;
1061                Osint.Fail
1062                  ("-gnatZ is no longer supported: consider using --RTS=zcx");
1063
1064             --  Processing for 83 switch
1065
1066             when '8' =>
1067                if Ptr = Max then
1068                   raise Bad_Switch;
1069                end if;
1070
1071                Ptr := Ptr + 1;
1072
1073                if Switch_Chars (Ptr) /= '3' then
1074                   raise Bad_Switch;
1075                else
1076                   Ptr := Ptr + 1;
1077                   Ada_Version := Ada_83;
1078                   Ada_Version_Explicit := Ada_Version;
1079                end if;
1080
1081             --  Processing for 95 switch
1082
1083             when '9' =>
1084                if Ptr = Max then
1085                   raise Bad_Switch;
1086                end if;
1087
1088                Ptr := Ptr + 1;
1089
1090                if Switch_Chars (Ptr) /= '5' then
1091                   raise Bad_Switch;
1092                else
1093                   Ptr := Ptr + 1;
1094                   Ada_Version := Ada_95;
1095                   Ada_Version_Explicit := Ada_Version;
1096                end if;
1097
1098             --  Processing for 05 switch
1099
1100             when '0' =>
1101                if Ptr = Max then
1102                   raise Bad_Switch;
1103                end if;
1104
1105                Ptr := Ptr + 1;
1106
1107                if Switch_Chars (Ptr) /= '5' then
1108                   raise Bad_Switch;
1109                else
1110                   Ptr := Ptr + 1;
1111                   Ada_Version := Ada_05;
1112                   Ada_Version_Explicit := Ada_Version;
1113                end if;
1114
1115             --  Ignore extra switch character
1116
1117             when '/' | '-' =>
1118                Ptr := Ptr + 1;
1119
1120             --  Anything else is an error (illegal switch character)
1121
1122             when others =>
1123                raise Bad_Switch;
1124             end case;
1125          end case;
1126
1127          if Store_Switch then
1128             Storing (First_Stored .. First_Stored + Ptr - First_Char - 1) :=
1129               Switch_Chars (First_Char .. Ptr - 1);
1130             Store_Compilation_Switch
1131               (Storing (Storing'First .. First_Stored + Ptr - First_Char - 1));
1132          end if;
1133
1134          First_Switch := False;
1135       end loop;
1136
1137    exception
1138       when Bad_Switch =>
1139          Osint.Fail ("invalid switch: ", (1 => C));
1140
1141       when Bad_Switch_Value =>
1142          Osint.Fail ("numeric value out of range for switch: ", (1 => C));
1143
1144       when Missing_Switch_Value =>
1145          Osint.Fail ("missing numeric value for switch: ", (1 => C));
1146
1147    end Scan_Front_End_Switches;
1148
1149 end Switch.C;