1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2005 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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
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 the --RTS switch. --RTS has been modified by
123 -- gcc and is now of the form -fRTS
126 and then Switch_Chars
(Ptr
.. Ptr
+ 3) = "fRTS"
131 or else Switch_Chars
(Ptr
+ 3) /= '='
133 Osint
.Fail
("missing path for --RTS");
135 -- Check that this is the first time --RTS is specified
136 -- or if it is not the first time, the same path has
139 if RTS_Specified
= null then
141 new String'(Switch_Chars (Ptr + 4 .. Max));
144 RTS_Specified.all /= Switch_Chars (Ptr + 4 .. Max)
147 ("--RTS cannot be specified multiple times");
150 -- Valid --RTS switch
152 Opt.No_Stdinc := True;
153 Opt.RTS_Switch := True;
155 RTS_Src_Path_Name := Get_RTS_Search_Dir
156 (Switch_Chars (Ptr + 4 .. Max),
158 RTS_Lib_Path_Name := Get_RTS_Search_Dir
159 (Switch_Chars (Ptr + 4 .. Max),
162 if RTS_Src_Path_Name /= null and then
163 RTS_Lib_Path_Name /= null
167 elsif RTS_Src_Path_Name = null and then
168 RTS_Lib_Path_Name = null
170 Osint.Fail ("RTS path not valid: missing " &
171 "adainclude and adalib directories");
173 elsif RTS_Src_Path_Name = null then
174 Osint.Fail ("RTS path not valid: missing " &
175 "adainclude directory");
177 elsif RTS_Lib_Path_Name = null then
178 Osint.Fail ("RTS path not valid: missing " &
188 -- Process -gnat* options
194 Assertions_Enabled := True;
196 -- Processing for A switch
200 Config_File := False;
202 -- Processing for b switch
206 Brief_Output := True;
208 -- Processing for c switch
211 if not First_Switch then
213 ("-gnatc must be first if combined with other switches");
217 Operating_Mode := Check_Semantics;
223 -- Processing for d switch
226 Store_Switch := False;
227 Storing (First_Stored) := 'd
';
230 -- Note: for the debug switch, the remaining characters in this
231 -- switch field must all be debug flags, since all valid switch
232 -- characters are also valid debug characters.
234 -- Loop to scan out debug flags
238 C := Switch_Chars (Ptr);
239 exit when C = ASCII.NUL or else C = '/' or else C = '-';
241 if C in '1' .. '9' or else
242 C in 'a
' .. 'z
' or else
246 Set_Dotted_Debug_Flag (C);
247 Storing (First_Stored + 1) := '.';
248 Storing (First_Stored + 2) := C;
249 Store_Compilation_Switch
250 (Storing (Storing'First .. First_Stored + 2));
255 Storing (First_Stored + 1) := C;
256 Store_Compilation_Switch
257 (Storing (Storing'First .. First_Stored + 1));
268 -- Make sure Zero_Cost_Exceptions is set if gnatdX set. This
269 -- is for backwards compatibility with old versions and usage.
271 if Debug_Flag_XX then
272 Zero_Cost_Exceptions_Set := True;
273 Zero_Cost_Exceptions_Val := True;
278 -- Processing for D switch
283 -- Note: -gnatD also sets -gnatx (to turn off cross-reference
284 -- generation in the ali file) since otherwise this generation
285 -- gets confused by the "wrong" Sloc values put in the tree.
287 Debug_Generated_Code := True;
288 Xref_Active := False;
289 Set_Debug_Flag ('g
');
291 -- -gnate? (extended switches)
296 -- The -gnate? switches are all double character switches
297 -- so we must always have a character after the e.
303 case Switch_Chars (Ptr) is
305 -- -gnatec (configuration pragmas)
308 Store_Switch := False;
311 -- There may be an equal sign between -gnatec and
312 -- the path name of the config file.
314 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
323 Config_File_Name : constant String_Access :=
325 (Switch_Chars
(Ptr
.. Max
));
328 if Config_File_Names
= null then
330 new String_List
'(1 => Config_File_Name);
334 New_Names : constant String_List_Access :=
337 Config_File_Names'Length + 1);
340 for Index in Config_File_Names'Range loop
342 Config_File_Names (Index);
343 Config_File_Names (Index) := null;
346 New_Names (New_Names'Last) := Config_File_Name;
347 Free (Config_File_Names);
348 Config_File_Names := New_Names;
355 -- -gnateD switch (symbol definition)
358 Store_Switch := False;
365 Add_Symbol_Definition (Switch_Chars (Ptr .. Max));
369 Storing (First_Stored .. First_Stored + 1) := "eD";
371 (First_Stored + 2 .. First_Stored + Max - Ptr + 2) :=
372 Switch_Chars (Ptr .. Max);
373 Store_Compilation_Switch (Storing
374 (Storing'First .. First_Stored + Max - Ptr + 2));
377 -- -gnatef (full source path for brief error messages)
380 Store_Switch := False;
382 Full_Path_Name_For_Brief_Errors := True;
385 -- -gnateI (index of unit in multi-unit source)
389 Scan_Pos (Switch_Chars, Max, Ptr, Multiple_Unit_Index);
391 -- -gnatem (mapping file)
394 Store_Switch := False;
397 -- There may be an equal sign between -gnatem and
398 -- the path name of the mapping file.
400 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
409 new String'(Switch_Chars
(Ptr
.. Max
));
412 -- -gnatep (preprocessing data file)
415 Store_Switch
:= False;
418 -- There may be an equal sign between -gnatep and
419 -- the path name of the mapping file.
421 if Ptr
<= Max
and then Switch_Chars
(Ptr
) = '=' then
429 Preprocessing_Data_File
:=
430 new String'(Switch_Chars (Ptr .. Max));
433 -- Because we may store a longer switch (we normalize
434 -- to -gnatep=), use a local variable.
438 (1 .. Preprocessing_Data_File'Length + 8);
441 To_Store (1 .. 8) := "-gnatep=";
442 To_Store (9 .. Preprocessing_Data_File'Length + 8) :=
443 Preprocessing_Data_File.all;
444 Store_Compilation_Switch (To_Store);
450 Store_Switch := False;
451 Disable_Switch_Storing;
454 -- All other -gnate? switches are unassigned
460 -- -gnatE (dynamic elaboration checks)
464 Dynamic_Elaboration_Checks := True;
466 -- -gnatf (full error messages)
470 All_Errors_Mode := True;
472 -- Processing for F switch
476 External_Name_Exp_Casing := Uppercase;
477 External_Name_Imp_Casing := Uppercase;
479 -- Processing for g switch
484 Identifier_Character_Set := 'n
';
485 System_Extend_Unit := Empty;
486 Warning_Mode := Treat_As_Error;
488 -- Set default warnings for -gnatg (same set as -gnatwa)
490 Check_Unreferenced := True;
491 Check_Unreferenced_Formals := True;
493 Constant_Condition_Warnings := True;
494 Implementation_Unit_Warnings := True;
495 Ineffective_Inline_Warnings := True;
496 Warn_On_Bad_Fixed_Value := True;
497 Warn_On_Constant := True;
498 Warn_On_Export_Import := True;
499 Warn_On_Modified_Unread := True;
500 Warn_On_No_Value_Assigned := True;
501 Warn_On_Obsolescent_Feature := True;
502 Warn_On_Redundant_Constructs := True;
503 Warn_On_Unchecked_Conversion := True;
504 Warn_On_Unrecognized_Pragma := True;
506 Set_Style_Check_Options ("3abcdefhiklmnprstu");
508 -- Processing for G switch
512 Print_Generated_Code := True;
514 -- Processing for h switch
518 Usage_Requested := True;
520 -- Processing for H switch
526 -- Processing for i switch
534 C := Switch_Chars (Ptr);
544 Identifier_Character_Set := C;
551 -- Processing for k switch
555 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_File_Name_Length);
557 -- Processing for l switch
563 -- Processing for L switch
567 Zero_Cost_Exceptions_Set := True;
568 Zero_Cost_Exceptions_Val := False;
570 -- Processing for m switch
574 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Errors);
576 -- Processing for n switch
580 Inline_Active := True;
582 -- Processing for N switch
586 Inline_Active := True;
587 Front_End_Inlining := True;
589 -- Processing for o switch
593 Suppress_Options (Overflow_Check) := False;
594 Opt.Enable_Overflow_Checks := True;
596 -- Processing for O switch
599 Store_Switch := False;
601 Output_File_Name_Present := True;
603 -- Processing for p switch
607 Suppress_Options := (others => True);
608 Validity_Checks_On := False;
609 Opt.Suppress_Checks := True;
610 Opt.Enable_Overflow_Checks := False;
612 -- Processing for P switch
616 Polling_Required := True;
618 -- Processing for q switch
622 Try_Semantics := True;
624 -- Processing for q switch
628 Force_ALI_Tree_File := True;
629 Try_Semantics := True;
631 -- Processing for R switch
635 Back_Annotate_Rep_Info := True;
636 List_Representation_Info := 1;
638 while Ptr <= Max loop
639 C := Switch_Chars (Ptr);
641 if C in '1' .. '3' then
642 List_Representation_Info :=
643 Character'Pos (C) - Character'Pos ('0');
645 elsif Switch_Chars (Ptr) = 's
' then
646 List_Representation_Info_To_File := True;
648 elsif Switch_Chars (Ptr) = 'm
' then
649 List_Representation_Info_Mechanisms := True;
658 -- Processing for s switch
661 if not First_Switch then
663 ("-gnats must be first if combined with other switches");
667 Operating_Mode := Check_Syntax;
669 -- Processing for S switch
672 Print_Standard := True;
675 -- Processing for t switch
681 if Operating_Mode = Check_Semantics then
685 Back_Annotate_Rep_Info := True;
687 -- Processing for T switch
691 Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor);
693 -- Processing for u switch
699 -- Processing for U switch
703 Unique_Error_Tag := True;
705 -- Processing for v switch
709 Verbose_Mode := True;
711 -- Processing for V switch
714 Store_Switch := False;
715 Storing (First_Stored) := 'V
';
726 Set_Validity_Check_Options
727 (Switch_Chars (Ptr .. Max), OK, Ptr);
733 for Index in First_Char + 1 .. Max loop
734 Storing (First_Stored + 1) :=
735 Switch_Chars (Index);
736 Store_Compilation_Switch
737 (Storing (Storing'First .. First_Stored + 1));
744 -- Processing for w switch
747 Store_Switch := False;
748 Storing (First_Stored) := 'w
';
755 while Ptr <= Max loop
756 C := Switch_Chars (Ptr);
760 Check_Unreferenced := True;
761 Check_Unreferenced_Formals := True;
763 Constant_Condition_Warnings := True;
764 Implementation_Unit_Warnings := True;
765 Ineffective_Inline_Warnings := True;
766 Warn_On_Ada_2005_Compatibility := True;
767 Warn_On_Bad_Fixed_Value := True;
768 Warn_On_Constant := True;
769 Warn_On_Export_Import := True;
770 Warn_On_Modified_Unread := True;
771 Warn_On_No_Value_Assigned := True;
772 Warn_On_Obsolescent_Feature := True;
773 Warn_On_Redundant_Constructs := True;
774 Warn_On_Unchecked_Conversion := True;
775 Warn_On_Unrecognized_Pragma := True;
778 Check_Unreferenced := False;
779 Check_Unreferenced_Formals := False;
780 Check_Withs := False;
781 Constant_Condition_Warnings := False;
782 Elab_Warnings := False;
783 Implementation_Unit_Warnings := False;
784 Ineffective_Inline_Warnings := False;
785 Warn_On_Ada_2005_Compatibility := False;
786 Warn_On_Bad_Fixed_Value := False;
787 Warn_On_Constant := False;
788 Warn_On_Dereference := False;
789 Warn_On_Export_Import := False;
790 Warn_On_Hiding := False;
791 Warn_On_Modified_Unread := False;
792 Warn_On_No_Value_Assigned := False;
793 Warn_On_Obsolescent_Feature := False;
794 Warn_On_Redundant_Constructs := False;
795 Warn_On_Unchecked_Conversion := False;
796 Warn_On_Unrecognized_Pragma := False;
799 Warn_On_Bad_Fixed_Value := True;
802 Warn_On_Bad_Fixed_Value := False;
805 Constant_Condition_Warnings := True;
808 Constant_Condition_Warnings := False;
811 Warn_On_Dereference := True;
814 Warn_On_Dereference := False;
817 Warning_Mode := Treat_As_Error;
820 Check_Unreferenced_Formals := True;
823 Check_Unreferenced_Formals := False;
826 Warn_On_Unrecognized_Pragma := True;
829 Warn_On_Unrecognized_Pragma := False;
832 Warn_On_Hiding := True;
835 Warn_On_Hiding := False;
838 Implementation_Unit_Warnings := True;
841 Implementation_Unit_Warnings := False;
844 Warn_On_Obsolescent_Feature := True;
847 Warn_On_Obsolescent_Feature := False;
850 Warn_On_Constant := True;
853 Warn_On_Constant := False;
856 Elab_Warnings := True;
859 Elab_Warnings := False;
862 Warn_On_Modified_Unread := True;
865 Warn_On_Modified_Unread := False;
868 Warning_Mode := Normal;
871 Address_Clause_Overlay_Warnings := True;
874 Address_Clause_Overlay_Warnings := False;
877 Ineffective_Inline_Warnings := True;
880 Ineffective_Inline_Warnings := False;
883 Warn_On_Redundant_Constructs := True;
886 Warn_On_Redundant_Constructs := False;
889 Warning_Mode := Suppress;
892 Check_Unreferenced := True;
894 Check_Unreferenced_Formals := True;
897 Check_Unreferenced := False;
898 Check_Withs := False;
899 Check_Unreferenced_Formals := False;
902 Warn_On_No_Value_Assigned := True;
905 Warn_On_No_Value_Assigned := False;
908 Warn_On_Export_Import := True;
911 Warn_On_Export_Import := False;
914 Warn_On_Ada_2005_Compatibility := True;
917 Warn_On_Ada_2005_Compatibility := False;
920 Warn_On_Unchecked_Conversion := True;
923 Warn_On_Unchecked_Conversion := False;
925 -- Allow and ignore 'w
' so that the old
926 -- format (e.g. -gnatwuwl) will work.
936 Storing (First_Stored + 1) := C;
937 Store_Compilation_Switch
938 (Storing (Storing'First .. First_Stored + 1));
946 -- Processing for W switch
955 for J in WC_Encoding_Method loop
956 if Switch_Chars (Ptr) = WC_Encoding_Letters (J) then
957 Wide_Character_Encoding_Method := J;
960 elsif J = WC_Encoding_Method'Last then
965 Upper_Half_Encoding :=
966 Wide_Character_Encoding_Method in
967 WC_Upper_Half_Encoding_Method;
971 -- Processing for x switch
975 Xref_Active := False;
977 -- Processing for X switch
981 Extensions_Allowed := True;
982 Ada_Version := Ada_Version_Type'Last;
983 Ada_Version_Explicit := Ada_Version;
985 -- Processing for y switch
991 Set_Default_Style_Check_Options;
994 Store_Switch := False;
995 Storing (First_Stored) := 'y
';
999 Last_Stored : Integer;
1002 Set_Style_Check_Options
1003 (Switch_Chars (Ptr .. Max), OK, Ptr);
1009 Ptr := First_Char + 1;
1011 while Ptr <= Max loop
1012 Last_Stored := First_Stored + 1;
1013 Storing (Last_Stored) := Switch_Chars (Ptr);
1015 if Switch_Chars (Ptr) = 'M
' then
1019 or else Switch_Chars (Ptr) not in '0' .. '9';
1020 Last_Stored := Last_Stored + 1;
1021 Storing (Last_Stored) := Switch_Chars (Ptr);
1028 Store_Compilation_Switch
1029 (Storing (Storing'First .. Last_Stored));
1034 -- Processing for z switch
1039 -- Allowed for compiler only if this is the only
1040 -- -z switch, we do not allow multiple occurrences
1042 if Distribution_Stub_Mode = No_Stubs then
1043 case Switch_Chars (Ptr) is
1045 Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
1048 Distribution_Stub_Mode := Generate_Caller_Stub_Body;
1058 -- Processing for Z switch
1062 Zero_Cost_Exceptions_Set := True;
1063 Zero_Cost_Exceptions_Val := True;
1065 -- Processing for 83 switch
1074 if Switch_Chars (Ptr) /= '3' then
1078 Ada_Version := Ada_83;
1079 Ada_Version_Explicit := Ada_Version;
1082 -- Processing for 95 switch
1091 if Switch_Chars (Ptr) /= '5' then
1095 Ada_Version := Ada_95;
1096 Ada_Version_Explicit := Ada_Version;
1099 -- Processing for 05 switch
1108 if Switch_Chars (Ptr) /= '5' then
1112 Ada_Version := Ada_05;
1113 Ada_Version_Explicit := Ada_Version;
1116 -- Ignore extra switch character
1121 -- Anything else is an error (illegal switch character)
1128 if Store_Switch then
1129 Storing (First_Stored .. First_Stored + Ptr - First_Char - 1) :=
1130 Switch_Chars (First_Char .. Ptr - 1);
1131 Store_Compilation_Switch
1132 (Storing (Storing'First .. First_Stored + Ptr - First_Char - 1));
1135 First_Switch := False;
1140 Osint.Fail ("invalid switch: ", (1 => C));
1142 when Bad_Switch_Value =>
1143 Osint.Fail ("numeric value out of range for switch: ", (1 => C));
1145 when Missing_Switch_Value =>
1146 Osint.Fail ("missing numeric value for switch: ", (1 => C));
1148 end Scan_Front_End_Switches;