OSDN Git Service

* gcc-interface/decl.c (gnat_to_gnu_entity) <E_Array_Type>: Factor out
[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-2009, 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             --  Processing for C switch
232
233             when 'C' =>
234                Ptr := Ptr + 1;
235                CodePeer_Mode := True;
236
237             --  Processing for d switch
238
239             when 'd' =>
240                Store_Switch := False;
241                Dot := False;
242
243                --  Note: for the debug switch, the remaining characters in this
244                --  switch field must all be debug flags, since all valid switch
245                --  characters are also valid debug characters.
246
247                --  Loop to scan out debug flags
248
249                while Ptr < Max loop
250                   Ptr := Ptr + 1;
251                   C := Switch_Chars (Ptr);
252                   exit when C = ASCII.NUL or else C = '/' or else C = '-';
253
254                   if C in '1' .. '9' or else
255                      C in 'a' .. 'z' or else
256                      C in 'A' .. 'Z'
257                   then
258                      if Dot then
259                         Set_Dotted_Debug_Flag (C);
260                         Store_Compilation_Switch ("-gnatd." & C);
261                      else
262                         Set_Debug_Flag (C);
263                         Store_Compilation_Switch ("-gnatd" & C);
264                      end if;
265
266                   elsif C = '.' then
267                      Dot := True;
268
269                   elsif Dot then
270                      Bad_Switch ("-gnatd." & Switch_Chars (Ptr .. Max));
271                   else
272                      Bad_Switch ("-gnatd" & Switch_Chars (Ptr .. Max));
273                   end if;
274                end loop;
275
276                return;
277
278             --  Processing for D switch
279
280             when 'D' =>
281                Ptr := Ptr + 1;
282
283                --  Scan optional integer line limit value
284
285                if Nat_Present (Switch_Chars, Max, Ptr) then
286                   Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'D');
287                   Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
288                end if;
289
290                --  Note: -gnatD also sets -gnatx (to turn off cross-reference
291                --  generation in the ali file) since otherwise this generation
292                --  gets confused by the "wrong" Sloc values put in the tree.
293
294                Debug_Generated_Code := True;
295                Xref_Active := False;
296                Set_Debug_Flag ('g');
297
298             --  -gnate? (extended switches)
299
300             when 'e' =>
301                Ptr := Ptr + 1;
302
303                --  The -gnate? switches are all double character switches
304                --  so we must always have a character after the e.
305
306                if Ptr > Max then
307                   Bad_Switch ("-gnate");
308                end if;
309
310                case Switch_Chars (Ptr) is
311
312                   --  -gnatea (initial delimiter of explicit switches)
313
314                   --  All switches that come before -gnatea have been added by
315                   --  the GCC driver and are not stored in the ALI file.
316                   --  See also -gnatez below.
317
318                   when 'a' =>
319                      Store_Switch := False;
320                      Enable_Switch_Storing;
321                      Ptr := Ptr + 1;
322
323                   --  -gnatec (configuration pragmas)
324
325                   when 'c' =>
326                      Store_Switch := False;
327                      Ptr := Ptr + 1;
328
329                      --  There may be an equal sign between -gnatec and
330                      --  the path name of the config file.
331
332                      if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
333                         Ptr := Ptr + 1;
334                      end if;
335
336                      if Ptr > Max then
337                         Bad_Switch ("-gnatec");
338                      end if;
339
340                      declare
341                         Config_File_Name : constant String_Access :=
342                                              new String'
343                                                   (Switch_Chars (Ptr .. Max));
344
345                      begin
346                         if Config_File_Names = null then
347                            Config_File_Names :=
348                              new String_List'(1 => Config_File_Name);
349
350                         else
351                            declare
352                               New_Names : constant String_List_Access :=
353                                             new String_List
354                                               (1 ..
355                                                Config_File_Names'Length + 1);
356
357                            begin
358                               for Index in Config_File_Names'Range loop
359                                  New_Names (Index) :=
360                                    Config_File_Names (Index);
361                                  Config_File_Names (Index) := null;
362                               end loop;
363
364                               New_Names (New_Names'Last) := Config_File_Name;
365                               Free (Config_File_Names);
366                               Config_File_Names := New_Names;
367                            end;
368                         end if;
369                      end;
370
371                      return;
372
373                   --  -gnateC switch (CodePeer SCIL generation)
374
375                   --  Not enabled for now, keep it for later???
376                   --  use -gnatd.I only for now
377
378                   --  when 'C' =>
379                   --     Ptr := Ptr + 1;
380                   --     Generate_SCIL := True;
381
382                   --  -gnateD switch (preprocessing symbol definition)
383
384                   when 'D' =>
385                      Store_Switch := False;
386                      Ptr := Ptr + 1;
387
388                      if Ptr > Max then
389                         Bad_Switch ("-gnateD");
390                      end if;
391
392                      Add_Symbol_Definition (Switch_Chars (Ptr .. Max));
393
394                      --  Store the switch
395
396                      Store_Compilation_Switch
397                        ("-gnateD" & Switch_Chars (Ptr .. Max));
398                      Ptr := Max + 1;
399
400                   --  -gnatef (full source path for brief error messages)
401
402                   when 'f' =>
403                      Store_Switch := False;
404                      Ptr := Ptr + 1;
405                      Full_Path_Name_For_Brief_Errors := True;
406                      return;
407
408                   --  -gnateG (save preprocessor output)
409
410                   when 'G' =>
411                      if Ptr < Max then
412                         Bad_Switch (Switch_Chars);
413                      end if;
414
415                      Generate_Processed_File := True;
416                      Ptr := Ptr + 1;
417
418                   --  -gnateI (index of unit in multi-unit source)
419
420                   when 'I' =>
421                      Ptr := Ptr + 1;
422                      Scan_Pos (Switch_Chars, Max, Ptr, Multiple_Unit_Index, C);
423
424                   --  -gnatem (mapping file)
425
426                   when 'm' =>
427                      Store_Switch := False;
428                      Ptr := Ptr + 1;
429
430                      --  There may be an equal sign between -gnatem and
431                      --  the path name of the mapping file.
432
433                      if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
434                         Ptr := Ptr + 1;
435                      end if;
436
437                      if Ptr > Max then
438                         Bad_Switch ("-gnatem");
439                      end if;
440
441                      Mapping_File_Name :=
442                        new String'(Switch_Chars (Ptr .. Max));
443                      return;
444
445                   --  -gnatep (preprocessing data file)
446
447                   when 'p' =>
448                      Store_Switch := False;
449                      Ptr := Ptr + 1;
450
451                      --  There may be an equal sign between -gnatep and
452                      --  the path name of the mapping file.
453
454                      if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
455                         Ptr := Ptr + 1;
456                      end if;
457
458                      if Ptr > Max then
459                         Bad_Switch ("-gnatep");
460                      end if;
461
462                      Preprocessing_Data_File :=
463                        new String'(Switch_Chars (Ptr .. Max));
464
465                      --  Store the switch, normalizing to -gnatep=
466
467                      Store_Compilation_Switch
468                        ("-gnatep=" & Preprocessing_Data_File.all);
469
470                      Ptr := Max + 1;
471
472                   --  -gnatez (final delimiter of explicit switches)
473
474                   --  All switches that come after -gnatez have been added by
475                   --  the GCC driver and are not stored in the ALI file. See
476                   --  also -gnatea above.
477
478                   when 'z' =>
479                      Store_Switch := False;
480                      Disable_Switch_Storing;
481                      Ptr := Ptr + 1;
482
483                   --  -gnateS (generate SCO information)
484
485                   --  Include Source Coverage Obligation information in ALI
486                   --  files for the benefit of source coverage analysis tools
487                   --  (xcov).
488
489                   when 'S' =>
490                      Generate_SCO := True;
491                      Ptr := Ptr + 1;
492
493                   --  All other -gnate? switches are unassigned
494
495                   when others =>
496                      Bad_Switch ("-gnate" & Switch_Chars (Ptr .. Max));
497                end case;
498
499             --  -gnatE (dynamic elaboration checks)
500
501             when 'E' =>
502                Ptr := Ptr + 1;
503                Dynamic_Elaboration_Checks := True;
504
505             --  -gnatf (full error messages)
506
507             when 'f' =>
508                Ptr := Ptr + 1;
509                All_Errors_Mode := True;
510
511             --  Processing for F switch
512
513             when 'F' =>
514                Ptr := Ptr + 1;
515                External_Name_Exp_Casing := Uppercase;
516                External_Name_Imp_Casing := Uppercase;
517
518             --  Processing for g switch
519
520             when 'g' =>
521                Ptr := Ptr + 1;
522                GNAT_Mode := True;
523                Identifier_Character_Set := 'n';
524                System_Extend_Unit := Empty;
525                Warning_Mode := Treat_As_Error;
526
527                --  Set Ada 2005 mode explicitly. We don't want to rely on the
528                --  implicit setting here, since for example, we want
529                --  Preelaborate_05 treated as Preelaborate
530
531                Ada_Version := Ada_05;
532                Ada_Version_Explicit := Ada_Version;
533
534                --  Set default warnings and style checks for -gnatg
535
536                Set_GNAT_Mode_Warnings;
537                Set_GNAT_Style_Check_Options;
538
539             --  Processing for G switch
540
541             when 'G' =>
542                Ptr := Ptr + 1;
543                Print_Generated_Code := True;
544
545                --  Scan optional integer line limit value
546
547                if Nat_Present (Switch_Chars, Max, Ptr) then
548                   Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'G');
549                   Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
550                end if;
551
552             --  Processing for h switch
553
554             when 'h' =>
555                Ptr := Ptr + 1;
556                Usage_Requested := True;
557
558             --  Processing for H switch
559
560             when 'H' =>
561                Ptr := Ptr + 1;
562                HLO_Active := True;
563
564             --  Processing for i switch
565
566             when 'i' =>
567                if Ptr = Max then
568                   Bad_Switch ("-gnati");
569                end if;
570
571                Ptr := Ptr + 1;
572                C := Switch_Chars (Ptr);
573
574                if C in '1' .. '5'
575                  or else C = '8'
576                  or else C = '9'
577                  or else C = 'p'
578                  or else C = 'f'
579                  or else C = 'n'
580                  or else C = 'w'
581                then
582                   Identifier_Character_Set := C;
583                   Ptr := Ptr + 1;
584
585                else
586                   Bad_Switch ("-gnati" & Switch_Chars (Ptr .. Max));
587                end if;
588
589             --  Processing for I switch
590
591             when 'I' =>
592                Ptr := Ptr + 1;
593                Ignore_Rep_Clauses := True;
594
595             --  Processing for j switch
596
597             when 'j' =>
598                Ptr := Ptr + 1;
599                Scan_Nat (Switch_Chars, Max, Ptr, Error_Msg_Line_Length, C);
600
601             --  Processing for k switch
602
603             when 'k' =>
604                Ptr := Ptr + 1;
605                   Scan_Pos
606                     (Switch_Chars, Max, Ptr, Maximum_File_Name_Length, C);
607
608             --  Processing for l switch
609
610             when 'l' =>
611                Ptr := Ptr + 1;
612                Full_List := True;
613
614                --  There may be an equal sign between -gnatl and a file name
615
616                if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
617                   if Ptr = Max then
618                      Osint.Fail ("file name for -gnatl= is null");
619                   else
620                      Opt.Full_List_File_Name :=
621                        new String'(Switch_Chars (Ptr + 1 .. Max));
622                      Ptr := Max + 1;
623                   end if;
624                end if;
625
626             --  Processing for L switch
627
628             when 'L' =>
629                Ptr := Ptr + 1;
630                Dump_Source_Text := True;
631
632             --  Processing for m switch
633
634             when 'm' =>
635                Ptr := Ptr + 1;
636                Scan_Nat (Switch_Chars, Max, Ptr, Maximum_Messages, 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                Back_Annotate_Rep_Info := True;
760
761             --  Processing for T switch
762
763             when 'T' =>
764                Ptr := Ptr + 1;
765                Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor, C);
766
767             --  Processing for u switch
768
769             when 'u' =>
770                Ptr := Ptr + 1;
771                List_Units := True;
772
773             --  Processing for U switch
774
775             when 'U' =>
776                Ptr := Ptr + 1;
777                Unique_Error_Tag := True;
778
779             --  Processing for v switch
780
781             when 'v' =>
782                Ptr := Ptr + 1;
783                Verbose_Mode := True;
784
785             --  Processing for V switch
786
787             when 'V' =>
788                Store_Switch := False;
789                Ptr := Ptr + 1;
790
791                if Ptr > Max then
792                   Bad_Switch ("-gnatV");
793
794                else
795                   declare
796                      OK  : Boolean;
797
798                   begin
799                      Set_Validity_Check_Options
800                        (Switch_Chars (Ptr .. Max), OK, Ptr);
801
802                      if not OK then
803                         Bad_Switch ("-gnatV" & Switch_Chars (Ptr .. Max));
804                      end if;
805
806                      for Index in First_Char + 1 .. Max loop
807                         Store_Compilation_Switch
808                           ("-gnatV" & Switch_Chars (Index));
809                      end loop;
810                   end;
811                end if;
812
813                Ptr := Max + 1;
814
815             --  Processing for w switch
816
817             when 'w' =>
818                Store_Switch := False;
819                Ptr := Ptr + 1;
820
821                if Ptr > Max then
822                   Bad_Switch ("-gnatw");
823                end if;
824
825                while Ptr <= Max loop
826                   C := Switch_Chars (Ptr);
827
828                   --  Case of dot switch
829
830                   if C = '.' and then Ptr < Max then
831                      Ptr := Ptr + 1;
832                      C := Switch_Chars (Ptr);
833
834                      if Set_Dot_Warning_Switch (C) then
835                         Store_Compilation_Switch ("-gnatw." & C);
836                      else
837                         Bad_Switch ("-gnatw." & Switch_Chars (Ptr .. Max));
838                      end if;
839
840                      --  Normal case, no dot
841
842                   else
843                      if Set_Warning_Switch (C) then
844                         Store_Compilation_Switch ("-gnatw" & C);
845                      else
846                         Bad_Switch ("-gnatw" & Switch_Chars (Ptr .. Max));
847                      end if;
848                   end if;
849
850                   Ptr := Ptr + 1;
851                end loop;
852
853                return;
854
855             --  Processing for W switch
856
857             when 'W' =>
858                Ptr := Ptr + 1;
859
860                if Ptr > Max then
861                   Bad_Switch ("-gnatW");
862                end if;
863
864                begin
865                   Wide_Character_Encoding_Method :=
866                     Get_WC_Encoding_Method (Switch_Chars (Ptr));
867                exception
868                   when Constraint_Error =>
869                      Bad_Switch ("-gnatW" & Switch_Chars (Ptr .. Max));
870                end;
871
872                Wide_Character_Encoding_Method_Specified := True;
873
874                Upper_Half_Encoding :=
875                  Wide_Character_Encoding_Method in
876                    WC_Upper_Half_Encoding_Method;
877
878                Ptr := Ptr + 1;
879
880             --  Processing for x switch
881
882             when 'x' =>
883                Ptr := Ptr + 1;
884                Xref_Active := False;
885
886             --  Processing for X switch
887
888             when 'X' =>
889                Ptr := Ptr + 1;
890                Extensions_Allowed := True;
891
892             --  Processing for y switch
893
894             when 'y' =>
895                Ptr := Ptr + 1;
896
897                if Ptr > Max then
898                   Set_Default_Style_Check_Options;
899
900                else
901                   Store_Switch := False;
902
903                   declare
904                      OK  : Boolean;
905
906                   begin
907                      Set_Style_Check_Options
908                        (Switch_Chars (Ptr .. Max), OK, Ptr);
909
910                      if not OK then
911                         Osint.Fail
912                           ("bad -gnaty switch (" &
913                            Style_Msg_Buf (1 .. Style_Msg_Len) & ')');
914                      end if;
915
916                      Ptr := First_Char + 1;
917                      while Ptr <= Max loop
918                         if Switch_Chars (Ptr) = 'M' then
919                            First_Char := Ptr;
920                            loop
921                               Ptr := Ptr + 1;
922                               exit when Ptr > Max
923                                 or else Switch_Chars (Ptr) not in '0' .. '9';
924                            end loop;
925
926                            Store_Compilation_Switch
927                              ("-gnaty" & Switch_Chars (First_Char .. Ptr - 1));
928
929                         else
930                            Store_Compilation_Switch
931                              ("-gnaty" & Switch_Chars (Ptr));
932                            Ptr := Ptr + 1;
933                         end if;
934                      end loop;
935                   end;
936                end if;
937
938             --  Processing for z switch
939
940             when 'z' =>
941                Ptr := Ptr + 1;
942
943                --  Allowed for compiler only if this is the only
944                --  -z switch, we do not allow multiple occurrences
945
946                if Distribution_Stub_Mode = No_Stubs then
947                   case Switch_Chars (Ptr) is
948                      when 'r' =>
949                         Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
950
951                      when 'c' =>
952                         Distribution_Stub_Mode := Generate_Caller_Stub_Body;
953
954                      when others =>
955                         Bad_Switch ("-gnatz" & Switch_Chars (Ptr .. Max));
956                   end case;
957
958                   Ptr := Ptr + 1;
959                end if;
960
961             --  Processing for Z switch
962
963             when 'Z' =>
964                Ptr := Ptr + 1;
965                Osint.Fail
966                  ("-gnatZ is no longer supported: consider using --RTS=zcx");
967
968             --  Processing for 83 switch
969
970             when '8' =>
971                if Ptr = Max then
972                   Bad_Switch ("-gnat8");
973                end if;
974
975                Ptr := Ptr + 1;
976
977                if Switch_Chars (Ptr) /= '3' then
978                   Bad_Switch ("-gnat8" & Switch_Chars (Ptr .. Max));
979                else
980                   Ptr := Ptr + 1;
981                   Ada_Version := Ada_83;
982                   Ada_Version_Explicit := Ada_Version;
983                end if;
984
985             --  Processing for 95 switch
986
987             when '9' =>
988                if Ptr = Max then
989                   Bad_Switch ("-gnat9");
990                end if;
991
992                Ptr := Ptr + 1;
993
994                if Switch_Chars (Ptr) /= '5' then
995                   Bad_Switch ("-gnat9" & Switch_Chars (Ptr .. Max));
996                else
997                   Ptr := Ptr + 1;
998                   Ada_Version := Ada_95;
999                   Ada_Version_Explicit := Ada_Version;
1000                end if;
1001
1002             --  Processing for 05 switch
1003
1004             when '0' =>
1005                if Ptr = Max then
1006                   Bad_Switch ("-gnat0");
1007                end if;
1008
1009                Ptr := Ptr + 1;
1010
1011                if Switch_Chars (Ptr) /= '5' then
1012                   Bad_Switch ("-gnat0" & Switch_Chars (Ptr .. Max));
1013                else
1014                   Ptr := Ptr + 1;
1015                   Ada_Version := Ada_05;
1016                   Ada_Version_Explicit := Ada_Version;
1017                end if;
1018
1019             --  Ignore extra switch character
1020
1021             when '/' | '-' =>
1022                Ptr := Ptr + 1;
1023
1024             --  Anything else is an error (illegal switch character)
1025
1026             when others =>
1027                Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
1028             end case;
1029
1030             if Store_Switch then
1031                Store_Compilation_Switch
1032                  ("-gnat" & Switch_Chars (First_Char .. Ptr - 1));
1033             end if;
1034
1035             First_Switch := False;
1036          end loop;
1037       end if;
1038    end Scan_Front_End_Switches;
1039
1040 end Switch.C;