1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2015, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
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;
32 with Osint; use Osint;
34 with Stylesw; use Stylesw;
35 with Targparm; use Targparm;
36 with Ttypes; use Ttypes;
37 with Validsw; use Validsw;
38 with Warnsw; use Warnsw;
40 with Ada.Unchecked_Deallocation;
42 with System.WCh_Con; use System.WCh_Con;
45 package body Switch.C is
47 RTS_Specified : String_Access := null;
48 -- Used to detect multiple use of --RTS= flag
50 procedure Add_Symbol_Definition (Def : String);
51 -- Add a symbol definition from the command line
54 new Ada.Unchecked_Deallocation (String_List, String_List_Access);
55 -- Avoid using System.Strings.Free, which also frees the designated strings
57 function Get_Overflow_Mode (C : Character) return Overflow_Mode_Type;
58 -- Given a digit in the range 0 .. 3, returns the corresponding value of
59 -- Overflow_Mode_Type. Raises Program_Error if C is outside this range.
61 function Switch_Subsequently_Cancelled
64 Arg_Rank : Positive) return Boolean;
65 -- This function is called from Scan_Front_End_Switches. It determines if
66 -- the switch currently being scanned is followed by a switch of the form
67 -- "-gnat-" & C, where C is the argument. If so, then True is returned,
68 -- and Scan_Front_End_Switches will cancel the effect of the switch. If
69 -- no such switch is found, False is returned.
71 ---------------------------
72 -- Add_Symbol_Definition --
73 ---------------------------
75 procedure Add_Symbol_Definition (Def : String) is
77 -- If Preprocessor_Symbol_Defs is not large enough, double its size
79 if Preprocessing_Symbol_Last = Preprocessing_Symbol_Defs'Last then
81 New_Symbol_Definitions : constant String_List_Access :=
82 new String_List (1 .. 2 * Preprocessing_Symbol_Last);
84 New_Symbol_Definitions (Preprocessing_Symbol_Defs'Range) :=
85 Preprocessing_Symbol_Defs.all;
86 Free (Preprocessing_Symbol_Defs);
87 Preprocessing_Symbol_Defs := New_Symbol_Definitions;
91 Preprocessing_Symbol_Last := Preprocessing_Symbol_Last + 1;
92 Preprocessing_Symbol_Defs (Preprocessing_Symbol_Last) :=
94 end Add_Symbol_Definition;
96 -----------------------
97 -- Get_Overflow_Mode --
98 -----------------------
100 function Get_Overflow_Mode (C : Character) return Overflow_Mode_Type is
109 -- Eliminated allowed only if Long_Long_Integer is 64 bits (since
110 -- the current implementation of System.Bignums assumes this).
113 if Standard_Long_Long_Integer_Size /= 64 then
114 Bad_Switch ("-gnato3 not implemented for this configuration");
122 end Get_Overflow_Mode;
124 -----------------------------
125 -- Scan_Front_End_Switches --
126 -----------------------------
128 procedure Scan_Front_End_Switches
129 (Switch_Chars : String;
133 First_Switch : Boolean := True;
134 -- False for all but first switch
136 Max : constant Natural := Switch_Chars'Last;
138 C : Character := ' ';
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
150 First_Char : Positive;
151 -- Marks start of switch to be stored
153 First_Ptr : Positive;
154 -- Save position of first character after -gnatd (for checking that
155 -- debug flags that must come first are first, in particular -gnatd.b),
158 Ptr := Switch_Chars'First;
160 -- Skip past the initial character (must be the switch character)
168 -- Handle switches that do not start with -gnat
170 if Ptr + 3 > Max or else Switch_Chars (Ptr .. Ptr + 3) /= "gnat" then
172 -- There are two front-end switches that do not start with -gnat:
175 if Switch_Chars (Ptr) = 'I' then
177 -- Set flag Search_Directory_Present if switch is "-I" only:
178 -- the directory will be the next argument.
181 Search_Directory_Present := True;
187 -- Find out whether this is a -I- or regular -Ixxx switch
189 -- Note: -I switches are not recorded in the ALI file, since the
190 -- meaning of the program depends on the source files compiled,
191 -- not where they came from.
193 if Ptr = Max and then Switch_Chars (Ptr) = '-' then
194 Look_In_Primary_Dir := False;
196 Add_Src_Search_Dir (Switch_Chars (Ptr .. Max));
199 -- Processing of the --RTS switch. --RTS may have been modified by
200 -- gcc into -fRTS (for GCC targets).
203 and then (Switch_Chars (Ptr .. Ptr + 3) = "fRTS"
205 Switch_Chars (Ptr .. Ptr + 3) = "-RTS")
210 or else Switch_Chars (Ptr + 3) /= '='
212 Osint.Fail ("missing path for --RTS");
216 Runtime_Dir : String_Access;
218 if System.OS_Lib.Is_Absolute_Path
219 (Switch_Chars (Ptr + 4 .. Max))
222 new String'(System.OS_Lib.Normalize_Pathname
223 (Switch_Chars (Ptr + 4 .. Max)));
226 new String'(Switch_Chars (Ptr + 4 .. Max));
229 -- Valid --RTS switch
231 Opt.No_Stdinc := True;
232 Opt.RTS_Switch := True;
235 Get_RTS_Search_Dir (Runtime_Dir.all, Include);
238 Get_RTS_Search_Dir (Runtime_Dir.all, Objects);
240 if RTS_Specified /= null then
241 if RTS_Src_Path_Name = null
242 or else RTS_Lib_Path_Name = null
244 System.OS_Lib.Normalize_Pathname
245 (RTS_Specified.all) /=
246 System.OS_Lib.Normalize_Pathname
247 (RTS_Lib_Path_Name.all)
250 ("--RTS cannot be specified multiple times");
253 elsif RTS_Src_Path_Name /= null
254 and then RTS_Lib_Path_Name /= null
256 -- Store the -fRTS switch (Note: Store_Compilation_Switch
257 -- changes -fRTS back into --RTS for the actual output).
259 Store_Compilation_Switch (Switch_Chars);
260 RTS_Specified := new String'(RTS_Lib_Path_Name.all);
262 elsif RTS_Src_Path_Name = null
263 and then RTS_Lib_Path_Name = null
265 Osint.Fail ("RTS path not valid: missing "
266 & "adainclude and adalib directories");
268 elsif RTS_Src_Path_Name = null then
269 Osint.Fail ("RTS path not valid: missing "
270 & "adainclude directory");
272 elsif RTS_Lib_Path_Name = null then
273 Osint.Fail ("RTS path not valid: missing "
274 & "adalib directory");
279 -- There are no other switches not starting with -gnat
282 Bad_Switch (Switch_Chars);
285 -- Case of switch starting with -gnat
290 -- Loop to scan through switches given in switch string
292 while Ptr <= Max loop
294 Store_Switch := True;
296 C := Switch_Chars (Ptr);
300 -- -gnata (assertions enabled)
304 Assertions_Enabled := True;
306 -- -gnatA (disregard gnat.adc)
310 Config_File := False;
312 -- -gnatb (brief messages to stderr)
316 Brief_Output := True;
318 -- -gnatB (assume no invalid values)
322 Assume_No_Invalid_Values := True;
324 -- -gnatc (check syntax and semantics only)
327 if not First_Switch then
329 ("-gnatc must be first if combined with other switches");
333 Operating_Mode := Check_Semantics;
335 -- -gnatC (Generate CodePeer information)
340 if not CodePeer_Mode then
341 CodePeer_Mode := True;
343 -- Suppress compiler warnings by default, since what we are
344 -- interested in here is what CodePeer can find out. Note
345 -- that if -gnatwxxx is specified after -gnatC on the
346 -- command line, we do not want to override this setting in
347 -- Adjust_Global_Switches, and assume that the user wants to
348 -- get both warnings from GNAT and CodePeer messages.
350 Warning_Mode := Suppress;
353 -- -gnatd (compiler debug options)
356 Store_Switch := False;
358 First_Ptr := Ptr + 1;
360 -- Note: for the debug switch, the remaining characters in this
361 -- switch field must all be debug flags, since all valid switch
362 -- characters are also valid debug characters.
364 -- Loop to scan out debug flags
368 C := Switch_Chars (Ptr);
369 exit when C = ASCII.NUL or else C = '/' or else C = '-';
371 if C in '1' .. '9' or else
372 C in 'a' .. 'z' or else
375 -- Case of dotted flag
378 Set_Dotted_Debug_Flag (C);
379 Store_Compilation_Switch ("-gnatd." & C);
381 -- Special check, -gnatd.b must come first
384 and then (Ptr /= First_Ptr + 1
385 or else not First_Switch)
388 ("-gnatd.b must be first if combined "
389 & "with other switches");
396 Store_Compilation_Switch ("-gnatd" & C);
403 Bad_Switch ("-gnatd." & Switch_Chars (Ptr .. Max));
405 Bad_Switch ("-gnatd" & Switch_Chars (Ptr .. Max));
411 -- -gnatD (debug expanded code)
416 -- Not allowed if previous -gnatR given
418 -- The reason for this prohibition is that the rewriting of
419 -- Sloc values causes strange malfunctions in the tests of
420 -- whether units belong to the main source. This is really a
421 -- bug, but too hard to fix for a marginal capability ???
423 -- The proper fix is to completely redo -gnatD processing so
424 -- that the tree is not messed with, and instead a separate
425 -- table is built on the side for debug information generation.
427 if List_Representation_Info /= 0 then
429 ("-gnatD not permitted since -gnatR given previously");
432 -- Scan optional integer line limit value
434 if Nat_Present (Switch_Chars, Max, Ptr) then
435 Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'D');
436 Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
439 -- Note: -gnatD also sets -gnatx (to turn off cross-reference
440 -- generation in the ali file) since otherwise this generation
441 -- gets confused by the "wrong" Sloc values put in the tree.
443 Debug_Generated_Code := True;
444 Xref_Active := False;
445 Set_Debug_Flag ('g');
447 -- -gnate? (extended switches)
452 -- The -gnate? switches are all double character switches
453 -- so we must always have a character after the e.
456 Bad_Switch ("-gnate");
459 case Switch_Chars (Ptr) is
461 -- -gnatea (initial delimiter of explicit switches)
463 -- This is an internal switch
465 -- All switches that come before -gnatea have been added by
466 -- the GCC driver and are not stored in the ALI file.
467 -- See also -gnatez below.
470 Store_Switch := False;
471 Enable_Switch_Storing;
474 -- -gnateA (aliasing checks on parameters)
478 Check_Aliasing_Of_Parameters := True;
480 -- -gnatec (configuration pragmas)
483 Store_Switch := False;
486 -- There may be an equal sign between -gnatec and
487 -- the path name of the config file.
489 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
494 Bad_Switch ("-gnatec");
498 Config_File_Name : constant String_Access :=
500 (Switch_Chars (Ptr .. Max));
503 if Config_File_Names = null then
505 new String_List'(1 => Config_File_Name);
509 New_Names : constant String_List_Access :=
512 Config_File_Names'Length + 1);
515 for Index in Config_File_Names'Range loop
517 Config_File_Names (Index);
518 Config_File_Names (Index) := null;
521 New_Names (New_Names'Last) := Config_File_Name;
522 Free (Config_File_Names);
523 Config_File_Names := New_Names;
530 -- -gnateC switch (generate CodePeer messages)
534 Generate_CodePeer_Messages := True;
536 -- -gnated switch (disable atomic synchronization)
539 Suppress_Options.Suppress (Atomic_Synchronization) :=
542 -- -gnateD switch (preprocessing symbol definition)
545 Store_Switch := False;
549 Bad_Switch ("-gnateD");
552 Add_Symbol_Definition (Switch_Chars (Ptr .. Max));
556 Store_Compilation_Switch
557 ("-gnateD" & Switch_Chars (Ptr .. Max));
560 -- -gnateE (extra exception information)
563 Exception_Extra_Info := True;
566 -- -gnatef (full source path for brief error messages)
569 Store_Switch := False;
571 Full_Path_Name_For_Brief_Errors := True;
573 -- -gnateF (Check_Float_Overflow)
577 Check_Float_Overflow := not Machine_Overflows_On_Target;
579 -- -gnateg (generate C code)
582 Generate_C_Code := True;
585 -- -gnateG (save preprocessor output)
588 Generate_Processed_File := True;
591 -- -gnatei (max number of instantiations)
596 (Switch_Chars, Max, Ptr, Maximum_Instantiations, C);
598 -- -gnateI (index of unit in multi-unit source)
602 Scan_Pos (Switch_Chars, Max, Ptr, Multiple_Unit_Index, C);
608 Elab_Info_Messages := True;
614 Elab_Info_Messages := False;
616 -- -gnatem (mapping file)
619 Store_Switch := False;
622 -- There may be an equal sign between -gnatem and
623 -- the path name of the mapping file.
625 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
630 Bad_Switch ("-gnatem");
634 new String'(Switch_Chars (Ptr .. Max));
637 -- -gnateO= (object path file)
639 -- This is an internal switch
642 Store_Switch := False;
647 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
648 Bad_Switch ("-gnateO");
650 Object_Path_File_Name :=
651 new String'(Switch_Chars (Ptr + 1 .. Max));
656 -- -gnatep (preprocessing data file)
659 Store_Switch := False;
662 -- There may be an equal sign between -gnatep and
663 -- the path name of the mapping file.
665 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
670 Bad_Switch ("-gnatep");
673 Preprocessing_Data_File :=
674 new String'(Switch_Chars (Ptr .. Max));
676 -- Store the switch, normalizing to -gnatep=
678 Store_Compilation_Switch
679 ("-gnatep=" & Preprocessing_Data_File.all);
683 -- -gnateP (Treat pragma Pure/Preelaborate errs as warnings)
686 Treat_Categorization_Errors_As_Warnings := True;
688 -- -gnates=file (specify extra file switches for gnat2why)
690 -- This is an internal switch
693 if not First_Switch then
695 ("-gnates must not be combined with other switches");
702 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
703 Bad_Switch ("-gnates");
705 SPARK_Switches_File_Name :=
706 new String'(Switch_Chars (Ptr + 1 .. Max));
711 -- -gnateS (generate SCO information)
713 -- Include Source Coverage Obligation information in ALI
714 -- files for use by source coverage analysis tools
715 -- (gnatcov) (equivalent to -fdump-scos, provided for
716 -- backwards compatibility).
719 Generate_SCO := True;
720 Generate_SCO_Instance_Table := True;
723 -- -gnatet (write target dependent information)
726 if not First_Switch then
728 ("-gnatet must not be combined with other switches");
735 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
736 Bad_Switch ("-gnatet");
738 Target_Dependent_Info_Write_Name :=
739 new String'(Switch_Chars (Ptr + 1 .. Max));
744 -- -gnateT (read target dependent information)
747 if not First_Switch then
749 ("-gnateT must not be combined with other switches");
756 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
757 Bad_Switch ("-gnateT");
759 -- This parameter was stored by Set_Targ earlier
762 (Target_Dependent_Info_Read_Name.all =
763 Switch_Chars (Ptr + 1 .. Max));
769 -- -gnateu (unrecognized y,V,w switches)
773 Ignore_Unrecognized_VWY_Switches := True;
775 -- -gnateV (validity checks on parameters)
779 Check_Validity_Of_Parameters := True;
781 -- -gnateY (ignore Style_Checks pragmas)
784 Ignore_Style_Checks_Pragmas := True;
787 -- -gnatez (final delimiter of explicit switches)
789 -- This is an internal switch
791 -- All switches that come after -gnatez have been added by
792 -- the GCC driver and are not stored in the ALI file. See
793 -- also -gnatea above.
796 Store_Switch := False;
797 Disable_Switch_Storing;
800 -- All other -gnate? switches are unassigned
803 Bad_Switch ("-gnate" & Switch_Chars (Ptr .. Max));
806 -- -gnatE (dynamic elaboration checks)
810 Dynamic_Elaboration_Checks := True;
812 -- -gnatf (full error messages)
816 All_Errors_Mode := True;
818 -- -gnatF (overflow of predefined float types)
822 External_Name_Exp_Casing := Uppercase;
823 External_Name_Imp_Casing := Uppercase;
825 -- -gnatg (GNAT implementation mode)
830 GNAT_Mode_Config := True;
831 Identifier_Character_Set := 'n';
832 System_Extend_Unit := Empty;
833 Warning_Mode := Treat_As_Error;
834 Style_Check_Main := True;
835 Ada_Version := Ada_2012;
836 Ada_Version_Explicit := Ada_2012;
837 Ada_Version_Pragma := Empty;
839 -- Set default warnings and style checks for -gnatg
841 Set_GNAT_Mode_Warnings;
842 Set_GNAT_Style_Check_Options;
844 -- -gnatG (output generated code)
848 Print_Generated_Code := True;
850 -- Scan optional integer line limit value
852 if Nat_Present (Switch_Chars, Max, Ptr) then
853 Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'G');
854 Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
857 -- -gnath (help information)
861 Usage_Requested := True;
863 -- -gnati (character set)
867 Bad_Switch ("-gnati");
871 C := Switch_Chars (Ptr);
881 Identifier_Character_Set := C;
885 Bad_Switch ("-gnati" & Switch_Chars (Ptr .. Max));
888 -- -gnatI (ignore representation clauses)
892 Ignore_Rep_Clauses := True;
894 -- -gnatj (messages in limited length lines)
898 Scan_Nat (Switch_Chars, Max, Ptr, Error_Msg_Line_Length, C);
900 -- -gnatk (limit file name length)
905 (Switch_Chars, Max, Ptr, Maximum_File_Name_Length, C);
907 -- -gnatl (output full source)
913 -- There may be an equal sign between -gnatl and a file name
915 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
917 Osint.Fail ("file name for -gnatl= is null");
919 Opt.Full_List_File_Name :=
920 new String'(Switch_Chars (Ptr + 1 .. Max));
925 -- -gnatL (corresponding source text)
929 Dump_Source_Text := True;
931 -- -gnatm (max number or errors/warnings)
935 Scan_Nat (Switch_Chars, Max, Ptr, Maximum_Messages, C);
937 -- -gnatn (enable pragma Inline)
941 Inline_Active := True;
943 -- There may be a digit (1 or 2) appended to the switch
946 C := Switch_Chars (Ptr);
948 if C in '1' .. '2' then
950 Inline_Level := Character'Pos (C) - Character'Pos ('0');
954 -- -gnatN (obsolescent)
958 Inline_Active := True;
959 Front_End_Inlining := True;
961 -- -gnato (overflow checks)
966 -- Case of -gnato0 (overflow checking turned off)
968 if Ptr <= Max and then Switch_Chars (Ptr) = '0' then
970 Suppress_Options.Suppress (Overflow_Check) := True;
972 -- We set strict mode in case overflow checking is turned
973 -- on locally (also records that we had a -gnato switch).
975 Suppress_Options.Overflow_Mode_General := Strict;
976 Suppress_Options.Overflow_Mode_Assertions := Strict;
978 -- All cases other than -gnato0 (overflow checking turned on)
981 Suppress_Options.Suppress (Overflow_Check) := False;
983 -- Case of no digits after the -gnato
986 or else Switch_Chars (Ptr) not in '1' .. '3'
988 Suppress_Options.Overflow_Mode_General := Strict;
989 Suppress_Options.Overflow_Mode_Assertions := Strict;
991 -- At least one digit after the -gnato
994 -- Handle first digit after -gnato
996 Suppress_Options.Overflow_Mode_General :=
997 Get_Overflow_Mode (Switch_Chars (Ptr));
1000 -- Only one digit after -gnato, set assertions mode to be
1001 -- the same as general mode.
1004 or else Switch_Chars (Ptr) not in '1' .. '3'
1006 Suppress_Options.Overflow_Mode_Assertions :=
1007 Suppress_Options.Overflow_Mode_General;
1009 -- Process second digit after -gnato
1012 Suppress_Options.Overflow_Mode_Assertions :=
1013 Get_Overflow_Mode (Switch_Chars (Ptr));
1019 -- -gnatO (specify name of the object file)
1021 -- This is an internal switch
1024 Store_Switch := False;
1026 Output_File_Name_Present := True;
1028 -- -gnatp (suppress all checks)
1033 -- Skip processing if cancelled by subsequent -gnat-p
1035 if Switch_Subsequently_Cancelled ("p", Args, Arg_Rank) then
1036 Store_Switch := False;
1039 -- Set all specific options as well as All_Checks in the
1040 -- Suppress_Options array, excluding Elaboration_Check,
1041 -- since this is treated specially because we do not want
1042 -- -gnatp to disable static elaboration processing. Also
1043 -- exclude Atomic_Synchronization, since this is not a real
1046 for J in Suppress_Options.Suppress'Range loop
1047 if J /= Elaboration_Check
1049 J /= Atomic_Synchronization
1051 Suppress_Options.Suppress (J) := True;
1055 Validity_Checks_On := False;
1056 Opt.Suppress_Checks := True;
1058 -- Set overflow mode checking to strict in case it gets
1059 -- turned on locally (also signals that overflow checking
1060 -- has been specifically turned off).
1062 Suppress_Options.Overflow_Mode_General := Strict;
1063 Suppress_Options.Overflow_Mode_Assertions := Strict;
1066 -- -gnatP (periodic poll)
1070 Polling_Required := True;
1072 -- -gnatq (don't quit)
1076 Try_Semantics := True;
1078 -- -gnatQ (always write ALI file)
1082 Force_ALI_Tree_File := True;
1083 Try_Semantics := True;
1085 -- -gnatr (restrictions as warnings)
1089 Treat_Restrictions_As_Warnings := True;
1091 -- -gnatR (list rep. info)
1095 -- Not allowed if previous -gnatD given. See more extensive
1096 -- comments in the 'D' section for the inverse test.
1098 if Debug_Generated_Code then
1100 ("-gnatR not permitted since -gnatD given previously");
1103 -- Set to annotate rep info, and set default -gnatR mode
1105 Back_Annotate_Rep_Info := True;
1106 List_Representation_Info := 1;
1108 -- Scan possible parameter
1111 while Ptr <= Max loop
1112 C := Switch_Chars (Ptr);
1114 if C in '1' .. '3' then
1115 List_Representation_Info :=
1116 Character'Pos (C) - Character'Pos ('0');
1118 elsif Switch_Chars (Ptr) = 's' then
1119 List_Representation_Info_To_File := True;
1121 elsif Switch_Chars (Ptr) = 'm' then
1122 List_Representation_Info_Mechanisms := True;
1125 Bad_Switch ("-gnatR" & Switch_Chars (Ptr .. Max));
1131 -- -gnats (syntax check only)
1134 if not First_Switch then
1136 ("-gnats must be first if combined with other switches");
1140 Operating_Mode := Check_Syntax;
1142 -- -gnatS (print package Standard)
1145 Print_Standard := True;
1148 -- -gnatt (output tree)
1152 Tree_Output := True;
1153 Back_Annotate_Rep_Info := True;
1155 -- -gnatT (change start of internal table sizes)
1159 Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor, C);
1161 -- -gnatu (list units for compilation)
1167 -- -gnatU (unique tags)
1171 Unique_Error_Tag := True;
1173 -- -gnatv (verbose mode)
1177 Verbose_Mode := True;
1179 -- -gnatV (validity checks)
1182 Store_Switch := False;
1186 Bad_Switch ("-gnatV");
1193 Set_Validity_Check_Options
1194 (Switch_Chars (Ptr .. Max), OK, Ptr);
1197 Bad_Switch ("-gnatV" & Switch_Chars (Ptr .. Max));
1200 for Index in First_Char + 1 .. Max loop
1201 Store_Compilation_Switch
1202 ("-gnatV" & Switch_Chars (Index));
1209 -- -gnatw (warning modes)
1212 Store_Switch := False;
1216 Bad_Switch ("-gnatw");
1219 while Ptr <= Max loop
1220 C := Switch_Chars (Ptr);
1222 -- Case of dot switch
1224 if C = '.' and then Ptr < Max then
1226 C := Switch_Chars (Ptr);
1228 if Set_Dot_Warning_Switch (C) then
1229 Store_Compilation_Switch ("-gnatw." & C);
1231 Bad_Switch ("-gnatw." & Switch_Chars (Ptr .. Max));
1234 -- Normal case, no dot
1237 if Set_Warning_Switch (C) then
1238 Store_Compilation_Switch ("-gnatw" & C);
1240 Bad_Switch ("-gnatw" & Switch_Chars (Ptr .. Max));
1249 -- -gnatW (wide character encoding method)
1255 Bad_Switch ("-gnatW");
1259 Wide_Character_Encoding_Method :=
1260 Get_WC_Encoding_Method (Switch_Chars (Ptr));
1262 when Constraint_Error =>
1263 Bad_Switch ("-gnatW" & Switch_Chars (Ptr .. Max));
1266 Wide_Character_Encoding_Method_Specified := True;
1268 Upper_Half_Encoding :=
1269 Wide_Character_Encoding_Method in
1270 WC_Upper_Half_Encoding_Method;
1274 -- -gnatx (suppress cross-ref information)
1278 Xref_Active := False;
1280 -- -gnatX (language extensions)
1284 Extensions_Allowed := True;
1285 Ada_Version := Ada_Version_Type'Last;
1286 Ada_Version_Explicit := Ada_Version_Type'Last;
1287 Ada_Version_Pragma := Empty;
1289 -- -gnaty (style checks)
1293 Style_Check_Main := True;
1296 Set_Default_Style_Check_Options;
1299 Store_Switch := False;
1305 Set_Style_Check_Options
1306 (Switch_Chars (Ptr .. Max), OK, Ptr);
1310 ("bad -gnaty switch (" &
1311 Style_Msg_Buf (1 .. Style_Msg_Len) & ')');
1314 Ptr := First_Char + 1;
1315 while Ptr <= Max loop
1316 if Switch_Chars (Ptr) = 'M' then
1321 or else Switch_Chars (Ptr) not in '0' .. '9';
1324 Store_Compilation_Switch
1325 ("-gnaty" & Switch_Chars (First_Char .. Ptr - 1));
1328 Store_Compilation_Switch
1329 ("-gnaty" & Switch_Chars (Ptr));
1336 -- -gnatz (stub generation)
1340 -- -gnatz must be the first and only switch in Switch_Chars,
1341 -- and is a two-letter switch.
1343 if Ptr /= Switch_Chars'First + 5
1344 or else (Max - Ptr + 1) > 2
1347 ("-gnatz* may not be combined with other switches");
1351 Bad_Switch ("-gnatz");
1356 -- Only one occurrence of -gnat* is permitted
1358 if Distribution_Stub_Mode = No_Stubs then
1359 case Switch_Chars (Ptr) is
1361 Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
1364 Distribution_Stub_Mode := Generate_Caller_Stub_Body;
1367 Bad_Switch ("-gnatz" & Switch_Chars (Ptr .. Max));
1373 Osint.Fail ("only one -gnatz* switch allowed");
1376 -- -gnatZ (obsolescent)
1381 ("-gnatZ is no longer supported: consider using --RTS=zcx");
1383 -- Note on language version switches: whenever a new language
1384 -- version switch is added, Switch.M.Normalize_Compiler_Switches
1391 Bad_Switch ("-gnat8");
1396 if Switch_Chars (Ptr) /= '3' then
1397 Bad_Switch ("-gnat8" & Switch_Chars (Ptr .. Max));
1400 Ada_Version := Ada_83;
1401 Ada_Version_Explicit := Ada_83;
1402 Ada_Version_Pragma := Empty;
1409 Bad_Switch ("-gnat9");
1414 if Switch_Chars (Ptr) /= '5' then
1415 Bad_Switch ("-gnat9" & Switch_Chars (Ptr .. Max));
1418 Ada_Version := Ada_95;
1419 Ada_Version_Explicit := Ada_95;
1420 Ada_Version_Pragma := Empty;
1427 Bad_Switch ("-gnat0");
1432 if Switch_Chars (Ptr) /= '5' then
1433 Bad_Switch ("-gnat0" & Switch_Chars (Ptr .. Max));
1436 Ada_Version := Ada_2005;
1437 Ada_Version_Explicit := Ada_2005;
1438 Ada_Version_Pragma := Empty;
1445 Bad_Switch ("-gnat1");
1450 if Switch_Chars (Ptr) /= '2' then
1451 Bad_Switch ("-gnat1" & Switch_Chars (Ptr .. Max));
1454 Ada_Version := Ada_2012;
1455 Ada_Version_Explicit := Ada_2012;
1456 Ada_Version_Pragma := Empty;
1459 -- -gnat2005 and -gnat2012
1462 if Ptr > Max - 3 then
1463 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
1465 elsif Switch_Chars (Ptr .. Ptr + 3) = "2005" then
1466 Ada_Version := Ada_2005;
1468 elsif Switch_Chars (Ptr .. Ptr + 3) = "2012" then
1469 Ada_Version := Ada_2012;
1472 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Ptr + 3));
1475 Ada_Version_Explicit := Ada_Version;
1476 Ada_Version_Pragma := Empty;
1479 -- Switch cancellation, currently only -gnat-p is allowed.
1480 -- All we do here is the error checking, since the actual
1481 -- processing for switch cancellation is done by calls to
1482 -- Switch_Subsequently_Cancelled at the appropriate point.
1486 -- Simple ignore -gnat-p
1488 if Switch_Chars = "-gnat-p" then
1491 -- Any other occurrence of minus is ignored. This is for
1492 -- maximum compatibility with previous version which ignored
1493 -- all occurrences of minus.
1496 Store_Switch := False;
1500 -- We ignore '/' in switches, this is historical, still needed???
1503 Store_Switch := False;
1505 -- Anything else is an error (illegal switch character)
1508 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
1511 if Store_Switch then
1512 Store_Compilation_Switch
1513 ("-gnat" & Switch_Chars (First_Char .. Ptr - 1));
1516 First_Switch := False;
1519 end Scan_Front_End_Switches;
1521 -----------------------------------
1522 -- Switch_Subsequently_Cancelled --
1523 -----------------------------------
1525 function Switch_Subsequently_Cancelled
1528 Arg_Rank : Positive) return Boolean
1531 -- Loop through arguments following the current one
1533 for Arg in Arg_Rank + 1 .. Args'Last loop
1534 if Args (Arg).all = "-gnat-" & C then
1539 -- No match found, not cancelled
1542 end Switch_Subsequently_Cancelled;