1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2003 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with GNAT
.OS_Lib
; use GNAT
.OS_Lib
;
29 with Debug
; use Debug
;
31 with Osint
; use Osint
;
33 with Prepcomp
; use Prepcomp
;
34 with Types
; use Types
;
35 with Validsw
; use Validsw
;
36 with Stylesw
; use Stylesw
;
38 with System
.WCh_Con
; use System
.WCh_Con
;
40 package body Switch
.C
is
42 RTS_Specified
: String_Access
:= null;
43 -- Used to detect multiple use of --RTS= flag
45 -----------------------------
46 -- Scan_Front_End_Switches --
47 -----------------------------
49 procedure Scan_Front_End_Switches
(Switch_Chars
: String) is
50 Switch_Starts_With_Gnat
: Boolean;
51 -- True if first four switch characters are "gnat"
53 First_Switch
: Boolean := True;
54 -- False for all but first switch
56 Ptr
: Integer := Switch_Chars
'First;
57 Max
: constant Integer := Switch_Chars
'Last;
61 Store_Switch
: Boolean := True;
62 First_Char
: Integer := Ptr
;
63 Storing
: String := Switch_Chars
;
64 First_Stored
: Positive := Ptr
+ 1;
65 -- The above need comments ???
68 -- Skip past the initial character (must be the switch character)
76 -- Remove "gnat" from the switch, if present
78 Switch_Starts_With_Gnat
:=
79 Ptr
+ 3 <= Max
and then Switch_Chars
(Ptr
.. Ptr
+ 3) = "gnat";
81 if Switch_Starts_With_Gnat
then
86 -- Loop to scan through switches given in switch string
91 C
:= Switch_Chars
(Ptr
);
93 -- Processing for a switch
95 case Switch_Starts_With_Gnat
is
99 -- There are few front-end switches that
100 -- do not start with -gnat: -I, --RTS, -nostdlib
102 if Switch_Chars
(Ptr
) = 'I' then
103 Store_Switch
:= False;
111 -- Find out whether this is a -I- or regular -Ixxx switch
113 if Ptr
= Max
and then Switch_Chars
(Ptr
) = '-' then
114 Look_In_Primary_Dir
:= False;
117 Add_Src_Search_Dir
(Switch_Chars
(Ptr
.. Max
));
122 -- Processing of -nostdlib
125 and then Switch_Chars
(Ptr
.. Ptr
+ 7) = "nostdlib"
127 Opt
.No_Stdlib
:= True;
130 -- Processing of the --RTS switch. --RTS has been modified by
131 -- gcc and is now of the form -fRTS
134 and then Switch_Chars
(Ptr
.. Ptr
+ 3) = "fRTS"
139 or else Switch_Chars
(Ptr
+ 3) /= '='
141 Osint
.Fail
("missing path for --RTS");
143 -- Check that this is the first time --RTS is specified
144 -- or if it is not the first time, the same path has
147 if RTS_Specified
= null then
149 new String'(Switch_Chars (Ptr + 4 .. Max));
152 RTS_Specified.all /= Switch_Chars (Ptr + 4 .. Max)
155 ("--RTS cannot be specified multiple times");
158 -- Valid --RTS switch
160 Opt.No_Stdinc := True;
161 Opt.RTS_Switch := True;
163 RTS_Src_Path_Name := Get_RTS_Search_Dir
164 (Switch_Chars (Ptr + 4 .. Max),
166 RTS_Lib_Path_Name := Get_RTS_Search_Dir
167 (Switch_Chars (Ptr + 4 .. Max),
170 if RTS_Src_Path_Name /= null and then
171 RTS_Lib_Path_Name /= null
175 elsif RTS_Src_Path_Name = null and then
176 RTS_Lib_Path_Name = null
178 Osint.Fail ("RTS path not valid: missing " &
179 "adainclude and adalib directories");
181 elsif RTS_Src_Path_Name = null then
182 Osint.Fail ("RTS path not valid: missing " &
183 "adainclude directory");
185 elsif RTS_Lib_Path_Name = null then
186 Osint.Fail ("RTS path not valid: missing " &
196 -- Process -gnat* options
202 Assertions_Enabled := True;
204 -- Processing for A switch
208 Config_File := False;
210 -- Processing for b switch
214 Brief_Output := True;
216 -- Processing for c switch
219 if not First_Switch then
221 ("-gnatc must be first if combined with other switches");
225 Operating_Mode := Check_Semantics;
231 -- Processing for d switch
234 Store_Switch := False;
235 Storing (First_Stored) := 'd
';
238 -- Note: for the debug switch, the remaining characters in this
239 -- switch field must all be debug flags, since all valid switch
240 -- characters are also valid debug characters.
242 -- Loop to scan out debug flags
246 C := Switch_Chars (Ptr);
247 exit when C = ASCII.NUL or else C = '/' or else C = '-';
249 if C in '1' .. '9' or else
250 C in 'a
' .. 'z
' or else
254 Set_Dotted_Debug_Flag (C);
255 Storing (First_Stored + 1) := '.';
256 Storing (First_Stored + 2) := C;
257 Store_Compilation_Switch
258 (Storing (Storing'First .. First_Stored + 2));
263 Storing (First_Stored + 1) := C;
264 Store_Compilation_Switch
265 (Storing (Storing'First .. First_Stored + 1));
276 -- Make sure Zero_Cost_Exceptions is set if gnatdX set. This
277 -- is for backwards compatibility with old versions and usage.
279 if Debug_Flag_XX then
280 Zero_Cost_Exceptions_Set := True;
281 Zero_Cost_Exceptions_Val := True;
286 -- Processing for D switch
291 -- Note: -gnatD also sets -gnatx (to turn off cross-reference
292 -- generation in the ali file) since otherwise this generation
293 -- gets confused by the "wrong" Sloc values put in the tree.
295 Debug_Generated_Code := True;
296 Xref_Active := False;
297 Set_Debug_Flag ('g
');
299 -- Processing for e switch
302 -- Only -gnateD and -gnatep= are stored
310 case Switch_Chars (Ptr) is
312 -- Configuration pragmas
315 Store_Switch := False;
318 -- There may be an equal sign between -gnatec and
319 -- the path name of the config file.
321 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
330 Config_File_Name : constant String_Access :=
332 (Switch_Chars
(Ptr
.. Max
));
335 if Config_File_Names
= null then
337 new String_List
'(1 => Config_File_Name);
341 New_Names : constant String_List_Access :=
344 Config_File_Names'Length + 1);
347 for Index in Config_File_Names'Range loop
349 Config_File_Names (Index);
350 Config_File_Names (Index) := null;
353 New_Names (New_Names'Last) := Config_File_Name;
354 Free (Config_File_Names);
355 Config_File_Names := New_Names;
365 Store_Switch := False;
372 Add_Symbol_Definition (Switch_Chars (Ptr .. Max));
376 Storing (First_Stored .. First_Stored + 1) := "eD";
378 (First_Stored + 2 .. First_Stored + Max - Ptr + 2) :=
379 Switch_Chars (Ptr .. Max);
380 Store_Compilation_Switch (Storing
381 (Storing'First .. First_Stored + Max - Ptr + 2));
384 -- Full source path for brief error messages
387 Store_Switch := False;
389 Full_Path_Name_For_Brief_Errors := True;
395 Store_Switch := False;
398 -- There may be an equal sign between -gnatem and
399 -- the path name of the mapping file.
401 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
410 new String'(Switch_Chars
(Ptr
.. Max
));
413 -- Preprocessing data file
416 Store_Switch
:= False;
419 -- There may be an equal sign between -gnatep and
420 -- the path name of the mapping file.
422 if Ptr
<= Max
and then Switch_Chars
(Ptr
) = '=' then
430 Preprocessing_Data_File
:=
431 new String'(Switch_Chars (Ptr .. Max));
434 -- Because we may store a longer switch (we normalize
435 -- to -gnatep=), use a local variable.
439 (1 .. Preprocessing_Data_File'Length + 8);
442 To_Store (1 .. 8) := "-gnatep=";
443 To_Store (9 .. Preprocessing_Data_File'Length + 8) :=
444 Preprocessing_Data_File.all;
445 Store_Compilation_Switch (To_Store);
454 -- Processing for E switch
458 Dynamic_Elaboration_Checks := True;
460 -- Processing for f switch
464 All_Errors_Mode := True;
466 -- Processing for F switch
470 External_Name_Exp_Casing := Uppercase;
471 External_Name_Imp_Casing := Uppercase;
473 -- Processing for g switch
478 Identifier_Character_Set := 'n
';
479 Warning_Mode := Treat_As_Error;
480 Check_Unreferenced := True;
482 Check_Unreferenced_Formals := True;
483 System_Extend_Unit := Empty;
485 Set_Default_Style_Check_Options;
487 -- Processing for G switch
491 Print_Generated_Code := True;
493 -- Processing for h switch
497 Usage_Requested := True;
499 -- Processing for H switch
505 -- Processing for i switch
513 C := Switch_Chars (Ptr);
523 Identifier_Character_Set := C;
530 -- Processing for k switch
534 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_File_Name_Length);
536 -- Processing for l switch
542 -- Processing for L switch
546 Zero_Cost_Exceptions_Set := True;
547 Zero_Cost_Exceptions_Val := False;
549 -- Processing for m switch
553 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Errors);
555 -- Processing for n switch
559 Inline_Active := True;
561 -- Processing for N switch
565 Inline_Active := True;
566 Front_End_Inlining := True;
568 -- Processing for o switch
572 Suppress_Options (Overflow_Check) := False;
573 Opt.Enable_Overflow_Checks := True;
575 -- Processing for O switch
578 Store_Switch := False;
580 Output_File_Name_Present := True;
582 -- Processing for p switch
586 Suppress_Options := (others => True);
587 Validity_Checks_On := False;
588 Opt.Suppress_Checks := True;
589 Opt.Enable_Overflow_Checks := False;
591 -- Processing for P switch
595 Polling_Required := True;
597 -- Processing for q switch
601 Try_Semantics := True;
603 -- Processing for q switch
607 Force_ALI_Tree_File := True;
608 Try_Semantics := True;
610 -- Processing for R switch
614 Back_Annotate_Rep_Info := True;
615 List_Representation_Info := 1;
617 while Ptr <= Max loop
618 C := Switch_Chars (Ptr);
620 if C in '1' .. '3' then
621 List_Representation_Info :=
622 Character'Pos (C) - Character'Pos ('0');
624 elsif Switch_Chars (Ptr) = 's
' then
625 List_Representation_Info_To_File := True;
627 elsif Switch_Chars (Ptr) = 'm
' then
628 List_Representation_Info_Mechanisms := True;
637 -- Processing for s switch
640 if not First_Switch then
642 ("-gnats must be first if combined with other switches");
646 Operating_Mode := Check_Syntax;
648 -- Processing for S switch
651 Print_Standard := True;
654 -- Processing for t switch
660 if Operating_Mode = Check_Semantics then
664 Back_Annotate_Rep_Info := True;
666 -- Processing for T switch
670 Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor);
672 -- Processing for u switch
678 -- Processing for U switch
682 Unique_Error_Tag := True;
684 -- Processing for v switch
688 Verbose_Mode := True;
690 -- Processing for V switch
693 Store_Switch := False;
694 Storing (First_Stored) := 'V
';
705 Set_Validity_Check_Options
706 (Switch_Chars (Ptr .. Max), OK, Ptr);
712 for Index in First_Char + 1 .. Max loop
713 Storing (First_Stored + 1) :=
714 Switch_Chars (Index);
715 Store_Compilation_Switch
716 (Storing (Storing'First .. First_Stored + 1));
723 -- Processing for w switch
726 Store_Switch := False;
727 Storing (First_Stored) := 'w
';
734 while Ptr <= Max loop
735 C := Switch_Chars (Ptr);
739 Check_Unreferenced := True;
740 Check_Unreferenced_Formals := True;
742 Constant_Condition_Warnings := True;
743 Implementation_Unit_Warnings := True;
744 Ineffective_Inline_Warnings := True;
745 Warn_On_Constant := True;
746 Warn_On_Export_Import := True;
747 Warn_On_Modified_Unread := True;
748 Warn_On_No_Value_Assigned := True;
749 Warn_On_Obsolescent_Feature := True;
750 Warn_On_Redundant_Constructs := True;
751 Warn_On_Unchecked_Conversion := True;
752 Warn_On_Unrecognized_Pragma := True;
755 Check_Unreferenced := False;
756 Check_Unreferenced_Formals := False;
757 Check_Withs := False;
758 Constant_Condition_Warnings := False;
759 Elab_Warnings := False;
760 Implementation_Unit_Warnings := False;
761 Ineffective_Inline_Warnings := False;
762 Warn_On_Constant := False;
763 Warn_On_Dereference := False;
764 Warn_On_Export_Import := False;
765 Warn_On_Hiding := False;
766 Warn_On_Modified_Unread := False;
767 Warn_On_No_Value_Assigned := False;
768 Warn_On_Obsolescent_Feature := False;
769 Warn_On_Redundant_Constructs := False;
770 Warn_On_Unchecked_Conversion := False;
771 Warn_On_Unrecognized_Pragma := False;
774 Constant_Condition_Warnings := True;
777 Constant_Condition_Warnings := False;
780 Warn_On_Dereference := True;
783 Warn_On_Dereference := False;
786 Warning_Mode := Treat_As_Error;
789 Check_Unreferenced_Formals := True;
792 Check_Unreferenced_Formals := False;
795 Warn_On_Unrecognized_Pragma := True;
798 Warn_On_Unrecognized_Pragma := False;
801 Warn_On_Hiding := True;
804 Warn_On_Hiding := False;
807 Implementation_Unit_Warnings := True;
810 Implementation_Unit_Warnings := False;
813 Warn_On_Obsolescent_Feature := True;
816 Warn_On_Obsolescent_Feature := False;
819 Warn_On_Constant := True;
822 Warn_On_Constant := False;
825 Elab_Warnings := True;
828 Elab_Warnings := False;
831 Warn_On_Modified_Unread := True;
834 Warn_On_Modified_Unread := False;
837 Warning_Mode := Normal;
840 Address_Clause_Overlay_Warnings := True;
843 Address_Clause_Overlay_Warnings := False;
846 Ineffective_Inline_Warnings := True;
849 Ineffective_Inline_Warnings := False;
852 Warn_On_Redundant_Constructs := True;
855 Warn_On_Redundant_Constructs := False;
858 Warning_Mode := Suppress;
861 Check_Unreferenced := True;
863 Check_Unreferenced_Formals := True;
866 Check_Unreferenced := False;
867 Check_Withs := False;
868 Check_Unreferenced_Formals := False;
871 Warn_On_No_Value_Assigned := True;
874 Warn_On_No_Value_Assigned := False;
877 Warn_On_Export_Import := True;
880 Warn_On_Export_Import := False;
883 Warn_On_Unchecked_Conversion := True;
886 Warn_On_Unchecked_Conversion := False;
888 -- Allow and ignore 'w
' so that the old
889 -- format (e.g. -gnatwuwl) will work.
899 Storing (First_Stored + 1) := C;
900 Store_Compilation_Switch
901 (Storing (Storing'First .. First_Stored + 1));
909 -- Processing for W switch
918 for J in WC_Encoding_Method loop
919 if Switch_Chars (Ptr) = WC_Encoding_Letters (J) then
920 Wide_Character_Encoding_Method := J;
923 elsif J = WC_Encoding_Method'Last then
928 Upper_Half_Encoding :=
929 Wide_Character_Encoding_Method in
930 WC_Upper_Half_Encoding_Method;
934 -- Processing for x switch
938 Xref_Active := False;
940 -- Processing for X switch
944 Extensions_Allowed := True;
946 -- Processing for y switch
952 Set_Default_Style_Check_Options;
955 Store_Switch := False;
956 Storing (First_Stored) := 'y
';
960 Last_Stored : Integer;
963 Set_Style_Check_Options
964 (Switch_Chars (Ptr .. Max), OK, Ptr);
970 Ptr := First_Char + 1;
972 while Ptr <= Max loop
973 Last_Stored := First_Stored + 1;
974 Storing (Last_Stored) := Switch_Chars (Ptr);
976 if Switch_Chars (Ptr) = 'M
' then
980 or else Switch_Chars (Ptr) not in '0' .. '9';
981 Last_Stored := Last_Stored + 1;
982 Storing (Last_Stored) := Switch_Chars (Ptr);
989 Store_Compilation_Switch
990 (Storing (Storing'First .. Last_Stored));
995 -- Processing for z switch
1000 -- Allowed for compiler only if this is the only
1001 -- -z switch, we do not allow multiple occurrences
1003 if Distribution_Stub_Mode = No_Stubs then
1004 case Switch_Chars (Ptr) is
1006 Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
1009 Distribution_Stub_Mode := Generate_Caller_Stub_Body;
1019 -- Processing for Z switch
1023 Zero_Cost_Exceptions_Set := True;
1024 Zero_Cost_Exceptions_Val := True;
1026 -- Processing for 83 switch
1036 if Switch_Chars (Ptr) /= '3' then
1044 -- Ignore extra switch character
1049 -- Anything else is an error (illegal switch character)
1056 if Store_Switch then
1057 Storing (First_Stored .. First_Stored + Ptr - First_Char - 1) :=
1058 Switch_Chars (First_Char .. Ptr - 1);
1059 Store_Compilation_Switch
1060 (Storing (Storing'First .. First_Stored + Ptr - First_Char - 1));
1063 First_Switch := False;
1068 Osint.Fail ("invalid switch: ", (1 => C));
1070 when Bad_Switch_Value =>
1071 Osint.Fail ("numeric value out of range for switch: ", (1 => C));
1073 when Missing_Switch_Value =>
1074 Osint.Fail ("missing numeric value for switch: ", (1 => C));
1076 end Scan_Front_End_Switches;