1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2016, 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
;
31 with Errout
; use Errout
;
33 with Osint
; use Osint
;
35 with Stylesw
; use Stylesw
;
36 with Targparm
; use Targparm
;
37 with Ttypes
; use Ttypes
;
38 with Validsw
; use Validsw
;
39 with Warnsw
; use Warnsw
;
41 with Ada
.Unchecked_Deallocation
;
43 with System
.WCh_Con
; use System
.WCh_Con
;
46 package body Switch
.C
is
48 RTS_Specified
: String_Access
:= null;
49 -- Used to detect multiple use of --RTS= flag
51 procedure Add_Symbol_Definition
(Def
: String);
52 -- Add a symbol definition from the command line
55 new Ada
.Unchecked_Deallocation
(String_List
, String_List_Access
);
56 -- Avoid using System.Strings.Free, which also frees the designated strings
58 function Get_Overflow_Mode
(C
: Character) return Overflow_Mode_Type
;
59 -- Given a digit in the range 0 .. 3, returns the corresponding value of
60 -- Overflow_Mode_Type. Raises Program_Error if C is outside this range.
62 function Switch_Subsequently_Cancelled
65 Arg_Rank
: Positive) return Boolean;
66 -- This function is called from Scan_Front_End_Switches. It determines if
67 -- the switch currently being scanned is followed by a switch of the form
68 -- "-gnat-" & C, where C is the argument. If so, then True is returned,
69 -- and Scan_Front_End_Switches will cancel the effect of the switch. If
70 -- no such switch is found, False is returned.
72 ---------------------------
73 -- Add_Symbol_Definition --
74 ---------------------------
76 procedure Add_Symbol_Definition
(Def
: String) is
78 -- If Preprocessor_Symbol_Defs is not large enough, double its size
80 if Preprocessing_Symbol_Last
= Preprocessing_Symbol_Defs
'Last then
82 New_Symbol_Definitions
: constant String_List_Access
:=
83 new String_List
(1 .. 2 * Preprocessing_Symbol_Last
);
85 New_Symbol_Definitions
(Preprocessing_Symbol_Defs
'Range) :=
86 Preprocessing_Symbol_Defs
.all;
87 Free
(Preprocessing_Symbol_Defs
);
88 Preprocessing_Symbol_Defs
:= New_Symbol_Definitions
;
92 Preprocessing_Symbol_Last
:= Preprocessing_Symbol_Last
+ 1;
93 Preprocessing_Symbol_Defs
(Preprocessing_Symbol_Last
) :=
95 end Add_Symbol_Definition;
97 -----------------------
98 -- Get_Overflow_Mode --
99 -----------------------
101 function Get_Overflow_Mode (C : Character) return Overflow_Mode_Type is
110 -- Eliminated allowed only if Long_Long_Integer is 64 bits (since
111 -- the current implementation of System.Bignums assumes this).
114 if Standard_Long_Long_Integer_Size /= 64 then
115 Bad_Switch ("-gnato3 not implemented for this configuration");
123 end Get_Overflow_Mode;
125 -----------------------------
126 -- Scan_Front_End_Switches --
127 -----------------------------
129 procedure Scan_Front_End_Switches
130 (Switch_Chars : String;
134 First_Switch : Boolean := True;
135 -- False for all but first switch
137 Max : constant Natural := Switch_Chars'Last;
139 C : Character := ' ';
142 Store_Switch : Boolean;
143 -- For -gnatxx switches, the normal processing, signalled by this flag
144 -- being set to True, is to store the switch on exit from the case
145 -- statement, the switch stored is -gnat followed by the characters
146 -- from First_Char to Ptr-1. For cases like -gnaty, where the switch
147 -- is stored in separate pieces, this flag is set to False, and the
148 -- appropriate calls to Store_Compilation_Switch are made from within
151 First_Char : Positive;
152 -- Marks start of switch to be stored
154 First_Ptr : Positive;
155 -- Save position of first character after -gnatd (for checking that
156 -- debug flags that must come first are first, in particular -gnatd.b),
159 Ptr := Switch_Chars'First;
161 -- Skip past the initial character (must be the switch character)
169 -- Handle switches that do not start with -gnat
171 if Ptr + 3 > Max or else Switch_Chars (Ptr .. Ptr + 3) /= "gnat" then
173 -- There are two front-end switches that do not start with -gnat:
176 if Switch_Chars (Ptr) = 'I
' then
178 -- Set flag Search_Directory_Present if switch is "-I" only:
179 -- the directory will be the next argument.
182 Search_Directory_Present := True;
188 -- Find out whether this is a -I- or regular -Ixxx switch
190 -- Note: -I switches are not recorded in the ALI file, since the
191 -- meaning of the program depends on the source files compiled,
192 -- not where they came from.
194 if Ptr = Max and then Switch_Chars (Ptr) = '-' then
195 Look_In_Primary_Dir := False;
197 Add_Src_Search_Dir (Switch_Chars (Ptr .. Max));
200 -- Processing of the --RTS switch. --RTS may have been modified by
201 -- gcc into -fRTS (for GCC targets).
204 and then (Switch_Chars (Ptr .. Ptr + 3) = "fRTS"
206 Switch_Chars (Ptr .. Ptr + 3) = "-RTS")
211 or else Switch_Chars (Ptr + 3) /= '='
213 Osint.Fail ("missing path for --RTS");
217 Runtime_Dir : String_Access;
219 if System.OS_Lib.Is_Absolute_Path
220 (Switch_Chars (Ptr + 4 .. Max))
223 new String'(System
.OS_Lib
.Normalize_Pathname
224 (Switch_Chars
(Ptr
+ 4 .. Max
)));
227 new String'(Switch_Chars (Ptr + 4 .. Max));
230 -- Valid --RTS switch
232 Opt.No_Stdinc := True;
233 Opt.RTS_Switch := True;
236 Get_RTS_Search_Dir (Runtime_Dir.all, Include);
239 Get_RTS_Search_Dir (Runtime_Dir.all, Objects);
241 if RTS_Specified /= null then
242 if RTS_Src_Path_Name = null
243 or else RTS_Lib_Path_Name = null
245 System.OS_Lib.Normalize_Pathname
246 (RTS_Specified.all) /=
247 System.OS_Lib.Normalize_Pathname
248 (RTS_Lib_Path_Name.all)
251 ("--RTS cannot be specified multiple times");
254 elsif RTS_Src_Path_Name /= null
255 and then RTS_Lib_Path_Name /= null
257 -- Store the -fRTS switch (Note: Store_Compilation_Switch
258 -- changes -fRTS back into --RTS for the actual output).
260 Store_Compilation_Switch (Switch_Chars);
261 RTS_Specified := new String'(RTS_Lib_Path_Name
.all);
263 elsif RTS_Src_Path_Name
= null
264 and then RTS_Lib_Path_Name
= null
266 Osint
.Fail
("RTS path not valid: missing "
267 & "adainclude and adalib directories");
269 elsif RTS_Src_Path_Name
= null then
270 Osint
.Fail
("RTS path not valid: missing "
271 & "adainclude directory");
273 elsif RTS_Lib_Path_Name
= null then
274 Osint
.Fail
("RTS path not valid: missing "
275 & "adalib directory");
280 -- There are no other switches not starting with -gnat
283 Bad_Switch
(Switch_Chars
);
286 -- Case of switch starting with -gnat
291 -- Loop to scan through switches given in switch string
293 while Ptr
<= Max
loop
295 Store_Switch
:= True;
297 C
:= Switch_Chars
(Ptr
);
301 -- -gnata (assertions enabled)
305 Assertions_Enabled
:= True;
307 -- -gnatA (disregard gnat.adc)
311 Config_File
:= False;
313 -- -gnatb (brief messages to stderr)
317 Brief_Output
:= True;
319 -- -gnatB (assume no invalid values)
323 Assume_No_Invalid_Values
:= True;
325 -- -gnatc (check syntax and semantics only)
328 if not First_Switch
then
330 ("-gnatc must be first if combined with other switches");
334 Operating_Mode
:= Check_Semantics
;
336 -- -gnatC (Generate CodePeer information)
341 if not CodePeer_Mode
then
342 CodePeer_Mode
:= True;
344 -- Suppress compiler warnings by default, since what we are
345 -- interested in here is what CodePeer can find out. Note
346 -- that if -gnatwxxx is specified after -gnatC on the
347 -- command line, we do not want to override this setting in
348 -- Adjust_Global_Switches, and assume that the user wants to
349 -- get both warnings from GNAT and CodePeer messages.
351 Warning_Mode
:= Suppress
;
354 -- -gnatd (compiler debug options)
357 Store_Switch
:= False;
359 First_Ptr
:= Ptr
+ 1;
361 -- Note: for the debug switch, the remaining characters in this
362 -- switch field must all be debug flags, since all valid switch
363 -- characters are also valid debug characters.
365 -- Loop to scan out debug flags
369 C
:= Switch_Chars
(Ptr
);
370 exit when C
= ASCII
.NUL
or else C
= '/' or else C
= '-';
372 if C
in '1' .. '9' or else
373 C
in 'a' .. 'z' or else
376 -- Case of dotted flag
379 Set_Dotted_Debug_Flag
(C
);
380 Store_Compilation_Switch
("-gnatd." & C
);
382 -- Special check, -gnatd.b must come first
385 and then (Ptr
/= First_Ptr
+ 1
386 or else not First_Switch
)
389 ("-gnatd.b must be first if combined "
390 & "with other switches");
397 Store_Compilation_Switch
("-gnatd" & C
);
404 Bad_Switch
("-gnatd." & Switch_Chars
(Ptr
.. Max
));
406 Bad_Switch
("-gnatd" & Switch_Chars
(Ptr
.. Max
));
412 -- -gnatD (debug expanded code)
417 -- Not allowed if previous -gnatR given
419 -- The reason for this prohibition is that the rewriting of
420 -- Sloc values causes strange malfunctions in the tests of
421 -- whether units belong to the main source. This is really a
422 -- bug, but too hard to fix for a marginal capability ???
424 -- The proper fix is to completely redo -gnatD processing so
425 -- that the tree is not messed with, and instead a separate
426 -- table is built on the side for debug information generation.
428 if List_Representation_Info
/= 0 then
430 ("-gnatD not permitted since -gnatR given previously");
433 -- Scan optional integer line limit value
435 if Nat_Present
(Switch_Chars
, Max
, Ptr
) then
436 Scan_Nat
(Switch_Chars
, Max
, Ptr
, Sprint_Line_Limit
, 'D');
437 Sprint_Line_Limit
:= Nat
'Max (Sprint_Line_Limit
, 40);
440 -- Note: -gnatD also sets -gnatx (to turn off cross-reference
441 -- generation in the ali file) since otherwise this generation
442 -- gets confused by the "wrong" Sloc values put in the tree.
444 Debug_Generated_Code
:= True;
445 Xref_Active
:= False;
446 Set_Debug_Flag
('g');
448 -- -gnate? (extended switches)
453 -- The -gnate? switches are all double character switches
454 -- so we must always have a character after the e.
457 Bad_Switch
("-gnate");
460 case Switch_Chars
(Ptr
) is
462 -- -gnatea (initial delimiter of explicit switches)
464 -- This is an internal switch
466 -- All switches that come before -gnatea have been added by
467 -- the GCC driver and are not stored in the ALI file.
468 -- See also -gnatez below.
471 Store_Switch
:= False;
472 Enable_Switch_Storing
;
475 -- -gnateA (aliasing checks on parameters)
479 Check_Aliasing_Of_Parameters
:= True;
481 -- -gnatec (configuration pragmas)
484 Store_Switch
:= False;
487 -- There may be an equal sign between -gnatec and
488 -- the path name of the config file.
490 if Ptr
<= Max
and then Switch_Chars
(Ptr
) = '=' then
495 Bad_Switch
("-gnatec");
499 Config_File_Name
: constant String_Access
:=
501 (Switch_Chars (Ptr .. Max));
504 if Config_File_Names = null then
506 new String_List'(1 => Config_File_Name
);
510 New_Names
: constant String_List_Access
:=
513 Config_File_Names
'Length + 1);
516 for Index
in Config_File_Names
'Range loop
518 Config_File_Names
(Index
);
519 Config_File_Names
(Index
) := null;
522 New_Names
(New_Names
'Last) := Config_File_Name
;
523 Free
(Config_File_Names
);
524 Config_File_Names
:= New_Names
;
531 -- -gnateC switch (generate CodePeer messages)
536 if not Generate_CodePeer_Messages
then
537 Generate_CodePeer_Messages
:= True;
538 CodePeer_Mode
:= True;
539 Warning_Mode
:= Normal
;
540 Warning_Doc_Switch
:= True; -- -gnatw.d
542 -- Enable warnings potentially useful for non GNAT
545 Constant_Condition_Warnings
:= True; -- -gnatwc
546 Warn_On_Assertion_Failure
:= True; -- -gnatw.a
547 Warn_On_Assumed_Low_Bound
:= True; -- -gnatww
548 Warn_On_Bad_Fixed_Value
:= True; -- -gnatwb
549 Warn_On_Biased_Representation
:= True; -- -gnatw.b
550 Warn_On_Export_Import
:= True; -- -gnatwx
551 Warn_On_Modified_Unread
:= True; -- -gnatwm
552 Warn_On_No_Value_Assigned
:= True; -- -gnatwv
553 Warn_On_Object_Renames_Function
:= True; -- -gnatw.r
554 Warn_On_Overlap
:= True; -- -gnatw.i
555 Warn_On_Parameter_Order
:= True; -- -gnatw.p
556 Warn_On_Questionable_Missing_Parens
:= True; -- -gnatwq
557 Warn_On_Redundant_Constructs
:= True; -- -gnatwr
558 Warn_On_Suspicious_Modulus_Value
:= True; -- -gnatw.m
561 -- -gnated switch (disable atomic synchronization)
564 Suppress_Options
.Suppress
(Atomic_Synchronization
) :=
567 -- -gnateD switch (preprocessing symbol definition)
570 Store_Switch
:= False;
574 Bad_Switch
("-gnateD");
577 Add_Symbol_Definition
(Switch_Chars
(Ptr
.. Max
));
581 Store_Compilation_Switch
582 ("-gnateD" & Switch_Chars
(Ptr
.. Max
));
585 -- -gnateE (extra exception information)
588 Exception_Extra_Info
:= True;
591 -- -gnatef (full source path for brief error messages)
594 Store_Switch
:= False;
596 Full_Path_Name_For_Brief_Errors
:= True;
598 -- -gnateF (Check_Float_Overflow)
602 Check_Float_Overflow
:= not Machine_Overflows_On_Target
;
604 -- -gnateg (generate C code)
607 -- Special check, -gnateg must occur after -gnatc
609 if Operating_Mode
/= Check_Semantics
then
611 ("gnateg requires previous occurrence of -gnatc");
614 Generate_C_Code
:= True;
617 -- -gnateG (save preprocessor output)
620 Generate_Processed_File
:= True;
623 -- -gnatei (max number of instantiations)
628 (Switch_Chars
, Max
, Ptr
, Maximum_Instantiations
, C
);
630 -- -gnateI (index of unit in multi-unit source)
634 Scan_Pos
(Switch_Chars
, Max
, Ptr
, Multiple_Unit_Index
, C
);
640 Elab_Info_Messages
:= True;
646 Elab_Info_Messages
:= False;
648 -- -gnatem (mapping file)
651 Store_Switch
:= False;
654 -- There may be an equal sign between -gnatem and
655 -- the path name of the mapping file.
657 if Ptr
<= Max
and then Switch_Chars
(Ptr
) = '=' then
662 Bad_Switch
("-gnatem");
666 new String'(Switch_Chars (Ptr .. Max));
669 -- -gnateO= (object path file)
671 -- This is an internal switch
674 Store_Switch := False;
679 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
680 Bad_Switch ("-gnateO");
682 Object_Path_File_Name :=
683 new String'(Switch_Chars
(Ptr
+ 1 .. Max
));
688 -- -gnatep (preprocessing data file)
691 Store_Switch
:= False;
694 -- There may be an equal sign between -gnatep and
695 -- the path name of the mapping file.
697 if Ptr
<= Max
and then Switch_Chars
(Ptr
) = '=' then
702 Bad_Switch
("-gnatep");
705 Preprocessing_Data_File
:=
706 new String'(Switch_Chars (Ptr .. Max));
708 -- Store the switch, normalizing to -gnatep=
710 Store_Compilation_Switch
711 ("-gnatep=" & Preprocessing_Data_File.all);
715 -- -gnateP (Treat pragma Pure/Preelaborate errs as warnings)
718 Treat_Categorization_Errors_As_Warnings := True;
720 -- -gnates=file (specify extra file switches for gnat2why)
722 -- This is an internal switch
725 if not First_Switch then
727 ("-gnates must not be combined with other switches");
734 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
735 Bad_Switch ("-gnates");
737 SPARK_Switches_File_Name :=
738 new String'(Switch_Chars
(Ptr
+ 1 .. Max
));
743 -- -gnateS (generate SCO information)
745 -- Include Source Coverage Obligation information in ALI
746 -- files for use by source coverage analysis tools
747 -- (gnatcov) (equivalent to -fdump-scos, provided for
748 -- backwards compatibility).
751 Generate_SCO
:= True;
752 Generate_SCO_Instance_Table
:= True;
755 -- -gnatet (write target dependent information)
758 if not First_Switch
then
760 ("-gnatet must not be combined with other switches");
767 if Ptr
>= Max
or else Switch_Chars
(Ptr
) /= '=' then
768 Bad_Switch
("-gnatet");
770 Target_Dependent_Info_Write_Name
:=
771 new String'(Switch_Chars (Ptr + 1 .. Max));
776 -- -gnateT (read target dependent information)
779 if not First_Switch then
781 ("-gnateT must not be combined with other switches");
788 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
789 Bad_Switch ("-gnateT");
791 -- This parameter was stored by Set_Targ earlier
794 (Target_Dependent_Info_Read_Name.all =
795 Switch_Chars (Ptr + 1 .. Max));
801 -- -gnateu (unrecognized y,V,w switches)
805 Ignore_Unrecognized_VWY_Switches := True;
807 -- -gnateV (validity checks on parameters)
811 Check_Validity_Of_Parameters := True;
813 -- -gnateY (ignore Style_Checks pragmas)
816 Ignore_Style_Checks_Pragmas := True;
819 -- -gnatez (final delimiter of explicit switches)
821 -- This is an internal switch
823 -- All switches that come after -gnatez have been added by
824 -- the GCC driver and are not stored in the ALI file. See
825 -- also -gnatea above.
828 Store_Switch := False;
829 Disable_Switch_Storing;
832 -- All other -gnate? switches are unassigned
835 Bad_Switch ("-gnate" & Switch_Chars (Ptr .. Max));
838 -- -gnatE (dynamic elaboration checks)
842 Dynamic_Elaboration_Checks := True;
844 -- -gnatf (full error messages)
848 All_Errors_Mode := True;
850 -- -gnatF (overflow of predefined float types)
854 External_Name_Exp_Casing := Uppercase;
855 External_Name_Imp_Casing := Uppercase;
857 -- -gnatg (GNAT implementation mode)
862 GNAT_Mode_Config := True;
863 Identifier_Character_Set := 'n
';
864 System_Extend_Unit := Empty;
865 Warning_Mode := Treat_As_Error;
866 Style_Check_Main := True;
867 Ada_Version := Ada_2012;
868 Ada_Version_Explicit := Ada_2012;
869 Ada_Version_Pragma := Empty;
871 -- Set default warnings and style checks for -gnatg
873 Set_GNAT_Mode_Warnings;
874 Set_GNAT_Style_Check_Options;
876 -- -gnatG (output generated code)
880 Print_Generated_Code := True;
882 -- Scan optional integer line limit value
884 if Nat_Present (Switch_Chars, Max, Ptr) then
885 Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'G
');
886 Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
889 -- -gnath (help information)
893 Usage_Requested := True;
895 -- -gnati (character set)
899 Bad_Switch ("-gnati");
903 C := Switch_Chars (Ptr);
913 Identifier_Character_Set := C;
917 Bad_Switch ("-gnati" & Switch_Chars (Ptr .. Max));
920 -- -gnatI (ignore representation clauses)
924 Ignore_Rep_Clauses := True;
926 -- -gnatj (messages in limited length lines)
930 Scan_Nat (Switch_Chars, Max, Ptr, Error_Msg_Line_Length, C);
932 -- -gnatk (limit file name length)
937 (Switch_Chars, Max, Ptr, Maximum_File_Name_Length, C);
939 -- -gnatl (output full source)
945 -- There may be an equal sign between -gnatl and a file name
947 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
949 Osint.Fail ("file name for -gnatl= is null");
951 Opt.Full_List_File_Name :=
952 new String'(Switch_Chars
(Ptr
+ 1 .. Max
));
957 -- -gnatL (corresponding source text)
961 Dump_Source_Text
:= True;
963 -- -gnatm (max number or errors/warnings)
967 Scan_Nat
(Switch_Chars
, Max
, Ptr
, Maximum_Messages
, C
);
969 -- -gnatn (enable pragma Inline)
973 Inline_Active
:= True;
975 -- There may be a digit (1 or 2) appended to the switch
978 C
:= Switch_Chars
(Ptr
);
980 if C
in '1' .. '2' then
982 Inline_Level
:= Character'Pos (C
) - Character'Pos ('0');
986 -- -gnatN (obsolescent)
990 Inline_Active
:= True;
991 Front_End_Inlining
:= True;
993 -- -gnato (overflow checks)
998 -- Case of -gnato0 (overflow checking turned off)
1000 if Ptr
<= Max
and then Switch_Chars
(Ptr
) = '0' then
1002 Suppress_Options
.Suppress
(Overflow_Check
) := True;
1004 -- We set strict mode in case overflow checking is turned
1005 -- on locally (also records that we had a -gnato switch).
1007 Suppress_Options
.Overflow_Mode_General
:= Strict
;
1008 Suppress_Options
.Overflow_Mode_Assertions
:= Strict
;
1010 -- All cases other than -gnato0 (overflow checking turned on)
1013 Suppress_Options
.Suppress
(Overflow_Check
) := False;
1015 -- Case of no digits after the -gnato
1018 or else Switch_Chars
(Ptr
) not in '1' .. '3'
1020 Suppress_Options
.Overflow_Mode_General
:= Strict
;
1021 Suppress_Options
.Overflow_Mode_Assertions
:= Strict
;
1023 -- At least one digit after the -gnato
1026 -- Handle first digit after -gnato
1028 Suppress_Options
.Overflow_Mode_General
:=
1029 Get_Overflow_Mode
(Switch_Chars
(Ptr
));
1032 -- Only one digit after -gnato, set assertions mode to be
1033 -- the same as general mode.
1036 or else Switch_Chars
(Ptr
) not in '1' .. '3'
1038 Suppress_Options
.Overflow_Mode_Assertions
:=
1039 Suppress_Options
.Overflow_Mode_General
;
1041 -- Process second digit after -gnato
1044 Suppress_Options
.Overflow_Mode_Assertions
:=
1045 Get_Overflow_Mode
(Switch_Chars
(Ptr
));
1051 -- -gnatO (specify name of the object file)
1053 -- This is an internal switch
1056 Store_Switch
:= False;
1058 Output_File_Name_Present
:= True;
1060 -- -gnatp (suppress all checks)
1065 -- Skip processing if cancelled by subsequent -gnat-p
1067 if Switch_Subsequently_Cancelled
("p", Args
, Arg_Rank
) then
1068 Store_Switch
:= False;
1071 -- Set all specific options as well as All_Checks in the
1072 -- Suppress_Options array, excluding Elaboration_Check,
1073 -- since this is treated specially because we do not want
1074 -- -gnatp to disable static elaboration processing. Also
1075 -- exclude Atomic_Synchronization, since this is not a real
1078 for J
in Suppress_Options
.Suppress
'Range loop
1079 if J
/= Elaboration_Check
1081 J
/= Atomic_Synchronization
1083 Suppress_Options
.Suppress
(J
) := True;
1087 Validity_Checks_On
:= False;
1088 Opt
.Suppress_Checks
:= True;
1090 -- Set overflow mode checking to strict in case it gets
1091 -- turned on locally (also signals that overflow checking
1092 -- has been specifically turned off).
1094 Suppress_Options
.Overflow_Mode_General
:= Strict
;
1095 Suppress_Options
.Overflow_Mode_Assertions
:= Strict
;
1098 -- -gnatP (periodic poll)
1102 Polling_Required
:= True;
1104 -- -gnatq (don't quit)
1108 Try_Semantics
:= True;
1110 -- -gnatQ (always write ALI file)
1114 Force_ALI_Tree_File
:= True;
1115 Try_Semantics
:= True;
1117 -- -gnatr (restrictions as warnings)
1121 Treat_Restrictions_As_Warnings
:= True;
1123 -- -gnatR (list rep. info)
1127 -- Not allowed if previous -gnatD given. See more extensive
1128 -- comments in the 'D' section for the inverse test.
1130 if Debug_Generated_Code
then
1132 ("-gnatR not permitted since -gnatD given previously");
1135 -- Set to annotate rep info, and set default -gnatR mode
1137 Back_Annotate_Rep_Info
:= True;
1138 List_Representation_Info
:= 1;
1140 -- Scan possible parameter
1143 while Ptr
<= Max
loop
1144 C
:= Switch_Chars
(Ptr
);
1146 if C
in '1' .. '3' then
1147 List_Representation_Info
:=
1148 Character'Pos (C
) - Character'Pos ('0');
1150 elsif Switch_Chars
(Ptr
) = 's' then
1151 List_Representation_Info_To_File
:= True;
1153 elsif Switch_Chars
(Ptr
) = 'm' then
1154 List_Representation_Info_Mechanisms
:= True;
1157 Bad_Switch
("-gnatR" & Switch_Chars
(Ptr
.. Max
));
1163 -- -gnats (syntax check only)
1166 if not First_Switch
then
1168 ("-gnats must be first if combined with other switches");
1172 Operating_Mode
:= Check_Syntax
;
1174 -- -gnatS (print package Standard)
1177 Print_Standard
:= True;
1180 -- -gnatt (output tree)
1184 Tree_Output
:= True;
1185 Back_Annotate_Rep_Info
:= True;
1187 -- -gnatT (change start of internal table sizes)
1191 Scan_Pos
(Switch_Chars
, Max
, Ptr
, Table_Factor
, C
);
1193 -- -gnatu (list units for compilation)
1199 -- -gnatU (unique tags)
1203 Unique_Error_Tag
:= True;
1205 -- -gnatv (verbose mode)
1209 Verbose_Mode
:= True;
1211 -- -gnatV (validity checks)
1214 Store_Switch
:= False;
1218 Bad_Switch
("-gnatV");
1225 Set_Validity_Check_Options
1226 (Switch_Chars
(Ptr
.. Max
), OK
, Ptr
);
1229 Bad_Switch
("-gnatV" & Switch_Chars
(Ptr
.. Max
));
1232 for Index
in First_Char
+ 1 .. Max
loop
1233 Store_Compilation_Switch
1234 ("-gnatV" & Switch_Chars
(Index
));
1241 -- -gnatw (warning modes)
1244 Store_Switch
:= False;
1248 Bad_Switch
("-gnatw");
1251 while Ptr
<= Max
loop
1252 C
:= Switch_Chars
(Ptr
);
1254 -- Case of dot switch
1256 if C
= '.' and then Ptr
< Max
then
1258 C
:= Switch_Chars
(Ptr
);
1260 if Set_Dot_Warning_Switch
(C
) then
1261 Store_Compilation_Switch
("-gnatw." & C
);
1263 Bad_Switch
("-gnatw." & Switch_Chars
(Ptr
.. Max
));
1266 -- Normal case, no dot
1269 if Set_Warning_Switch
(C
) then
1270 Store_Compilation_Switch
("-gnatw" & C
);
1272 Bad_Switch
("-gnatw" & Switch_Chars
(Ptr
.. Max
));
1281 -- -gnatW (wide character encoding method)
1287 Bad_Switch
("-gnatW");
1291 Wide_Character_Encoding_Method
:=
1292 Get_WC_Encoding_Method
(Switch_Chars
(Ptr
));
1294 when Constraint_Error
=>
1295 Bad_Switch
("-gnatW" & Switch_Chars
(Ptr
.. Max
));
1298 Wide_Character_Encoding_Method_Specified
:= True;
1300 Upper_Half_Encoding
:=
1301 Wide_Character_Encoding_Method
in
1302 WC_Upper_Half_Encoding_Method
;
1306 -- -gnatx (suppress cross-ref information)
1310 Xref_Active
:= False;
1312 -- -gnatX (language extensions)
1316 Extensions_Allowed
:= True;
1317 Ada_Version
:= Ada_Version_Type
'Last;
1318 Ada_Version_Explicit
:= Ada_Version_Type
'Last;
1319 Ada_Version_Pragma
:= Empty
;
1321 -- -gnaty (style checks)
1325 Style_Check_Main
:= True;
1328 Set_Default_Style_Check_Options
;
1331 Store_Switch
:= False;
1337 Set_Style_Check_Options
1338 (Switch_Chars
(Ptr
.. Max
), OK
, Ptr
);
1342 ("bad -gnaty switch (" &
1343 Style_Msg_Buf
(1 .. Style_Msg_Len
) & ')');
1346 Ptr
:= First_Char
+ 1;
1347 while Ptr
<= Max
loop
1348 if Switch_Chars
(Ptr
) = 'M' then
1353 or else Switch_Chars
(Ptr
) not in '0' .. '9';
1356 Store_Compilation_Switch
1357 ("-gnaty" & Switch_Chars
(First_Char
.. Ptr
- 1));
1360 Store_Compilation_Switch
1361 ("-gnaty" & Switch_Chars
(Ptr
));
1368 -- -gnatz (stub generation)
1372 -- -gnatz must be the first and only switch in Switch_Chars,
1373 -- and is a two-letter switch.
1375 if Ptr
/= Switch_Chars
'First + 5
1376 or else (Max
- Ptr
+ 1) > 2
1379 ("-gnatz* may not be combined with other switches");
1383 Bad_Switch
("-gnatz");
1388 -- Only one occurrence of -gnat* is permitted
1390 if Distribution_Stub_Mode
= No_Stubs
then
1391 case Switch_Chars
(Ptr
) is
1393 Distribution_Stub_Mode
:= Generate_Receiver_Stub_Body
;
1396 Distribution_Stub_Mode
:= Generate_Caller_Stub_Body
;
1399 Bad_Switch
("-gnatz" & Switch_Chars
(Ptr
.. Max
));
1405 Osint
.Fail
("only one -gnatz* switch allowed");
1408 -- -gnatZ (obsolescent)
1413 ("-gnatZ is no longer supported: consider using --RTS=zcx");
1415 -- Note on language version switches: whenever a new language
1416 -- version switch is added, Switch.M.Normalize_Compiler_Switches
1423 Bad_Switch
("-gnat8");
1428 if Switch_Chars
(Ptr
) /= '3' or else Latest_Ada_Only
then
1429 Bad_Switch
("-gnat8" & Switch_Chars
(Ptr
.. Max
));
1432 Ada_Version
:= Ada_83
;
1433 Ada_Version_Explicit
:= Ada_83
;
1434 Ada_Version_Pragma
:= Empty
;
1441 Bad_Switch
("-gnat9");
1446 if Switch_Chars
(Ptr
) /= '5' or else Latest_Ada_Only
then
1447 Bad_Switch
("-gnat9" & Switch_Chars
(Ptr
.. Max
));
1450 Ada_Version
:= Ada_95
;
1451 Ada_Version_Explicit
:= Ada_95
;
1452 Ada_Version_Pragma
:= Empty
;
1459 Bad_Switch
("-gnat0");
1464 if Switch_Chars
(Ptr
) /= '5' or else Latest_Ada_Only
then
1465 Bad_Switch
("-gnat0" & Switch_Chars
(Ptr
.. Max
));
1468 Ada_Version
:= Ada_2005
;
1469 Ada_Version_Explicit
:= Ada_2005
;
1470 Ada_Version_Pragma
:= Empty
;
1477 Bad_Switch
("-gnat1");
1482 if Switch_Chars
(Ptr
) /= '2' then
1483 Bad_Switch
("-gnat1" & Switch_Chars
(Ptr
.. Max
));
1486 Ada_Version
:= Ada_2012
;
1487 Ada_Version_Explicit
:= Ada_2012
;
1488 Ada_Version_Pragma
:= Empty
;
1491 -- -gnat2005 and -gnat2012
1494 if Ptr
> Max
- 3 then
1495 Bad_Switch
("-gnat" & Switch_Chars
(Ptr
.. Max
));
1497 elsif Switch_Chars
(Ptr
.. Ptr
+ 3) = "2005"
1498 and then not Latest_Ada_Only
1500 Ada_Version
:= Ada_2005
;
1502 elsif Switch_Chars
(Ptr
.. Ptr
+ 3) = "2012" then
1503 Ada_Version
:= Ada_2012
;
1505 elsif Switch_Chars
(Ptr
.. Ptr
+ 3) = "2020" then
1506 Ada_Version
:= Ada_2020
;
1509 Bad_Switch
("-gnat" & Switch_Chars
(Ptr
.. Ptr
+ 3));
1512 Ada_Version_Explicit
:= Ada_Version
;
1513 Ada_Version_Pragma
:= Empty
;
1516 -- Switch cancellation, currently only -gnat-p is allowed.
1517 -- All we do here is the error checking, since the actual
1518 -- processing for switch cancellation is done by calls to
1519 -- Switch_Subsequently_Cancelled at the appropriate point.
1523 -- Simple ignore -gnat-p
1525 if Switch_Chars
= "-gnat-p" then
1528 -- Any other occurrence of minus is ignored. This is for
1529 -- maximum compatibility with previous version which ignored
1530 -- all occurrences of minus.
1533 Store_Switch
:= False;
1537 -- We ignore '/' in switches, this is historical, still needed???
1540 Store_Switch
:= False;
1542 -- Anything else is an error (illegal switch character)
1545 Bad_Switch
("-gnat" & Switch_Chars
(Ptr
.. Max
));
1548 if Store_Switch
then
1549 Store_Compilation_Switch
1550 ("-gnat" & Switch_Chars
(First_Char
.. Ptr
- 1));
1553 First_Switch
:= False;
1556 end Scan_Front_End_Switches
;
1558 -----------------------------------
1559 -- Switch_Subsequently_Cancelled --
1560 -----------------------------------
1562 function Switch_Subsequently_Cancelled
1565 Arg_Rank
: Positive) return Boolean
1568 -- Loop through arguments following the current one
1570 for Arg
in Arg_Rank
+ 1 .. Args
'Last loop
1571 if Args
(Arg
).all = "-gnat-" & C
then
1576 -- No match found, not cancelled
1579 end Switch_Subsequently_Cancelled
;