1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2021, 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 requires Long_Long_Integer'Size = 64");
123 end Get_Overflow_Mode;
125 -----------------------------
126 -- Scan_Front_End_Switches --
127 -----------------------------
129 procedure Scan_Front_End_Switches
130 (Switch_Chars : String;
134 Max : constant Natural := Switch_Chars'Last;
135 C : Character := ' ';
139 -- This flag is set upon encountering a dot in a debug switch
141 First_Char : Positive;
142 -- Marks start of switch to be stored
144 First_Ptr : Positive;
145 -- Save position of first character after -gnatd (for checking that
146 -- debug flags that must come first are first, in particular -gnatd.b).
148 First_Switch : Boolean := True;
149 -- False for all but first switch
151 Store_Switch : Boolean;
152 -- For -gnatxx switches, the normal processing, signalled by this flag
153 -- being set to True, is to store the switch on exit from the case
154 -- statement, the switch stored is -gnat followed by the characters
155 -- from First_Char to Ptr-1. For cases like -gnaty, where the switch
156 -- is stored in separate pieces, this flag is set to False, and the
157 -- appropriate calls to Store_Compilation_Switch are made from within
160 Underscore : Boolean;
161 -- This flag is set upon encountering an underscode in a debug switch
164 Ptr := Switch_Chars'First;
166 -- Skip past the initial character (must be the switch character)
174 -- Handle switches that do not start with -gnat
176 if Ptr + 3 > Max or else Switch_Chars (Ptr .. Ptr + 3) /= "gnat" then
178 -- There are two front-end switches that do not start with -gnat:
181 if Switch_Chars (Ptr) = 'I
' then
183 -- Set flag Search_Directory_Present if switch is "-I" only:
184 -- the directory will be the next argument.
187 Search_Directory_Present := True;
193 -- Find out whether this is a -I- or regular -Ixxx switch
195 -- Note: -I switches are not recorded in the ALI file, since the
196 -- meaning of the program depends on the source files compiled,
197 -- not where they came from.
199 if Ptr = Max and then Switch_Chars (Ptr) = '-' then
200 Look_In_Primary_Dir := False;
202 Add_Src_Search_Dir (Switch_Chars (Ptr .. Max));
205 -- Processing of the --RTS switch. --RTS may have been modified by
206 -- gcc into -fRTS (for GCC targets).
209 and then (Switch_Chars (Ptr .. Ptr + 3) = "fRTS"
211 Switch_Chars (Ptr .. Ptr + 3) = "-RTS")
216 or else Switch_Chars (Ptr + 3) /= '='
218 Osint.Fail ("missing path for --RTS");
222 Runtime_Dir : String_Access;
224 if System.OS_Lib.Is_Absolute_Path
225 (Switch_Chars (Ptr + 4 .. Max))
228 new String'(System
.OS_Lib
.Normalize_Pathname
229 (Switch_Chars
(Ptr
+ 4 .. Max
)));
232 new String'(Switch_Chars (Ptr + 4 .. Max));
235 -- Valid --RTS switch
237 Opt.No_Stdinc := True;
238 Opt.RTS_Switch := True;
241 Get_RTS_Search_Dir (Runtime_Dir.all, Include);
244 Get_RTS_Search_Dir (Runtime_Dir.all, Objects);
246 if RTS_Specified /= null then
247 if RTS_Src_Path_Name = null
248 or else RTS_Lib_Path_Name = null
250 System.OS_Lib.Normalize_Pathname
251 (RTS_Specified.all) /=
252 System.OS_Lib.Normalize_Pathname
253 (RTS_Lib_Path_Name.all)
256 ("--RTS cannot be specified multiple times");
259 elsif RTS_Src_Path_Name /= null
260 and then RTS_Lib_Path_Name /= null
262 -- Store the -fRTS switch (Note: Store_Compilation_Switch
263 -- changes -fRTS back into --RTS for the actual output).
265 Store_Compilation_Switch (Switch_Chars);
266 RTS_Specified := new String'(RTS_Lib_Path_Name
.all);
268 elsif RTS_Src_Path_Name
= null
269 and then RTS_Lib_Path_Name
= null
271 Osint
.Fail
("RTS path not valid: missing "
272 & "adainclude and adalib directories");
274 elsif RTS_Src_Path_Name
= null then
275 Osint
.Fail
("RTS path not valid: missing "
276 & "adainclude directory");
278 elsif RTS_Lib_Path_Name
= null then
279 Osint
.Fail
("RTS path not valid: missing "
280 & "adalib directory");
285 -- There are no other switches not starting with -gnat
288 Bad_Switch
(Switch_Chars
);
291 -- Case of switch starting with -gnat
296 -- Loop to scan through switches given in switch string
298 while Ptr
<= Max
loop
300 Store_Switch
:= True;
302 C
:= Switch_Chars
(Ptr
);
306 -- -gnata (assertions enabled)
310 Assertions_Enabled
:= True;
312 -- -gnatA (disregard gnat.adc)
316 Config_File
:= False;
318 -- -gnatb (brief messages to stderr)
322 Brief_Output
:= True;
324 -- -gnatB (assume no invalid values)
328 Assume_No_Invalid_Values
:= True;
330 -- -gnatc (check syntax and semantics only)
333 if not First_Switch
then
335 ("-gnatc must be first if combined with other switches");
339 Operating_Mode
:= Check_Semantics
;
341 -- -gnatC (Generate CodePeer information)
345 CodePeer_Mode
:= True;
347 -- -gnatd (compiler debug options)
351 Store_Switch
:= False;
354 First_Ptr
:= Ptr
+ 1;
356 -- Note: for the debug switch, the remaining characters in this
357 -- switch field must all be debug flags, since all valid switch
358 -- characters are also valid debug characters.
360 -- Loop to scan out debug flags
364 C
:= Switch_Chars
(Ptr
);
365 exit when C
= ASCII
.NUL
or else C
= '/' or else C
= '-';
367 if C
in '1' .. '9' or else
368 C
in 'a' .. 'z' or else
371 -- Case of dotted flag
374 Set_Dotted_Debug_Flag
(C
);
375 Store_Compilation_Switch
("-gnatd." & C
);
377 -- Special check, -gnatd.b must come first
380 and then (Ptr
/= First_Ptr
+ 1
381 or else not First_Switch
)
384 ("-gnatd.b must be first if combined with other "
388 -- Case of an underscored flag
390 elsif Underscore
then
391 Set_Underscored_Debug_Flag
(C
);
392 Store_Compilation_Switch
("-gnatd_" & C
);
398 Store_Compilation_Switch
("-gnatd" & C
);
408 Bad_Switch
("-gnatd." & Switch_Chars
(Ptr
.. Max
));
410 elsif Underscore
then
411 Bad_Switch
("-gnatd_" & Switch_Chars
(Ptr
.. Max
));
414 Bad_Switch
("-gnatd" & Switch_Chars
(Ptr
.. Max
));
420 -- -gnatD (debug expanded code)
425 -- Not allowed if previous -gnatR given
427 -- The reason for this prohibition is that the rewriting of
428 -- Sloc values causes strange malfunctions in the tests of
429 -- whether units belong to the main source. This is really a
430 -- bug, but too hard to fix for a marginal capability.
432 -- The proper fix is to completely redo -gnatD processing so
433 -- that the tree is not messed with, and instead a separate
434 -- table is built on the side for debug information generation.
436 if List_Representation_Info
/= 0 then
438 ("-gnatD not permitted since -gnatR given previously");
441 -- Scan optional integer line limit value
443 if Nat_Present
(Switch_Chars
, Max
, Ptr
) then
444 Scan_Nat
(Switch_Chars
, Max
, Ptr
, Sprint_Line_Limit
, 'D');
445 Sprint_Line_Limit
:= Nat
'Max (Sprint_Line_Limit
, 40);
448 -- Note: -gnatD also sets -gnatx (to turn off cross-reference
449 -- generation in the ali file) since otherwise this generation
450 -- gets confused by the "wrong" Sloc values put in the tree.
452 Debug_Generated_Code
:= True;
453 Xref_Active
:= False;
454 Set_Debug_Flag
('g');
456 -- -gnate? (extended switches)
461 -- The -gnate? switches are all double character switches
462 -- so we must always have a character after the e.
465 Bad_Switch
("-gnate");
468 case Switch_Chars
(Ptr
) is
470 -- -gnatea (initial delimiter of explicit switches)
472 -- This is an internal switch
474 -- All switches that come before -gnatea have been added by
475 -- the GCC driver and are not stored in the ALI file.
476 -- See also -gnatez below.
479 Store_Switch
:= False;
480 Enable_Switch_Storing
;
483 -- -gnateA (aliasing checks on parameters)
487 Check_Aliasing_Of_Parameters
:= True;
489 -- -gnateb (config file basenames and checksums in ALI)
493 Config_Files_Store_Basename
:= True;
495 -- -gnatec (configuration pragmas)
498 Store_Switch
:= False;
501 -- There may be an equal sign between -gnatec and
502 -- the path name of the config file.
504 if Ptr
<= Max
and then Switch_Chars
(Ptr
) = '=' then
509 Bad_Switch
("-gnatec");
513 Config_File_Name
: constant String_Access
:=
515 (Switch_Chars (Ptr .. Max));
518 if Config_File_Names = null then
520 new String_List'(1 => Config_File_Name
);
524 New_Names
: constant String_List_Access
:=
527 Config_File_Names
'Length + 1);
530 for Index
in Config_File_Names
'Range loop
532 Config_File_Names
(Index
);
533 Config_File_Names
(Index
) := null;
536 New_Names
(New_Names
'Last) := Config_File_Name
;
537 Free
(Config_File_Names
);
538 Config_File_Names
:= New_Names
;
545 -- -gnateC switch (generate CodePeer messages)
550 if not Generate_CodePeer_Messages
then
551 Generate_CodePeer_Messages
:= True;
552 CodePeer_Mode
:= True;
553 Warning_Mode
:= Normal
;
554 Warning_Doc_Switch
:= True; -- -gnatw.d
556 -- Enable warnings potentially useful for non GNAT
559 Constant_Condition_Warnings
:= True; -- -gnatwc
560 Warn_On_Assertion_Failure
:= True; -- -gnatw.a
561 Warn_On_Assumed_Low_Bound
:= True; -- -gnatww
562 Warn_On_Bad_Fixed_Value
:= True; -- -gnatwb
563 Warn_On_Biased_Representation
:= True; -- -gnatw.b
564 Warn_On_Export_Import
:= True; -- -gnatwx
565 Warn_On_No_Value_Assigned
:= True; -- -gnatwv
566 Warn_On_Object_Renames_Function
:= True; -- -gnatw.r
567 Warn_On_Overlap
:= True; -- -gnatw.i
568 Warn_On_Parameter_Order
:= True; -- -gnatw.p
569 Warn_On_Questionable_Missing_Parens
:= True; -- -gnatwq
570 Warn_On_Redundant_Constructs
:= True; -- -gnatwr
571 Warn_On_Suspicious_Modulus_Value
:= True; -- -gnatw.m
574 -- -gnated switch (disable atomic synchronization)
577 Suppress_Options
.Suppress
(Atomic_Synchronization
) :=
580 -- -gnateD switch (preprocessing symbol definition)
583 Store_Switch
:= False;
587 Bad_Switch
("-gnateD");
590 Add_Symbol_Definition
(Switch_Chars
(Ptr
.. Max
));
594 Store_Compilation_Switch
595 ("-gnateD" & Switch_Chars
(Ptr
.. Max
));
598 -- -gnateE (extra exception information)
601 Exception_Extra_Info
:= True;
604 -- -gnatef (full source path for brief error messages)
607 Store_Switch
:= False;
609 Full_Path_Name_For_Brief_Errors
:= True;
611 -- -gnateF (Check_Float_Overflow)
615 Check_Float_Overflow
:= not Machine_Overflows_On_Target
;
617 -- -gnateg (generate C code)
620 -- Special check, -gnateg must occur after -gnatc
622 if Operating_Mode
/= Check_Semantics
then
624 ("gnateg requires previous occurrence of -gnatc");
627 Generate_C_Code
:= True;
630 -- -gnateG (save preprocessor output)
633 Generate_Processed_File
:= True;
636 -- -gnatei (max number of instantiations)
641 (Switch_Chars
, Max
, Ptr
, Maximum_Instantiations
, C
);
643 -- -gnateI (index of unit in multi-unit source)
647 Scan_Pos
(Switch_Chars
, Max
, Ptr
, Multiple_Unit_Index
, C
);
653 Elab_Info_Messages
:= True;
659 Elab_Info_Messages
:= False;
661 -- -gnatem (mapping file)
664 Store_Switch
:= False;
667 -- There may be an equal sign between -gnatem and
668 -- the path name of the mapping file.
670 if Ptr
<= Max
and then Switch_Chars
(Ptr
) = '=' then
675 Bad_Switch
("-gnatem");
679 new String'(Switch_Chars (Ptr .. Max));
682 -- -gnaten (memory to allocate for nodes)
687 (Switch_Chars, Max, Ptr, Nodes_Size_In_Meg, C);
689 -- -gnateO= (object path file)
691 -- This is an internal switch
694 Store_Switch := False;
699 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
700 Bad_Switch ("-gnateO");
702 Object_Path_File_Name :=
703 new String'(Switch_Chars
(Ptr
+ 1 .. Max
));
708 -- -gnatep (preprocessing data file)
711 Store_Switch
:= False;
714 -- There may be an equal sign between -gnatep and
715 -- the path name of the mapping file.
717 if Ptr
<= Max
and then Switch_Chars
(Ptr
) = '=' then
722 Bad_Switch
("-gnatep");
725 Preprocessing_Data_File
:=
726 new String'(Switch_Chars (Ptr .. Max));
728 -- Store the switch, normalizing to -gnatep=
730 Store_Compilation_Switch
731 ("-gnatep=" & Preprocessing_Data_File.all);
735 -- -gnateP (Treat pragma Pure/Preelaborate errs as warnings)
738 Treat_Categorization_Errors_As_Warnings := True;
741 -- -gnates=file (specify extra file switches for gnat2why)
743 -- This is an internal switch
746 if not First_Switch then
748 ("-gnates must not be combined with other switches");
755 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
756 Bad_Switch ("-gnates");
758 SPARK_Switches_File_Name :=
759 new String'(Switch_Chars
(Ptr
+ 1 .. Max
));
764 -- -gnateS (generate SCO information)
766 -- Include Source Coverage Obligation information in ALI
767 -- files for use by source coverage analysis tools
768 -- (gnatcov) (equivalent to -fdump-scos, provided for
769 -- backwards compatibility).
772 Generate_SCO
:= True;
773 Generate_SCO_Instance_Table
:= True;
776 -- -gnatet (write 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 Target_Dependent_Info_Write_Name
:=
792 new String'(Switch_Chars (Ptr + 1 .. Max));
797 -- -gnateT (read target dependent information)
800 if not First_Switch then
802 ("-gnateT must not be combined with other switches");
809 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
810 Bad_Switch ("-gnateT");
812 -- This parameter was stored by Set_Targ earlier
815 (Target_Dependent_Info_Read_Name.all =
816 Switch_Chars (Ptr + 1 .. Max));
822 -- -gnateu (unrecognized y,V,w switches)
825 Ignore_Unrecognized_VWY_Switches := True;
828 -- -gnateV (validity checks on parameters)
832 Check_Validity_Of_Parameters := True;
834 -- -gnateY (ignore Style_Checks pragmas)
837 Ignore_Style_Checks_Pragmas := True;
840 -- -gnatez (final delimiter of explicit switches)
842 -- This is an internal switch
844 -- All switches that come after -gnatez have been added by
845 -- the GCC driver and are not stored in the ALI file. See
846 -- also -gnatea above.
849 Store_Switch := False;
850 Disable_Switch_Storing;
853 -- All other -gnate? switches are unassigned
856 Bad_Switch ("-gnate" & Switch_Chars (Ptr .. Max));
859 -- -gnatE (dynamic elaboration checks)
863 Dynamic_Elaboration_Checks := True;
865 -- -gnatf (full error messages)
869 All_Errors_Mode := True;
871 -- -gnatF (overflow of predefined float types)
875 External_Name_Exp_Casing := Uppercase;
876 External_Name_Imp_Casing := Uppercase;
878 -- -gnatg (GNAT implementation mode)
883 GNAT_Mode_Config := True;
884 Identifier_Character_Set := 'n
';
885 System_Extend_Unit := Empty;
886 Warning_Mode := Treat_As_Error;
887 Style_Check_Main := True;
888 Ada_Version := Ada_2012;
889 Ada_Version_Explicit := Ada_2012;
890 Ada_Version_Pragma := Empty;
892 -- Set default warnings and style checks for -gnatg
894 Set_GNAT_Mode_Warnings;
895 Set_GNAT_Style_Check_Options;
897 -- -gnatG (output generated code)
901 Print_Generated_Code := True;
903 -- Scan optional integer line limit value
905 if Nat_Present (Switch_Chars, Max, Ptr) then
906 Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'G
');
907 Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
910 -- -gnath (help information)
914 Usage_Requested := True;
916 -- -gnatH (legacy static elaboration checking mode enabled)
920 Legacy_Elaboration_Checks := True;
922 -- -gnati (character set)
926 Bad_Switch ("-gnati");
930 C := Switch_Chars (Ptr);
932 if C in '1' .. '5' | '8' | 'p
' | '9' | 'f
' | 'n
' | 'w
' then
933 Identifier_Character_Set := C;
937 Bad_Switch ("-gnati" & Switch_Chars (Ptr .. Max));
940 -- -gnatI (ignore representation clauses)
944 Ignore_Rep_Clauses := True;
946 -- -gnatj (messages in limited length lines)
950 Scan_Nat (Switch_Chars, Max, Ptr, Error_Msg_Line_Length, C);
952 -- -gnatJ (relaxed elaboration checking mode enabled)
956 Relaxed_Elaboration_Checks := True;
958 -- Common relaxations for both ABE mechanisms
960 -- -gnatd.G (ignore calls through generic formal parameters
962 -- -gnatd.U (ignore indirect calls for static elaboration)
963 -- -gnatd.y (disable implicit pragma Elaborate_All on task
966 Debug_Flag_Dot_GG := True;
967 Debug_Flag_Dot_UU := True;
968 Debug_Flag_Dot_Y := True;
970 -- Relaxatons to the legacy ABE mechanism
972 if Legacy_Elaboration_Checks then
975 -- Relaxations to the default ABE mechanism
977 -- -gnatd_a (stop elaboration checks on accept or select
979 -- -gnatd_e (ignore entry calls and requeue statements for
981 -- -gnatd_i (ignore activations and calls to instances for
983 -- -gnatd_p (ignore assertion pragmas for elaboration)
984 -- -gnatd_s (stop elaboration checks on synchronous
986 -- -gnatdL (ignore external calls from instances for
990 Debug_Flag_Underscore_A := True;
991 Debug_Flag_Underscore_E := True;
992 Debug_Flag_Underscore_I := True;
993 Debug_Flag_Underscore_P := True;
994 Debug_Flag_Underscore_S := True;
995 Debug_Flag_LL := True;
998 -- -gnatk (limit file name length)
1003 (Switch_Chars, Max, Ptr, Maximum_File_Name_Length, C);
1005 -- -gnatl (output full source)
1011 -- There may be an equal sign between -gnatl and a file name
1013 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
1015 Osint.Fail ("file name for -gnatl= is null");
1017 Opt.Full_List_File_Name :=
1018 new String'(Switch_Chars
(Ptr
+ 1 .. Max
));
1023 -- -gnatL (corresponding source text)
1027 Dump_Source_Text
:= True;
1029 -- -gnatm (max number or errors/warnings)
1033 Scan_Nat
(Switch_Chars
, Max
, Ptr
, Maximum_Messages
, C
);
1035 -- -gnatn (enable pragma Inline)
1039 Inline_Active
:= True;
1041 -- There may be a digit (1 or 2) appended to the switch
1044 C
:= Switch_Chars
(Ptr
);
1046 if C
in '1' .. '2' then
1048 Inline_Level
:= Character'Pos (C
) - Character'Pos ('0');
1052 -- -gnatN (obsolescent)
1056 Inline_Active
:= True;
1057 Front_End_Inlining
:= True;
1059 -- -gnato (overflow checks)
1064 -- Case of -gnato0 (overflow checking turned off)
1066 if Ptr
<= Max
and then Switch_Chars
(Ptr
) = '0' then
1068 Suppress_Options
.Suppress
(Overflow_Check
) := True;
1070 -- We set strict mode in case overflow checking is turned
1071 -- on locally (also records that we had a -gnato switch).
1073 Suppress_Options
.Overflow_Mode_General
:= Strict
;
1074 Suppress_Options
.Overflow_Mode_Assertions
:= Strict
;
1076 -- All cases other than -gnato0 (overflow checking turned on)
1079 Suppress_Options
.Suppress
(Overflow_Check
) := False;
1081 -- Case of no digits after the -gnato
1084 or else Switch_Chars
(Ptr
) not in '1' .. '3'
1086 Suppress_Options
.Overflow_Mode_General
:= Strict
;
1087 Suppress_Options
.Overflow_Mode_Assertions
:= Strict
;
1089 -- At least one digit after the -gnato
1092 -- Handle first digit after -gnato
1094 Suppress_Options
.Overflow_Mode_General
:=
1095 Get_Overflow_Mode
(Switch_Chars
(Ptr
));
1098 -- Only one digit after -gnato, set assertions mode to be
1099 -- the same as general mode.
1102 or else Switch_Chars
(Ptr
) not in '1' .. '3'
1104 Suppress_Options
.Overflow_Mode_Assertions
:=
1105 Suppress_Options
.Overflow_Mode_General
;
1107 -- Process second digit after -gnato
1110 Suppress_Options
.Overflow_Mode_Assertions
:=
1111 Get_Overflow_Mode
(Switch_Chars
(Ptr
));
1117 -- -gnatO (specify name of the object file)
1119 -- This is an internal switch
1122 Store_Switch
:= False;
1124 Output_File_Name_Present
:= True;
1126 -- -gnatp (suppress all checks)
1131 -- Skip processing if cancelled by subsequent -gnat-p
1133 if Switch_Subsequently_Cancelled
("p", Args
, Arg_Rank
) then
1134 Store_Switch
:= False;
1137 -- Set all specific options as well as All_Checks in the
1138 -- Suppress_Options array, excluding Elaboration_Check,
1139 -- since this is treated specially because we do not want
1140 -- -gnatp to disable static elaboration processing. Also
1141 -- exclude Atomic_Synchronization, since this is not a real
1144 for J
in Suppress_Options
.Suppress
'Range loop
1145 if J
/= Elaboration_Check
1147 J
/= Atomic_Synchronization
1149 Suppress_Options
.Suppress
(J
) := True;
1153 Validity_Checks_On
:= False;
1154 Opt
.Suppress_Checks
:= True;
1156 -- Set overflow mode checking to strict in case it gets
1157 -- turned on locally (also signals that overflow checking
1158 -- has been specifically turned off).
1160 Suppress_Options
.Overflow_Mode_General
:= Strict
;
1161 Suppress_Options
.Overflow_Mode_Assertions
:= Strict
;
1164 -- -gnatq (don't quit)
1168 Try_Semantics
:= True;
1170 -- -gnatQ (always write ALI file)
1174 Force_ALI_File
:= True;
1175 Try_Semantics
:= True;
1177 -- -gnatr (restrictions as warnings)
1181 Treat_Restrictions_As_Warnings
:= True;
1183 -- -gnatR (list rep. info)
1187 -- Not allowed if previous -gnatD given. See more extensive
1188 -- comments in the 'D' section for the inverse test.
1190 if Debug_Generated_Code
then
1192 ("-gnatR not permitted since -gnatD given previously");
1195 -- Set to annotate rep info, and set default -gnatR mode
1197 Back_Annotate_Rep_Info
:= True;
1198 List_Representation_Info
:= 1;
1200 -- Scan possible parameter
1203 while Ptr
<= Max
loop
1204 C
:= Switch_Chars
(Ptr
);
1209 List_Representation_Info
:=
1210 Character'Pos (C
) - Character'Pos ('0');
1213 List_Representation_Info_To_File
:= True;
1216 List_Representation_Info_To_JSON
:= True;
1219 List_Representation_Info_Mechanisms
:= True;
1222 List_Representation_Info_Extended
:= True;
1225 Bad_Switch
("-gnatR" & Switch_Chars
(Ptr
.. Max
));
1231 if List_Representation_Info_To_JSON
1232 and then List_Representation_Info_Extended
1234 Osint
.Fail
("-gnatRe is incompatible with -gnatRj");
1237 -- -gnats (syntax check only)
1240 if not First_Switch
then
1242 ("-gnats must be first if combined with other switches");
1246 Operating_Mode
:= Check_Syntax
;
1248 -- -gnatS (print package Standard)
1251 Print_Standard
:= True;
1254 -- -gnatT (change start of internal table sizes)
1258 Scan_Pos
(Switch_Chars
, Max
, Ptr
, Table_Factor
, C
);
1260 -- -gnatu (list units for compilation)
1266 -- -gnatU (unique tags)
1270 Unique_Error_Tag
:= True;
1272 -- -gnatv (verbose mode)
1276 Verbose_Mode
:= True;
1278 -- -gnatV (validity checks)
1281 Store_Switch
:= False;
1285 Bad_Switch
("-gnatV");
1292 Set_Validity_Check_Options
1293 (Switch_Chars
(Ptr
.. Max
), OK
, Ptr
);
1296 Bad_Switch
("-gnatV" & Switch_Chars
(Ptr
.. Max
));
1299 for Index
in First_Char
+ 1 .. Max
loop
1300 Store_Compilation_Switch
1301 ("-gnatV" & Switch_Chars
(Index
));
1308 -- -gnatw (warning modes)
1311 Store_Switch
:= False;
1315 Bad_Switch
("-gnatw");
1318 while Ptr
<= Max
loop
1319 C
:= Switch_Chars
(Ptr
);
1321 -- Case of dot switch
1323 if C
= '.' and then Ptr
< Max
then
1325 C
:= Switch_Chars
(Ptr
);
1327 if Set_Dot_Warning_Switch
(C
) then
1328 Store_Compilation_Switch
("-gnatw." & C
);
1330 Bad_Switch
("-gnatw." & Switch_Chars
(Ptr
.. Max
));
1333 -- Case of underscore switch
1335 elsif C
= '_' and then Ptr
< Max
then
1337 C
:= Switch_Chars
(Ptr
);
1339 if Set_Underscore_Warning_Switch
(C
) then
1340 Store_Compilation_Switch
("-gnatw_" & C
);
1342 Bad_Switch
("-gnatw_" & Switch_Chars
(Ptr
.. Max
));
1348 if Set_Warning_Switch
(C
) then
1349 Store_Compilation_Switch
("-gnatw" & C
);
1351 Bad_Switch
("-gnatw" & Switch_Chars
(Ptr
.. Max
));
1360 -- -gnatW (wide character encoding method)
1366 Bad_Switch
("-gnatW");
1370 Wide_Character_Encoding_Method
:=
1371 Get_WC_Encoding_Method
(Switch_Chars
(Ptr
));
1373 when Constraint_Error
=>
1374 Bad_Switch
("-gnatW" & Switch_Chars
(Ptr
.. Max
));
1377 Wide_Character_Encoding_Method_Specified
:= True;
1379 Upper_Half_Encoding
:=
1380 Wide_Character_Encoding_Method
in
1381 WC_Upper_Half_Encoding_Method
;
1385 -- -gnatx (suppress cross-ref information)
1389 Xref_Active
:= False;
1391 -- -gnatX (language extensions)
1395 Ada_Version
:= Ada_With_Extensions
;
1396 Ada_Version_Explicit
:= Ada_With_Extensions
;
1397 Ada_Version_Pragma
:= Empty
;
1399 -- -gnaty (style checks)
1403 Style_Check_Main
:= True;
1406 Set_Default_Style_Check_Options
;
1409 Store_Switch
:= False;
1415 Set_Style_Check_Options
1416 (Switch_Chars
(Ptr
.. Max
), OK
, Ptr
);
1420 ("bad -gnaty switch (" &
1421 Style_Msg_Buf
(1 .. Style_Msg_Len
) & ')');
1424 Ptr
:= First_Char
+ 1;
1425 while Ptr
<= Max
loop
1426 if Switch_Chars
(Ptr
) = 'M' then
1431 or else Switch_Chars
(Ptr
) not in '0' .. '9';
1434 Store_Compilation_Switch
1435 ("-gnaty" & Switch_Chars
(First_Char
.. Ptr
- 1));
1438 Store_Compilation_Switch
1439 ("-gnaty" & Switch_Chars
(Ptr
));
1446 -- -gnatz (stub generation)
1450 -- -gnatz must be the first and only switch in Switch_Chars,
1451 -- and is a two-letter switch.
1453 if Ptr
/= Switch_Chars
'First + 5
1454 or else (Max
- Ptr
+ 1) > 2
1457 ("-gnatz* may not be combined with other switches");
1461 Bad_Switch
("-gnatz");
1466 -- Only one occurrence of -gnat* is permitted
1468 if Distribution_Stub_Mode
= No_Stubs
then
1469 case Switch_Chars
(Ptr
) is
1471 Distribution_Stub_Mode
:= Generate_Receiver_Stub_Body
;
1474 Distribution_Stub_Mode
:= Generate_Caller_Stub_Body
;
1477 Bad_Switch
("-gnatz" & Switch_Chars
(Ptr
.. Max
));
1483 Osint
.Fail
("only one -gnatz* switch allowed");
1486 -- -gnatZ (obsolescent)
1491 ("-gnatZ is no longer supported: consider using --RTS=zcx");
1493 -- Note on language version switches: whenever a new language
1494 -- version switch is added, Switch.M.Normalize_Compiler_Switches
1501 Bad_Switch
("-gnat8");
1506 if Switch_Chars
(Ptr
) /= '3' or else Latest_Ada_Only
then
1507 Bad_Switch
("-gnat8" & Switch_Chars
(Ptr
.. Max
));
1510 Ada_Version
:= Ada_83
;
1511 Ada_Version_Explicit
:= Ada_83
;
1512 Ada_Version_Pragma
:= Empty
;
1519 Bad_Switch
("-gnat9");
1524 if Switch_Chars
(Ptr
) /= '5' or else Latest_Ada_Only
then
1525 Bad_Switch
("-gnat9" & Switch_Chars
(Ptr
.. Max
));
1528 Ada_Version
:= Ada_95
;
1529 Ada_Version_Explicit
:= Ada_95
;
1530 Ada_Version_Pragma
:= Empty
;
1537 Bad_Switch
("-gnat0");
1542 if Switch_Chars
(Ptr
) /= '5' or else Latest_Ada_Only
then
1543 Bad_Switch
("-gnat0" & Switch_Chars
(Ptr
.. Max
));
1546 Ada_Version
:= Ada_2005
;
1547 Ada_Version_Explicit
:= Ada_2005
;
1548 Ada_Version_Pragma
:= Empty
;
1555 Bad_Switch
("-gnat1");
1560 if Switch_Chars
(Ptr
) /= '2' then
1561 Bad_Switch
("-gnat1" & Switch_Chars
(Ptr
.. Max
));
1564 Ada_Version
:= Ada_2012
;
1565 Ada_Version_Explicit
:= Ada_2012
;
1566 Ada_Version_Pragma
:= Empty
;
1569 -- -gnat2005 and -gnat2012
1572 if Ptr
> Max
- 3 then
1573 Bad_Switch
("-gnat" & Switch_Chars
(Ptr
.. Max
));
1575 elsif Switch_Chars
(Ptr
.. Ptr
+ 3) = "2005"
1576 and then not Latest_Ada_Only
1578 Ada_Version
:= Ada_2005
;
1580 elsif Switch_Chars
(Ptr
.. Ptr
+ 3) = "2012" then
1581 Ada_Version
:= Ada_2012
;
1583 elsif Switch_Chars
(Ptr
.. Ptr
+ 3) = "2020"
1584 or else Switch_Chars
(Ptr
.. Ptr
+ 3) = "2022"
1586 Ada_Version
:= Ada_2022
;
1589 Bad_Switch
("-gnat" & Switch_Chars
(Ptr
.. Ptr
+ 3));
1592 Ada_Version_Explicit
:= Ada_Version
;
1593 Ada_Version_Pragma
:= Empty
;
1596 -- Switch cancellation, currently only -gnat-p is allowed.
1597 -- All we do here is the error checking, since the actual
1598 -- processing for switch cancellation is done by calls to
1599 -- Switch_Subsequently_Cancelled at the appropriate point.
1603 -- Simple ignore -gnat-p
1605 if Switch_Chars
= "-gnat-p" then
1608 -- Any other occurrence of minus is ignored. This is for
1609 -- maximum compatibility with previous version which ignored
1610 -- all occurrences of minus.
1613 Store_Switch
:= False;
1617 -- Anything else is an error (illegal switch character)
1620 Bad_Switch
("-gnat" & Switch_Chars
(Ptr
.. Max
));
1623 if Store_Switch
then
1624 Store_Compilation_Switch
1625 ("-gnat" & Switch_Chars
(First_Char
.. Ptr
- 1));
1628 First_Switch
:= False;
1631 end Scan_Front_End_Switches
;
1633 -----------------------------------
1634 -- Switch_Subsequently_Cancelled --
1635 -----------------------------------
1637 function Switch_Subsequently_Cancelled
1640 Arg_Rank
: Positive) return Boolean
1643 -- Loop through arguments following the current one
1645 for Arg
in Arg_Rank
+ 1 .. Args
'Last loop
1646 if Args
(Arg
).all = "-gnat-" & C
then
1651 -- No match found, not cancelled
1654 end Switch_Subsequently_Cancelled
;