1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
27 ------------------------------------------------------------------------------
29 -- Option switch scanning for both the compiler and the binder
31 -- Note: this version of the package should be usable in both Unix and DOS
33 with Debug; use Debug;
34 with Osint; use Osint;
36 with Validsw; use Validsw;
37 with Stylesw; use Stylesw;
38 with Types; use Types;
40 with System.WCh_Con; use System.WCh_Con;
42 package body Switch is
44 Bad_Switch : exception;
45 -- Exception raised if bad switch encountered
47 Bad_Switch_Value : exception;
48 -- Exception raised if bad switch value encountered
50 Missing_Switch_Value : exception;
51 -- Exception raised if no switch value encountered
53 Too_Many_Output_Files : exception;
54 -- Exception raised if the -o switch is encountered more than once
56 Switch_Max_Value : constant := 999;
57 -- Maximum value permitted in switches that take a value
60 (Switch_Chars : String;
64 -- Scan natural integer parameter for switch. On entry, Ptr points
65 -- just past the switch character, on exit it points past the last
66 -- digit of the integer value.
69 (Switch_Chars : String;
73 -- Scan positive integer parameter for switch. On entry, Ptr points
74 -- just past the switch character, on exit it points past the last
75 -- digit of the integer value.
77 -------------------------
78 -- Is_Front_End_Switch --
79 -------------------------
81 function Is_Front_End_Switch (Switch_Chars : String) return Boolean is
82 Ptr : constant Positive := Switch_Chars'First;
84 return Is_Switch (Switch_Chars)
86 (Switch_Chars (Ptr + 1) = 'I'
88 (Switch_Chars'Length >= 5
89 and then Switch_Chars (Ptr + 1 .. Ptr + 4) = "gnat"));
90 end Is_Front_End_Switch;
96 function Is_Switch (Switch_Chars : String) return Boolean is
98 return Switch_Chars'Length > 1
99 and then (Switch_Chars (Switch_Chars'First) = '-'
101 Switch_Chars (Switch_Chars'First) = Switch_Character);
104 --------------------------
105 -- Scan_Binder_Switches --
106 --------------------------
108 procedure Scan_Binder_Switches (Switch_Chars : String) is
109 Ptr : Integer := Switch_Chars'First;
110 Max : Integer := Switch_Chars'Last;
111 C : Character := ' ';
114 -- Skip past the initial character (must be the switch character)
122 -- A little check, "gnat" at the start of a switch is not allowed
123 -- except for the compiler
125 if Switch_Chars'Last >= Ptr + 3
126 and then Switch_Chars (Ptr .. Ptr + 3) = "gnat"
128 Osint.Fail ("invalid switch: """, Switch_Chars, """"
129 & " (gnat not needed here)");
133 -- Loop to scan through switches given in switch string
135 while Ptr <= Max loop
136 C := Switch_Chars (Ptr);
140 -- Processing for A switch
145 Ada_Bind_File := True;
147 -- Processing for b switch
151 Brief_Output := True;
153 -- Processing for c switch
160 -- Processing for C switch
165 Ada_Bind_File := False;
167 -- Processing for d switch
171 -- Note: for the debug switch, the remaining characters in this
172 -- switch field must all be debug flags, since all valid switch
173 -- characters are also valid debug characters.
175 -- Loop to scan out debug flags
179 C := Switch_Chars (Ptr);
180 exit when C = ASCII.NUL or else C = '/' or else C = '-';
182 if C in '1' .. '9' or else
183 C in 'a' .. 'z' or else
192 -- Make sure Zero_Cost_Exceptions is set if gnatdX set. This
193 -- is for backwards compatibility with old versions and usage.
195 if Debug_Flag_XX then
196 Zero_Cost_Exceptions_Set := True;
197 Zero_Cost_Exceptions_Val := True;
202 -- Processing for e switch
206 Elab_Dependency_Output := True;
208 -- Processing for E switch
212 Exception_Tracebacks := True;
214 -- Processing for f switch
218 Force_RM_Elaboration_Order := True;
220 -- Processing for g switch
225 C := Switch_Chars (Ptr);
226 if C in '0' .. '3' then
229 (Switch_Chars (Ptr)) - Character'Pos ('0');
236 -- Processing for G switch
240 Print_Generated_Code := True;
242 -- Processing for h switch
246 Usage_Requested := True;
248 -- Processing for i switch
256 C := Switch_Chars (Ptr);
268 Identifier_Character_Set := C;
274 -- Processing for K switch
279 if Program = Binder then
280 Output_Linker_Option_List := True;
285 -- Processing for l switch
289 Elab_Order_Output := True;
291 -- Processing for m switch
295 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Errors);
297 -- Processing for n switch
301 Bind_Main_Program := False;
303 -- Note: The -L option of the binder also implies -n, so
304 -- any change here must also be reflected in the processing
305 -- for -L that is found in Gnatbind.Scan_Bind_Arg.
307 -- Processing for o switch
312 if Output_File_Name_Present then
313 raise Too_Many_Output_Files;
316 Output_File_Name_Present := True;
319 -- Processing for O switch
323 Output_Object_List := True;
325 -- Processing for p switch
329 Pessimistic_Elab_Order := True;
331 -- Processing for q switch
335 Quiet_Output := True;
337 -- Processing for s switch
342 Check_Source_Files := True;
344 -- Processing for t switch
348 Tolerate_Consistency_Errors := True;
350 -- Processing for T switch
354 Time_Slice_Set := True;
355 Scan_Nat (Switch_Chars, Max, Ptr, Time_Slice_Value);
357 -- Processing for v switch
361 Verbose_Mode := True;
363 -- Processing for w switch
367 -- For the binder we only allow suppress/error cases
371 case Switch_Chars (Ptr) is
374 Warning_Mode := Treat_As_Error;
377 Warning_Mode := Suppress;
385 -- Processing for W switch
390 for J in WC_Encoding_Method loop
391 if Switch_Chars (Ptr) = WC_Encoding_Letters (J) then
392 Wide_Character_Encoding_Method := J;
395 elsif J = WC_Encoding_Method'Last then
400 Upper_Half_Encoding :=
401 Wide_Character_Encoding_Method in
402 WC_Upper_Half_Encoding_Method;
406 -- Processing for x switch
410 All_Sources := False;
411 Check_Source_Files := False;
413 -- Processing for z switch
417 No_Main_Subprogram := True;
419 -- Ignore extra switch character
424 -- Anything else is an error (illegal switch character)
433 Osint.Fail ("invalid switch: ", (1 => C));
435 when Bad_Switch_Value =>
436 Osint.Fail ("numeric value too big for switch: ", (1 => C));
438 when Missing_Switch_Value =>
439 Osint.Fail ("missing numeric value for switch: ", (1 => C));
441 when Too_Many_Output_Files =>
442 Osint.Fail ("duplicate -o switch");
443 end Scan_Binder_Switches;
445 -----------------------------
446 -- Scan_Front_End_Switches --
447 -----------------------------
449 procedure Scan_Front_End_Switches (Switch_Chars : String) is
450 Switch_Starts_With_Gnat : Boolean;
451 Ptr : Integer := Switch_Chars'First;
452 Max : constant Integer := Switch_Chars'Last;
453 C : Character := ' ';
456 -- Skip past the initial character (must be the switch character)
465 -- A little check, "gnat" at the start of a switch is not allowed
466 -- except for the compiler (where it was already removed)
468 Switch_Starts_With_Gnat :=
469 Ptr + 3 <= Max and then Switch_Chars (Ptr .. Ptr + 3) = "gnat";
471 if Switch_Starts_With_Gnat then
475 -- Loop to scan through switches given in switch string
477 while Ptr <= Max loop
478 C := Switch_Chars (Ptr);
480 -- Processing for a switch
482 case Switch_Starts_With_Gnat is
485 -- There is only one front-end switch that
486 -- does not start with -gnat, namely -I
497 -- Find out whether this is a -I- or regular -Ixxx switch
499 if Ptr = Max and then Switch_Chars (Ptr) = '-' then
500 Look_In_Primary_Dir := False;
503 Add_Src_Search_Dir (Switch_Chars (Ptr .. Max));
509 -- Should not happen, as Scan_Switches is supposed
510 -- to be called for front-end switches only.
511 -- Still, it is safest to raise Bad_Switch error.
517 -- Process -gnat* options
523 Assertions_Enabled := True;
525 -- Processing for A switch
529 Config_File := False;
531 -- Processing for b switch
535 Brief_Output := True;
537 -- Processing for c switch
541 Operating_Mode := Check_Semantics;
543 -- Processing for C switch
547 Compress_Debug_Names := True;
549 -- Processing for d switch
553 -- Note: for the debug switch, the remaining characters in this
554 -- switch field must all be debug flags, since all valid switch
555 -- characters are also valid debug characters.
557 -- Loop to scan out debug flags
561 C := Switch_Chars (Ptr);
562 exit when C = ASCII.NUL or else C = '/' or else C = '-';
564 if C in '1' .. '9' or else
565 C in 'a' .. 'z' or else
575 -- Make sure Zero_Cost_Exceptions is set if gnatdX set. This
576 -- is for backwards compatibility with old versions and usage.
578 if Debug_Flag_XX then
579 Zero_Cost_Exceptions_Set := True;
580 Zero_Cost_Exceptions_Val := True;
585 -- Processing for D switch
590 -- Note: -gnatD also sets -gnatx (to turn off cross-reference
591 -- generation in the ali file) since otherwise this generation
592 -- gets confused by the "wrong" Sloc values put in the tree.
594 Debug_Generated_Code := True;
595 Xref_Active := False;
596 Set_Debug_Flag ('g');
598 -- Processing for e switch
607 case Switch_Chars (Ptr) is
612 Osint.Fail ("Invalid switch: ", "ec");
616 new String'(Switch_Chars (Ptr .. Max));
621 Osint.Fail ("Invalid switch: ",
622 (1 => 'e', 2 => Switch_Chars (Ptr)));
625 -- Processing for E switch
629 Dynamic_Elaboration_Checks := True;
631 -- Processing for f switch
635 All_Errors_Mode := True;
637 -- Processing for F switch
641 External_Name_Exp_Casing := Uppercase;
642 External_Name_Imp_Casing := Uppercase;
644 -- Processing for g switch
649 Identifier_Character_Set := 'n';
650 Warning_Mode := Treat_As_Error;
651 Check_Unreferenced := True;
654 Set_Default_Style_Check_Options;
656 -- Processing for G switch
660 Print_Generated_Code := True;
662 -- Processing for h switch
666 Usage_Requested := True;
668 -- Processing for H switch
674 -- Processing for i switch
682 C := Switch_Chars (Ptr);
694 Identifier_Character_Set := C;
701 -- Processing for k switch
705 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_File_Name_Length);
707 -- Processing for l switch
713 -- Processing for L switch
717 Zero_Cost_Exceptions_Set := True;
718 Zero_Cost_Exceptions_Val := False;
720 -- Processing for m switch
724 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Errors);
726 -- Processing for n switch
730 Inline_Active := True;
732 -- Processing for N switch
736 Inline_Active := True;
737 Front_End_Inlining := True;
739 -- Processing for o switch
743 Suppress_Options.Overflow_Checks := False;
745 -- Processing for O switch
749 Output_File_Name_Present := True;
751 -- Processing for p switch
755 Suppress_Options.Access_Checks := True;
756 Suppress_Options.Accessibility_Checks := True;
757 Suppress_Options.Discriminant_Checks := True;
758 Suppress_Options.Division_Checks := True;
759 Suppress_Options.Elaboration_Checks := True;
760 Suppress_Options.Index_Checks := True;
761 Suppress_Options.Length_Checks := True;
762 Suppress_Options.Overflow_Checks := True;
763 Suppress_Options.Range_Checks := True;
764 Suppress_Options.Division_Checks := True;
765 Suppress_Options.Length_Checks := True;
766 Suppress_Options.Range_Checks := True;
767 Suppress_Options.Storage_Checks := True;
768 Suppress_Options.Tag_Checks := True;
770 Validity_Checks_On := False;
772 -- Processing for P switch
776 Polling_Required := True;
778 -- Processing for q switch
782 Try_Semantics := True;
784 -- Processing for q switch
788 Force_ALI_Tree_File := True;
789 Try_Semantics := True;
791 -- Processing for r switch
796 -- Temporarily allow -gnatr to mean -gnatyl (use RM layout)
797 -- for compatibility with pre 3.12 versions of GNAT,
798 -- to be removed for 3.13 ???
800 Set_Style_Check_Options ("l");
802 -- Processing for R switch
806 Back_Annotate_Rep_Info := True;
809 and then Switch_Chars (Ptr) in '0' .. '9'
811 C := Switch_Chars (Ptr);
813 if C in '4' .. '9' then
816 List_Representation_Info :=
817 Character'Pos (C) - Character'Pos ('0');
822 List_Representation_Info := 1;
825 -- Processing for s switch
829 Operating_Mode := Check_Syntax;
831 -- Processing for t switch
836 Back_Annotate_Rep_Info := True;
838 -- Processing for T switch
842 Time_Slice_Set := True;
843 Scan_Nat (Switch_Chars, Max, Ptr, Time_Slice_Value);
845 -- Processing for u switch
851 -- Processing for U switch
855 Unique_Error_Tag := True;
857 -- Processing for v switch
861 Verbose_Mode := True;
863 -- Processing for V switch
876 Set_Validity_Check_Options
877 (Switch_Chars (Ptr .. Max), OK, Ptr);
885 -- Processing for w switch
894 while Ptr <= Max loop
895 C := Switch_Chars (Ptr);
900 Constant_Condition_Warnings := True;
901 Elab_Warnings := True;
902 Check_Unreferenced := True;
904 Implementation_Unit_Warnings := True;
905 Ineffective_Inline_Warnings := True;
906 Warn_On_Redundant_Constructs := True;
909 Constant_Condition_Warnings := False;
910 Elab_Warnings := False;
911 Check_Unreferenced := False;
912 Check_Withs := False;
913 Implementation_Unit_Warnings := False;
914 Warn_On_Biased_Rounding := False;
915 Warn_On_Hiding := False;
916 Warn_On_Redundant_Constructs := False;
917 Ineffective_Inline_Warnings := False;
920 Constant_Condition_Warnings := True;
923 Constant_Condition_Warnings := False;
926 Warn_On_Biased_Rounding := True;
929 Warn_On_Biased_Rounding := False;
932 Warning_Mode := Treat_As_Error;
935 Warn_On_Hiding := True;
938 Warn_On_Hiding := False;
941 Implementation_Unit_Warnings := True;
944 Implementation_Unit_Warnings := False;
947 Elab_Warnings := True;
950 Elab_Warnings := False;
953 Address_Clause_Overlay_Warnings := True;
956 Address_Clause_Overlay_Warnings := False;
959 Ineffective_Inline_Warnings := True;
962 Ineffective_Inline_Warnings := False;
965 Warn_On_Redundant_Constructs := True;
968 Warn_On_Redundant_Constructs := False;
971 Warning_Mode := Suppress;
974 Check_Unreferenced := True;
978 Check_Unreferenced := False;
979 Check_Withs := False;
981 -- Allow and ignore 'w' so that the old
982 -- format (e.g. -gnatwuwl) will work.
996 -- Processing for W switch
1001 for J in WC_Encoding_Method loop
1002 if Switch_Chars (Ptr) = WC_Encoding_Letters (J) then
1003 Wide_Character_Encoding_Method := J;
1006 elsif J = WC_Encoding_Method'Last then
1011 Upper_Half_Encoding :=
1012 Wide_Character_Encoding_Method in
1013 WC_Upper_Half_Encoding_Method;
1017 -- Processing for x switch
1021 Xref_Active := False;
1023 -- Processing for X switch
1027 Extensions_Allowed := True;
1029 -- Processing for y switch
1035 Set_Default_Style_Check_Options;
1042 Set_Style_Check_Options
1043 (Switch_Chars (Ptr .. Max), OK, Ptr);
1051 -- Processing for z switch
1056 -- Allowed for compiler, only if this is the only
1057 -- -z switch, we do not allow multiple occurrences
1059 if Distribution_Stub_Mode = No_Stubs then
1060 case Switch_Chars (Ptr) is
1062 Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
1065 Distribution_Stub_Mode := Generate_Caller_Stub_Body;
1075 -- Processing for Z switch
1079 Zero_Cost_Exceptions_Set := True;
1080 Zero_Cost_Exceptions_Val := True;
1082 -- Processing for 83 switch
1092 if Switch_Chars (Ptr) /= '3' then
1100 -- Ignore extra switch character
1105 -- Anything else is an error (illegal switch character)
1115 Osint.Fail ("invalid switch: ", (1 => C));
1117 when Bad_Switch_Value =>
1118 Osint.Fail ("numeric value too big for switch: ", (1 => C));
1120 when Missing_Switch_Value =>
1121 Osint.Fail ("missing numeric value for switch: ", (1 => C));
1123 end Scan_Front_End_Switches;
1125 ------------------------
1126 -- Scan_Make_Switches --
1127 ------------------------
1129 procedure Scan_Make_Switches (Switch_Chars : String) is
1130 Ptr : Integer := Switch_Chars'First;
1131 Max : Integer := Switch_Chars'Last;
1132 C : Character := ' ';
1135 -- Skip past the initial character (must be the switch character)
1144 -- A little check, "gnat" at the start of a switch is not allowed
1145 -- except for the compiler (where it was already removed)
1147 if Switch_Chars'Length >= Ptr + 3
1148 and then Switch_Chars (Ptr .. Ptr + 3) = "gnat"
1151 ("invalid switch: """, Switch_Chars, """ (gnat not needed here)");
1154 -- Loop to scan through switches given in switch string
1156 while Ptr <= Max loop
1157 C := Switch_Chars (Ptr);
1159 -- Processing for a switch
1165 Check_Readonly_Files := True;
1167 -- Processing for c switch
1171 Compile_Only := True;
1175 -- Note: for the debug switch, the remaining characters in this
1176 -- switch field must all be debug flags, since all valid switch
1177 -- characters are also valid debug characters.
1179 -- Loop to scan out debug flags
1181 while Ptr < Max loop
1183 C := Switch_Chars (Ptr);
1184 exit when C = ASCII.NUL or else C = '/' or else C = '-';
1186 if C in '1' .. '9' or else
1187 C in 'a' .. 'z' or else
1196 -- Make sure Zero_Cost_Exceptions is set if gnatdX set. This
1197 -- is for backwards compatibility with old versions and usage.
1199 if Debug_Flag_XX then
1200 Zero_Cost_Exceptions_Set := True;
1201 Zero_Cost_Exceptions_Val := True;
1206 -- Processing for f switch
1210 Force_Compilations := True;
1212 -- Processing for G switch
1216 Print_Generated_Code := True;
1218 -- Processing for h switch
1222 Usage_Requested := True;
1224 -- Processing for i switch
1228 In_Place_Mode := True;
1230 -- Processing for j switch
1238 Scan_Pos (Switch_Chars, Max, Ptr, Max_Proc);
1239 Maximum_Processes := Positive (Max_Proc);
1242 -- Processing for k switch
1250 List_Dependencies := True;
1252 -- Processing for n switch
1256 Do_Not_Execute := True;
1258 -- Processing for o switch
1263 if Output_File_Name_Present then
1264 raise Too_Many_Output_Files;
1266 Output_File_Name_Present := True;
1269 -- Processing for q switch
1273 Quiet_Output := True;
1275 -- Processing for s switch
1279 Check_Switches := True;
1281 -- Processing for v switch
1285 Verbose_Mode := True;
1287 -- Processing for z switch
1291 No_Main_Subprogram := True;
1293 -- Ignore extra switch character
1298 -- Anything else is an error (illegal switch character)
1308 Osint.Fail ("invalid switch: ", (1 => C));
1310 when Bad_Switch_Value =>
1311 Osint.Fail ("numeric value too big for switch: ", (1 => C));
1313 when Missing_Switch_Value =>
1314 Osint.Fail ("missing numeric value for switch: ", (1 => C));
1316 when Too_Many_Output_Files =>
1317 Osint.Fail ("duplicate -o switch");
1319 end Scan_Make_Switches;
1326 (Switch_Chars : String;
1328 Ptr : in out Integer;
1329 Result : out Nat) is
1332 if Ptr > Max or else Switch_Chars (Ptr) not in '0' .. '9' then
1333 raise Missing_Switch_Value;
1336 while Ptr <= Max and then Switch_Chars (Ptr) in '0' .. '9' loop
1337 Result := Result * 10 +
1338 Character'Pos (Switch_Chars (Ptr)) - Character'Pos ('0');
1341 if Result > Switch_Max_Value then
1342 raise Bad_Switch_Value;
1352 (Switch_Chars : String;
1354 Ptr : in out Integer;
1355 Result : out Pos) is
1358 Scan_Nat (Switch_Chars, Max, Ptr, Result);
1360 raise Bad_Switch_Value;