* config/darwin.c (darwin_assemble_visibility): Treat
[official-gcc.git] / gcc / ada / switch-c.adb
blob7dbbd8a86b6284218de6082770046516e2dbe6cc
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-2012, 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 Ttypes; use Ttypes;
37 with Warnsw; use Warnsw;
39 with Ada.Unchecked_Deallocation;
40 with System.WCh_Con; use System.WCh_Con;
42 package body Switch.C is
44 RTS_Specified : String_Access := null;
45 -- Used to detect multiple use of --RTS= flag
47 procedure Add_Symbol_Definition (Def : String);
48 -- Add a symbol definition from the command line
50 procedure Free is
51 new Ada.Unchecked_Deallocation (String_List, String_List_Access);
52 -- Avoid using System.Strings.Free, which also frees the designated strings
54 function Get_Overflow_Mode (C : Character) return Overflow_Check_Type;
55 -- Given a digit in the range 0 .. 3, returns the corresponding value of
56 -- Overflow_Check_Type. Raises program error if C is outside this range.
58 function Switch_Subsequently_Cancelled
59 (C : String;
60 Args : String_List;
61 Arg_Rank : Positive) return Boolean;
62 -- This function is called from Scan_Front_End_Switches. It determines if
63 -- the switch currently being scanned is followed by a switch of the form
64 -- "-gnat-" & C, where C is the argument. If so, then True is returned,
65 -- and Scan_Front_End_Switches will cancel the effect of the switch. If
66 -- no such switch is found, False is returned.
68 ---------------------------
69 -- Add_Symbol_Definition --
70 ---------------------------
72 procedure Add_Symbol_Definition (Def : String) is
73 begin
74 -- If Preprocessor_Symbol_Defs is not large enough, double its size
76 if Preprocessing_Symbol_Last = Preprocessing_Symbol_Defs'Last then
77 declare
78 New_Symbol_Definitions : constant String_List_Access :=
79 new String_List (1 .. 2 * Preprocessing_Symbol_Last);
80 begin
81 New_Symbol_Definitions (Preprocessing_Symbol_Defs'Range) :=
82 Preprocessing_Symbol_Defs.all;
83 Free (Preprocessing_Symbol_Defs);
84 Preprocessing_Symbol_Defs := New_Symbol_Definitions;
85 end;
86 end if;
88 Preprocessing_Symbol_Last := Preprocessing_Symbol_Last + 1;
89 Preprocessing_Symbol_Defs (Preprocessing_Symbol_Last) :=
90 new String'(Def);
91 end Add_Symbol_Definition;
93 -----------------------
94 -- Get_Overflow_Mode --
95 -----------------------
97 function Get_Overflow_Mode (C : Character) return Overflow_Check_Type is
98 begin
99 case C is
100 when '0' =>
101 return Suppressed;
103 when '1' =>
104 return Checked;
106 when '2' =>
107 return Minimized;
109 -- Eliminated allowed only if Long_Long_Integer is 64 bits (since
110 -- the current implementation of System.Bignums assumes this).
112 when '3' =>
113 if Standard_Long_Long_Integer_Size /= 64 then
114 Bad_Switch ("-gnato3 not implemented for this configuration");
115 else
116 return Eliminated;
117 end if;
119 when others =>
120 raise Program_Error;
121 end case;
122 end Get_Overflow_Mode;
124 -----------------------------
125 -- Scan_Front_End_Switches --
126 -----------------------------
128 procedure Scan_Front_End_Switches
129 (Switch_Chars : String;
130 Args : String_List;
131 Arg_Rank : Positive)
133 First_Switch : Boolean := True;
134 -- False for all but first switch
136 Max : constant Natural := Switch_Chars'Last;
137 Ptr : Natural;
138 C : Character := ' ';
139 Dot : Boolean;
141 Store_Switch : Boolean;
142 -- For -gnatxx switches, the normal processing, signalled by this flag
143 -- being set to True, is to store the switch on exit from the case
144 -- statement, the switch stored is -gnat followed by the characters
145 -- from First_Char to Ptr-1. For cases like -gnaty, where the switch
146 -- is stored in separate pieces, this flag is set to False, and the
147 -- appropriate calls to Store_Compilation_Switch are made from within
148 -- the case branch.
150 First_Char : Positive;
151 -- Marks start of switch to be stored
153 begin
154 Ptr := Switch_Chars'First;
156 -- Skip past the initial character (must be the switch character)
158 if Ptr = Max then
159 Bad_Switch (C);
160 else
161 Ptr := Ptr + 1;
162 end if;
164 -- Handle switches that do not start with -gnat
166 if Ptr + 3 > Max or else Switch_Chars (Ptr .. Ptr + 3) /= "gnat" then
168 -- There are two front-end switches that do not start with -gnat:
169 -- -I, --RTS
171 if Switch_Chars (Ptr) = 'I' then
173 -- Set flag Search_Directory_Present if switch is "-I" only:
174 -- the directory will be the next argument.
176 if Ptr = Max then
177 Search_Directory_Present := True;
178 return;
179 end if;
181 Ptr := Ptr + 1;
183 -- Find out whether this is a -I- or regular -Ixxx switch
185 -- Note: -I switches are not recorded in the ALI file, since the
186 -- meaning of the program depends on the source files compiled,
187 -- not where they came from.
189 if Ptr = Max and then Switch_Chars (Ptr) = '-' then
190 Look_In_Primary_Dir := False;
191 else
192 Add_Src_Search_Dir (Switch_Chars (Ptr .. Max));
193 end if;
195 -- Processing of the --RTS switch. --RTS may have been modified by
196 -- gcc into -fRTS (for GCC targets).
198 elsif Ptr + 3 <= Max
199 and then (Switch_Chars (Ptr .. Ptr + 3) = "fRTS"
200 or else
201 Switch_Chars (Ptr .. Ptr + 3) = "-RTS")
202 then
203 Ptr := Ptr + 1;
205 if Ptr + 4 > Max
206 or else Switch_Chars (Ptr + 3) /= '='
207 then
208 Osint.Fail ("missing path for --RTS");
209 else
210 -- Check that this is the first time --RTS is specified or if
211 -- it is not the first time, the same path has been specified.
213 if RTS_Specified = null then
214 RTS_Specified := new String'(Switch_Chars (Ptr + 4 .. Max));
216 elsif
217 RTS_Specified.all /= Switch_Chars (Ptr + 4 .. Max)
218 then
219 Osint.Fail ("--RTS cannot be specified multiple times");
220 end if;
222 -- Valid --RTS switch
224 Opt.No_Stdinc := True;
225 Opt.RTS_Switch := True;
227 RTS_Src_Path_Name :=
228 Get_RTS_Search_Dir
229 (Switch_Chars (Ptr + 4 .. Max), Include);
231 RTS_Lib_Path_Name :=
232 Get_RTS_Search_Dir
233 (Switch_Chars (Ptr + 4 .. Max), Objects);
235 if RTS_Src_Path_Name /= null
236 and then RTS_Lib_Path_Name /= null
237 then
238 -- Store the -fRTS switch (Note: Store_Compilation_Switch
239 -- changes -fRTS back into --RTS for the actual output).
241 Store_Compilation_Switch (Switch_Chars);
243 elsif RTS_Src_Path_Name = null
244 and then RTS_Lib_Path_Name = null
245 then
246 Osint.Fail ("RTS path not valid: missing " &
247 "adainclude and adalib directories");
249 elsif RTS_Src_Path_Name = null then
250 Osint.Fail ("RTS path not valid: missing " &
251 "adainclude directory");
253 elsif RTS_Lib_Path_Name = null then
254 Osint.Fail ("RTS path not valid: missing " &
255 "adalib directory");
256 end if;
257 end if;
259 -- There are no other switches not starting with -gnat
261 else
262 Bad_Switch (Switch_Chars);
263 end if;
265 -- Case of switch starting with -gnat
267 else
268 Ptr := Ptr + 4;
270 -- Loop to scan through switches given in switch string
272 while Ptr <= Max loop
273 First_Char := Ptr;
274 Store_Switch := True;
276 C := Switch_Chars (Ptr);
278 case C is
280 when 'a' =>
281 Ptr := Ptr + 1;
282 Assertions_Enabled := True;
283 Debug_Pragmas_Enabled := True;
285 -- Processing for A switch
287 when 'A' =>
288 Ptr := Ptr + 1;
289 Config_File := False;
291 -- Processing for b switch
293 when 'b' =>
294 Ptr := Ptr + 1;
295 Brief_Output := True;
297 -- Processing for B switch
299 when 'B' =>
300 Ptr := Ptr + 1;
301 Assume_No_Invalid_Values := True;
303 -- Processing for c switch
305 when 'c' =>
306 if not First_Switch then
307 Osint.Fail
308 ("-gnatc must be first if combined with other switches");
309 end if;
311 Ptr := Ptr + 1;
312 Operating_Mode := Check_Semantics;
314 -- Processing for C switch
316 when 'C' =>
317 Ptr := Ptr + 1;
319 if not CodePeer_Mode then
320 CodePeer_Mode := True;
322 -- Suppress compiler warnings by default, since what we are
323 -- interested in here is what CodePeer can find out. Note
324 -- that if -gnatwxxx is specified after -gnatC on the
325 -- command line, we do not want to override this setting in
326 -- Adjust_Global_Switches, and assume that the user wants to
327 -- get both warnings from GNAT and CodePeer messages.
329 Warning_Mode := Suppress;
330 end if;
332 -- Processing for d switch
334 when 'd' =>
335 Store_Switch := False;
336 Dot := False;
338 -- Note: for the debug switch, the remaining characters in this
339 -- switch field must all be debug flags, since all valid switch
340 -- characters are also valid debug characters.
342 -- Loop to scan out debug flags
344 while Ptr < Max loop
345 Ptr := Ptr + 1;
346 C := Switch_Chars (Ptr);
347 exit when C = ASCII.NUL or else C = '/' or else C = '-';
349 if C in '1' .. '9' or else
350 C in 'a' .. 'z' or else
351 C in 'A' .. 'Z'
352 then
353 if Dot then
354 Set_Dotted_Debug_Flag (C);
355 Store_Compilation_Switch ("-gnatd." & C);
356 else
357 Set_Debug_Flag (C);
358 Store_Compilation_Switch ("-gnatd" & C);
359 end if;
361 elsif C = '.' then
362 Dot := True;
364 elsif Dot then
365 Bad_Switch ("-gnatd." & Switch_Chars (Ptr .. Max));
366 else
367 Bad_Switch ("-gnatd" & Switch_Chars (Ptr .. Max));
368 end if;
369 end loop;
371 return;
373 -- Processing for D switch
375 when 'D' =>
376 Ptr := Ptr + 1;
378 -- Scan optional integer line limit value
380 if Nat_Present (Switch_Chars, Max, Ptr) then
381 Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'D');
382 Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
383 end if;
385 -- Note: -gnatD also sets -gnatx (to turn off cross-reference
386 -- generation in the ali file) since otherwise this generation
387 -- gets confused by the "wrong" Sloc values put in the tree.
389 Debug_Generated_Code := True;
390 Xref_Active := False;
391 Set_Debug_Flag ('g');
393 -- -gnate? (extended switches)
395 when 'e' =>
396 Ptr := Ptr + 1;
398 -- The -gnate? switches are all double character switches
399 -- so we must always have a character after the e.
401 if Ptr > Max then
402 Bad_Switch ("-gnate");
403 end if;
405 case Switch_Chars (Ptr) is
407 -- -gnatea (initial delimiter of explicit switches)
409 -- All switches that come before -gnatea have been added by
410 -- the GCC driver and are not stored in the ALI file.
411 -- See also -gnatez below.
413 when 'a' =>
414 Store_Switch := False;
415 Enable_Switch_Storing;
416 Ptr := Ptr + 1;
418 -- -gnateA (aliasing checks on parameters)
420 when 'A' =>
421 Ptr := Ptr + 1;
422 Check_Aliasing_Of_Parameters := True;
424 -- -gnatec (configuration pragmas)
426 when 'c' =>
427 Store_Switch := False;
428 Ptr := Ptr + 1;
430 -- There may be an equal sign between -gnatec and
431 -- the path name of the config file.
433 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
434 Ptr := Ptr + 1;
435 end if;
437 if Ptr > Max then
438 Bad_Switch ("-gnatec");
439 end if;
441 declare
442 Config_File_Name : constant String_Access :=
443 new String'
444 (Switch_Chars (Ptr .. Max));
446 begin
447 if Config_File_Names = null then
448 Config_File_Names :=
449 new String_List'(1 => Config_File_Name);
451 else
452 declare
453 New_Names : constant String_List_Access :=
454 new String_List
455 (1 ..
456 Config_File_Names'Length + 1);
458 begin
459 for Index in Config_File_Names'Range loop
460 New_Names (Index) :=
461 Config_File_Names (Index);
462 Config_File_Names (Index) := null;
463 end loop;
465 New_Names (New_Names'Last) := Config_File_Name;
466 Free (Config_File_Names);
467 Config_File_Names := New_Names;
468 end;
469 end if;
470 end;
472 return;
474 -- -gnateC switch (CodePeer SCIL generation)
476 -- Not enabled for now, keep it for later???
477 -- use -gnatd.I only for now
479 -- when 'C' =>
480 -- Ptr := Ptr + 1;
481 -- Generate_SCIL := True;
483 -- -gnated switch (disable atomic synchronization)
485 when 'd' =>
486 Suppress_Options.Suppress (Atomic_Synchronization) :=
487 True;
489 -- -gnateD switch (preprocessing symbol definition)
491 when 'D' =>
492 Store_Switch := False;
493 Ptr := Ptr + 1;
495 if Ptr > Max then
496 Bad_Switch ("-gnateD");
497 end if;
499 Add_Symbol_Definition (Switch_Chars (Ptr .. Max));
501 -- Store the switch
503 Store_Compilation_Switch
504 ("-gnateD" & Switch_Chars (Ptr .. Max));
505 Ptr := Max + 1;
507 -- -gnateE (extra exception information)
509 when 'E' =>
510 Exception_Extra_Info := True;
511 Ptr := Ptr + 1;
513 -- -gnatef (full source path for brief error messages)
515 when 'f' =>
516 Store_Switch := False;
517 Ptr := Ptr + 1;
518 Full_Path_Name_For_Brief_Errors := True;
520 -- -gnateG (save preprocessor output)
522 when 'G' =>
523 Generate_Processed_File := True;
524 Ptr := Ptr + 1;
526 -- -gnatei (max number of instantiations)
528 when 'i' =>
529 Ptr := Ptr + 1;
530 Scan_Pos
531 (Switch_Chars, Max, Ptr, Maximum_Instantiations, C);
533 -- -gnateI (index of unit in multi-unit source)
535 when 'I' =>
536 Ptr := Ptr + 1;
537 Scan_Pos (Switch_Chars, Max, Ptr, Multiple_Unit_Index, C);
539 -- -gnatem (mapping file)
541 when 'm' =>
542 Store_Switch := False;
543 Ptr := Ptr + 1;
545 -- There may be an equal sign between -gnatem and
546 -- the path name of the mapping file.
548 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
549 Ptr := Ptr + 1;
550 end if;
552 if Ptr > Max then
553 Bad_Switch ("-gnatem");
554 end if;
556 Mapping_File_Name :=
557 new String'(Switch_Chars (Ptr .. Max));
558 return;
560 -- -gnateO= (object path file)
562 when 'O' =>
563 Store_Switch := False;
564 Ptr := Ptr + 1;
566 -- Check for '='
568 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
569 Bad_Switch ("-gnateO");
571 else
572 Object_Path_File_Name :=
573 new String'(Switch_Chars (Ptr + 1 .. Max));
574 end if;
576 return;
578 -- -gnatep (preprocessing data file)
580 when 'p' =>
581 Store_Switch := False;
582 Ptr := Ptr + 1;
584 -- There may be an equal sign between -gnatep and
585 -- the path name of the mapping file.
587 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
588 Ptr := Ptr + 1;
589 end if;
591 if Ptr > Max then
592 Bad_Switch ("-gnatep");
593 end if;
595 Preprocessing_Data_File :=
596 new String'(Switch_Chars (Ptr .. Max));
598 -- Store the switch, normalizing to -gnatep=
600 Store_Compilation_Switch
601 ("-gnatep=" & Preprocessing_Data_File.all);
603 Ptr := Max + 1;
605 -- -gnateP (Treat pragma Pure/Preelaborate errs as warnings)
607 when 'P' =>
608 Treat_Categorization_Errors_As_Warnings := True;
610 -- -gnateS (generate SCO information)
612 -- Include Source Coverage Obligation information in ALI
613 -- files for the benefit of source coverage analysis tools
614 -- (xcov).
616 when 'S' =>
617 Generate_SCO := True;
618 Ptr := Ptr + 1;
620 -- -gnateV (validity checks on parameters)
622 when 'V' =>
623 Ptr := Ptr + 1;
624 Check_Validity_Of_Parameters := True;
626 -- -gnatez (final delimiter of explicit switches)
628 -- All switches that come after -gnatez have been added by
629 -- the GCC driver and are not stored in the ALI file. See
630 -- also -gnatea above.
632 when 'z' =>
633 Store_Switch := False;
634 Disable_Switch_Storing;
635 Ptr := Ptr + 1;
637 -- All other -gnate? switches are unassigned
639 when others =>
640 Bad_Switch ("-gnate" & Switch_Chars (Ptr .. Max));
641 end case;
643 -- -gnatE (dynamic elaboration checks)
645 when 'E' =>
646 Ptr := Ptr + 1;
647 Dynamic_Elaboration_Checks := True;
649 -- -gnatf (full error messages)
651 when 'f' =>
652 Ptr := Ptr + 1;
653 All_Errors_Mode := True;
655 -- Processing for F switch
657 when 'F' =>
658 Ptr := Ptr + 1;
659 External_Name_Exp_Casing := Uppercase;
660 External_Name_Imp_Casing := Uppercase;
662 -- Processing for g switch
664 when 'g' =>
665 Ptr := Ptr + 1;
666 GNAT_Mode := True;
667 Identifier_Character_Set := 'n';
668 System_Extend_Unit := Empty;
669 Warning_Mode := Treat_As_Error;
671 -- Set Ada 2012 mode explicitly. We don't want to rely on the
672 -- implicit setting here, since for example, we want
673 -- Preelaborate_05 treated as Preelaborate
675 Ada_Version := Ada_2012;
676 Ada_Version_Explicit := Ada_Version;
678 -- Set default warnings and style checks for -gnatg
680 Set_GNAT_Mode_Warnings;
681 Set_GNAT_Style_Check_Options;
683 -- Processing for G switch
685 when 'G' =>
686 Ptr := Ptr + 1;
687 Print_Generated_Code := True;
689 -- Scan optional integer line limit value
691 if Nat_Present (Switch_Chars, Max, Ptr) then
692 Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'G');
693 Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
694 end if;
696 -- Processing for h switch
698 when 'h' =>
699 Ptr := Ptr + 1;
700 Usage_Requested := True;
702 -- Processing for i switch
704 when 'i' =>
705 if Ptr = Max then
706 Bad_Switch ("-gnati");
707 end if;
709 Ptr := Ptr + 1;
710 C := Switch_Chars (Ptr);
712 if C in '1' .. '5'
713 or else C = '8'
714 or else C = '9'
715 or else C = 'p'
716 or else C = 'f'
717 or else C = 'n'
718 or else C = 'w'
719 then
720 Identifier_Character_Set := C;
721 Ptr := Ptr + 1;
723 else
724 Bad_Switch ("-gnati" & Switch_Chars (Ptr .. Max));
725 end if;
727 -- Processing for I switch
729 when 'I' =>
730 Ptr := Ptr + 1;
731 Ignore_Rep_Clauses := True;
733 -- Processing for j switch
735 when 'j' =>
736 Ptr := Ptr + 1;
737 Scan_Nat (Switch_Chars, Max, Ptr, Error_Msg_Line_Length, C);
739 -- Processing for k switch
741 when 'k' =>
742 Ptr := Ptr + 1;
743 Scan_Pos
744 (Switch_Chars, Max, Ptr, Maximum_File_Name_Length, C);
746 -- Processing for l switch
748 when 'l' =>
749 Ptr := Ptr + 1;
750 Full_List := True;
752 -- There may be an equal sign between -gnatl and a file name
754 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
755 if Ptr = Max then
756 Osint.Fail ("file name for -gnatl= is null");
757 else
758 Opt.Full_List_File_Name :=
759 new String'(Switch_Chars (Ptr + 1 .. Max));
760 Ptr := Max + 1;
761 end if;
762 end if;
764 -- Processing for L switch
766 when 'L' =>
767 Ptr := Ptr + 1;
768 Dump_Source_Text := True;
770 -- Processing for m switch
772 when 'm' =>
773 Ptr := Ptr + 1;
774 Scan_Nat (Switch_Chars, Max, Ptr, Maximum_Messages, C);
776 -- Processing for n switch
778 when 'n' =>
779 Ptr := Ptr + 1;
780 Inline_Active := True;
782 -- There may be a digit (1 or 2) appended to the switch
784 if Ptr <= Max then
785 C := Switch_Chars (Ptr);
787 if C in '1' .. '2' then
788 Ptr := Ptr + 1;
789 Inline_Level := Character'Pos (C) - Character'Pos ('0');
790 end if;
791 end if;
793 -- Processing for N switch
795 when 'N' =>
796 Ptr := Ptr + 1;
797 Inline_Active := True;
798 Front_End_Inlining := True;
800 -- Processing for o switch
802 when 'o' =>
803 Ptr := Ptr + 1;
805 -- Case of no digits after the -gnato
807 if Ptr > Max or else Switch_Chars (Ptr) not in '0' .. '3' then
808 Suppress_Options.Overflow_Checks_General := Checked;
809 Suppress_Options.Overflow_Checks_Assertions := Checked;
811 -- At least one digit after the -gnato
813 else
814 -- Handle first digit after -gnato
816 Suppress_Options.Overflow_Checks_General :=
817 Get_Overflow_Mode (Switch_Chars (Ptr));
818 Ptr := Ptr + 1;
820 -- Only one digit after -gnato, set assertions mode to
821 -- be the same as general mode.
823 if Ptr > Max
824 or else Switch_Chars (Ptr) not in '0' .. '3'
825 then
826 Suppress_Options.Overflow_Checks_Assertions :=
827 Suppress_Options.Overflow_Checks_General;
829 -- Process second digit after -gnato
831 else
832 Suppress_Options.Overflow_Checks_Assertions :=
833 Get_Overflow_Mode (Switch_Chars (Ptr));
834 Ptr := Ptr + 1;
835 end if;
836 end if;
838 -- Processing for O switch
840 when 'O' =>
841 Store_Switch := False;
842 Ptr := Ptr + 1;
843 Output_File_Name_Present := True;
845 -- Processing for p switch
847 when 'p' =>
848 Ptr := Ptr + 1;
850 -- Skip processing if cancelled by subsequent -gnat-p
852 if Switch_Subsequently_Cancelled ("p", Args, Arg_Rank) then
853 Store_Switch := False;
855 else
856 -- Set all specific options as well as All_Checks in the
857 -- Suppress_Options array, excluding Elaboration_Check,
858 -- since this is treated specially because we do not want
859 -- -gnatp to disable static elaboration processing. Also
860 -- exclude Atomic_Synchronization, since this is not a real
861 -- check.
863 for J in Suppress_Options.Suppress'Range loop
864 if J /= Elaboration_Check
865 and then
866 J /= Atomic_Synchronization
867 then
868 Suppress_Options.Suppress (J) := True;
869 end if;
871 Suppress_Options.Overflow_Checks_General := Suppressed;
872 Suppress_Options.Overflow_Checks_Assertions := Suppressed;
873 end loop;
875 Validity_Checks_On := False;
876 Opt.Suppress_Checks := True;
877 end if;
879 -- Processing for P switch
881 when 'P' =>
882 Ptr := Ptr + 1;
883 Polling_Required := True;
885 -- Processing for q switch
887 when 'q' =>
888 Ptr := Ptr + 1;
889 Try_Semantics := True;
891 -- Processing for Q switch
893 when 'Q' =>
894 Ptr := Ptr + 1;
895 Force_ALI_Tree_File := True;
896 Try_Semantics := True;
898 -- Processing for r switch
900 when 'r' =>
901 Ptr := Ptr + 1;
902 Treat_Restrictions_As_Warnings := True;
904 -- Processing for R switch
906 when 'R' =>
907 Back_Annotate_Rep_Info := True;
908 List_Representation_Info := 1;
910 Ptr := Ptr + 1;
911 while Ptr <= Max loop
912 C := Switch_Chars (Ptr);
914 if C in '1' .. '3' then
915 List_Representation_Info :=
916 Character'Pos (C) - Character'Pos ('0');
918 elsif Switch_Chars (Ptr) = 's' then
919 List_Representation_Info_To_File := True;
921 elsif Switch_Chars (Ptr) = 'm' then
922 List_Representation_Info_Mechanisms := True;
924 else
925 Bad_Switch ("-gnatR" & Switch_Chars (Ptr .. Max));
926 end if;
928 Ptr := Ptr + 1;
929 end loop;
931 -- Processing for s switch
933 when 's' =>
934 if not First_Switch then
935 Osint.Fail
936 ("-gnats must be first if combined with other switches");
937 end if;
939 Ptr := Ptr + 1;
940 Operating_Mode := Check_Syntax;
942 -- Processing for S switch
944 when 'S' =>
945 Print_Standard := True;
946 Ptr := Ptr + 1;
948 -- Processing for t switch
950 when 't' =>
951 Ptr := Ptr + 1;
952 Tree_Output := True;
953 Back_Annotate_Rep_Info := True;
955 -- Processing for T switch
957 when 'T' =>
958 Ptr := Ptr + 1;
959 Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor, C);
961 -- Processing for u switch
963 when 'u' =>
964 Ptr := Ptr + 1;
965 List_Units := True;
967 -- Processing for U switch
969 when 'U' =>
970 Ptr := Ptr + 1;
971 Unique_Error_Tag := True;
973 -- Processing for v switch
975 when 'v' =>
976 Ptr := Ptr + 1;
977 Verbose_Mode := True;
979 -- Processing for V switch
981 when 'V' =>
982 Store_Switch := False;
983 Ptr := Ptr + 1;
985 if Ptr > Max then
986 Bad_Switch ("-gnatV");
988 else
989 declare
990 OK : Boolean;
992 begin
993 Set_Validity_Check_Options
994 (Switch_Chars (Ptr .. Max), OK, Ptr);
996 if not OK then
997 Bad_Switch ("-gnatV" & Switch_Chars (Ptr .. Max));
998 end if;
1000 for Index in First_Char + 1 .. Max loop
1001 Store_Compilation_Switch
1002 ("-gnatV" & Switch_Chars (Index));
1003 end loop;
1004 end;
1005 end if;
1007 Ptr := Max + 1;
1009 -- Processing for w switch
1011 when 'w' =>
1012 Store_Switch := False;
1013 Ptr := Ptr + 1;
1015 if Ptr > Max then
1016 Bad_Switch ("-gnatw");
1017 end if;
1019 while Ptr <= Max loop
1020 C := Switch_Chars (Ptr);
1022 -- Case of dot switch
1024 if C = '.' and then Ptr < Max then
1025 Ptr := Ptr + 1;
1026 C := Switch_Chars (Ptr);
1028 if Set_Dot_Warning_Switch (C) then
1029 Store_Compilation_Switch ("-gnatw." & C);
1030 else
1031 Bad_Switch ("-gnatw." & Switch_Chars (Ptr .. Max));
1032 end if;
1034 -- Normal case, no dot
1036 else
1037 if Set_Warning_Switch (C) then
1038 Store_Compilation_Switch ("-gnatw" & C);
1039 else
1040 Bad_Switch ("-gnatw" & Switch_Chars (Ptr .. Max));
1041 end if;
1042 end if;
1044 Ptr := Ptr + 1;
1045 end loop;
1047 return;
1049 -- Processing for W switch
1051 when 'W' =>
1052 Ptr := Ptr + 1;
1054 if Ptr > Max then
1055 Bad_Switch ("-gnatW");
1056 end if;
1058 begin
1059 Wide_Character_Encoding_Method :=
1060 Get_WC_Encoding_Method (Switch_Chars (Ptr));
1061 exception
1062 when Constraint_Error =>
1063 Bad_Switch ("-gnatW" & Switch_Chars (Ptr .. Max));
1064 end;
1066 Wide_Character_Encoding_Method_Specified := True;
1068 Upper_Half_Encoding :=
1069 Wide_Character_Encoding_Method in
1070 WC_Upper_Half_Encoding_Method;
1072 Ptr := Ptr + 1;
1074 -- Processing for x switch
1076 when 'x' =>
1077 Ptr := Ptr + 1;
1078 Xref_Active := False;
1080 -- Processing for X switch
1082 when 'X' =>
1083 Ptr := Ptr + 1;
1084 Extensions_Allowed := True;
1085 Ada_Version := Ada_Version_Type'Last;
1086 Ada_Version_Explicit := Ada_Version_Type'Last;
1088 -- Processing for y switch
1090 when 'y' =>
1091 Ptr := Ptr + 1;
1093 if Ptr > Max then
1094 Set_Default_Style_Check_Options;
1096 else
1097 Store_Switch := False;
1099 declare
1100 OK : Boolean;
1102 begin
1103 Set_Style_Check_Options
1104 (Switch_Chars (Ptr .. Max), OK, Ptr);
1106 if not OK then
1107 Osint.Fail
1108 ("bad -gnaty switch (" &
1109 Style_Msg_Buf (1 .. Style_Msg_Len) & ')');
1110 end if;
1112 Ptr := First_Char + 1;
1113 while Ptr <= Max loop
1114 if Switch_Chars (Ptr) = 'M' then
1115 First_Char := Ptr;
1116 loop
1117 Ptr := Ptr + 1;
1118 exit when Ptr > Max
1119 or else Switch_Chars (Ptr) not in '0' .. '9';
1120 end loop;
1122 Store_Compilation_Switch
1123 ("-gnaty" & Switch_Chars (First_Char .. Ptr - 1));
1125 else
1126 Store_Compilation_Switch
1127 ("-gnaty" & Switch_Chars (Ptr));
1128 Ptr := Ptr + 1;
1129 end if;
1130 end loop;
1131 end;
1132 end if;
1134 -- Processing for z switch
1136 when 'z' =>
1138 -- -gnatz must be the first and only switch in Switch_Chars,
1139 -- and is a two-letter switch.
1141 if Ptr /= Switch_Chars'First + 5
1142 or else (Max - Ptr + 1) > 2
1143 then
1144 Osint.Fail
1145 ("-gnatz* may not be combined with other switches");
1146 end if;
1148 if Ptr = Max then
1149 Bad_Switch ("-gnatz");
1150 end if;
1152 Ptr := Ptr + 1;
1154 -- Only one occurrence of -gnat* is permitted
1156 if Distribution_Stub_Mode = No_Stubs then
1157 case Switch_Chars (Ptr) is
1158 when 'r' =>
1159 Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
1161 when 'c' =>
1162 Distribution_Stub_Mode := Generate_Caller_Stub_Body;
1164 when others =>
1165 Bad_Switch ("-gnatz" & Switch_Chars (Ptr .. Max));
1166 end case;
1168 Ptr := Ptr + 1;
1170 else
1171 Osint.Fail ("only one -gnatz* switch allowed");
1172 end if;
1174 -- Processing for Z switch
1176 when 'Z' =>
1177 Ptr := Ptr + 1;
1178 Osint.Fail
1179 ("-gnatZ is no longer supported: consider using --RTS=zcx");
1181 -- Note on language version switches: whenever a new language
1182 -- version switch is added, Switch.M.Normalize_Compiler_Switches
1183 -- must be updated.
1185 -- Processing for 83 switch
1187 when '8' =>
1188 if Ptr = Max then
1189 Bad_Switch ("-gnat8");
1190 end if;
1192 Ptr := Ptr + 1;
1194 if Switch_Chars (Ptr) /= '3' then
1195 Bad_Switch ("-gnat8" & Switch_Chars (Ptr .. Max));
1196 else
1197 Ptr := Ptr + 1;
1198 Ada_Version := Ada_83;
1199 Ada_Version_Explicit := Ada_Version;
1200 end if;
1202 -- Processing for 95 switch
1204 when '9' =>
1205 if Ptr = Max then
1206 Bad_Switch ("-gnat9");
1207 end if;
1209 Ptr := Ptr + 1;
1211 if Switch_Chars (Ptr) /= '5' then
1212 Bad_Switch ("-gnat9" & Switch_Chars (Ptr .. Max));
1213 else
1214 Ptr := Ptr + 1;
1215 Ada_Version := Ada_95;
1216 Ada_Version_Explicit := Ada_Version;
1217 end if;
1219 -- Processing for 05 switch
1221 when '0' =>
1222 if Ptr = Max then
1223 Bad_Switch ("-gnat0");
1224 end if;
1226 Ptr := Ptr + 1;
1228 if Switch_Chars (Ptr) /= '5' then
1229 Bad_Switch ("-gnat0" & Switch_Chars (Ptr .. Max));
1230 else
1231 Ptr := Ptr + 1;
1232 Ada_Version := Ada_2005;
1233 Ada_Version_Explicit := Ada_Version;
1234 end if;
1236 -- Processing for 12 switch
1238 when '1' =>
1239 if Ptr = Max then
1240 Bad_Switch ("-gnat1");
1241 end if;
1243 Ptr := Ptr + 1;
1245 if Switch_Chars (Ptr) /= '2' then
1246 Bad_Switch ("-gnat1" & Switch_Chars (Ptr .. Max));
1247 else
1248 Ptr := Ptr + 1;
1249 Ada_Version := Ada_2012;
1250 Ada_Version_Explicit := Ada_Version;
1251 end if;
1253 -- Processing for 2005 and 2012 switches
1255 when '2' =>
1256 if Ptr > Max - 3 then
1257 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
1259 elsif Switch_Chars (Ptr .. Ptr + 3) = "2005" then
1260 Ada_Version := Ada_2005;
1262 elsif Switch_Chars (Ptr .. Ptr + 3) = "2012" then
1263 Ada_Version := Ada_2012;
1265 else
1266 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Ptr + 3));
1267 end if;
1269 Ada_Version_Explicit := Ada_Version;
1270 Ptr := Ptr + 4;
1272 -- Switch cancellation, currently only -gnat-p is allowed.
1273 -- All we do here is the error checking, since the actual
1274 -- processing for switch cancellation is done by calls to
1275 -- Switch_Subsequently_Cancelled at the appropriate point.
1277 when '-' =>
1279 -- Simple ignore -gnat-p
1281 if Switch_Chars = "-gnat-p" then
1282 return;
1284 -- Any other occurrence of minus is ignored. This is for
1285 -- maximum compatibility with previous version which ignored
1286 -- all occurrences of minus.
1288 else
1289 Store_Switch := False;
1290 Ptr := Ptr + 1;
1291 end if;
1293 -- We ignore '/' in switches, this is historical, still needed???
1295 when '/' =>
1296 Store_Switch := False;
1298 -- Anything else is an error (illegal switch character)
1300 when others =>
1301 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
1302 end case;
1304 if Store_Switch then
1305 Store_Compilation_Switch
1306 ("-gnat" & Switch_Chars (First_Char .. Ptr - 1));
1307 end if;
1309 First_Switch := False;
1310 end loop;
1311 end if;
1312 end Scan_Front_End_Switches;
1314 -----------------------------------
1315 -- Switch_Subsequently_Cancelled --
1316 -----------------------------------
1318 function Switch_Subsequently_Cancelled
1319 (C : String;
1320 Args : String_List;
1321 Arg_Rank : Positive) return Boolean
1323 begin
1324 -- Loop through arguments following the current one
1326 for Arg in Arg_Rank + 1 .. Args'Last loop
1327 if Args (Arg).all = "-gnat-" & C then
1328 return True;
1329 end if;
1330 end loop;
1332 -- No match found, not cancelled
1334 return False;
1335 end Switch_Subsequently_Cancelled;
1337 end Switch.C;