OSDN Git Service

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