[multiple changes]
[gcc.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-2011, 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 -- This package is for switch processing and should not depend on higher level
27 -- packages such as those for the scanner, parser, etc. Doing so may cause
28 -- circularities, especially for back ends using Adabkend.
29
30 with Debug; use Debug;
31 with Lib; use Lib;
32 with Osint; use Osint;
33 with Opt; use Opt;
34 with Validsw; use Validsw;
35 with Stylesw; use Stylesw;
36 with Warnsw; use Warnsw;
37
38 with Ada.Unchecked_Deallocation;
39 with System.WCh_Con; use System.WCh_Con;
40
41 package body Switch.C is
42
43 RTS_Specified : String_Access := null;
44 -- Used to detect multiple use of --RTS= flag
45
46 procedure Add_Symbol_Definition (Def : String);
47 -- Add a symbol definition from the command line
48
49 procedure Free is
50 new Ada.Unchecked_Deallocation (String_List, String_List_Access);
51 -- Avoid using System.Strings.Free, which also frees the designated strings
52
53 function Switch_Subsequently_Cancelled
54 (C : String;
55 Args : String_List;
56 Arg_Rank : Positive) return Boolean;
57 -- This function is called from Scan_Front_End_Switches. It determines if
58 -- the switch currently being scanned is followed by a switch of the form
59 -- "-gnat-" & C, where C is the argument. If so, then True is returned,
60 -- and Scan_Front_End_Switches will cancel the effect of the switch. If
61 -- no such switch is found, False is returned.
62
63 ---------------------------
64 -- Add_Symbol_Definition --
65 ---------------------------
66
67 procedure Add_Symbol_Definition (Def : String) is
68 begin
69 -- If Preprocessor_Symbol_Defs is not large enough, double its size
70
71 if Preprocessing_Symbol_Last = Preprocessing_Symbol_Defs'Last then
72 declare
73 New_Symbol_Definitions : constant String_List_Access :=
74 new String_List (1 .. 2 * Preprocessing_Symbol_Last);
75
76 begin
77 New_Symbol_Definitions (Preprocessing_Symbol_Defs'Range) :=
78 Preprocessing_Symbol_Defs.all;
79 Free (Preprocessing_Symbol_Defs);
80 Preprocessing_Symbol_Defs := New_Symbol_Definitions;
81 end;
82 end if;
83
84 Preprocessing_Symbol_Last := Preprocessing_Symbol_Last + 1;
85 Preprocessing_Symbol_Defs (Preprocessing_Symbol_Last) :=
86 new String'(Def);
87 end Add_Symbol_Definition;
88
89 -----------------------------
90 -- Scan_Front_End_Switches --
91 -----------------------------
92
93 procedure Scan_Front_End_Switches
94 (Switch_Chars : String;
95 Args : String_List;
96 Arg_Rank : Positive)
97 is
98 First_Switch : Boolean := True;
99 -- False for all but first switch
100
101 Max : constant Natural := Switch_Chars'Last;
102 Ptr : Natural;
103 C : Character := ' ';
104 Dot : Boolean;
105
106 Store_Switch : Boolean;
107 -- For -gnatxx switches, the normal processing, signalled by this flag
108 -- being set to True, is to store the switch on exit from the case
109 -- statement, the switch stored is -gnat followed by the characters
110 -- from First_Char to Ptr-1. For cases like -gnaty, where the switch
111 -- is stored in separate pieces, this flag is set to False, and the
112 -- appropriate calls to Store_Compilation_Switch are made from within
113 -- the case branch.
114
115 First_Char : Positive;
116 -- Marks start of switch to be stored
117
118 begin
119 Ptr := Switch_Chars'First;
120
121 -- Skip past the initial character (must be the switch character)
122
123 if Ptr = Max then
124 Bad_Switch (C);
125 else
126 Ptr := Ptr + 1;
127 end if;
128
129 -- Handle switches that do not start with -gnat
130
131 if Ptr + 3 > Max
132 or else Switch_Chars (Ptr .. Ptr + 3) /= "gnat"
133 then
134 -- There are two front-end switches that do not start with -gnat:
135 -- -I, --RTS
136
137 if Switch_Chars (Ptr) = 'I' then
138
139 -- Set flag Search_Directory_Present if switch is "-I" only:
140 -- the directory will be the next argument.
141
142 if Ptr = Max then
143 Search_Directory_Present := True;
144 return;
145 end if;
146
147 Ptr := Ptr + 1;
148
149 -- Find out whether this is a -I- or regular -Ixxx switch
150
151 -- Note: -I switches are not recorded in the ALI file, since the
152 -- meaning of the program depends on the source files compiled,
153 -- not where they came from.
154
155 if Ptr = Max and then Switch_Chars (Ptr) = '-' then
156 Look_In_Primary_Dir := False;
157 else
158 Add_Src_Search_Dir (Switch_Chars (Ptr .. Max));
159 end if;
160
161 -- Processing of the --RTS switch. --RTS may have been modified by
162 -- gcc into -fRTS (for GCC targets).
163
164 elsif Ptr + 3 <= Max
165 and then (Switch_Chars (Ptr .. Ptr + 3) = "fRTS"
166 or else
167 Switch_Chars (Ptr .. Ptr + 3) = "-RTS")
168 then
169 Ptr := Ptr + 1;
170
171 if Ptr + 4 > Max
172 or else Switch_Chars (Ptr + 3) /= '='
173 then
174 Osint.Fail ("missing path for --RTS");
175 else
176 -- Check that this is the first time --RTS is specified or if
177 -- it is not the first time, the same path has been specified.
178
179 if RTS_Specified = null then
180 RTS_Specified := new String'(Switch_Chars (Ptr + 4 .. Max));
181
182 elsif
183 RTS_Specified.all /= Switch_Chars (Ptr + 4 .. Max)
184 then
185 Osint.Fail ("--RTS cannot be specified multiple times");
186 end if;
187
188 -- Valid --RTS switch
189
190 Opt.No_Stdinc := True;
191 Opt.RTS_Switch := True;
192
193 RTS_Src_Path_Name :=
194 Get_RTS_Search_Dir
195 (Switch_Chars (Ptr + 4 .. Max), Include);
196
197 RTS_Lib_Path_Name :=
198 Get_RTS_Search_Dir
199 (Switch_Chars (Ptr + 4 .. Max), Objects);
200
201 if RTS_Src_Path_Name /= null
202 and then RTS_Lib_Path_Name /= null
203 then
204 -- Store the -fRTS switch (Note: Store_Compilation_Switch
205 -- changes -fRTS back into --RTS for the actual output).
206
207 Store_Compilation_Switch (Switch_Chars);
208
209 elsif RTS_Src_Path_Name = null
210 and then RTS_Lib_Path_Name = null
211 then
212 Osint.Fail ("RTS path not valid: missing " &
213 "adainclude and adalib directories");
214
215 elsif RTS_Src_Path_Name = null then
216 Osint.Fail ("RTS path not valid: missing " &
217 "adainclude directory");
218
219 elsif RTS_Lib_Path_Name = null then
220 Osint.Fail ("RTS path not valid: missing " &
221 "adalib directory");
222 end if;
223 end if;
224
225 -- There are no other switches not starting with -gnat
226
227 else
228 Bad_Switch (Switch_Chars);
229 end if;
230
231 -- Case of switch starting with -gnat
232
233 else
234 Ptr := Ptr + 4;
235
236 -- Loop to scan through switches given in switch string
237
238 while Ptr <= Max loop
239 First_Char := Ptr;
240 Store_Switch := True;
241
242 C := Switch_Chars (Ptr);
243
244 case C is
245
246 when 'a' =>
247 Ptr := Ptr + 1;
248 Assertions_Enabled := True;
249 Debug_Pragmas_Enabled := True;
250
251 -- Processing for A switch
252
253 when 'A' =>
254 Ptr := Ptr + 1;
255 Config_File := False;
256
257 -- Processing for b switch
258
259 when 'b' =>
260 Ptr := Ptr + 1;
261 Brief_Output := True;
262
263 -- Processing for B switch
264
265 when 'B' =>
266 Ptr := Ptr + 1;
267 Assume_No_Invalid_Values := True;
268
269 -- Processing for c switch
270
271 when 'c' =>
272 if not First_Switch then
273 Osint.Fail
274 ("-gnatc must be first if combined with other switches");
275 end if;
276
277 Ptr := Ptr + 1;
278 Operating_Mode := Check_Semantics;
279
280 -- Processing for C switch
281
282 when 'C' =>
283 Ptr := Ptr + 1;
284
285 if not CodePeer_Mode then
286 CodePeer_Mode := True;
287
288 -- Suppress compiler warnings by default, since what we are
289 -- interested in here is what CodePeer can find out. Note
290 -- that if -gnatwxxx is specified after -gnatC on the
291 -- command line, we do not want to override this setting in
292 -- Adjust_Global_Switches, and assume that the user wants to
293 -- get both warnings from GNAT and CodePeer messages.
294
295 Warning_Mode := Suppress;
296 end if;
297
298 -- Processing for d switch
299
300 when 'd' =>
301 Store_Switch := False;
302 Dot := False;
303
304 -- Note: for the debug switch, the remaining characters in this
305 -- switch field must all be debug flags, since all valid switch
306 -- characters are also valid debug characters.
307
308 -- Loop to scan out debug flags
309
310 while Ptr < Max loop
311 Ptr := Ptr + 1;
312 C := Switch_Chars (Ptr);
313 exit when C = ASCII.NUL or else C = '/' or else C = '-';
314
315 if C in '1' .. '9' or else
316 C in 'a' .. 'z' or else
317 C in 'A' .. 'Z'
318 then
319 if Dot then
320 Set_Dotted_Debug_Flag (C);
321 Store_Compilation_Switch ("-gnatd." & C);
322 else
323 Set_Debug_Flag (C);
324 Store_Compilation_Switch ("-gnatd" & C);
325 end if;
326
327 elsif C = '.' then
328 Dot := True;
329
330 elsif Dot then
331 Bad_Switch ("-gnatd." & Switch_Chars (Ptr .. Max));
332 else
333 Bad_Switch ("-gnatd" & Switch_Chars (Ptr .. Max));
334 end if;
335 end loop;
336
337 return;
338
339 -- Processing for D switch
340
341 when 'D' =>
342 Ptr := Ptr + 1;
343
344 -- Scan optional integer line limit value
345
346 if Nat_Present (Switch_Chars, Max, Ptr) then
347 Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'D');
348 Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
349 end if;
350
351 -- Note: -gnatD also sets -gnatx (to turn off cross-reference
352 -- generation in the ali file) since otherwise this generation
353 -- gets confused by the "wrong" Sloc values put in the tree.
354
355 Debug_Generated_Code := True;
356 Xref_Active := False;
357 Set_Debug_Flag ('g');
358
359 -- -gnate? (extended switches)
360
361 when 'e' =>
362 Ptr := Ptr + 1;
363
364 -- The -gnate? switches are all double character switches
365 -- so we must always have a character after the e.
366
367 if Ptr > Max then
368 Bad_Switch ("-gnate");
369 end if;
370
371 case Switch_Chars (Ptr) is
372
373 -- -gnatea (initial delimiter of explicit switches)
374
375 -- All switches that come before -gnatea have been added by
376 -- the GCC driver and are not stored in the ALI file.
377 -- See also -gnatez below.
378
379 when 'a' =>
380 Store_Switch := False;
381 Enable_Switch_Storing;
382 Ptr := Ptr + 1;
383
384 -- -gnatec (configuration pragmas)
385
386 when 'c' =>
387 Store_Switch := False;
388 Ptr := Ptr + 1;
389
390 -- There may be an equal sign between -gnatec and
391 -- the path name of the config file.
392
393 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
394 Ptr := Ptr + 1;
395 end if;
396
397 if Ptr > Max then
398 Bad_Switch ("-gnatec");
399 end if;
400
401 declare
402 Config_File_Name : constant String_Access :=
403 new String'
404 (Switch_Chars (Ptr .. Max));
405
406 begin
407 if Config_File_Names = null then
408 Config_File_Names :=
409 new String_List'(1 => Config_File_Name);
410
411 else
412 declare
413 New_Names : constant String_List_Access :=
414 new String_List
415 (1 ..
416 Config_File_Names'Length + 1);
417
418 begin
419 for Index in Config_File_Names'Range loop
420 New_Names (Index) :=
421 Config_File_Names (Index);
422 Config_File_Names (Index) := null;
423 end loop;
424
425 New_Names (New_Names'Last) := Config_File_Name;
426 Free (Config_File_Names);
427 Config_File_Names := New_Names;
428 end;
429 end if;
430 end;
431
432 return;
433
434 -- -gnateC switch (CodePeer SCIL generation)
435
436 -- Not enabled for now, keep it for later???
437 -- use -gnatd.I only for now
438
439 -- when 'C' =>
440 -- Ptr := Ptr + 1;
441 -- Generate_SCIL := True;
442
443 -- -gnateD switch (preprocessing symbol definition)
444
445 when 'D' =>
446 Store_Switch := False;
447 Ptr := Ptr + 1;
448
449 if Ptr > Max then
450 Bad_Switch ("-gnateD");
451 end if;
452
453 Add_Symbol_Definition (Switch_Chars (Ptr .. Max));
454
455 -- Store the switch
456
457 Store_Compilation_Switch
458 ("-gnateD" & Switch_Chars (Ptr .. Max));
459 Ptr := Max + 1;
460
461 -- -gnateE (extra exception information)
462
463 when 'E' =>
464 Exception_Extra_Info := True;
465 Ptr := Ptr + 1;
466
467 -- -gnatef (full source path for brief error messages)
468
469 when 'f' =>
470 Store_Switch := False;
471 Ptr := Ptr + 1;
472 Full_Path_Name_For_Brief_Errors := True;
473
474 -- -gnateG (save preprocessor output)
475
476 when 'G' =>
477 Generate_Processed_File := True;
478 Ptr := Ptr + 1;
479
480 -- -gnateI (index of unit in multi-unit source)
481
482 when 'I' =>
483 Ptr := Ptr + 1;
484 Scan_Pos (Switch_Chars, Max, Ptr, Multiple_Unit_Index, C);
485
486 -- -gnatem (mapping file)
487
488 when 'm' =>
489 Store_Switch := False;
490 Ptr := Ptr + 1;
491
492 -- There may be an equal sign between -gnatem and
493 -- the path name of the mapping file.
494
495 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
496 Ptr := Ptr + 1;
497 end if;
498
499 if Ptr > Max then
500 Bad_Switch ("-gnatem");
501 end if;
502
503 Mapping_File_Name :=
504 new String'(Switch_Chars (Ptr .. Max));
505 return;
506
507 -- -gnatep (preprocessing data file)
508
509 when 'p' =>
510 Store_Switch := False;
511 Ptr := Ptr + 1;
512
513 -- There may be an equal sign between -gnatep and
514 -- the path name of the mapping file.
515
516 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
517 Ptr := Ptr + 1;
518 end if;
519
520 if Ptr > Max then
521 Bad_Switch ("-gnatep");
522 end if;
523
524 Preprocessing_Data_File :=
525 new String'(Switch_Chars (Ptr .. Max));
526
527 -- Store the switch, normalizing to -gnatep=
528
529 Store_Compilation_Switch
530 ("-gnatep=" & Preprocessing_Data_File.all);
531
532 Ptr := Max + 1;
533
534 -- -gnateP (Treat pragma Pure/Preelaborate errs as warnings)
535
536 when 'P' =>
537 Treat_Categorization_Errors_As_Warnings := True;
538
539 -- -gnatez (final delimiter of explicit switches)
540
541 -- All switches that come after -gnatez have been added by
542 -- the GCC driver and are not stored in the ALI file. See
543 -- also -gnatea above.
544
545 when 'z' =>
546 Store_Switch := False;
547 Disable_Switch_Storing;
548 Ptr := Ptr + 1;
549
550 -- -gnateS (generate SCO information)
551
552 -- Include Source Coverage Obligation information in ALI
553 -- files for the benefit of source coverage analysis tools
554 -- (xcov).
555
556 when 'S' =>
557 Generate_SCO := True;
558 Ptr := Ptr + 1;
559
560 -- All other -gnate? switches are unassigned
561
562 when others =>
563 Bad_Switch ("-gnate" & Switch_Chars (Ptr .. Max));
564 end case;
565
566 -- -gnatE (dynamic elaboration checks)
567
568 when 'E' =>
569 Ptr := Ptr + 1;
570 Dynamic_Elaboration_Checks := True;
571
572 -- -gnatf (full error messages)
573
574 when 'f' =>
575 Ptr := Ptr + 1;
576 All_Errors_Mode := True;
577
578 -- Processing for F switch
579
580 when 'F' =>
581 Ptr := Ptr + 1;
582 External_Name_Exp_Casing := Uppercase;
583 External_Name_Imp_Casing := Uppercase;
584
585 -- Processing for g switch
586
587 when 'g' =>
588 Ptr := Ptr + 1;
589 GNAT_Mode := True;
590 Identifier_Character_Set := 'n';
591 System_Extend_Unit := Empty;
592 Warning_Mode := Treat_As_Error;
593
594 -- Set Ada 2012 mode explicitly. We don't want to rely on the
595 -- implicit setting here, since for example, we want
596 -- Preelaborate_05 treated as Preelaborate
597
598 Ada_Version := Ada_2012;
599 Ada_Version_Explicit := Ada_Version;
600
601 -- Set default warnings and style checks for -gnatg
602
603 Set_GNAT_Mode_Warnings;
604 Set_GNAT_Style_Check_Options;
605
606 -- Processing for G switch
607
608 when 'G' =>
609 Ptr := Ptr + 1;
610 Print_Generated_Code := True;
611
612 -- Scan optional integer line limit value
613
614 if Nat_Present (Switch_Chars, Max, Ptr) then
615 Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'G');
616 Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
617 end if;
618
619 -- Processing for h switch
620
621 when 'h' =>
622 Ptr := Ptr + 1;
623 Usage_Requested := True;
624
625 -- Processing for H switch
626
627 when 'H' =>
628 Ptr := Ptr + 1;
629 HLO_Active := True;
630
631 -- Processing for i switch
632
633 when 'i' =>
634 if Ptr = Max then
635 Bad_Switch ("-gnati");
636 end if;
637
638 Ptr := Ptr + 1;
639 C := Switch_Chars (Ptr);
640
641 if C in '1' .. '5'
642 or else C = '8'
643 or else C = '9'
644 or else C = 'p'
645 or else C = 'f'
646 or else C = 'n'
647 or else C = 'w'
648 then
649 Identifier_Character_Set := C;
650 Ptr := Ptr + 1;
651
652 else
653 Bad_Switch ("-gnati" & Switch_Chars (Ptr .. Max));
654 end if;
655
656 -- Processing for I switch
657
658 when 'I' =>
659 Ptr := Ptr + 1;
660 Ignore_Rep_Clauses := True;
661
662 -- Processing for j switch
663
664 when 'j' =>
665 Ptr := Ptr + 1;
666 Scan_Nat (Switch_Chars, Max, Ptr, Error_Msg_Line_Length, C);
667
668 -- Processing for k switch
669
670 when 'k' =>
671 Ptr := Ptr + 1;
672 Scan_Pos
673 (Switch_Chars, Max, Ptr, Maximum_File_Name_Length, C);
674
675 -- Processing for l switch
676
677 when 'l' =>
678 Ptr := Ptr + 1;
679 Full_List := True;
680
681 -- There may be an equal sign between -gnatl and a file name
682
683 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
684 if Ptr = Max then
685 Osint.Fail ("file name for -gnatl= is null");
686 else
687 Opt.Full_List_File_Name :=
688 new String'(Switch_Chars (Ptr + 1 .. Max));
689 Ptr := Max + 1;
690 end if;
691 end if;
692
693 -- Processing for L switch
694
695 when 'L' =>
696 Ptr := Ptr + 1;
697 Dump_Source_Text := True;
698
699 -- Processing for m switch
700
701 when 'm' =>
702 Ptr := Ptr + 1;
703 Scan_Nat (Switch_Chars, Max, Ptr, Maximum_Messages, C);
704
705 -- Processing for n switch
706
707 when 'n' =>
708 Ptr := Ptr + 1;
709 Inline_Active := True;
710
711 -- Processing for N switch
712
713 when 'N' =>
714 Ptr := Ptr + 1;
715 Inline_Active := True;
716 Front_End_Inlining := True;
717
718 -- Processing for o switch
719
720 when 'o' =>
721 Ptr := Ptr + 1;
722 Suppress_Options (Overflow_Check) := False;
723 Opt.Enable_Overflow_Checks := True;
724
725 -- Processing for O switch
726
727 when 'O' =>
728 Store_Switch := False;
729 Ptr := Ptr + 1;
730 Output_File_Name_Present := True;
731
732 -- Processing for p switch
733
734 when 'p' =>
735 Ptr := Ptr + 1;
736
737 -- Skip processing if cancelled by subsequent -gnat-p
738
739 if Switch_Subsequently_Cancelled ("p", Args, Arg_Rank) then
740 Store_Switch := False;
741
742 else
743 -- Set all specific options as well as All_Checks in the
744 -- Suppress_Options array, excluding Elaboration_Check,
745 -- since this is treated specially because we do not want
746 -- -gnatp to disable static elaboration processing.
747
748 for J in Suppress_Options'Range loop
749 if J /= Elaboration_Check then
750 Suppress_Options (J) := True;
751 end if;
752 end loop;
753
754 Validity_Checks_On := False;
755 Opt.Suppress_Checks := True;
756 Opt.Enable_Overflow_Checks := False;
757 end if;
758
759 -- Processing for P switch
760
761 when 'P' =>
762 Ptr := Ptr + 1;
763 Polling_Required := True;
764
765 -- Processing for q switch
766
767 when 'q' =>
768 Ptr := Ptr + 1;
769 Try_Semantics := True;
770
771 -- Processing for Q switch
772
773 when 'Q' =>
774 Ptr := Ptr + 1;
775 Force_ALI_Tree_File := True;
776 Try_Semantics := True;
777
778 -- Processing for r switch
779
780 when 'r' =>
781 Ptr := Ptr + 1;
782 Treat_Restrictions_As_Warnings := True;
783
784 -- Processing for R switch
785
786 when 'R' =>
787 Back_Annotate_Rep_Info := True;
788 List_Representation_Info := 1;
789
790 Ptr := Ptr + 1;
791 while Ptr <= Max loop
792 C := Switch_Chars (Ptr);
793
794 if C in '1' .. '3' then
795 List_Representation_Info :=
796 Character'Pos (C) - Character'Pos ('0');
797
798 elsif Switch_Chars (Ptr) = 's' then
799 List_Representation_Info_To_File := True;
800
801 elsif Switch_Chars (Ptr) = 'm' then
802 List_Representation_Info_Mechanisms := True;
803
804 else
805 Bad_Switch ("-gnatR" & Switch_Chars (Ptr .. Max));
806 end if;
807
808 Ptr := Ptr + 1;
809 end loop;
810
811 -- Processing for s switch
812
813 when 's' =>
814 if not First_Switch then
815 Osint.Fail
816 ("-gnats must be first if combined with other switches");
817 end if;
818
819 Ptr := Ptr + 1;
820 Operating_Mode := Check_Syntax;
821
822 -- Processing for S switch
823
824 when 'S' =>
825 Print_Standard := True;
826 Ptr := Ptr + 1;
827
828 -- Processing for t switch
829
830 when 't' =>
831 Ptr := Ptr + 1;
832 Tree_Output := True;
833 Back_Annotate_Rep_Info := True;
834
835 -- Processing for T switch
836
837 when 'T' =>
838 Ptr := Ptr + 1;
839 Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor, C);
840
841 -- Processing for u switch
842
843 when 'u' =>
844 Ptr := Ptr + 1;
845 List_Units := True;
846
847 -- Processing for U switch
848
849 when 'U' =>
850 Ptr := Ptr + 1;
851 Unique_Error_Tag := True;
852
853 -- Processing for v switch
854
855 when 'v' =>
856 Ptr := Ptr + 1;
857 Verbose_Mode := True;
858
859 -- Processing for V switch
860
861 when 'V' =>
862 Store_Switch := False;
863 Ptr := Ptr + 1;
864
865 if Ptr > Max then
866 Bad_Switch ("-gnatV");
867
868 else
869 declare
870 OK : Boolean;
871
872 begin
873 Set_Validity_Check_Options
874 (Switch_Chars (Ptr .. Max), OK, Ptr);
875
876 if not OK then
877 Bad_Switch ("-gnatV" & Switch_Chars (Ptr .. Max));
878 end if;
879
880 for Index in First_Char + 1 .. Max loop
881 Store_Compilation_Switch
882 ("-gnatV" & Switch_Chars (Index));
883 end loop;
884 end;
885 end if;
886
887 Ptr := Max + 1;
888
889 -- Processing for w switch
890
891 when 'w' =>
892 Store_Switch := False;
893 Ptr := Ptr + 1;
894
895 if Ptr > Max then
896 Bad_Switch ("-gnatw");
897 end if;
898
899 while Ptr <= Max loop
900 C := Switch_Chars (Ptr);
901
902 -- Case of dot switch
903
904 if C = '.' and then Ptr < Max then
905 Ptr := Ptr + 1;
906 C := Switch_Chars (Ptr);
907
908 if Set_Dot_Warning_Switch (C) then
909 Store_Compilation_Switch ("-gnatw." & C);
910 else
911 Bad_Switch ("-gnatw." & Switch_Chars (Ptr .. Max));
912 end if;
913
914 -- Normal case, no dot
915
916 else
917 if Set_Warning_Switch (C) then
918 Store_Compilation_Switch ("-gnatw" & C);
919 else
920 Bad_Switch ("-gnatw" & Switch_Chars (Ptr .. Max));
921 end if;
922 end if;
923
924 Ptr := Ptr + 1;
925 end loop;
926
927 return;
928
929 -- Processing for W switch
930
931 when 'W' =>
932 Ptr := Ptr + 1;
933
934 if Ptr > Max then
935 Bad_Switch ("-gnatW");
936 end if;
937
938 begin
939 Wide_Character_Encoding_Method :=
940 Get_WC_Encoding_Method (Switch_Chars (Ptr));
941 exception
942 when Constraint_Error =>
943 Bad_Switch ("-gnatW" & Switch_Chars (Ptr .. Max));
944 end;
945
946 Wide_Character_Encoding_Method_Specified := True;
947
948 Upper_Half_Encoding :=
949 Wide_Character_Encoding_Method in
950 WC_Upper_Half_Encoding_Method;
951
952 Ptr := Ptr + 1;
953
954 -- Processing for x switch
955
956 when 'x' =>
957 Ptr := Ptr + 1;
958 Xref_Active := False;
959
960 -- Processing for X switch
961
962 when 'X' =>
963 Ptr := Ptr + 1;
964 Extensions_Allowed := True;
965 Ada_Version := Ada_Version_Type'Last;
966 Ada_Version_Explicit := Ada_Version_Type'Last;
967
968 -- Processing for y switch
969
970 when 'y' =>
971 Ptr := Ptr + 1;
972
973 if Ptr > Max then
974 Set_Default_Style_Check_Options;
975
976 else
977 Store_Switch := False;
978
979 declare
980 OK : Boolean;
981
982 begin
983 Set_Style_Check_Options
984 (Switch_Chars (Ptr .. Max), OK, Ptr);
985
986 if not OK then
987 Osint.Fail
988 ("bad -gnaty switch (" &
989 Style_Msg_Buf (1 .. Style_Msg_Len) & ')');
990 end if;
991
992 Ptr := First_Char + 1;
993 while Ptr <= Max loop
994 if Switch_Chars (Ptr) = 'M' then
995 First_Char := Ptr;
996 loop
997 Ptr := Ptr + 1;
998 exit when Ptr > Max
999 or else Switch_Chars (Ptr) not in '0' .. '9';
1000 end loop;
1001
1002 Store_Compilation_Switch
1003 ("-gnaty" & Switch_Chars (First_Char .. Ptr - 1));
1004
1005 else
1006 Store_Compilation_Switch
1007 ("-gnaty" & Switch_Chars (Ptr));
1008 Ptr := Ptr + 1;
1009 end if;
1010 end loop;
1011 end;
1012 end if;
1013
1014 -- Processing for z switch
1015
1016 when 'z' =>
1017
1018 -- -gnatz must be the first and only switch in Switch_Chars,
1019 -- and is a two-letter switch.
1020
1021 if Ptr /= Switch_Chars'First + 5
1022 or else (Max - Ptr + 1) > 2
1023 then
1024 Osint.Fail
1025 ("-gnatz* may not be combined with other switches");
1026 end if;
1027
1028 if Ptr = Max then
1029 Bad_Switch ("-gnatz");
1030 end if;
1031
1032 Ptr := Ptr + 1;
1033
1034 -- Only one occurrence of -gnat* is permitted
1035
1036 if Distribution_Stub_Mode = No_Stubs then
1037 case Switch_Chars (Ptr) is
1038 when 'r' =>
1039 Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
1040
1041 when 'c' =>
1042 Distribution_Stub_Mode := Generate_Caller_Stub_Body;
1043
1044 when others =>
1045 Bad_Switch ("-gnatz" & Switch_Chars (Ptr .. Max));
1046 end case;
1047
1048 Ptr := Ptr + 1;
1049
1050 else
1051 Osint.Fail ("only one -gnatz* switch allowed");
1052 end if;
1053
1054 -- Processing for Z switch
1055
1056 when 'Z' =>
1057 Ptr := Ptr + 1;
1058 Osint.Fail
1059 ("-gnatZ is no longer supported: consider using --RTS=zcx");
1060
1061 -- Note on language version switches: whenever a new language
1062 -- version switch is added, function Switch.Is_Language_Switch and
1063 -- procedure Switch.M.Normalize_Compiler_Switches must be updated.
1064
1065 -- Processing for 83 switch
1066
1067 when '8' =>
1068 if Ptr = Max then
1069 Bad_Switch ("-gnat8");
1070 end if;
1071
1072 Ptr := Ptr + 1;
1073
1074 if Switch_Chars (Ptr) /= '3' then
1075 Bad_Switch ("-gnat8" & Switch_Chars (Ptr .. Max));
1076 else
1077 Ptr := Ptr + 1;
1078 Ada_Version := Ada_83;
1079 Ada_Version_Explicit := Ada_Version;
1080 end if;
1081
1082 -- Processing for 95 switch
1083
1084 when '9' =>
1085 if Ptr = Max then
1086 Bad_Switch ("-gnat9");
1087 end if;
1088
1089 Ptr := Ptr + 1;
1090
1091 if Switch_Chars (Ptr) /= '5' then
1092 Bad_Switch ("-gnat9" & Switch_Chars (Ptr .. Max));
1093 else
1094 Ptr := Ptr + 1;
1095 Ada_Version := Ada_95;
1096 Ada_Version_Explicit := Ada_Version;
1097 end if;
1098
1099 -- Processing for 05 switch
1100
1101 when '0' =>
1102 if Ptr = Max then
1103 Bad_Switch ("-gnat0");
1104 end if;
1105
1106 Ptr := Ptr + 1;
1107
1108 if Switch_Chars (Ptr) /= '5' then
1109 Bad_Switch ("-gnat0" & Switch_Chars (Ptr .. Max));
1110 else
1111 Ptr := Ptr + 1;
1112 Ada_Version := Ada_2005;
1113 Ada_Version_Explicit := Ada_Version;
1114 end if;
1115
1116 -- Processing for 12 switch
1117
1118 when '1' =>
1119 if Ptr = Max then
1120 Bad_Switch ("-gnat1");
1121 end if;
1122
1123 Ptr := Ptr + 1;
1124
1125 if Switch_Chars (Ptr) /= '2' then
1126 Bad_Switch ("-gnat1" & Switch_Chars (Ptr .. Max));
1127 else
1128 Ptr := Ptr + 1;
1129 Ada_Version := Ada_2012;
1130 Ada_Version_Explicit := Ada_Version;
1131 end if;
1132
1133 -- Processing for 2005 and 2012 switches
1134
1135 when '2' =>
1136 if Ptr > Max - 3 then
1137 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
1138
1139 elsif Switch_Chars (Ptr .. Ptr + 3) = "2005" then
1140 Ada_Version := Ada_2005;
1141
1142 elsif Switch_Chars (Ptr .. Ptr + 3) = "2012" then
1143 Ada_Version := Ada_2012;
1144
1145 else
1146 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Ptr + 3));
1147 end if;
1148
1149 Ada_Version_Explicit := Ada_Version;
1150 Ptr := Ptr + 4;
1151
1152 -- Switch cancellation, currently only -gnat-p is allowed.
1153 -- All we do here is the error checking, since the actual
1154 -- processing for switch cancellation is done by calls to
1155 -- Switch_Subsequently_Cancelled at the appropriate point.
1156
1157 when '-' =>
1158
1159 -- Simple ignore -gnat-p
1160
1161 if Switch_Chars = "-gnat-p" then
1162 return;
1163
1164 -- Any other occurrence of minus is ignored. This is for
1165 -- maximum compatibility with previous version which ignored
1166 -- all occurrences of minus.
1167
1168 else
1169 Store_Switch := False;
1170 Ptr := Ptr + 1;
1171 end if;
1172
1173 -- We ignore '/' in switches, this is historical, still needed???
1174
1175 when '/' =>
1176 Store_Switch := False;
1177
1178 -- Anything else is an error (illegal switch character)
1179
1180 when others =>
1181 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
1182 end case;
1183
1184 if Store_Switch then
1185 Store_Compilation_Switch
1186 ("-gnat" & Switch_Chars (First_Char .. Ptr - 1));
1187 end if;
1188
1189 First_Switch := False;
1190 end loop;
1191 end if;
1192 end Scan_Front_End_Switches;
1193
1194 -----------------------------------
1195 -- Switch_Subsequently_Cancelled --
1196 -----------------------------------
1197
1198 function Switch_Subsequently_Cancelled
1199 (C : String;
1200 Args : String_List;
1201 Arg_Rank : Positive) return Boolean
1202 is
1203 begin
1204 -- Loop through arguments following the current one
1205
1206 for Arg in Arg_Rank + 1 .. Args'Last loop
1207 if Args (Arg).all = "-gnat-" & C then
1208 return True;
1209 end if;
1210 end loop;
1211
1212 -- No match found, not cancelled
1213
1214 return False;
1215 end Switch_Subsequently_Cancelled;
1216
1217 end Switch.C;