1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2004 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
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 C switch
227 Scan_Pos (Switch_Chars, 999, Ptr, Multiple_Unit_Index);
229 -- Processing for d switch
232 Store_Switch := False;
233 Storing (First_Stored) := 'd';
236 -- Note: for the debug switch, the remaining characters in this
237 -- switch field must all be debug flags, since all valid switch
238 -- characters are also valid debug characters.
240 -- Loop to scan out debug flags
244 C := Switch_Chars (Ptr);
245 exit when C = ASCII.NUL or else C = '/' or else C = '-';
247 if C in '1' .. '9' or else
248 C in 'a' .. 'z' or else
252 Set_Dotted_Debug_Flag (C);
253 Storing (First_Stored + 1) := '.';
254 Storing (First_Stored + 2) := C;
255 Store_Compilation_Switch
256 (Storing (Storing'First .. First_Stored + 2));
261 Storing (First_Stored + 1) := C;
262 Store_Compilation_Switch
263 (Storing (Storing'First .. First_Stored + 1));
274 -- Make sure Zero_Cost_Exceptions is set if gnatdX set. This
275 -- is for backwards compatibility with old versions and usage.
277 if Debug_Flag_XX then
278 Zero_Cost_Exceptions_Set := True;
279 Zero_Cost_Exceptions_Val := True;
284 -- Processing for D switch
289 -- Note: -gnatD also sets -gnatx (to turn off cross-reference
290 -- generation in the ali file) since otherwise this generation
291 -- gets confused by the "wrong" Sloc values put in the tree.
293 Debug_Generated_Code := True;
294 Xref_Active := False;
295 Set_Debug_Flag ('g');
297 -- -gnate? (extended switches)
302 -- The -gnate? switches are all double character switches
303 -- so we must always have a character after the e.
309 case Switch_Chars (Ptr) is
311 -- -gnatec (configuration pragmas)
314 Store_Switch := False;
317 -- There may be an equal sign between -gnatec and
318 -- the path name of the config file.
320 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
329 Config_File_Name : constant String_Access :=
331 (Switch_Chars (Ptr .. Max));
334 if Config_File_Names = null then
336 new String_List'(1 => Config_File_Name);
340 New_Names : constant String_List_Access :=
343 Config_File_Names'Length + 1);
346 for Index in Config_File_Names'Range loop
348 Config_File_Names (Index);
349 Config_File_Names (Index) := null;
352 New_Names (New_Names'Last) := Config_File_Name;
353 Free (Config_File_Names);
354 Config_File_Names := New_Names;
361 -- -gnateD switch (symbol definition)
364 Store_Switch := False;
371 Add_Symbol_Definition (Switch_Chars (Ptr .. Max));
375 Storing (First_Stored .. First_Stored + 1) := "eD";
377 (First_Stored + 2 .. First_Stored + Max - Ptr + 2) :=
378 Switch_Chars (Ptr .. Max);
379 Store_Compilation_Switch (Storing
380 (Storing'First .. First_Stored + Max - Ptr + 2));
383 -- -gnatef (full source path for brief error messages)
386 Store_Switch := False;
388 Full_Path_Name_For_Brief_Errors := True;
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);
449 -- All other -gnate? switches are unassigned
455 -- -gnatE (dynamic elaboration checks)
459 Dynamic_Elaboration_Checks := True;
461 -- -gnatf (full error messages)
465 All_Errors_Mode := True;
467 -- Processing for F switch
471 External_Name_Exp_Casing := Uppercase;
472 External_Name_Imp_Casing := Uppercase;
474 -- Processing for g switch
479 Identifier_Character_Set := 'n';
480 System_Extend_Unit := Empty;
481 Warning_Mode := Treat_As_Error;
483 -- Set default warnings (basically -gnatwa)
485 Check_Unreferenced := True;
486 Check_Unreferenced_Formals := True;
488 Constant_Condition_Warnings := True;
489 Implementation_Unit_Warnings := True;
490 Ineffective_Inline_Warnings := True;
491 Warn_On_Constant := True;
492 Warn_On_Export_Import := True;
493 Warn_On_Modified_Unread := True;
494 Warn_On_No_Value_Assigned := True;
495 Warn_On_Obsolescent_Feature := True;
496 Warn_On_Redundant_Constructs := True;
497 Warn_On_Unchecked_Conversion := True;
498 Warn_On_Unrecognized_Pragma := True;
500 Set_Default_Style_Check_Options;
502 -- Processing for G switch
506 Print_Generated_Code := True;
508 -- Processing for h switch
512 Usage_Requested := True;
514 -- Processing for H switch
520 -- Processing for i switch
528 C := Switch_Chars (Ptr);
538 Identifier_Character_Set := C;
545 -- Processing for k switch
549 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_File_Name_Length);
551 -- Processing for l switch
557 -- Processing for L switch
561 Zero_Cost_Exceptions_Set := True;
562 Zero_Cost_Exceptions_Val := False;
564 -- Processing for m switch
568 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Errors);
570 -- Processing for n switch
574 Inline_Active := True;
576 -- Processing for N switch
580 Inline_Active := True;
581 Front_End_Inlining := True;
583 -- Processing for o switch
587 Suppress_Options (Overflow_Check) := False;
588 Opt.Enable_Overflow_Checks := True;
590 -- Processing for O switch
593 Store_Switch := False;
595 Output_File_Name_Present := True;
597 -- Processing for p switch
601 Suppress_Options := (others => True);
602 Validity_Checks_On := False;
603 Opt.Suppress_Checks := True;
604 Opt.Enable_Overflow_Checks := False;
606 -- Processing for P switch
610 Polling_Required := True;
612 -- Processing for q switch
616 Try_Semantics := True;
618 -- Processing for q switch
622 Force_ALI_Tree_File := True;
623 Try_Semantics := True;
625 -- Processing for R switch
629 Back_Annotate_Rep_Info := True;
630 List_Representation_Info := 1;
632 while Ptr <= Max loop
633 C := Switch_Chars (Ptr);
635 if C in '1' .. '3' then
636 List_Representation_Info :=
637 Character'Pos (C) - Character'Pos ('0');
639 elsif Switch_Chars (Ptr) = 's' then
640 List_Representation_Info_To_File := True;
642 elsif Switch_Chars (Ptr) = 'm' then
643 List_Representation_Info_Mechanisms := True;
652 -- Processing for s switch
655 if not First_Switch then
657 ("-gnats must be first if combined with other switches");
661 Operating_Mode := Check_Syntax;
663 -- Processing for S switch
666 Print_Standard := True;
669 -- Processing for t switch
675 if Operating_Mode = Check_Semantics then
679 Back_Annotate_Rep_Info := True;
681 -- Processing for T switch
685 Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor);
687 -- Processing for u switch
693 -- Processing for U switch
697 Unique_Error_Tag := True;
699 -- Processing for v switch
703 Verbose_Mode := True;
705 -- Processing for V switch
708 Store_Switch := False;
709 Storing (First_Stored) := 'V';
720 Set_Validity_Check_Options
721 (Switch_Chars (Ptr .. Max), OK, Ptr);
727 for Index in First_Char + 1 .. Max loop
728 Storing (First_Stored + 1) :=
729 Switch_Chars (Index);
730 Store_Compilation_Switch
731 (Storing (Storing'First .. First_Stored + 1));
738 -- Processing for w switch
741 Store_Switch := False;
742 Storing (First_Stored) := 'w';
749 while Ptr <= Max loop
750 C := Switch_Chars (Ptr);
754 Check_Unreferenced := True;
755 Check_Unreferenced_Formals := True;
757 Constant_Condition_Warnings := True;
758 Implementation_Unit_Warnings := True;
759 Ineffective_Inline_Warnings := True;
760 Warn_On_Constant := True;
761 Warn_On_Export_Import := True;
762 Warn_On_Modified_Unread := True;
763 Warn_On_No_Value_Assigned := True;
764 Warn_On_Obsolescent_Feature := True;
765 Warn_On_Redundant_Constructs := True;
766 Warn_On_Unchecked_Conversion := True;
767 Warn_On_Unrecognized_Pragma := True;
770 Check_Unreferenced := False;
771 Check_Unreferenced_Formals := False;
772 Check_Withs := False;
773 Constant_Condition_Warnings := False;
774 Elab_Warnings := False;
775 Implementation_Unit_Warnings := False;
776 Ineffective_Inline_Warnings := False;
777 Warn_On_Constant := False;
778 Warn_On_Dereference := False;
779 Warn_On_Export_Import := False;
780 Warn_On_Hiding := False;
781 Warn_On_Modified_Unread := False;
782 Warn_On_No_Value_Assigned := False;
783 Warn_On_Obsolescent_Feature := False;
784 Warn_On_Redundant_Constructs := False;
785 Warn_On_Unchecked_Conversion := False;
786 Warn_On_Unrecognized_Pragma := False;
789 Constant_Condition_Warnings := True;
792 Constant_Condition_Warnings := False;
795 Warn_On_Dereference := True;
798 Warn_On_Dereference := False;
801 Warning_Mode := Treat_As_Error;
804 Check_Unreferenced_Formals := True;
807 Check_Unreferenced_Formals := False;
810 Warn_On_Unrecognized_Pragma := True;
813 Warn_On_Unrecognized_Pragma := False;
816 Warn_On_Hiding := True;
819 Warn_On_Hiding := False;
822 Implementation_Unit_Warnings := True;
825 Implementation_Unit_Warnings := False;
828 Warn_On_Obsolescent_Feature := True;
831 Warn_On_Obsolescent_Feature := False;
834 Warn_On_Constant := True;
837 Warn_On_Constant := False;
840 Elab_Warnings := True;
843 Elab_Warnings := False;
846 Warn_On_Modified_Unread := True;
849 Warn_On_Modified_Unread := False;
852 Warning_Mode := Normal;
855 Address_Clause_Overlay_Warnings := True;
858 Address_Clause_Overlay_Warnings := False;
861 Ineffective_Inline_Warnings := True;
864 Ineffective_Inline_Warnings := False;
867 Warn_On_Redundant_Constructs := True;
870 Warn_On_Redundant_Constructs := False;
873 Warning_Mode := Suppress;
876 Check_Unreferenced := True;
878 Check_Unreferenced_Formals := True;
881 Check_Unreferenced := False;
882 Check_Withs := False;
883 Check_Unreferenced_Formals := False;
886 Warn_On_No_Value_Assigned := True;
889 Warn_On_No_Value_Assigned := False;
892 Warn_On_Export_Import := True;
895 Warn_On_Export_Import := False;
898 Warn_On_Unchecked_Conversion := True;
901 Warn_On_Unchecked_Conversion := False;
903 -- Allow and ignore 'w' so that the old
904 -- format (e.g. -gnatwuwl) will work.
914 Storing (First_Stored + 1) := C;
915 Store_Compilation_Switch
916 (Storing (Storing'First .. First_Stored + 1));
924 -- Processing for W switch
933 for J in WC_Encoding_Method loop
934 if Switch_Chars (Ptr) = WC_Encoding_Letters (J) then
935 Wide_Character_Encoding_Method := J;
938 elsif J = WC_Encoding_Method'Last then
943 Upper_Half_Encoding :=
944 Wide_Character_Encoding_Method in
945 WC_Upper_Half_Encoding_Method;
949 -- Processing for x switch
953 Xref_Active := False;
955 -- Processing for X switch
959 Extensions_Allowed := True;
961 -- Processing for y switch
967 Set_Default_Style_Check_Options;
970 Store_Switch := False;
971 Storing (First_Stored) := 'y';
975 Last_Stored : Integer;
978 Set_Style_Check_Options
979 (Switch_Chars (Ptr .. Max), OK, Ptr);
985 Ptr := First_Char + 1;
987 while Ptr <= Max loop
988 Last_Stored := First_Stored + 1;
989 Storing (Last_Stored) := Switch_Chars (Ptr);
991 if Switch_Chars (Ptr) = 'M' then
995 or else Switch_Chars (Ptr) not in '0' .. '9';
996 Last_Stored := Last_Stored + 1;
997 Storing (Last_Stored) := Switch_Chars (Ptr);
1004 Store_Compilation_Switch
1005 (Storing (Storing'First .. Last_Stored));
1010 -- Processing for z switch
1015 -- Allowed for compiler only if this is the only
1016 -- -z switch, we do not allow multiple occurrences
1018 if Distribution_Stub_Mode = No_Stubs then
1019 case Switch_Chars (Ptr) is
1021 Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
1024 Distribution_Stub_Mode := Generate_Caller_Stub_Body;
1034 -- Processing for Z switch
1038 Zero_Cost_Exceptions_Set := True;
1039 Zero_Cost_Exceptions_Val := True;
1041 -- Processing for 83 switch
1051 if Switch_Chars (Ptr) /= '3' then
1059 -- Ignore extra switch character
1064 -- Anything else is an error (illegal switch character)
1071 if Store_Switch then
1072 Storing (First_Stored .. First_Stored + Ptr - First_Char - 1) :=
1073 Switch_Chars (First_Char .. Ptr - 1);
1074 Store_Compilation_Switch
1075 (Storing (Storing'First .. First_Stored + Ptr - First_Char - 1));
1078 First_Switch := False;
1083 Osint.Fail ("invalid switch: ", (1 => C));
1085 when Bad_Switch_Value =>
1086 Osint.Fail ("numeric value out of range for switch: ", (1 => C));
1088 when Missing_Switch_Value =>
1089 Osint.Fail ("missing numeric value for switch: ", (1 => C));
1091 end Scan_Front_End_Switches;