OSDN Git Service

2007-08-31 Robert Dewar <dewar@adacore.com>
[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-2007, 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 Debug;    use Debug;
28 with Lib;      use Lib;
29 with Osint;    use Osint;
30 with Opt;      use Opt;
31 with Prepcomp; use Prepcomp;
32 with Validsw;  use Validsw;
33 with Sem_Warn; use Sem_Warn;
34 with Stylesw;  use Stylesw;
35
36 with System.OS_Lib; use System.OS_Lib;
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       First_Switch : Boolean := True;
51       --  False for all but first switch
52
53       Max : constant Natural := Switch_Chars'Last;
54       Ptr : Natural;
55       C   : Character := ' ';
56       Dot : Boolean;
57
58       Store_Switch : Boolean;
59       --  For -gnatxx switches, the normal processing, signalled by this flag
60       --  being set to True, is to store the switch on exit from the case
61       --  statement, the switch stored is -gnat followed by the characters
62       --  from First_Char to Ptr-1. For cases like -gnaty, where the switch
63       --  is stored in separate pieces, this flag is set to False, and the
64       --  appropriate calls to Store_Compilation_Switch are made from within
65       --  the case branch.
66
67       First_Char : Positive;
68       --  Marks start of switch to be stored
69
70    begin
71       Ptr := Switch_Chars'First;
72
73       --  Skip past the initial character (must be the switch character)
74
75       if Ptr = Max then
76          Bad_Switch (C);
77       else
78          Ptr := Ptr + 1;
79       end if;
80
81       --  Handle switches that do not start with -gnat
82
83       if Ptr + 3 > Max
84         or else Switch_Chars (Ptr .. Ptr + 3) /= "gnat"
85       then
86          --  There are two front-end switches that do not start with -gnat:
87          --  -I, --RTS
88
89          if Switch_Chars (Ptr) = 'I' then
90
91             --  Set flag Search_Directory_Present if switch is "-I" only:
92             --  the directory will be the next argument.
93
94             if Ptr = Max then
95                Search_Directory_Present := True;
96                return;
97             end if;
98
99             Ptr := Ptr + 1;
100
101             --  Find out whether this is a -I- or regular -Ixxx switch
102
103             --  Note: -I switches are not recorded in the ALI file, since the
104             --  meaning of the program depends on the source files compiled,
105             --  not where they came from.
106
107             if Ptr = Max and then Switch_Chars (Ptr) = '-' then
108                Look_In_Primary_Dir := False;
109             else
110                Add_Src_Search_Dir (Switch_Chars (Ptr .. Max));
111             end if;
112
113          --  Processing of the --RTS switch. --RTS may have been modified by
114          --  gcc into -fRTS (for GCC targets).
115
116          elsif Ptr + 3 <= Max
117            and then (Switch_Chars (Ptr .. Ptr + 3) = "fRTS"
118                        or else
119                      Switch_Chars (Ptr .. Ptr + 3) = "-RTS")
120          then
121             Ptr := Ptr + 1;
122
123             if Ptr + 4 > Max
124               or else Switch_Chars (Ptr + 3) /= '='
125             then
126                Osint.Fail ("missing path for --RTS");
127             else
128                --  Check that this is the first time --RTS is specified or if
129                --  it is not the first time, the same path has been specified.
130
131                if RTS_Specified = null then
132                   RTS_Specified := new String'(Switch_Chars (Ptr + 4 .. Max));
133
134                elsif
135                  RTS_Specified.all /= Switch_Chars (Ptr + 4 .. Max)
136                then
137                   Osint.Fail
138                     ("--RTS cannot be specified multiple times");
139                end if;
140
141                --  Valid --RTS switch
142
143                Opt.No_Stdinc := True;
144                Opt.RTS_Switch := True;
145
146                RTS_Src_Path_Name :=
147                  Get_RTS_Search_Dir
148                    (Switch_Chars (Ptr + 4 .. Max), Include);
149
150                RTS_Lib_Path_Name :=
151                  Get_RTS_Search_Dir
152                    (Switch_Chars (Ptr + 4 .. Max), Objects);
153
154                if RTS_Src_Path_Name /= null
155                  and then RTS_Lib_Path_Name /= null
156                then
157                   --  Store the -fRTS switch (Note: Store_Compilation_Switch
158                   --  changes -fRTS back into --RTS for the actual output).
159
160                   Store_Compilation_Switch (Switch_Chars);
161
162                elsif RTS_Src_Path_Name = null
163                  and then RTS_Lib_Path_Name = null
164                then
165                   Osint.Fail ("RTS path not valid: missing " &
166                               "adainclude and adalib directories");
167
168                elsif RTS_Src_Path_Name = null then
169                   Osint.Fail ("RTS path not valid: missing " &
170                               "adainclude directory");
171
172                elsif RTS_Lib_Path_Name = null then
173                   Osint.Fail ("RTS path not valid: missing " &
174                               "adalib directory");
175                end if;
176             end if;
177
178             --  There are no other switches not starting with -gnat
179
180          else
181             Bad_Switch (Switch_Chars);
182          end if;
183
184       --  Case of switch starting with -gnat
185
186       else
187          Ptr := Ptr + 4;
188
189          --  Loop to scan through switches given in switch string
190
191          while Ptr <= Max loop
192             First_Char := Ptr;
193             Store_Switch := True;
194
195             C := Switch_Chars (Ptr);
196
197             case C is
198
199             when 'a' =>
200                Ptr := Ptr + 1;
201                Assertions_Enabled := True;
202                Debug_Pragmas_Enabled := True;
203
204             --  Processing for A switch
205
206             when 'A' =>
207                Ptr := Ptr + 1;
208                Config_File := False;
209
210             --  Processing for b switch
211
212             when 'b' =>
213                Ptr := Ptr + 1;
214                Brief_Output := True;
215
216             --  Processing for c switch
217
218             when 'c' =>
219                if not First_Switch then
220                   Osint.Fail
221                     ("-gnatc must be first if combined with other switches");
222                end if;
223
224                Ptr := Ptr + 1;
225                Operating_Mode := Check_Semantics;
226
227                if Tree_Output then
228                   ASIS_Mode := True;
229                end if;
230
231             --  Processing for d switch
232
233             when 'd' =>
234                Store_Switch := False;
235                Dot := False;
236
237                --  Note: for the debug switch, the remaining characters in this
238                --  switch field must all be debug flags, since all valid switch
239                --  characters are also valid debug characters.
240
241                --  Loop to scan out debug flags
242
243                while Ptr < Max loop
244                   Ptr := Ptr + 1;
245                   C := Switch_Chars (Ptr);
246                   exit when C = ASCII.NUL or else C = '/' or else C = '-';
247
248                   if C in '1' .. '9' or else
249                      C in 'a' .. 'z' or else
250                      C in 'A' .. 'Z'
251                   then
252                      if Dot then
253                         Set_Dotted_Debug_Flag (C);
254                         Store_Compilation_Switch ("-gnatd." & C);
255                      else
256                         Set_Debug_Flag (C);
257                         Store_Compilation_Switch ("-gnatd" & C);
258                      end if;
259
260                   elsif C = '.' then
261                      Dot := True;
262
263                   elsif Dot then
264                      Bad_Switch ("-gnatd." & Switch_Chars (Ptr .. Max));
265                   else
266                      Bad_Switch ("-gnatd" & Switch_Chars (Ptr .. Max));
267                   end if;
268                end loop;
269
270                return;
271
272             --  Processing for D switch
273
274             when 'D' =>
275                Ptr := Ptr + 1;
276
277                --  Note: -gnatD also sets -gnatx (to turn off cross-reference
278                --  generation in the ali file) since otherwise this generation
279                --  gets confused by the "wrong" Sloc values put in the tree.
280
281                Debug_Generated_Code := True;
282                Xref_Active := False;
283                Set_Debug_Flag ('g');
284
285             --  -gnate? (extended switches)
286
287             when 'e' =>
288                Ptr := Ptr + 1;
289
290                --  The -gnate? switches are all double character switches
291                --  so we must always have a character after the e.
292
293                if Ptr > Max then
294                   Bad_Switch ("-gnate");
295                end if;
296
297                case Switch_Chars (Ptr) is
298
299                   --  -gnatec (configuration pragmas)
300
301                   when 'c' =>
302                      Store_Switch := False;
303                      Ptr := Ptr + 1;
304
305                      --  There may be an equal sign between -gnatec and
306                      --  the path name of the config file.
307
308                      if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
309                         Ptr := Ptr + 1;
310                      end if;
311
312                      if Ptr > Max then
313                         Bad_Switch ("-gnatec");
314                      end if;
315
316                      declare
317                         Config_File_Name : constant String_Access :=
318                                              new String'
319                                                   (Switch_Chars (Ptr .. Max));
320
321                      begin
322                         if Config_File_Names = null then
323                            Config_File_Names :=
324                              new String_List'(1 => Config_File_Name);
325
326                         else
327                            declare
328                               New_Names : constant String_List_Access :=
329                                             new String_List
330                                               (1 ..
331                                                Config_File_Names'Length + 1);
332
333                            begin
334                               for Index in Config_File_Names'Range loop
335                                  New_Names (Index) :=
336                                    Config_File_Names (Index);
337                                  Config_File_Names (Index) := null;
338                               end loop;
339
340                               New_Names (New_Names'Last) := Config_File_Name;
341                               Free (Config_File_Names);
342                               Config_File_Names := New_Names;
343                            end;
344                         end if;
345                      end;
346
347                      return;
348
349                   --  -gnateD switch (preprocessing symbol definition)
350
351                   when 'D' =>
352                      Store_Switch := False;
353                      Ptr := Ptr + 1;
354
355                      if Ptr > Max then
356                         Bad_Switch ("-gnateD");
357                      end if;
358
359                      Add_Symbol_Definition (Switch_Chars (Ptr .. Max));
360
361                      --  Store the switch
362
363                      Store_Compilation_Switch
364                        ("-gnateD" & Switch_Chars (Ptr .. Max));
365                      Ptr := Max + 1;
366
367                   --  -gnatef (full source path for brief error messages)
368
369                   when 'f' =>
370                      Store_Switch := False;
371                      Ptr := Ptr + 1;
372                      Full_Path_Name_For_Brief_Errors := True;
373                      return;
374
375                   --  -gnateI (index of unit in multi-unit source)
376
377                   when 'I' =>
378                      Ptr := Ptr + 1;
379                      Scan_Pos (Switch_Chars, Max, Ptr, Multiple_Unit_Index, C);
380
381                   --  -gnatem (mapping file)
382
383                   when 'm' =>
384                      Store_Switch := False;
385                      Ptr := Ptr + 1;
386
387                      --  There may be an equal sign between -gnatem and
388                      --  the path name of the mapping file.
389
390                      if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
391                         Ptr := Ptr + 1;
392                      end if;
393
394                      if Ptr > Max then
395                         Bad_Switch ("-gnatem");
396                      end if;
397
398                      Mapping_File_Name :=
399                        new String'(Switch_Chars (Ptr .. Max));
400                      return;
401
402                   --  -gnatep (preprocessing data file)
403
404                   when 'p' =>
405                      Store_Switch := False;
406                      Ptr := Ptr + 1;
407
408                      --  There may be an equal sign between -gnatep and
409                      --  the path name of the mapping file.
410
411                      if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
412                         Ptr := Ptr + 1;
413                      end if;
414
415                      if Ptr > Max then
416                         Bad_Switch ("-gnatep");
417                      end if;
418
419                      Preprocessing_Data_File :=
420                        new String'(Switch_Chars (Ptr .. Max));
421
422                      --  Store the switch, normalizing to -gnatep=
423
424                      Store_Compilation_Switch
425                        ("-gnatep=" & Preprocessing_Data_File.all);
426
427                      Ptr := Max + 1;
428
429                   when 'z' =>
430                      Store_Switch := False;
431                      Disable_Switch_Storing;
432                      Ptr := Ptr + 1;
433
434                   --  All other -gnate? switches are unassigned
435
436                   when others =>
437                      Bad_Switch ("-gnate" & Switch_Chars (Ptr .. Max));
438                end case;
439
440             --  -gnatE (dynamic elaboration checks)
441
442             when 'E' =>
443                Ptr := Ptr + 1;
444                Dynamic_Elaboration_Checks := True;
445
446             --  -gnatf (full error messages)
447
448             when 'f' =>
449                Ptr := Ptr + 1;
450                All_Errors_Mode := True;
451
452             --  Processing for F switch
453
454             when 'F' =>
455                Ptr := Ptr + 1;
456                External_Name_Exp_Casing := Uppercase;
457                External_Name_Imp_Casing := Uppercase;
458
459             --  Processing for g switch
460
461             when 'g' =>
462                Ptr := Ptr + 1;
463                GNAT_Mode := True;
464                Identifier_Character_Set := 'n';
465                System_Extend_Unit := Empty;
466                Warning_Mode := Treat_As_Error;
467
468                --  Set Ada 2005 mode explicitly. We don't want to rely on the
469                --  implicit setting here, since for example, we want
470                --  Preelaborate_05 treated as Preelaborate
471
472                Ada_Version := Ada_05;
473                Ada_Version_Explicit := Ada_Version;
474
475                --  Set default warnings for -gnatg
476
477                Check_Unreferenced              := True;
478                Check_Unreferenced_Formals      := True;
479                Check_Withs                     := True;
480                Constant_Condition_Warnings     := True;
481                Implementation_Unit_Warnings    := True;
482                Ineffective_Inline_Warnings     := True;
483                Warn_On_Assumed_Low_Bound       := True;
484                Warn_On_Bad_Fixed_Value         := 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_Non_Local_Exception     := False;
490                Warn_On_Obsolescent_Feature     := True;
491                Warn_On_Redundant_Constructs    := True;
492                Warn_On_Object_Renames_Function := True;
493                Warn_On_Unchecked_Conversion    := True;
494                Warn_On_Unrecognized_Pragma     := True;
495
496                Set_GNAT_Style_Check_Options;
497
498             --  Processing for G switch
499
500             when 'G' =>
501                Ptr := Ptr + 1;
502                Print_Generated_Code := True;
503
504             --  Processing for h switch
505
506             when 'h' =>
507                Ptr := Ptr + 1;
508                Usage_Requested := True;
509
510             --  Processing for H switch
511
512             when 'H' =>
513                Ptr := Ptr + 1;
514                HLO_Active := True;
515
516             --  Processing for i switch
517
518             when 'i' =>
519                if Ptr = Max then
520                   Bad_Switch ("-gnati");
521                end if;
522
523                Ptr := Ptr + 1;
524                C := Switch_Chars (Ptr);
525
526                if C in '1' .. '5'
527                  or else C = '8'
528                  or else C = '9'
529                  or else C = 'p'
530                  or else C = 'f'
531                  or else C = 'n'
532                  or else C = 'w'
533                then
534                   Identifier_Character_Set := C;
535                   Ptr := Ptr + 1;
536
537                else
538                   Bad_Switch ("-gnati" & Switch_Chars (Ptr .. Max));
539                end if;
540
541             --  Processing for I switch
542
543             when 'I' =>
544                Ptr := Ptr + 1;
545                Ignore_Rep_Clauses := True;
546
547             --  Processing for j switch
548
549             when 'j' =>
550                Ptr := Ptr + 1;
551
552                --  There may be an equal sign between -gnatj and the value
553
554                if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
555                   Ptr := Ptr + 1;
556                end if;
557
558                Scan_Nat (Switch_Chars, Max, Ptr, Error_Msg_Line_Length, C);
559
560             --  Processing for k switch
561
562             when 'k' =>
563                Ptr := Ptr + 1;
564                   Scan_Pos
565                     (Switch_Chars, Max, Ptr, Maximum_File_Name_Length, C);
566
567             --  Processing for l switch
568
569             when 'l' =>
570                Ptr := Ptr + 1;
571                Full_List := True;
572
573                --  There may be an equal sign between -gnatl and a file name
574
575                if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
576                   if Ptr = Max then
577                      Osint.Fail ("file name for -gnatl= is null");
578                   else
579                      Opt.Full_List_File_Name :=
580                        new String'(Switch_Chars (Ptr + 1 .. Max));
581                      Ptr := Max + 1;
582                   end if;
583                end if;
584
585             --  Processing for L switch
586
587             when 'L' =>
588                Ptr := Ptr + 1;
589                Dump_Source_Text := True;
590
591             --  Processing for m switch
592
593             when 'm' =>
594                Ptr := Ptr + 1;
595
596                --  There may be an equal sign between -gnatm and the value
597
598                if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
599                   Ptr := Ptr + 1;
600                end if;
601
602                Scan_Nat (Switch_Chars, Max, Ptr, Maximum_Errors, C);
603
604             --  Processing for n switch
605
606             when 'n' =>
607                Ptr := Ptr + 1;
608                Inline_Active := True;
609
610             --  Processing for N switch
611
612             when 'N' =>
613                Ptr := Ptr + 1;
614                Inline_Active := True;
615                Front_End_Inlining := True;
616
617             --  Processing for o switch
618
619             when 'o' =>
620                Ptr := Ptr + 1;
621                Suppress_Options (Overflow_Check) := False;
622                Opt.Enable_Overflow_Checks := True;
623
624             --  Processing for O switch
625
626             when 'O' =>
627                Store_Switch := False;
628                Ptr := Ptr + 1;
629                Output_File_Name_Present := True;
630
631             --  Processing for p switch
632
633             when 'p' =>
634                Ptr := Ptr + 1;
635
636                --  Set all specific options as well as All_Checks in the
637                --  Suppress_Options array, excluding Elaboration_Check, since
638                --  this is treated specially because we do not want -gnatp to
639                --  disable static elaboration processing.
640
641                for J in Suppress_Options'Range loop
642                   if J /= Elaboration_Check then
643                      Suppress_Options (J) := True;
644                   end if;
645                end loop;
646
647                Validity_Checks_On         := False;
648                Opt.Suppress_Checks        := True;
649                Opt.Enable_Overflow_Checks := False;
650
651             --  Processing for P switch
652
653             when 'P' =>
654                Ptr := Ptr + 1;
655                Polling_Required := True;
656
657             --  Processing for q switch
658
659             when 'q' =>
660                Ptr := Ptr + 1;
661                Try_Semantics := True;
662
663             --  Processing for q switch
664
665             when 'Q' =>
666                Ptr := Ptr + 1;
667                Force_ALI_Tree_File := True;
668                Try_Semantics := True;
669
670             --  Processing for R switch
671
672             when 'R' =>
673                Back_Annotate_Rep_Info := True;
674                List_Representation_Info := 1;
675
676                Ptr := Ptr + 1;
677                while Ptr <= Max loop
678                   C := Switch_Chars (Ptr);
679
680                   if C in '1' .. '3' then
681                      List_Representation_Info :=
682                        Character'Pos (C) - Character'Pos ('0');
683
684                   elsif Switch_Chars (Ptr) = 's' then
685                      List_Representation_Info_To_File := True;
686
687                   elsif Switch_Chars (Ptr) = 'm' then
688                      List_Representation_Info_Mechanisms := True;
689
690                   else
691                      Bad_Switch ("-gnatR" & Switch_Chars (Ptr .. Max));
692                   end if;
693
694                   Ptr := Ptr + 1;
695                end loop;
696
697             --  Processing for s switch
698
699             when 's' =>
700                if not First_Switch then
701                   Osint.Fail
702                     ("-gnats must be first if combined with other switches");
703                end if;
704
705                Ptr := Ptr + 1;
706                Operating_Mode := Check_Syntax;
707
708             --  Processing for S switch
709
710             when 'S' =>
711                Print_Standard := True;
712                Ptr := Ptr + 1;
713
714             --  Processing for t switch
715
716             when 't' =>
717                Ptr := Ptr + 1;
718                Tree_Output := True;
719
720                if Operating_Mode = Check_Semantics then
721                   ASIS_Mode := True;
722                end if;
723
724                Back_Annotate_Rep_Info := True;
725
726             --  Processing for T switch
727
728             when 'T' =>
729                Ptr := Ptr + 1;
730                Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor, C);
731
732             --  Processing for u switch
733
734             when 'u' =>
735                Ptr := Ptr + 1;
736                List_Units := True;
737
738             --  Processing for U switch
739
740             when 'U' =>
741                Ptr := Ptr + 1;
742                Unique_Error_Tag := True;
743
744             --  Processing for v switch
745
746             when 'v' =>
747                Ptr := Ptr + 1;
748                Verbose_Mode := True;
749
750             --  Processing for V switch
751
752             when 'V' =>
753                Store_Switch := False;
754                Ptr := Ptr + 1;
755
756                if Ptr > Max then
757                   Bad_Switch ("-gnatV");
758
759                else
760                   declare
761                      OK  : Boolean;
762
763                   begin
764                      Set_Validity_Check_Options
765                        (Switch_Chars (Ptr .. Max), OK, Ptr);
766
767                      if not OK then
768                         Bad_Switch ("-gnatV" & Switch_Chars (Ptr .. Max));
769                      end if;
770
771                      for Index in First_Char + 1 .. Max loop
772                         Store_Compilation_Switch
773                           ("-gnatV" & Switch_Chars (Index));
774                      end loop;
775                   end;
776                end if;
777
778                Ptr := Max + 1;
779
780             --  Processing for w switch
781
782             when 'w' =>
783                Store_Switch := False;
784                Ptr := Ptr + 1;
785
786                if Ptr > Max then
787                   Bad_Switch ("-gnatw");
788                end if;
789
790                while Ptr <= Max loop
791                   C := Switch_Chars (Ptr);
792
793                   --  Case of dot switch
794
795                   if C = '.' and then Ptr < Max then
796                      Ptr := Ptr + 1;
797                      C := Switch_Chars (Ptr);
798
799                      if Set_Dot_Warning_Switch (C) then
800                         Store_Compilation_Switch ("-gnatw." & C);
801                      else
802                         Bad_Switch ("-gnatw." & Switch_Chars (Ptr .. Max));
803                      end if;
804
805                      --  Normal case, no dot
806
807                   else
808                      if Set_Warning_Switch (C) then
809                         Store_Compilation_Switch ("-gnatw" & C);
810                      else
811                         Bad_Switch ("-gnatw" & Switch_Chars (Ptr .. Max));
812                      end if;
813                   end if;
814
815                   Ptr := Ptr + 1;
816                end loop;
817
818                return;
819
820             --  Processing for W switch
821
822             when 'W' =>
823                Ptr := Ptr + 1;
824
825                if Ptr > Max then
826                   Bad_Switch ("-gnatW");
827                end if;
828
829                begin
830                   Wide_Character_Encoding_Method :=
831                     Get_WC_Encoding_Method (Switch_Chars (Ptr));
832                exception
833                   when Constraint_Error =>
834                      Bad_Switch ("-gnatW" & Switch_Chars (Ptr .. Max));
835                end;
836
837                Upper_Half_Encoding :=
838                  Wide_Character_Encoding_Method in
839                  WC_Upper_Half_Encoding_Method;
840
841                Ptr := Ptr + 1;
842
843             --  Processing for x switch
844
845             when 'x' =>
846                Ptr := Ptr + 1;
847                Xref_Active := False;
848
849             --  Processing for X switch
850
851             when 'X' =>
852                Ptr := Ptr + 1;
853                Extensions_Allowed := True;
854
855             --  Processing for y switch
856
857             when 'y' =>
858                Ptr := Ptr + 1;
859
860                if Ptr > Max then
861                   Set_Default_Style_Check_Options;
862
863                else
864                   Store_Switch := False;
865
866                   declare
867                      OK  : Boolean;
868
869                   begin
870                      Set_Style_Check_Options
871                        (Switch_Chars (Ptr .. Max), OK, Ptr);
872
873                      if not OK then
874                         Osint.Fail
875                           ("bad -gnaty switch (" &
876                            Style_Msg_Buf (1 .. Style_Msg_Len) & ')');
877                      end if;
878
879                      Ptr := First_Char + 1;
880                      while Ptr <= Max loop
881                         if Switch_Chars (Ptr) = 'M' then
882                            First_Char := Ptr;
883                            loop
884                               Ptr := Ptr + 1;
885                               exit when Ptr > Max
886                                 or else Switch_Chars (Ptr) not in '0' .. '9';
887                            end loop;
888
889                            Store_Compilation_Switch
890                              ("-gnaty" & Switch_Chars (First_Char .. Ptr - 1));
891
892                         else
893                            Store_Compilation_Switch
894                              ("-gnaty" & Switch_Chars (Ptr));
895                            Ptr := Ptr + 1;
896                         end if;
897                      end loop;
898                   end;
899                end if;
900
901             --  Processing for z switch
902
903             when 'z' =>
904                Ptr := Ptr + 1;
905
906                --  Allowed for compiler only if this is the only
907                --  -z switch, we do not allow multiple occurrences
908
909                if Distribution_Stub_Mode = No_Stubs then
910                   case Switch_Chars (Ptr) is
911                      when 'r' =>
912                         Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
913
914                      when 'c' =>
915                         Distribution_Stub_Mode := Generate_Caller_Stub_Body;
916
917                      when others =>
918                         Bad_Switch ("-gnatz" & Switch_Chars (Ptr .. Max));
919                   end case;
920
921                   Ptr := Ptr + 1;
922                end if;
923
924             --  Processing for Z switch
925
926             when 'Z' =>
927                Ptr := Ptr + 1;
928                Osint.Fail
929                  ("-gnatZ is no longer supported: consider using --RTS=zcx");
930
931             --  Processing for 83 switch
932
933             when '8' =>
934                if Ptr = Max then
935                   Bad_Switch ("-gnat8");
936                end if;
937
938                Ptr := Ptr + 1;
939
940                if Switch_Chars (Ptr) /= '3' then
941                   Bad_Switch ("-gnat8" & Switch_Chars (Ptr .. Max));
942                else
943                   Ptr := Ptr + 1;
944                   Ada_Version := Ada_83;
945                   Ada_Version_Explicit := Ada_Version;
946                end if;
947
948             --  Processing for 95 switch
949
950             when '9' =>
951                if Ptr = Max then
952                   Bad_Switch ("-gnat9");
953                end if;
954
955                Ptr := Ptr + 1;
956
957                if Switch_Chars (Ptr) /= '5' then
958                   Bad_Switch ("-gnat9" & Switch_Chars (Ptr .. Max));
959                else
960                   Ptr := Ptr + 1;
961                   Ada_Version := Ada_95;
962                   Ada_Version_Explicit := Ada_Version;
963                end if;
964
965             --  Processing for 05 switch
966
967             when '0' =>
968                if Ptr = Max then
969                   Bad_Switch ("-gnat0");
970                end if;
971
972                Ptr := Ptr + 1;
973
974                if Switch_Chars (Ptr) /= '5' then
975                   Bad_Switch ("-gnat0" & Switch_Chars (Ptr .. Max));
976                else
977                   Ptr := Ptr + 1;
978                   Ada_Version := Ada_05;
979                   Ada_Version_Explicit := Ada_Version;
980                end if;
981
982             --  Ignore extra switch character
983
984             when '/' | '-' =>
985                Ptr := Ptr + 1;
986
987             --  Anything else is an error (illegal switch character)
988
989             when others =>
990                Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
991             end case;
992
993             if Store_Switch then
994                Store_Compilation_Switch
995                  ("-gnat" & Switch_Chars (First_Char .. Ptr - 1));
996             end if;
997
998             First_Switch := False;
999          end loop;
1000       end if;
1001    end Scan_Front_End_Switches;
1002
1003 end Switch.C;