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 only two front-end switches that
100 -- do not start with -gnat, namely -I and --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;
219 -- Processing for d switch
222 Store_Switch := False;
223 Storing (First_Stored) := 'd';
226 -- Note: for the debug switch, the remaining characters in this
227 -- switch field must all be debug flags, since all valid switch
228 -- characters are also valid debug characters.
230 -- Loop to scan out debug flags
234 C := Switch_Chars (Ptr);
235 exit when C = ASCII.NUL or else C = '/' or else C = '-';
237 if C in '1' .. '9' or else
238 C in 'a' .. 'z' or else
242 Set_Dotted_Debug_Flag (C);
243 Storing (First_Stored + 1) := '.';
244 Storing (First_Stored + 2) := C;
245 Store_Compilation_Switch
246 (Storing (Storing'First .. First_Stored + 2));
251 Storing (First_Stored + 1) := C;
252 Store_Compilation_Switch
253 (Storing (Storing'First .. First_Stored + 1));
264 -- Make sure Zero_Cost_Exceptions is set if gnatdX set. This
265 -- is for backwards compatibility with old versions and usage.
267 if Debug_Flag_XX then
268 Zero_Cost_Exceptions_Set := True;
269 Zero_Cost_Exceptions_Val := True;
274 -- Processing for D switch
279 -- Note: -gnatD also sets -gnatx (to turn off cross-reference
280 -- generation in the ali file) since otherwise this generation
281 -- gets confused by the "wrong" Sloc values put in the tree.
283 Debug_Generated_Code := True;
284 Xref_Active := False;
285 Set_Debug_Flag ('g');
287 -- Processing for e switch
290 -- Only -gnateD and -gnatep= are stored
298 case Switch_Chars (Ptr) is
300 -- Configuration pragmas
303 Store_Switch := False;
306 -- There may be an equal sign between -gnatec and
307 -- the path name of the config file.
309 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
318 Config_File_Name : constant String_Access :=
320 (Switch_Chars (Ptr .. Max));
323 if Config_File_Names = null then
325 new String_List'(1 => Config_File_Name);
329 New_Names : constant String_List_Access :=
332 Config_File_Names'Length + 1);
335 for Index in Config_File_Names'Range loop
337 Config_File_Names (Index);
338 Config_File_Names (Index) := null;
341 New_Names (New_Names'Last) := Config_File_Name;
342 Free (Config_File_Names);
343 Config_File_Names := New_Names;
353 Store_Switch := False;
360 Add_Symbol_Definition (Switch_Chars (Ptr .. Max));
364 Storing (First_Stored .. First_Stored + 1) := "eD";
366 (First_Stored + 2 .. First_Stored + Max - Ptr + 2) :=
367 Switch_Chars (Ptr .. Max);
368 Store_Compilation_Switch (Storing
369 (Storing'First .. First_Stored + Max - Ptr + 2));
372 -- Full source path for brief error messages
375 Store_Switch := False;
377 Full_Path_Name_For_Brief_Errors := True;
383 Store_Switch := False;
386 -- There may be an equal sign between -gnatem and
387 -- the path name of the mapping file.
389 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
398 new String'(Switch_Chars (Ptr .. Max));
401 -- Preprocessing data file
404 Store_Switch := False;
407 -- There may be an equal sign between -gnatep and
408 -- the path name of the mapping file.
410 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
418 Preprocessing_Data_File :=
419 new String'(Switch_Chars (Ptr .. Max));
422 -- Because we may store a longer switch (we normalize
423 -- to -gnatep=), use a local variable.
427 (1 .. Preprocessing_Data_File'Length + 8);
430 To_Store (1 .. 8) := "-gnatep=";
431 To_Store (9 .. Preprocessing_Data_File'Length + 8) :=
432 Preprocessing_Data_File.all;
433 Store_Compilation_Switch (To_Store);
442 -- Processing for E switch
446 Dynamic_Elaboration_Checks := True;
448 -- Processing for f switch
452 All_Errors_Mode := True;
454 -- Processing for F switch
458 External_Name_Exp_Casing := Uppercase;
459 External_Name_Imp_Casing := Uppercase;
461 -- Processing for g switch
466 Identifier_Character_Set := 'n';
467 Warning_Mode := Treat_As_Error;
468 Check_Unreferenced := True;
470 Check_Unreferenced_Formals := True;
471 System_Extend_Unit := Empty;
473 Set_Default_Style_Check_Options;
475 -- Processing for G switch
479 Print_Generated_Code := True;
481 -- Processing for h switch
485 Usage_Requested := True;
487 -- Processing for H switch
493 -- Processing for i switch
501 C := Switch_Chars (Ptr);
511 Identifier_Character_Set := C;
518 -- Processing for k switch
522 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_File_Name_Length);
524 -- Processing for l switch
530 -- Processing for L switch
534 Zero_Cost_Exceptions_Set := True;
535 Zero_Cost_Exceptions_Val := False;
537 -- Processing for m switch
541 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Errors);
543 -- Processing for n switch
547 Inline_Active := True;
549 -- Processing for N switch
553 Inline_Active := True;
554 Front_End_Inlining := True;
556 -- Processing for o switch
560 Suppress_Options (Overflow_Check) := False;
561 Opt.Enable_Overflow_Checks := True;
563 -- Processing for O switch
566 Store_Switch := False;
568 Output_File_Name_Present := True;
570 -- Processing for p switch
574 Suppress_Options := (others => True);
575 Validity_Checks_On := False;
576 Opt.Suppress_Checks := True;
577 Opt.Enable_Overflow_Checks := False;
579 -- Processing for P switch
583 Polling_Required := True;
585 -- Processing for q switch
589 Try_Semantics := True;
591 -- Processing for q switch
595 Force_ALI_Tree_File := True;
596 Try_Semantics := True;
598 -- Processing for R switch
602 Back_Annotate_Rep_Info := True;
603 List_Representation_Info := 1;
605 while Ptr <= Max loop
606 C := Switch_Chars (Ptr);
608 if C in '1' .. '3' then
609 List_Representation_Info :=
610 Character'Pos (C) - Character'Pos ('0');
612 elsif Switch_Chars (Ptr) = 's' then
613 List_Representation_Info_To_File := True;
615 elsif Switch_Chars (Ptr) = 'm' then
616 List_Representation_Info_Mechanisms := True;
625 -- Processing for s switch
628 if not First_Switch then
630 ("-gnats must be first if combined with other switches");
634 Operating_Mode := Check_Syntax;
636 -- Processing for t switch
642 Back_Annotate_Rep_Info := True;
644 -- Processing for T switch
648 Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor);
650 -- Processing for u switch
656 -- Processing for U switch
660 Unique_Error_Tag := True;
662 -- Processing for v switch
666 Verbose_Mode := True;
668 -- Processing for V switch
671 Store_Switch := False;
672 Storing (First_Stored) := 'V';
683 Set_Validity_Check_Options
684 (Switch_Chars (Ptr .. Max), OK, Ptr);
690 for Index in First_Char + 1 .. Max loop
691 Storing (First_Stored + 1) :=
692 Switch_Chars (Index);
693 Store_Compilation_Switch
694 (Storing (Storing'First .. First_Stored + 1));
701 -- Processing for w switch
704 Store_Switch := False;
705 Storing (First_Stored) := 'w';
712 while Ptr <= Max loop
713 C := Switch_Chars (Ptr);
717 Check_Unreferenced := True;
718 Check_Unreferenced_Formals := True;
720 Constant_Condition_Warnings := True;
721 Implementation_Unit_Warnings := True;
722 Ineffective_Inline_Warnings := True;
723 Warn_On_Constant := True;
724 Warn_On_Export_Import := True;
725 Warn_On_Modified_Unread := True;
726 Warn_On_No_Value_Assigned := True;
727 Warn_On_Obsolescent_Feature := True;
728 Warn_On_Redundant_Constructs := True;
729 Warn_On_Unchecked_Conversion := True;
730 Warn_On_Unrecognized_Pragma := True;
733 Check_Unreferenced := False;
734 Check_Unreferenced_Formals := False;
735 Check_Withs := False;
736 Constant_Condition_Warnings := False;
737 Elab_Warnings := False;
738 Implementation_Unit_Warnings := False;
739 Ineffective_Inline_Warnings := False;
740 Warn_On_Constant := False;
741 Warn_On_Dereference := False;
742 Warn_On_Export_Import := False;
743 Warn_On_Hiding := False;
744 Warn_On_Modified_Unread := False;
745 Warn_On_No_Value_Assigned := False;
746 Warn_On_Obsolescent_Feature := False;
747 Warn_On_Redundant_Constructs := False;
748 Warn_On_Unchecked_Conversion := False;
749 Warn_On_Unrecognized_Pragma := False;
752 Constant_Condition_Warnings := True;
755 Constant_Condition_Warnings := False;
758 Warn_On_Dereference := True;
761 Warn_On_Dereference := False;
764 Warning_Mode := Treat_As_Error;
767 Check_Unreferenced_Formals := True;
770 Check_Unreferenced_Formals := False;
773 Warn_On_Unrecognized_Pragma := True;
776 Warn_On_Unrecognized_Pragma := False;
779 Warn_On_Hiding := True;
782 Warn_On_Hiding := False;
785 Implementation_Unit_Warnings := True;
788 Implementation_Unit_Warnings := False;
791 Warn_On_Obsolescent_Feature := True;
794 Warn_On_Obsolescent_Feature := False;
797 Warn_On_Constant := True;
800 Warn_On_Constant := False;
803 Elab_Warnings := True;
806 Elab_Warnings := False;
809 Warn_On_Modified_Unread := True;
812 Warn_On_Modified_Unread := False;
815 Warning_Mode := Normal;
818 Address_Clause_Overlay_Warnings := True;
821 Address_Clause_Overlay_Warnings := False;
824 Ineffective_Inline_Warnings := True;
827 Ineffective_Inline_Warnings := False;
830 Warn_On_Redundant_Constructs := True;
833 Warn_On_Redundant_Constructs := False;
836 Warning_Mode := Suppress;
839 Check_Unreferenced := True;
841 Check_Unreferenced_Formals := True;
844 Check_Unreferenced := False;
845 Check_Withs := False;
846 Check_Unreferenced_Formals := False;
849 Warn_On_No_Value_Assigned := True;
852 Warn_On_No_Value_Assigned := False;
855 Warn_On_Export_Import := True;
858 Warn_On_Export_Import := False;
861 Warn_On_Unchecked_Conversion := True;
864 Warn_On_Unchecked_Conversion := False;
866 -- Allow and ignore 'w' so that the old
867 -- format (e.g. -gnatwuwl) will work.
877 Storing (First_Stored + 1) := C;
878 Store_Compilation_Switch
879 (Storing (Storing'First .. First_Stored + 1));
887 -- Processing for W switch
896 for J in WC_Encoding_Method loop
897 if Switch_Chars (Ptr) = WC_Encoding_Letters (J) then
898 Wide_Character_Encoding_Method := J;
901 elsif J = WC_Encoding_Method'Last then
906 Upper_Half_Encoding :=
907 Wide_Character_Encoding_Method in
908 WC_Upper_Half_Encoding_Method;
912 -- Processing for x switch
916 Xref_Active := False;
918 -- Processing for X switch
922 Extensions_Allowed := True;
924 -- Processing for y switch
930 Set_Default_Style_Check_Options;
933 Store_Switch := False;
934 Storing (First_Stored) := 'y';
938 Last_Stored : Integer;
941 Set_Style_Check_Options
942 (Switch_Chars (Ptr .. Max), OK, Ptr);
948 Ptr := First_Char + 1;
950 while Ptr <= Max loop
951 Last_Stored := First_Stored + 1;
952 Storing (Last_Stored) := Switch_Chars (Ptr);
954 if Switch_Chars (Ptr) = 'M' then
958 or else Switch_Chars (Ptr) not in '0' .. '9';
959 Last_Stored := Last_Stored + 1;
960 Storing (Last_Stored) := Switch_Chars (Ptr);
967 Store_Compilation_Switch
968 (Storing (Storing'First .. Last_Stored));
973 -- Processing for z switch
978 -- Allowed for compiler only if this is the only
979 -- -z switch, we do not allow multiple occurrences
981 if Distribution_Stub_Mode = No_Stubs then
982 case Switch_Chars (Ptr) is
984 Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
987 Distribution_Stub_Mode := Generate_Caller_Stub_Body;
997 -- Processing for Z switch
1001 Zero_Cost_Exceptions_Set := True;
1002 Zero_Cost_Exceptions_Val := True;
1004 -- Processing for 83 switch
1014 if Switch_Chars (Ptr) /= '3' then
1022 -- Ignore extra switch character
1027 -- Anything else is an error (illegal switch character)
1034 if Store_Switch then
1035 Storing (First_Stored .. First_Stored + Ptr - First_Char - 1) :=
1036 Switch_Chars (First_Char .. Ptr - 1);
1037 Store_Compilation_Switch
1038 (Storing (Storing'First .. First_Stored + Ptr - First_Char - 1));
1041 First_Switch := False;
1046 Osint.Fail ("invalid switch: ", (1 => C));
1048 when Bad_Switch_Value =>
1049 Osint.Fail ("numeric value out of range for switch: ", (1 => C));
1051 when Missing_Switch_Value =>
1052 Osint.Fail ("missing numeric value for switch: ", (1 => C));
1054 end Scan_Front_End_Switches;