OSDN Git Service

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