re PR bootstrap/51346 (LTO bootstrap failed with bootstrap-profiled)
[official-gcc.git] / gcc / ada / switch-c.adb
blobe900faa4bd26ca91e62477b26ef34339a8822d05
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 ------------------------------------------------------------------------------
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.
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;
38 with Ada.Unchecked_Deallocation;
39 with System.WCh_Con; use System.WCh_Con;
41 package body Switch.C is
43 RTS_Specified : String_Access := null;
44 -- Used to detect multiple use of --RTS= flag
46 procedure Add_Symbol_Definition (Def : String);
47 -- Add a symbol definition from the command line
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
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.
63 ---------------------------
64 -- Add_Symbol_Definition --
65 ---------------------------
67 procedure Add_Symbol_Definition (Def : String) is
68 begin
69 -- If Preprocessor_Symbol_Defs is not large enough, double its size
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);
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;
84 Preprocessing_Symbol_Last := Preprocessing_Symbol_Last + 1;
85 Preprocessing_Symbol_Defs (Preprocessing_Symbol_Last) :=
86 new String'(Def);
87 end Add_Symbol_Definition;
89 -----------------------------
90 -- Scan_Front_End_Switches --
91 -----------------------------
93 procedure Scan_Front_End_Switches
94 (Switch_Chars : String;
95 Args : String_List;
96 Arg_Rank : Positive)
98 First_Switch : Boolean := True;
99 -- False for all but first switch
101 Max : constant Natural := Switch_Chars'Last;
102 Ptr : Natural;
103 C : Character := ' ';
104 Dot : Boolean;
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.
115 First_Char : Positive;
116 -- Marks start of switch to be stored
118 begin
119 Ptr := Switch_Chars'First;
121 -- Skip past the initial character (must be the switch character)
123 if Ptr = Max then
124 Bad_Switch (C);
125 else
126 Ptr := Ptr + 1;
127 end if;
129 -- Handle switches that do not start with -gnat
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
137 if Switch_Chars (Ptr) = 'I' then
139 -- Set flag Search_Directory_Present if switch is "-I" only:
140 -- the directory will be the next argument.
142 if Ptr = Max then
143 Search_Directory_Present := True;
144 return;
145 end if;
147 Ptr := Ptr + 1;
149 -- Find out whether this is a -I- or regular -Ixxx switch
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.
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;
161 -- Processing of the --RTS switch. --RTS may have been modified by
162 -- gcc into -fRTS (for GCC targets).
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;
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.
179 if RTS_Specified = null then
180 RTS_Specified := new String'(Switch_Chars (Ptr + 4 .. Max));
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;
188 -- Valid --RTS switch
190 Opt.No_Stdinc := True;
191 Opt.RTS_Switch := True;
193 RTS_Src_Path_Name :=
194 Get_RTS_Search_Dir
195 (Switch_Chars (Ptr + 4 .. Max), Include);
197 RTS_Lib_Path_Name :=
198 Get_RTS_Search_Dir
199 (Switch_Chars (Ptr + 4 .. Max), Objects);
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).
207 Store_Compilation_Switch (Switch_Chars);
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");
215 elsif RTS_Src_Path_Name = null then
216 Osint.Fail ("RTS path not valid: missing " &
217 "adainclude directory");
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;
225 -- There are no other switches not starting with -gnat
227 else
228 Bad_Switch (Switch_Chars);
229 end if;
231 -- Case of switch starting with -gnat
233 else
234 Ptr := Ptr + 4;
236 -- Loop to scan through switches given in switch string
238 while Ptr <= Max loop
239 First_Char := Ptr;
240 Store_Switch := True;
242 C := Switch_Chars (Ptr);
244 case C is
246 when 'a' =>
247 Ptr := Ptr + 1;
248 Assertions_Enabled := True;
249 Debug_Pragmas_Enabled := True;
251 -- Processing for A switch
253 when 'A' =>
254 Ptr := Ptr + 1;
255 Config_File := False;
257 -- Processing for b switch
259 when 'b' =>
260 Ptr := Ptr + 1;
261 Brief_Output := True;
263 -- Processing for B switch
265 when 'B' =>
266 Ptr := Ptr + 1;
267 Assume_No_Invalid_Values := True;
269 -- Processing for c switch
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;
277 Ptr := Ptr + 1;
278 Operating_Mode := Check_Semantics;
280 -- Processing for C switch
282 when 'C' =>
283 Ptr := Ptr + 1;
285 if not CodePeer_Mode then
286 CodePeer_Mode := True;
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.
295 Warning_Mode := Suppress;
296 end if;
298 -- Processing for d switch
300 when 'd' =>
301 Store_Switch := False;
302 Dot := False;
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.
308 -- Loop to scan out debug flags
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 = '-';
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;
327 elsif C = '.' then
328 Dot := True;
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;
337 return;
339 -- Processing for D switch
341 when 'D' =>
342 Ptr := Ptr + 1;
344 -- Scan optional integer line limit value
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;
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.
355 Debug_Generated_Code := True;
356 Xref_Active := False;
357 Set_Debug_Flag ('g');
359 -- -gnate? (extended switches)
361 when 'e' =>
362 Ptr := Ptr + 1;
364 -- The -gnate? switches are all double character switches
365 -- so we must always have a character after the e.
367 if Ptr > Max then
368 Bad_Switch ("-gnate");
369 end if;
371 case Switch_Chars (Ptr) is
373 -- -gnatea (initial delimiter of explicit switches)
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.
379 when 'a' =>
380 Store_Switch := False;
381 Enable_Switch_Storing;
382 Ptr := Ptr + 1;
384 -- -gnatec (configuration pragmas)
386 when 'c' =>
387 Store_Switch := False;
388 Ptr := Ptr + 1;
390 -- There may be an equal sign between -gnatec and
391 -- the path name of the config file.
393 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
394 Ptr := Ptr + 1;
395 end if;
397 if Ptr > Max then
398 Bad_Switch ("-gnatec");
399 end if;
401 declare
402 Config_File_Name : constant String_Access :=
403 new String'
404 (Switch_Chars (Ptr .. Max));
406 begin
407 if Config_File_Names = null then
408 Config_File_Names :=
409 new String_List'(1 => Config_File_Name);
411 else
412 declare
413 New_Names : constant String_List_Access :=
414 new String_List
415 (1 ..
416 Config_File_Names'Length + 1);
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;
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;
432 return;
434 -- -gnateC switch (CodePeer SCIL generation)
436 -- Not enabled for now, keep it for later???
437 -- use -gnatd.I only for now
439 -- when 'C' =>
440 -- Ptr := Ptr + 1;
441 -- Generate_SCIL := True;
443 -- -gnated switch (disable atomic synchronization)
445 when 'd' =>
446 Suppress_Options (Atomic_Synchronization) := True;
448 -- -gnateD switch (preprocessing symbol definition)
450 when 'D' =>
451 Store_Switch := False;
452 Ptr := Ptr + 1;
454 if Ptr > Max then
455 Bad_Switch ("-gnateD");
456 end if;
458 Add_Symbol_Definition (Switch_Chars (Ptr .. Max));
460 -- Store the switch
462 Store_Compilation_Switch
463 ("-gnateD" & Switch_Chars (Ptr .. Max));
464 Ptr := Max + 1;
466 -- -gnateE (extra exception information)
468 when 'E' =>
469 Exception_Extra_Info := True;
470 Ptr := Ptr + 1;
472 -- -gnatef (full source path for brief error messages)
474 when 'f' =>
475 Store_Switch := False;
476 Ptr := Ptr + 1;
477 Full_Path_Name_For_Brief_Errors := True;
479 -- -gnateG (save preprocessor output)
481 when 'G' =>
482 Generate_Processed_File := True;
483 Ptr := Ptr + 1;
485 -- -gnateI (index of unit in multi-unit source)
487 when 'I' =>
488 Ptr := Ptr + 1;
489 Scan_Pos (Switch_Chars, Max, Ptr, Multiple_Unit_Index, C);
491 -- -gnatem (mapping file)
493 when 'm' =>
494 Store_Switch := False;
495 Ptr := Ptr + 1;
497 -- There may be an equal sign between -gnatem and
498 -- the path name of the mapping file.
500 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
501 Ptr := Ptr + 1;
502 end if;
504 if Ptr > Max then
505 Bad_Switch ("-gnatem");
506 end if;
508 Mapping_File_Name :=
509 new String'(Switch_Chars (Ptr .. Max));
510 return;
512 -- -gnatep (preprocessing data file)
514 when 'p' =>
515 Store_Switch := False;
516 Ptr := Ptr + 1;
518 -- There may be an equal sign between -gnatep and
519 -- the path name of the mapping file.
521 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
522 Ptr := Ptr + 1;
523 end if;
525 if Ptr > Max then
526 Bad_Switch ("-gnatep");
527 end if;
529 Preprocessing_Data_File :=
530 new String'(Switch_Chars (Ptr .. Max));
532 -- Store the switch, normalizing to -gnatep=
534 Store_Compilation_Switch
535 ("-gnatep=" & Preprocessing_Data_File.all);
537 Ptr := Max + 1;
539 -- -gnateP (Treat pragma Pure/Preelaborate errs as warnings)
541 when 'P' =>
542 Treat_Categorization_Errors_As_Warnings := True;
544 -- -gnatez (final delimiter of explicit switches)
546 -- All switches that come after -gnatez have been added by
547 -- the GCC driver and are not stored in the ALI file. See
548 -- also -gnatea above.
550 when 'z' =>
551 Store_Switch := False;
552 Disable_Switch_Storing;
553 Ptr := Ptr + 1;
555 -- -gnateS (generate SCO information)
557 -- Include Source Coverage Obligation information in ALI
558 -- files for the benefit of source coverage analysis tools
559 -- (xcov).
561 when 'S' =>
562 Generate_SCO := True;
563 Ptr := Ptr + 1;
565 -- All other -gnate? switches are unassigned
567 when others =>
568 Bad_Switch ("-gnate" & Switch_Chars (Ptr .. Max));
569 end case;
571 -- -gnatE (dynamic elaboration checks)
573 when 'E' =>
574 Ptr := Ptr + 1;
575 Dynamic_Elaboration_Checks := True;
577 -- -gnatf (full error messages)
579 when 'f' =>
580 Ptr := Ptr + 1;
581 All_Errors_Mode := True;
583 -- Processing for F switch
585 when 'F' =>
586 Ptr := Ptr + 1;
587 External_Name_Exp_Casing := Uppercase;
588 External_Name_Imp_Casing := Uppercase;
590 -- Processing for g switch
592 when 'g' =>
593 Ptr := Ptr + 1;
594 GNAT_Mode := True;
595 Identifier_Character_Set := 'n';
596 System_Extend_Unit := Empty;
597 Warning_Mode := Treat_As_Error;
599 -- Set Ada 2012 mode explicitly. We don't want to rely on the
600 -- implicit setting here, since for example, we want
601 -- Preelaborate_05 treated as Preelaborate
603 Ada_Version := Ada_2012;
604 Ada_Version_Explicit := Ada_Version;
606 -- Set default warnings and style checks for -gnatg
608 Set_GNAT_Mode_Warnings;
609 Set_GNAT_Style_Check_Options;
611 -- Processing for G switch
613 when 'G' =>
614 Ptr := Ptr + 1;
615 Print_Generated_Code := True;
617 -- Scan optional integer line limit value
619 if Nat_Present (Switch_Chars, Max, Ptr) then
620 Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'G');
621 Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
622 end if;
624 -- Processing for h switch
626 when 'h' =>
627 Ptr := Ptr + 1;
628 Usage_Requested := True;
630 -- Processing for H switch
632 when 'H' =>
633 Ptr := Ptr + 1;
634 HLO_Active := True;
636 -- Processing for i switch
638 when 'i' =>
639 if Ptr = Max then
640 Bad_Switch ("-gnati");
641 end if;
643 Ptr := Ptr + 1;
644 C := Switch_Chars (Ptr);
646 if C in '1' .. '5'
647 or else C = '8'
648 or else C = '9'
649 or else C = 'p'
650 or else C = 'f'
651 or else C = 'n'
652 or else C = 'w'
653 then
654 Identifier_Character_Set := C;
655 Ptr := Ptr + 1;
657 else
658 Bad_Switch ("-gnati" & Switch_Chars (Ptr .. Max));
659 end if;
661 -- Processing for I switch
663 when 'I' =>
664 Ptr := Ptr + 1;
665 Ignore_Rep_Clauses := True;
667 -- Processing for j switch
669 when 'j' =>
670 Ptr := Ptr + 1;
671 Scan_Nat (Switch_Chars, Max, Ptr, Error_Msg_Line_Length, C);
673 -- Processing for k switch
675 when 'k' =>
676 Ptr := Ptr + 1;
677 Scan_Pos
678 (Switch_Chars, Max, Ptr, Maximum_File_Name_Length, C);
680 -- Processing for l switch
682 when 'l' =>
683 Ptr := Ptr + 1;
684 Full_List := True;
686 -- There may be an equal sign between -gnatl and a file name
688 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
689 if Ptr = Max then
690 Osint.Fail ("file name for -gnatl= is null");
691 else
692 Opt.Full_List_File_Name :=
693 new String'(Switch_Chars (Ptr + 1 .. Max));
694 Ptr := Max + 1;
695 end if;
696 end if;
698 -- Processing for L switch
700 when 'L' =>
701 Ptr := Ptr + 1;
702 Dump_Source_Text := True;
704 -- Processing for m switch
706 when 'm' =>
707 Ptr := Ptr + 1;
708 Scan_Nat (Switch_Chars, Max, Ptr, Maximum_Messages, C);
710 -- Processing for n switch
712 when 'n' =>
713 Ptr := Ptr + 1;
714 Inline_Active := True;
716 -- Processing for N switch
718 when 'N' =>
719 Ptr := Ptr + 1;
720 Inline_Active := True;
721 Front_End_Inlining := True;
723 -- Processing for o switch
725 when 'o' =>
726 Ptr := Ptr + 1;
727 Suppress_Options (Overflow_Check) := False;
728 Opt.Enable_Overflow_Checks := True;
730 -- Processing for O switch
732 when 'O' =>
733 Store_Switch := False;
734 Ptr := Ptr + 1;
735 Output_File_Name_Present := True;
737 -- Processing for p switch
739 when 'p' =>
740 Ptr := Ptr + 1;
742 -- Skip processing if cancelled by subsequent -gnat-p
744 if Switch_Subsequently_Cancelled ("p", Args, Arg_Rank) then
745 Store_Switch := False;
747 else
748 -- Set all specific options as well as All_Checks in the
749 -- Suppress_Options array, excluding Elaboration_Check,
750 -- since this is treated specially because we do not want
751 -- -gnatp to disable static elaboration processing. Also
752 -- exclude Atomic_Synchronization, since this is not a real
753 -- check.
755 for J in Suppress_Options'Range loop
756 if J /= Elaboration_Check
757 and then J /= Atomic_Synchronization
758 then
759 Suppress_Options (J) := True;
760 end if;
761 end loop;
763 Validity_Checks_On := False;
764 Opt.Suppress_Checks := True;
765 Opt.Enable_Overflow_Checks := False;
766 end if;
768 -- Processing for P switch
770 when 'P' =>
771 Ptr := Ptr + 1;
772 Polling_Required := True;
774 -- Processing for q switch
776 when 'q' =>
777 Ptr := Ptr + 1;
778 Try_Semantics := True;
780 -- Processing for Q switch
782 when 'Q' =>
783 Ptr := Ptr + 1;
784 Force_ALI_Tree_File := True;
785 Try_Semantics := True;
787 -- Processing for r switch
789 when 'r' =>
790 Ptr := Ptr + 1;
791 Treat_Restrictions_As_Warnings := True;
793 -- Processing for R switch
795 when 'R' =>
796 Back_Annotate_Rep_Info := True;
797 List_Representation_Info := 1;
799 Ptr := Ptr + 1;
800 while Ptr <= Max loop
801 C := Switch_Chars (Ptr);
803 if C in '1' .. '3' then
804 List_Representation_Info :=
805 Character'Pos (C) - Character'Pos ('0');
807 elsif Switch_Chars (Ptr) = 's' then
808 List_Representation_Info_To_File := True;
810 elsif Switch_Chars (Ptr) = 'm' then
811 List_Representation_Info_Mechanisms := True;
813 else
814 Bad_Switch ("-gnatR" & Switch_Chars (Ptr .. Max));
815 end if;
817 Ptr := Ptr + 1;
818 end loop;
820 -- Processing for s switch
822 when 's' =>
823 if not First_Switch then
824 Osint.Fail
825 ("-gnats must be first if combined with other switches");
826 end if;
828 Ptr := Ptr + 1;
829 Operating_Mode := Check_Syntax;
831 -- Processing for S switch
833 when 'S' =>
834 Print_Standard := True;
835 Ptr := Ptr + 1;
837 -- Processing for t switch
839 when 't' =>
840 Ptr := Ptr + 1;
841 Tree_Output := True;
842 Back_Annotate_Rep_Info := True;
844 -- Processing for T switch
846 when 'T' =>
847 Ptr := Ptr + 1;
848 Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor, C);
850 -- Processing for u switch
852 when 'u' =>
853 Ptr := Ptr + 1;
854 List_Units := True;
856 -- Processing for U switch
858 when 'U' =>
859 Ptr := Ptr + 1;
860 Unique_Error_Tag := True;
862 -- Processing for v switch
864 when 'v' =>
865 Ptr := Ptr + 1;
866 Verbose_Mode := True;
868 -- Processing for V switch
870 when 'V' =>
871 Store_Switch := False;
872 Ptr := Ptr + 1;
874 if Ptr > Max then
875 Bad_Switch ("-gnatV");
877 else
878 declare
879 OK : Boolean;
881 begin
882 Set_Validity_Check_Options
883 (Switch_Chars (Ptr .. Max), OK, Ptr);
885 if not OK then
886 Bad_Switch ("-gnatV" & Switch_Chars (Ptr .. Max));
887 end if;
889 for Index in First_Char + 1 .. Max loop
890 Store_Compilation_Switch
891 ("-gnatV" & Switch_Chars (Index));
892 end loop;
893 end;
894 end if;
896 Ptr := Max + 1;
898 -- Processing for w switch
900 when 'w' =>
901 Store_Switch := False;
902 Ptr := Ptr + 1;
904 if Ptr > Max then
905 Bad_Switch ("-gnatw");
906 end if;
908 while Ptr <= Max loop
909 C := Switch_Chars (Ptr);
911 -- Case of dot switch
913 if C = '.' and then Ptr < Max then
914 Ptr := Ptr + 1;
915 C := Switch_Chars (Ptr);
917 if Set_Dot_Warning_Switch (C) then
918 Store_Compilation_Switch ("-gnatw." & C);
919 else
920 Bad_Switch ("-gnatw." & Switch_Chars (Ptr .. Max));
921 end if;
923 -- Normal case, no dot
925 else
926 if Set_Warning_Switch (C) then
927 Store_Compilation_Switch ("-gnatw" & C);
928 else
929 Bad_Switch ("-gnatw" & Switch_Chars (Ptr .. Max));
930 end if;
931 end if;
933 Ptr := Ptr + 1;
934 end loop;
936 return;
938 -- Processing for W switch
940 when 'W' =>
941 Ptr := Ptr + 1;
943 if Ptr > Max then
944 Bad_Switch ("-gnatW");
945 end if;
947 begin
948 Wide_Character_Encoding_Method :=
949 Get_WC_Encoding_Method (Switch_Chars (Ptr));
950 exception
951 when Constraint_Error =>
952 Bad_Switch ("-gnatW" & Switch_Chars (Ptr .. Max));
953 end;
955 Wide_Character_Encoding_Method_Specified := True;
957 Upper_Half_Encoding :=
958 Wide_Character_Encoding_Method in
959 WC_Upper_Half_Encoding_Method;
961 Ptr := Ptr + 1;
963 -- Processing for x switch
965 when 'x' =>
966 Ptr := Ptr + 1;
967 Xref_Active := False;
969 -- Processing for X switch
971 when 'X' =>
972 Ptr := Ptr + 1;
973 Extensions_Allowed := True;
974 Ada_Version := Ada_Version_Type'Last;
975 Ada_Version_Explicit := Ada_Version_Type'Last;
977 -- Processing for y switch
979 when 'y' =>
980 Ptr := Ptr + 1;
982 if Ptr > Max then
983 Set_Default_Style_Check_Options;
985 else
986 Store_Switch := False;
988 declare
989 OK : Boolean;
991 begin
992 Set_Style_Check_Options
993 (Switch_Chars (Ptr .. Max), OK, Ptr);
995 if not OK then
996 Osint.Fail
997 ("bad -gnaty switch (" &
998 Style_Msg_Buf (1 .. Style_Msg_Len) & ')');
999 end if;
1001 Ptr := First_Char + 1;
1002 while Ptr <= Max loop
1003 if Switch_Chars (Ptr) = 'M' then
1004 First_Char := Ptr;
1005 loop
1006 Ptr := Ptr + 1;
1007 exit when Ptr > Max
1008 or else Switch_Chars (Ptr) not in '0' .. '9';
1009 end loop;
1011 Store_Compilation_Switch
1012 ("-gnaty" & Switch_Chars (First_Char .. Ptr - 1));
1014 else
1015 Store_Compilation_Switch
1016 ("-gnaty" & Switch_Chars (Ptr));
1017 Ptr := Ptr + 1;
1018 end if;
1019 end loop;
1020 end;
1021 end if;
1023 -- Processing for z switch
1025 when 'z' =>
1027 -- -gnatz must be the first and only switch in Switch_Chars,
1028 -- and is a two-letter switch.
1030 if Ptr /= Switch_Chars'First + 5
1031 or else (Max - Ptr + 1) > 2
1032 then
1033 Osint.Fail
1034 ("-gnatz* may not be combined with other switches");
1035 end if;
1037 if Ptr = Max then
1038 Bad_Switch ("-gnatz");
1039 end if;
1041 Ptr := Ptr + 1;
1043 -- Only one occurrence of -gnat* is permitted
1045 if Distribution_Stub_Mode = No_Stubs then
1046 case Switch_Chars (Ptr) is
1047 when 'r' =>
1048 Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
1050 when 'c' =>
1051 Distribution_Stub_Mode := Generate_Caller_Stub_Body;
1053 when others =>
1054 Bad_Switch ("-gnatz" & Switch_Chars (Ptr .. Max));
1055 end case;
1057 Ptr := Ptr + 1;
1059 else
1060 Osint.Fail ("only one -gnatz* switch allowed");
1061 end if;
1063 -- Processing for Z switch
1065 when 'Z' =>
1066 Ptr := Ptr + 1;
1067 Osint.Fail
1068 ("-gnatZ is no longer supported: consider using --RTS=zcx");
1070 -- Note on language version switches: whenever a new language
1071 -- version switch is added, Switch.M.Normalize_Compiler_Switches
1072 -- must be updated.
1074 -- Processing for 83 switch
1076 when '8' =>
1077 if Ptr = Max then
1078 Bad_Switch ("-gnat8");
1079 end if;
1081 Ptr := Ptr + 1;
1083 if Switch_Chars (Ptr) /= '3' then
1084 Bad_Switch ("-gnat8" & Switch_Chars (Ptr .. Max));
1085 else
1086 Ptr := Ptr + 1;
1087 Ada_Version := Ada_83;
1088 Ada_Version_Explicit := Ada_Version;
1089 end if;
1091 -- Processing for 95 switch
1093 when '9' =>
1094 if Ptr = Max then
1095 Bad_Switch ("-gnat9");
1096 end if;
1098 Ptr := Ptr + 1;
1100 if Switch_Chars (Ptr) /= '5' then
1101 Bad_Switch ("-gnat9" & Switch_Chars (Ptr .. Max));
1102 else
1103 Ptr := Ptr + 1;
1104 Ada_Version := Ada_95;
1105 Ada_Version_Explicit := Ada_Version;
1106 end if;
1108 -- Processing for 05 switch
1110 when '0' =>
1111 if Ptr = Max then
1112 Bad_Switch ("-gnat0");
1113 end if;
1115 Ptr := Ptr + 1;
1117 if Switch_Chars (Ptr) /= '5' then
1118 Bad_Switch ("-gnat0" & Switch_Chars (Ptr .. Max));
1119 else
1120 Ptr := Ptr + 1;
1121 Ada_Version := Ada_2005;
1122 Ada_Version_Explicit := Ada_Version;
1123 end if;
1125 -- Processing for 12 switch
1127 when '1' =>
1128 if Ptr = Max then
1129 Bad_Switch ("-gnat1");
1130 end if;
1132 Ptr := Ptr + 1;
1134 if Switch_Chars (Ptr) /= '2' then
1135 Bad_Switch ("-gnat1" & Switch_Chars (Ptr .. Max));
1136 else
1137 Ptr := Ptr + 1;
1138 Ada_Version := Ada_2012;
1139 Ada_Version_Explicit := Ada_Version;
1140 end if;
1142 -- Processing for 2005 and 2012 switches
1144 when '2' =>
1145 if Ptr > Max - 3 then
1146 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
1148 elsif Switch_Chars (Ptr .. Ptr + 3) = "2005" then
1149 Ada_Version := Ada_2005;
1151 elsif Switch_Chars (Ptr .. Ptr + 3) = "2012" then
1152 Ada_Version := Ada_2012;
1154 else
1155 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Ptr + 3));
1156 end if;
1158 Ada_Version_Explicit := Ada_Version;
1159 Ptr := Ptr + 4;
1161 -- Switch cancellation, currently only -gnat-p is allowed.
1162 -- All we do here is the error checking, since the actual
1163 -- processing for switch cancellation is done by calls to
1164 -- Switch_Subsequently_Cancelled at the appropriate point.
1166 when '-' =>
1168 -- Simple ignore -gnat-p
1170 if Switch_Chars = "-gnat-p" then
1171 return;
1173 -- Any other occurrence of minus is ignored. This is for
1174 -- maximum compatibility with previous version which ignored
1175 -- all occurrences of minus.
1177 else
1178 Store_Switch := False;
1179 Ptr := Ptr + 1;
1180 end if;
1182 -- We ignore '/' in switches, this is historical, still needed???
1184 when '/' =>
1185 Store_Switch := False;
1187 -- Anything else is an error (illegal switch character)
1189 when others =>
1190 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
1191 end case;
1193 if Store_Switch then
1194 Store_Compilation_Switch
1195 ("-gnat" & Switch_Chars (First_Char .. Ptr - 1));
1196 end if;
1198 First_Switch := False;
1199 end loop;
1200 end if;
1201 end Scan_Front_End_Switches;
1203 -----------------------------------
1204 -- Switch_Subsequently_Cancelled --
1205 -----------------------------------
1207 function Switch_Subsequently_Cancelled
1208 (C : String;
1209 Args : String_List;
1210 Arg_Rank : Positive) return Boolean
1212 begin
1213 -- Loop through arguments following the current one
1215 for Arg in Arg_Rank + 1 .. Args'Last loop
1216 if Args (Arg).all = "-gnat-" & C then
1217 return True;
1218 end if;
1219 end loop;
1221 -- No match found, not cancelled
1223 return False;
1224 end Switch_Subsequently_Cancelled;
1226 end Switch.C;