1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2023, 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 requires Long_Long_Integer'Size = 64");
122 end Get_Overflow_Mode;
124 -----------------------------
125 -- Scan_Front_End_Switches --
126 -----------------------------
128 procedure Scan_Front_End_Switches
129 (Switch_Chars : String;
133 Max : constant Natural := Switch_Chars'Last;
134 C : Character := ' ';
138 -- This flag is set upon encountering a dot in a debug switch
140 First_Char : Positive;
141 -- Marks start of switch to be stored
143 First_Ptr : Positive;
144 -- Save position of first character after -gnatd (for checking that
145 -- debug flags that must come first are first, in particular -gnatd.b).
147 First_Switch : Boolean := True;
148 -- False for all but first switch
150 Store_Switch : Boolean;
151 -- For -gnatxx switches, the normal processing, signalled by this flag
152 -- being set to True, is to store the switch on exit from the case
153 -- statement, the switch stored is -gnat followed by the characters
154 -- from First_Char to Ptr-1. For cases like -gnaty, where the switch
155 -- is stored in separate pieces, this flag is set to False, and the
156 -- appropriate calls to Store_Compilation_Switch are made from within
159 Underscore : Boolean;
160 -- This flag is set upon encountering an underscode in a debug switch
163 Ptr := Switch_Chars'First;
165 -- Skip past the initial character (must be the switch character)
173 -- Handle switches that do not start with -gnat
175 if Ptr + 3 > Max or else Switch_Chars (Ptr .. Ptr + 3) /= "gnat" then
177 -- There are two front-end switches that do not start with -gnat:
180 if Switch_Chars (Ptr) = 'I
' then
182 -- Set flag Search_Directory_Present if switch is "-I" only:
183 -- the directory will be the next argument.
186 Search_Directory_Present := True;
192 -- Find out whether this is a -I- or regular -Ixxx switch
194 -- Note: -I switches are not recorded in the ALI file, since the
195 -- meaning of the program depends on the source files compiled,
196 -- not where they came from.
198 if Ptr = Max and then Switch_Chars (Ptr) = '-' then
199 Look_In_Primary_Dir := False;
201 Add_Src_Search_Dir (Switch_Chars (Ptr .. Max));
204 -- Processing of the --RTS switch. --RTS may have been modified by
205 -- gcc into -fRTS (for GCC targets).
208 and then (Switch_Chars (Ptr .. Ptr + 3) = "fRTS"
210 Switch_Chars (Ptr .. Ptr + 3) = "-RTS")
215 or else Switch_Chars (Ptr + 3) /= '='
217 Osint.Fail ("missing path for --RTS");
221 Runtime_Dir : String_Access;
223 if System.OS_Lib.Is_Absolute_Path
224 (Switch_Chars (Ptr + 4 .. Max))
227 new String'(System
.OS_Lib
.Normalize_Pathname
228 (Switch_Chars
(Ptr
+ 4 .. Max
)));
231 new String'(Switch_Chars (Ptr + 4 .. Max));
234 -- Valid --RTS switch
236 Opt.No_Stdinc := True;
237 Opt.RTS_Switch := True;
240 Get_RTS_Search_Dir (Runtime_Dir.all, Include);
243 Get_RTS_Search_Dir (Runtime_Dir.all, Objects);
245 if RTS_Specified /= null then
246 if RTS_Src_Path_Name = null
247 or else RTS_Lib_Path_Name = null
249 System.OS_Lib.Normalize_Pathname
250 (RTS_Specified.all) /=
251 System.OS_Lib.Normalize_Pathname
252 (RTS_Lib_Path_Name.all)
255 ("--RTS cannot be specified multiple times");
258 elsif RTS_Src_Path_Name /= null
259 and then RTS_Lib_Path_Name /= null
261 -- Store the -fRTS switch (Note: Store_Compilation_Switch
262 -- changes -fRTS back into --RTS for the actual output).
264 Store_Compilation_Switch (Switch_Chars);
265 RTS_Specified := new String'(RTS_Lib_Path_Name
.all);
267 elsif RTS_Src_Path_Name
= null
268 and then RTS_Lib_Path_Name
= null
270 Osint
.Fail
("RTS path not valid: missing "
271 & "adainclude and adalib directories");
273 elsif RTS_Src_Path_Name
= null then
274 Osint
.Fail
("RTS path not valid: missing "
275 & "adainclude directory");
277 elsif RTS_Lib_Path_Name
= null then
278 Osint
.Fail
("RTS path not valid: missing "
279 & "adalib directory");
284 -- There are no other switches not starting with -gnat
287 Bad_Switch
(Switch_Chars
);
290 -- Case of switch starting with -gnat
295 -- Loop to scan through switches given in switch string
297 while Ptr
<= Max
loop
299 Store_Switch
:= True;
301 C
:= Switch_Chars
(Ptr
);
305 -- -gnata (assertions enabled)
309 Assertions_Enabled
:= True;
311 -- -gnatA (disregard gnat.adc)
315 Config_File
:= False;
317 -- -gnatb (brief messages to stderr)
321 Brief_Output
:= True;
323 -- -gnatB (assume no invalid values)
327 Assume_No_Invalid_Values
:= True;
329 -- -gnatc (check syntax and semantics only)
332 if not First_Switch
then
334 ("-gnatc must be first if combined with other switches");
338 Operating_Mode
:= Check_Semantics
;
340 -- -gnatC (Generate CodePeer information)
344 CodePeer_Mode
:= True;
346 -- -gnatd (compiler debug options)
350 Store_Switch
:= False;
353 First_Ptr
:= Ptr
+ 1;
355 -- Note: for the debug switch, the remaining characters in this
356 -- switch field must all be debug flags, since all valid switch
357 -- characters are also valid debug characters.
359 -- Loop to scan out debug flags
363 C
:= Switch_Chars
(Ptr
);
364 exit when C
= ASCII
.NUL
or else C
= '/' or else C
= '-';
366 if C
in '1' .. '9' or else
367 C
in 'a' .. 'z' or else
370 -- Case of dotted flag
373 Set_Dotted_Debug_Flag
(C
);
374 Store_Compilation_Switch
("-gnatd." & C
);
376 -- Special check, -gnatd.b must come first
379 and then (Ptr
/= First_Ptr
+ 1
380 or else not First_Switch
)
383 ("-gnatd.b must be first if combined with other "
387 -- Case of an underscored flag
389 elsif Underscore
then
390 Set_Underscored_Debug_Flag
(C
);
391 Store_Compilation_Switch
("-gnatd_" & C
);
392 if Debug_Flag_Underscore_C
then
393 Enable_CUDA_Expansion
:= True;
400 Store_Compilation_Switch
("-gnatd" & C
);
410 Bad_Switch
("-gnatd." & Switch_Chars
(Ptr
.. Max
));
412 elsif Underscore
then
413 Bad_Switch
("-gnatd_" & Switch_Chars
(Ptr
.. Max
));
416 Bad_Switch
("-gnatd" & Switch_Chars
(Ptr
.. Max
));
422 -- -gnatD (debug expanded code)
427 -- Not allowed if previous -gnatR given
429 -- The reason for this prohibition is that the rewriting of
430 -- Sloc values causes strange malfunctions in the tests of
431 -- whether units belong to the main source. This is really a
432 -- bug, but too hard to fix for a marginal capability.
434 -- The proper fix is to completely redo -gnatD processing so
435 -- that the tree is not messed with, and instead a separate
436 -- table is built on the side for debug information generation.
438 if List_Representation_Info
/= 0 then
440 ("-gnatD not permitted since -gnatR given previously");
443 -- Scan optional integer line limit value
445 if Nat_Present
(Switch_Chars
, Max
, Ptr
) then
446 Scan_Nat
(Switch_Chars
, Max
, Ptr
, Sprint_Line_Limit
, 'D');
447 Sprint_Line_Limit
:= Nat
'Max (Sprint_Line_Limit
, 40);
450 -- Note: -gnatD also sets -gnatx (to turn off cross-reference
451 -- generation in the ali file) since otherwise this generation
452 -- gets confused by the "wrong" Sloc values put in the tree.
454 Debug_Generated_Code
:= True;
455 Xref_Active
:= False;
457 -- -gnate? (extended switches)
462 -- The -gnate? switches are all double character switches
463 -- so we must always have a character after the e.
466 Bad_Switch
("-gnate");
469 case Switch_Chars
(Ptr
) is
471 -- -gnatea (initial delimiter of explicit switches)
473 -- This is an internal switch
475 -- All switches that come before -gnatea have been added by
476 -- the GCC driver and are not stored in the ALI file.
477 -- See also -gnatez below.
480 Store_Switch
:= False;
481 Enable_Switch_Storing
;
484 -- -gnateA (aliasing checks on parameters)
488 Check_Aliasing_Of_Parameters
:= True;
490 -- -gnateb (config file basenames and checksums in ALI)
494 Config_Files_Store_Basename
:= True;
496 -- -gnatec (configuration pragmas)
499 Store_Switch
:= False;
502 -- There may be an equal sign between -gnatec and
503 -- the path name of the config file.
505 if Ptr
<= Max
and then Switch_Chars
(Ptr
) = '=' then
510 Bad_Switch
("-gnatec");
514 Config_File_Name
: constant String_Access
:=
516 (Switch_Chars (Ptr .. Max));
519 if Config_File_Names = null then
521 new String_List'(1 => Config_File_Name
);
525 New_Names
: constant String_List_Access
:=
528 Config_File_Names
'Length + 1);
531 for Index
in Config_File_Names
'Range loop
533 Config_File_Names
(Index
);
534 Config_File_Names
(Index
) := null;
537 New_Names
(New_Names
'Last) := Config_File_Name
;
538 Free
(Config_File_Names
);
539 Config_File_Names
:= New_Names
;
546 -- -gnateC switch (generate CodePeer messages)
551 if not Generate_CodePeer_Messages
then
552 Generate_CodePeer_Messages
:= True;
553 CodePeer_Mode
:= True;
554 Warning_Mode
:= Normal
;
555 Warning_Doc_Switch
:= True; -- -gnatw.d
557 -- Enable warnings potentially useful for non GNAT
560 Constant_Condition_Warnings
:= True; -- -gnatwc
561 Warn_On_Assertion_Failure
:= True; -- -gnatw.a
562 Warn_On_Assumed_Low_Bound
:= True; -- -gnatww
563 Warn_On_Bad_Fixed_Value
:= True; -- -gnatwb
564 Warn_On_Biased_Representation
:= True; -- -gnatw.b
565 Warn_On_Export_Import
:= True; -- -gnatwx
566 Warn_On_No_Value_Assigned
:= True; -- -gnatwv
567 Warn_On_Object_Renames_Function
:= True; -- -gnatw.r
568 Warn_On_Overlap
:= True; -- -gnatw.i
569 Warn_On_Parameter_Order
:= True; -- -gnatw.p
570 Warn_On_Questionable_Missing_Parens
:= True; -- -gnatwq
571 Warn_On_Redundant_Constructs
:= True; -- -gnatwr
572 Warn_On_Suspicious_Modulus_Value
:= True; -- -gnatw.m
575 -- -gnated switch (disable atomic synchronization)
578 Suppress_Options
.Suppress
(Atomic_Synchronization
) :=
581 -- -gnateD switch (preprocessing symbol definition)
584 Store_Switch
:= False;
588 Bad_Switch
("-gnateD");
591 Add_Symbol_Definition
(Switch_Chars
(Ptr
.. Max
));
595 Store_Compilation_Switch
596 ("-gnateD" & Switch_Chars
(Ptr
.. Max
));
599 -- -gnateE (extra exception information)
602 Exception_Extra_Info
:= True;
605 -- -gnatef (full source path for brief error messages and
606 -- absolute paths for -fdiagnostics-format=json)
609 Store_Switch
:= False;
611 Full_Path_Name_For_Brief_Errors
:= True;
613 -- -gnateF (Check_Float_Overflow)
617 Check_Float_Overflow
:= not Machine_Overflows_On_Target
;
619 -- -gnateg (generate C code)
622 -- Special check, -gnateg must occur after -gnatc
624 if Operating_Mode
/= Check_Semantics
then
626 ("gnateg requires previous occurrence of -gnatc");
629 Generate_C_Code
:= True;
632 -- -gnateG (save preprocessor output)
635 Generate_Processed_File
:= True;
638 -- -gnateH (set reverse Bit_Order threshold to 64)
641 Reverse_Bit_Order_Threshold
:= 64;
644 -- -gnatei (max number of instantiations)
649 (Switch_Chars
, Max
, Ptr
, Maximum_Instantiations
, C
);
651 -- -gnateI (index of unit in multi-unit source)
655 Scan_Pos
(Switch_Chars
, Max
, Ptr
, Multiple_Unit_Index
, C
);
661 Elab_Info_Messages
:= True;
667 Elab_Info_Messages
:= False;
669 -- -gnatem (mapping file)
672 Store_Switch
:= False;
675 -- There may be an equal sign between -gnatem and
676 -- the path name of the mapping file.
678 if Ptr
<= Max
and then Switch_Chars
(Ptr
) = '=' then
683 Bad_Switch
("-gnatem");
687 new String'(Switch_Chars (Ptr .. Max));
690 -- -gnaten (memory to allocate for nodes)
695 (Switch_Chars, Max, Ptr, Nodes_Size_In_Meg, C);
697 -- -gnateO= (object path file)
699 -- This is an internal switch
702 Store_Switch := False;
707 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
708 Bad_Switch ("-gnateO");
710 Object_Path_File_Name :=
711 new String'(Switch_Chars
(Ptr
+ 1 .. Max
));
716 -- -gnatep (preprocessing data file)
719 Store_Switch
:= False;
722 -- There may be an equal sign between -gnatep and
723 -- the path name of the mapping file.
725 if Ptr
<= Max
and then Switch_Chars
(Ptr
) = '=' then
730 Bad_Switch
("-gnatep");
733 Preprocessing_Data_File
:=
734 new String'(Switch_Chars (Ptr .. Max));
736 -- Store the switch, normalizing to -gnatep=
738 Store_Compilation_Switch
739 ("-gnatep=" & Preprocessing_Data_File.all);
743 -- -gnateP (Treat pragma Pure/Preelaborate errs as warnings)
746 Treat_Categorization_Errors_As_Warnings := True;
749 -- -gnates=file (specify extra file switches for gnat2why)
751 -- This is an internal switch
754 if not First_Switch then
756 ("-gnates must not be combined with other switches");
763 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
764 Bad_Switch ("-gnates");
766 SPARK_Switches_File_Name :=
767 new String'(Switch_Chars
(Ptr
+ 1 .. Max
));
772 -- -gnateS (generate SCO information)
774 -- Include Source Coverage Obligation information in ALI
775 -- files for use by source coverage analysis tools
776 -- (gnatcov) (equivalent to -fdump-scos, provided for
777 -- backwards compatibility).
780 Generate_SCO
:= True;
781 Generate_SCO_Instance_Table
:= True;
784 -- -gnatet (write target dependent information)
787 if not First_Switch
then
789 ("-gnatet must not be combined with other switches");
796 if Ptr
>= Max
or else Switch_Chars
(Ptr
) /= '=' then
797 Bad_Switch
("-gnatet");
799 Target_Dependent_Info_Write_Name
:=
800 new String'(Switch_Chars (Ptr + 1 .. Max));
805 -- -gnateT (read target dependent information)
808 if not First_Switch then
810 ("-gnateT must not be combined with other switches");
817 if Ptr >= Max or else Switch_Chars (Ptr) /= '=' then
818 Bad_Switch ("-gnateT");
820 -- This parameter was stored by Set_Targ earlier
823 (Target_Dependent_Info_Read_Name.all =
824 Switch_Chars (Ptr + 1 .. Max));
830 -- -gnateu (unrecognized y,V,w switches)
833 Ignore_Unrecognized_VWY_Switches := True;
836 -- -gnateV (validity checks on parameters)
840 Check_Validity_Of_Parameters := True;
842 -- -gnateY (ignore Style_Checks pragmas)
845 Ignore_Style_Checks_Pragmas := True;
848 -- -gnatez (final delimiter of explicit switches)
850 -- This is an internal switch
852 -- All switches that come after -gnatez have been added by
853 -- the GCC driver and are not stored in the ALI file. See
854 -- also -gnatea above.
857 Store_Switch := False;
858 Disable_Switch_Storing;
861 -- All other -gnate? switches are unassigned
864 Bad_Switch ("-gnate" & Switch_Chars (Ptr .. Max));
867 -- -gnatE (dynamic elaboration checks)
871 Dynamic_Elaboration_Checks := True;
873 -- -gnatf (full error messages)
877 All_Errors_Mode := True;
879 -- -gnatF (overflow of predefined float types)
883 External_Name_Exp_Casing := Uppercase;
884 External_Name_Imp_Casing := Uppercase;
886 -- -gnatg (GNAT implementation mode)
891 GNAT_Mode_Config := True;
892 Identifier_Character_Set := 'n
';
893 System_Extend_Unit := Empty;
894 Warning_Mode := Treat_As_Error;
895 Style_Check_Main := True;
896 Ada_Version := Ada_2012;
897 Ada_Version_Explicit := Ada_2012;
898 Ada_Version_Pragma := Empty;
900 -- Set default warnings and style checks for -gnatg
902 Set_GNAT_Mode_Warnings;
903 Set_GNAT_Style_Check_Options;
905 -- -gnatG (output generated code)
909 Print_Generated_Code := True;
911 -- Scan optional integer line limit value
913 if Nat_Present (Switch_Chars, Max, Ptr) then
914 Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'G
');
915 Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
918 -- -gnath (help information)
922 Usage_Requested := True;
924 -- -gnatH (legacy static elaboration checking mode enabled)
928 Legacy_Elaboration_Checks := True;
930 -- -gnati (character set)
934 Bad_Switch ("-gnati");
938 C := Switch_Chars (Ptr);
940 if C in '1' .. '5' | '8' | 'p
' | '9' | 'f
' | 'n
' | 'w
' then
941 Identifier_Character_Set := C;
945 Bad_Switch ("-gnati" & Switch_Chars (Ptr .. Max));
948 -- -gnatI (ignore representation clauses)
952 Ignore_Rep_Clauses := True;
954 -- -gnatj (messages in limited length lines)
958 Scan_Nat (Switch_Chars, Max, Ptr, Error_Msg_Line_Length, C);
960 -- -gnatJ (relaxed elaboration checking mode enabled)
964 Relaxed_Elaboration_Checks := True;
966 -- Common relaxations for both ABE mechanisms
968 -- -gnatd.G (ignore calls through generic formal parameters
970 -- -gnatd.U (ignore indirect calls for static elaboration)
971 -- -gnatd.y (disable implicit pragma Elaborate_All on task
974 Debug_Flag_Dot_GG := True;
975 Debug_Flag_Dot_UU := True;
976 Debug_Flag_Dot_Y := True;
978 -- Relaxatons to the legacy ABE mechanism
980 if Legacy_Elaboration_Checks then
983 -- Relaxations to the default ABE mechanism
985 -- -gnatd_a (stop elaboration checks on accept or select
987 -- -gnatd_e (ignore entry calls and requeue statements for
989 -- -gnatd_i (ignore activations and calls to instances for
991 -- -gnatd_p (ignore assertion pragmas for elaboration)
992 -- -gnatd_s (stop elaboration checks on synchronous
994 -- -gnatdL (ignore external calls from instances for
998 Debug_Flag_Underscore_A := True;
999 Debug_Flag_Underscore_E := True;
1000 Debug_Flag_Underscore_I := True;
1001 Debug_Flag_Underscore_P := True;
1002 Debug_Flag_Underscore_S := True;
1003 Debug_Flag_LL := True;
1006 -- -gnatk (limit file name length)
1011 (Switch_Chars, Max, Ptr, Maximum_File_Name_Length, C);
1013 -- -gnatl (output full source)
1019 -- There may be an equal sign between -gnatl and a file name
1021 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
1023 Osint.Fail ("file name for -gnatl= is null");
1025 Opt.Full_List_File_Name :=
1026 new String'(Switch_Chars
(Ptr
+ 1 .. Max
));
1031 -- -gnatL (corresponding source text)
1035 Dump_Source_Text
:= True;
1037 -- -gnatm (max number or errors/warnings)
1041 Scan_Nat
(Switch_Chars
, Max
, Ptr
, Maximum_Messages
, C
);
1043 -- -gnatn (enable pragma Inline)
1047 Inline_Active
:= True;
1049 -- There may be a digit (1 or 2) appended to the switch
1052 C
:= Switch_Chars
(Ptr
);
1054 if C
in '1' .. '2' then
1056 Inline_Level
:= Character'Pos (C
) - Character'Pos ('0');
1060 -- -gnatN (obsolescent)
1064 Inline_Active
:= True;
1065 Front_End_Inlining
:= True;
1067 -- -gnato (overflow checks)
1072 -- Case of -gnato0 (overflow checking turned off)
1074 if Ptr
<= Max
and then Switch_Chars
(Ptr
) = '0' then
1076 Suppress_Options
.Suppress
(Overflow_Check
) := True;
1078 -- We set strict mode in case overflow checking is turned
1079 -- on locally (also records that we had a -gnato switch).
1081 Suppress_Options
.Overflow_Mode_General
:= Strict
;
1082 Suppress_Options
.Overflow_Mode_Assertions
:= Strict
;
1084 -- All cases other than -gnato0 (overflow checking turned on)
1087 Suppress_Options
.Suppress
(Overflow_Check
) := False;
1089 -- Case of no digits after the -gnato
1092 or else Switch_Chars
(Ptr
) not in '1' .. '3'
1094 Suppress_Options
.Overflow_Mode_General
:= Strict
;
1095 Suppress_Options
.Overflow_Mode_Assertions
:= Strict
;
1097 -- At least one digit after the -gnato
1100 -- Handle first digit after -gnato
1102 Suppress_Options
.Overflow_Mode_General
:=
1103 Get_Overflow_Mode
(Switch_Chars
(Ptr
));
1106 -- Only one digit after -gnato, set assertions mode to be
1107 -- the same as general mode.
1110 or else Switch_Chars
(Ptr
) not in '1' .. '3'
1112 Suppress_Options
.Overflow_Mode_Assertions
:=
1113 Suppress_Options
.Overflow_Mode_General
;
1115 -- Process second digit after -gnato
1118 Suppress_Options
.Overflow_Mode_Assertions
:=
1119 Get_Overflow_Mode
(Switch_Chars
(Ptr
));
1125 -- -gnatO (specify name of the object file)
1127 -- This is an internal switch
1130 Store_Switch
:= False;
1132 Output_File_Name_Present
:= True;
1134 -- -gnatp (suppress all checks)
1139 -- Skip processing if cancelled by subsequent -gnat-p
1141 if Switch_Subsequently_Cancelled
("p", Args
, Arg_Rank
) then
1142 Store_Switch
:= False;
1145 -- Set all specific options as well as All_Checks in the
1146 -- Suppress_Options array, excluding Elaboration_Check,
1147 -- since this is treated specially because we do not want
1148 -- -gnatp to disable static elaboration processing. Also
1149 -- exclude Atomic_Synchronization, since this is not a real
1152 for J
in Suppress_Options
.Suppress
'Range loop
1153 if J
/= Elaboration_Check
1155 J
/= Atomic_Synchronization
1157 Suppress_Options
.Suppress
(J
) := True;
1161 Validity_Checks_On
:= False;
1162 Opt
.Suppress_Checks
:= True;
1164 -- Set overflow mode checking to strict in case it gets
1165 -- turned on locally (also signals that overflow checking
1166 -- has been specifically turned off).
1168 Suppress_Options
.Overflow_Mode_General
:= Strict
;
1169 Suppress_Options
.Overflow_Mode_Assertions
:= Strict
;
1172 -- -gnatq (don't quit)
1176 Try_Semantics
:= True;
1178 -- -gnatQ (always write ALI file)
1182 Force_ALI_File
:= True;
1183 Try_Semantics
:= True;
1185 -- -gnatr (restrictions as warnings)
1189 Treat_Restrictions_As_Warnings
:= True;
1191 -- -gnatR (list rep. info)
1195 -- Not allowed if previous -gnatD given. See more extensive
1196 -- comments in the 'D' section for the inverse test.
1198 if Debug_Generated_Code
then
1200 ("-gnatR not permitted since -gnatD given previously");
1203 -- Set to annotate rep info, and set default -gnatR mode
1205 Back_Annotate_Rep_Info
:= True;
1206 List_Representation_Info
:= 1;
1208 -- Scan possible parameter
1211 while Ptr
<= Max
loop
1212 C
:= Switch_Chars
(Ptr
);
1217 List_Representation_Info
:=
1218 Character'Pos (C
) - Character'Pos ('0');
1221 List_Representation_Info_To_File
:= True;
1224 List_Representation_Info_To_JSON
:= True;
1227 List_Representation_Info_Mechanisms
:= True;
1230 List_Representation_Info_Extended
:= True;
1233 Bad_Switch
("-gnatR" & Switch_Chars
(Ptr
.. Max
));
1239 if List_Representation_Info_To_JSON
1240 and then List_Representation_Info_Extended
1242 Osint
.Fail
("-gnatRe is incompatible with -gnatRj");
1245 -- -gnats (syntax check only)
1248 if not First_Switch
then
1250 ("-gnats must be first if combined with other switches");
1254 Operating_Mode
:= Check_Syntax
;
1256 -- -gnatS (print package Standard)
1259 Print_Standard
:= True;
1262 -- -gnatT (change start of internal table sizes)
1266 Scan_Pos
(Switch_Chars
, Max
, Ptr
, Table_Factor
, C
);
1268 -- -gnatu (list units for compilation)
1274 -- -gnatU (unique tags)
1278 Unique_Error_Tag
:= True;
1280 -- -gnatv (verbose mode)
1284 Verbose_Mode
:= True;
1286 -- -gnatV (validity checks)
1289 Store_Switch
:= False;
1293 Bad_Switch
("-gnatV");
1300 Set_Validity_Check_Options
1301 (Switch_Chars
(Ptr
.. Max
), OK
, Ptr
);
1304 Bad_Switch
("-gnatV" & Switch_Chars
(Ptr
.. Max
));
1307 for Index
in First_Char
+ 1 .. Max
loop
1308 Store_Compilation_Switch
1309 ("-gnatV" & Switch_Chars
(Index
));
1316 -- -gnatw (warning modes)
1319 Store_Switch
:= False;
1323 Bad_Switch
("-gnatw");
1326 while Ptr
<= Max
loop
1327 C
:= Switch_Chars
(Ptr
);
1329 -- Case of dot switch
1331 if C
= '.' and then Ptr
< Max
then
1333 C
:= Switch_Chars
(Ptr
);
1335 if Set_Warning_Switch
('.', C
) then
1336 Store_Compilation_Switch
("-gnatw." & C
);
1338 Bad_Switch
("-gnatw." & Switch_Chars
(Ptr
.. Max
));
1341 -- Case of underscore switch
1343 elsif C
= '_' and then Ptr
< Max
then
1345 C
:= Switch_Chars
(Ptr
);
1347 if Set_Warning_Switch
('_', C
) then
1348 Store_Compilation_Switch
("-gnatw_" & C
);
1350 Bad_Switch
("-gnatw_" & Switch_Chars
(Ptr
.. Max
));
1356 if Set_Warning_Switch
(Plain
, C
) then
1357 Store_Compilation_Switch
("-gnatw" & C
);
1359 Bad_Switch
("-gnatw" & Switch_Chars
(Ptr
.. Max
));
1368 -- -gnatW (wide character encoding method)
1374 Bad_Switch
("-gnatW");
1378 Wide_Character_Encoding_Method
:=
1379 Get_WC_Encoding_Method
(Switch_Chars
(Ptr
));
1381 when Constraint_Error
=>
1382 Bad_Switch
("-gnatW" & Switch_Chars
(Ptr
.. Max
));
1385 Wide_Character_Encoding_Method_Specified
:= True;
1387 Upper_Half_Encoding
:=
1388 Wide_Character_Encoding_Method
in
1389 WC_Upper_Half_Encoding_Method
;
1393 -- -gnatx (suppress cross-ref information)
1397 Xref_Active
:= False;
1399 -- -gnatX (core language extensions)
1404 if Ptr
<= Max
and then Switch_Chars
(Ptr
) = '0' then
1405 -- -gnatX0 (all language extensions)
1408 Ada_Version
:= Ada_With_All_Extensions
;
1410 Ada_Version
:= Ada_With_Core_Extensions
;
1413 Ada_Version_Explicit
:= Ada_Version
;
1414 Ada_Version_Pragma
:= Empty
;
1416 -- -gnaty (style checks)
1420 Style_Check_Main
:= True;
1423 Set_Default_Style_Check_Options
;
1426 Store_Switch
:= False;
1432 Set_Style_Check_Options
1433 (Switch_Chars
(Ptr
.. Max
), OK
, Ptr
);
1437 ("bad -gnaty switch (" &
1438 Style_Msg_Buf
(1 .. Style_Msg_Len
) & ')');
1441 Ptr
:= First_Char
+ 1;
1442 while Ptr
<= Max
loop
1443 if Switch_Chars
(Ptr
) = 'M' then
1448 or else Switch_Chars
(Ptr
) not in '0' .. '9';
1451 Store_Compilation_Switch
1452 ("-gnaty" & Switch_Chars
(First_Char
.. Ptr
- 1));
1455 Store_Compilation_Switch
1456 ("-gnaty" & Switch_Chars
(Ptr
));
1463 -- -gnatz (stub generation)
1467 -- -gnatz must be the first and only switch in Switch_Chars,
1468 -- and is a two-letter switch.
1470 if Ptr
/= Switch_Chars
'First + 5
1471 or else (Max
- Ptr
+ 1) > 2
1474 ("-gnatz* may not be combined with other switches");
1478 Bad_Switch
("-gnatz");
1483 -- Only one occurrence of -gnat* is permitted
1485 if Distribution_Stub_Mode
= No_Stubs
then
1486 case Switch_Chars
(Ptr
) is
1488 Distribution_Stub_Mode
:= Generate_Receiver_Stub_Body
;
1491 Distribution_Stub_Mode
:= Generate_Caller_Stub_Body
;
1494 Bad_Switch
("-gnatz" & Switch_Chars
(Ptr
.. Max
));
1500 Osint
.Fail
("only one -gnatz* switch allowed");
1503 -- -gnatZ (obsolescent)
1508 ("-gnatZ is no longer supported: consider using --RTS=zcx");
1510 -- Note on language version switches: whenever a new language
1511 -- version switch is added, Switch.M.Normalize_Compiler_Switches
1518 Bad_Switch
("-gnat8");
1523 if Switch_Chars
(Ptr
) /= '3' or else Latest_Ada_Only
then
1524 Bad_Switch
("-gnat8" & Switch_Chars
(Ptr
.. Max
));
1527 Ada_Version
:= Ada_83
;
1528 Ada_Version_Explicit
:= Ada_83
;
1529 Ada_Version_Pragma
:= Empty
;
1536 Bad_Switch
("-gnat9");
1541 if Switch_Chars
(Ptr
) /= '5' or else Latest_Ada_Only
then
1542 Bad_Switch
("-gnat9" & Switch_Chars
(Ptr
.. Max
));
1545 Ada_Version
:= Ada_95
;
1546 Ada_Version_Explicit
:= Ada_95
;
1547 Ada_Version_Pragma
:= Empty
;
1554 Bad_Switch
("-gnat0");
1559 if Switch_Chars
(Ptr
) /= '5' or else Latest_Ada_Only
then
1560 Bad_Switch
("-gnat0" & Switch_Chars
(Ptr
.. Max
));
1563 Ada_Version
:= Ada_2005
;
1564 Ada_Version_Explicit
:= Ada_2005
;
1565 Ada_Version_Pragma
:= Empty
;
1572 Bad_Switch
("-gnat1");
1577 if Switch_Chars
(Ptr
) /= '2' then
1578 Bad_Switch
("-gnat1" & Switch_Chars
(Ptr
.. Max
));
1581 Ada_Version
:= Ada_2012
;
1582 Ada_Version_Explicit
:= Ada_2012
;
1583 Ada_Version_Pragma
:= Empty
;
1586 -- -gnat2005 and -gnat2012
1589 if Ptr
> Max
- 3 then
1590 Bad_Switch
("-gnat" & Switch_Chars
(Ptr
.. Max
));
1592 elsif Switch_Chars
(Ptr
.. Ptr
+ 3) = "2005"
1593 and then not Latest_Ada_Only
1595 Ada_Version
:= Ada_2005
;
1597 elsif Switch_Chars
(Ptr
.. Ptr
+ 3) = "2012" then
1598 Ada_Version
:= Ada_2012
;
1600 elsif Switch_Chars
(Ptr
.. Ptr
+ 3) = "2020"
1601 or else Switch_Chars
(Ptr
.. Ptr
+ 3) = "2022"
1603 Ada_Version
:= Ada_2022
;
1606 Bad_Switch
("-gnat" & Switch_Chars
(Ptr
.. Ptr
+ 3));
1609 Ada_Version_Explicit
:= Ada_Version
;
1610 Ada_Version_Pragma
:= Empty
;
1613 -- Switch cancellation, currently only -gnat-p is allowed.
1614 -- All we do here is the error checking, since the actual
1615 -- processing for switch cancellation is done by calls to
1616 -- Switch_Subsequently_Cancelled at the appropriate point.
1620 -- Simple ignore -gnat-p
1622 if Switch_Chars
= "-gnat-p" then
1625 -- Any other occurrence of minus is ignored. This is for
1626 -- maximum compatibility with previous version which ignored
1627 -- all occurrences of minus.
1630 Store_Switch
:= False;
1634 -- Anything else is an error (illegal switch character)
1637 Bad_Switch
("-gnat" & Switch_Chars
(Ptr
.. Max
));
1640 if Store_Switch
then
1641 Store_Compilation_Switch
1642 ("-gnat" & Switch_Chars
(First_Char
.. Ptr
- 1));
1645 First_Switch
:= False;
1648 end Scan_Front_End_Switches
;
1650 -----------------------------------
1651 -- Switch_Subsequently_Cancelled --
1652 -----------------------------------
1654 function Switch_Subsequently_Cancelled
1657 Arg_Rank
: Positive) return Boolean
1660 -- Loop through arguments following the current one
1662 for Arg
in Arg_Rank
+ 1 .. Args
'Last loop
1663 if Args
(Arg
).all = "-gnat-" & C
then
1668 -- No match found, not cancelled
1671 end Switch_Subsequently_Cancelled
;