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 Validsw; use Validsw;
35 with Stylesw; use Stylesw;
37 with System.WCh_Con; use System.WCh_Con;
39 package body Switch.C is
41 RTS_Specified : String_Access := null;
42 -- Used to detect multiple use of --RTS= flag
44 -----------------------------
45 -- Scan_Front_End_Switches --
46 -----------------------------
48 procedure Scan_Front_End_Switches (Switch_Chars : String) is
49 Switch_Starts_With_Gnat : Boolean;
50 -- True if first four switch characters are "gnat"
52 First_Switch : Boolean := True;
53 -- False for all but first switch
55 Ptr : Integer := Switch_Chars'First;
56 Max : constant Integer := Switch_Chars'Last;
60 Store_Switch : Boolean := True;
61 First_Char : Integer := Ptr;
62 Storing : String := Switch_Chars;
63 First_Stored : Positive := Ptr + 1;
64 -- The above need comments ???
67 -- Skip past the initial character (must be the switch character)
75 -- Remove "gnat" from the switch, if present
77 Switch_Starts_With_Gnat :=
78 Ptr + 3 <= Max and then Switch_Chars (Ptr .. Ptr + 3) = "gnat";
80 if Switch_Starts_With_Gnat then
85 -- Loop to scan through switches given in switch string
90 C := Switch_Chars (Ptr);
92 -- Processing for a switch
94 case Switch_Starts_With_Gnat is
98 -- There are few front-end switches that
99 -- do not start with -gnat: -I, --RTS
101 if Switch_Chars (Ptr) = 'I' then
102 Store_Switch := False;
110 -- Find out whether this is a -I- or regular -Ixxx switch
112 if Ptr = Max and then Switch_Chars (Ptr) = '-' then
113 Look_In_Primary_Dir := False;
116 Add_Src_Search_Dir (Switch_Chars (Ptr .. Max));
121 -- Processing of the --RTS switch. --RTS has been modified by
122 -- gcc and is now of the form -fRTS
125 and then Switch_Chars (Ptr .. Ptr + 3) = "fRTS"
130 or else Switch_Chars (Ptr + 3) /= '='
132 Osint.Fail ("missing path for --RTS");
134 -- Check that this is the first time --RTS is specified
135 -- or if it is not the first time, the same path has
138 if RTS_Specified = null then
140 new String'(Switch_Chars (Ptr + 4 .. Max));
143 RTS_Specified.all /= Switch_Chars (Ptr + 4 .. Max)
146 ("--RTS cannot be specified multiple times");
149 -- Valid --RTS switch
151 Opt.No_Stdinc := True;
152 Opt.RTS_Switch := True;
154 RTS_Src_Path_Name := Get_RTS_Search_Dir
155 (Switch_Chars (Ptr + 4 .. Max),
157 RTS_Lib_Path_Name := Get_RTS_Search_Dir
158 (Switch_Chars (Ptr + 4 .. Max),
161 if RTS_Src_Path_Name /= null and then
162 RTS_Lib_Path_Name /= null
166 elsif RTS_Src_Path_Name = null and then
167 RTS_Lib_Path_Name = null
169 Osint.Fail ("RTS path not valid: missing " &
170 "adainclude and adalib directories");
172 elsif RTS_Src_Path_Name = null then
173 Osint.Fail ("RTS path not valid: missing " &
174 "adainclude directory");
176 elsif RTS_Lib_Path_Name = null then
177 Osint.Fail ("RTS path not valid: missing " &
187 -- Process -gnat* options
193 Assertions_Enabled := True;
194 Debug_Pragmas_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));
270 -- Processing for D switch
275 -- Note: -gnatD also sets -gnatx (to turn off cross-reference
276 -- generation in the ali file) since otherwise this generation
277 -- gets confused by the "wrong" Sloc values put in the tree.
279 Debug_Generated_Code := True;
280 Xref_Active := False;
281 Set_Debug_Flag ('g');
283 -- -gnate? (extended switches)
288 -- The -gnate? switches are all double character switches
289 -- so we must always have a character after the e.
295 case Switch_Chars (Ptr) is
297 -- -gnatec (configuration pragmas)
300 Store_Switch := False;
303 -- There may be an equal sign between -gnatec and
304 -- the path name of the config file.
306 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
315 Config_File_Name : constant String_Access :=
317 (Switch_Chars (Ptr .. Max));
320 if Config_File_Names = null then
322 new String_List'(1 => Config_File_Name);
326 New_Names : constant String_List_Access :=
329 Config_File_Names'Length + 1);
332 for Index in Config_File_Names'Range loop
334 Config_File_Names (Index);
335 Config_File_Names (Index) := null;
338 New_Names (New_Names'Last) := Config_File_Name;
339 Free (Config_File_Names);
340 Config_File_Names := New_Names;
347 -- -gnateD switch (symbol definition)
350 Store_Switch := False;
357 Add_Symbol_Definition (Switch_Chars (Ptr .. Max));
361 Storing (First_Stored .. First_Stored + 1) := "eD";
363 (First_Stored + 2 .. First_Stored + Max - Ptr + 2) :=
364 Switch_Chars (Ptr .. Max);
365 Store_Compilation_Switch (Storing
366 (Storing'First .. First_Stored + Max - Ptr + 2));
369 -- -gnatef (full source path for brief error messages)
372 Store_Switch := False;
374 Full_Path_Name_For_Brief_Errors := True;
377 -- -gnateI (index of unit in multi-unit source)
381 Scan_Pos (Switch_Chars, Max, Ptr, Multiple_Unit_Index);
383 -- -gnatem (mapping file)
386 Store_Switch := False;
389 -- There may be an equal sign between -gnatem and
390 -- the path name of the mapping file.
392 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
401 new String'(Switch_Chars (Ptr .. Max));
404 -- -gnatep (preprocessing data file)
407 Store_Switch := False;
410 -- There may be an equal sign between -gnatep and
411 -- the path name of the mapping file.
413 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
421 Preprocessing_Data_File :=
422 new String'(Switch_Chars (Ptr .. Max));
425 -- Because we may store a longer switch (we normalize
426 -- to -gnatep=), use a local variable.
430 (1 .. Preprocessing_Data_File'Length + 8);
433 To_Store (1 .. 8) := "-gnatep=";
434 To_Store (9 .. Preprocessing_Data_File'Length + 8) :=
435 Preprocessing_Data_File.all;
436 Store_Compilation_Switch (To_Store);
442 Store_Switch := False;
443 Disable_Switch_Storing;
446 -- All other -gnate? switches are unassigned
452 -- -gnatE (dynamic elaboration checks)
456 Dynamic_Elaboration_Checks := True;
458 -- -gnatf (full error messages)
462 All_Errors_Mode := True;
464 -- Processing for F switch
468 External_Name_Exp_Casing := Uppercase;
469 External_Name_Imp_Casing := Uppercase;
471 -- Processing for g switch
476 Identifier_Character_Set := 'n';
477 System_Extend_Unit := Empty;
478 Warning_Mode := Treat_As_Error;
480 -- Set Ada 2005 mode explicitly. We don't want to rely on the
481 -- implicit setting here, since for example, we want
482 -- Preelaborate_05 treated as Preelaborate
484 Ada_Version := Ada_05;
485 Ada_Version_Explicit := Ada_Version;
487 -- Set default warnings for -gnatg (same set as -gnatwa)
489 Check_Unreferenced := True;
490 Check_Unreferenced_Formals := True;
492 Constant_Condition_Warnings := True;
493 Implementation_Unit_Warnings := True;
494 Ineffective_Inline_Warnings := True;
495 Warn_On_Bad_Fixed_Value := True;
496 Warn_On_Constant := True;
497 Warn_On_Export_Import := True;
498 Warn_On_Modified_Unread := True;
499 Warn_On_No_Value_Assigned := True;
500 Warn_On_Obsolescent_Feature := True;
501 Warn_On_Redundant_Constructs := True;
502 Warn_On_Unchecked_Conversion := True;
503 Warn_On_Unrecognized_Pragma := True;
505 Set_Style_Check_Options ("3abcdefhiklmnprstu");
507 -- Processing for G switch
511 Print_Generated_Code := True;
513 -- Processing for h switch
517 Usage_Requested := True;
519 -- Processing for H switch
525 -- Processing for i switch
533 C := Switch_Chars (Ptr);
543 Identifier_Character_Set := C;
550 -- Processing for k switch
554 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_File_Name_Length);
556 -- Processing for l switch
562 -- Processing for L switch
567 ("-gnatL is no longer supported: consider using --RTS=sjlj");
569 -- Processing for m switch
573 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Errors);
575 -- Processing for n switch
579 Inline_Active := True;
581 -- Processing for N switch
585 Inline_Active := True;
586 Front_End_Inlining := True;
588 -- Processing for o switch
592 Suppress_Options (Overflow_Check) := False;
593 Opt.Enable_Overflow_Checks := True;
595 -- Processing for O switch
598 Store_Switch := False;
600 Output_File_Name_Present := True;
602 -- Processing for p switch
606 Suppress_Options := (others => True);
607 Validity_Checks_On := False;
608 Opt.Suppress_Checks := True;
609 Opt.Enable_Overflow_Checks := False;
611 -- Processing for P switch
615 Polling_Required := True;
617 -- Processing for q switch
621 Try_Semantics := True;
623 -- Processing for q switch
627 Force_ALI_Tree_File := True;
628 Try_Semantics := True;
630 -- Processing for R switch
634 Back_Annotate_Rep_Info := True;
635 List_Representation_Info := 1;
637 while Ptr <= Max loop
638 C := Switch_Chars (Ptr);
640 if C in '1' .. '3' then
641 List_Representation_Info :=
642 Character'Pos (C) - Character'Pos ('0');
644 elsif Switch_Chars (Ptr) = 's' then
645 List_Representation_Info_To_File := True;
647 elsif Switch_Chars (Ptr) = 'm' then
648 List_Representation_Info_Mechanisms := True;
657 -- Processing for s switch
660 if not First_Switch then
662 ("-gnats must be first if combined with other switches");
666 Operating_Mode := Check_Syntax;
668 -- Processing for S switch
671 Print_Standard := True;
674 -- Processing for t switch
680 if Operating_Mode = Check_Semantics then
684 Back_Annotate_Rep_Info := True;
686 -- Processing for T switch
690 Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor);
692 -- Processing for u switch
698 -- Processing for U switch
702 Unique_Error_Tag := True;
704 -- Processing for v switch
708 Verbose_Mode := True;
710 -- Processing for V switch
713 Store_Switch := False;
714 Storing (First_Stored) := 'V';
725 Set_Validity_Check_Options
726 (Switch_Chars (Ptr .. Max), OK, Ptr);
732 for Index in First_Char + 1 .. Max loop
733 Storing (First_Stored + 1) :=
734 Switch_Chars (Index);
735 Store_Compilation_Switch
736 (Storing (Storing'First .. First_Stored + 1));
743 -- Processing for w switch
746 Store_Switch := False;
747 Storing (First_Stored) := 'w';
754 while Ptr <= Max loop
755 C := Switch_Chars (Ptr);
759 Check_Unreferenced := True;
760 Check_Unreferenced_Formals := True;
762 Constant_Condition_Warnings := True;
763 Implementation_Unit_Warnings := True;
764 Ineffective_Inline_Warnings := True;
765 Warn_On_Ada_2005_Compatibility := True;
766 Warn_On_Bad_Fixed_Value := True;
767 Warn_On_Constant := True;
768 Warn_On_Export_Import := True;
769 Warn_On_Modified_Unread := True;
770 Warn_On_No_Value_Assigned := True;
771 Warn_On_Obsolescent_Feature := True;
772 Warn_On_Redundant_Constructs := True;
773 Warn_On_Unchecked_Conversion := True;
774 Warn_On_Unrecognized_Pragma := True;
777 Check_Unreferenced := False;
778 Check_Unreferenced_Formals := False;
779 Check_Withs := False;
780 Constant_Condition_Warnings := False;
781 Elab_Warnings := False;
782 Implementation_Unit_Warnings := False;
783 Ineffective_Inline_Warnings := False;
784 Warn_On_Ada_2005_Compatibility := False;
785 Warn_On_Bad_Fixed_Value := False;
786 Warn_On_Constant := False;
787 Warn_On_Dereference := False;
788 Warn_On_Export_Import := False;
789 Warn_On_Hiding := False;
790 Warn_On_Modified_Unread := False;
791 Warn_On_No_Value_Assigned := False;
792 Warn_On_Obsolescent_Feature := False;
793 Warn_On_Redundant_Constructs := False;
794 Warn_On_Unchecked_Conversion := False;
795 Warn_On_Unrecognized_Pragma := False;
798 Warn_On_Bad_Fixed_Value := True;
801 Warn_On_Bad_Fixed_Value := False;
804 Constant_Condition_Warnings := True;
807 Constant_Condition_Warnings := False;
810 Warn_On_Dereference := True;
813 Warn_On_Dereference := False;
816 Warning_Mode := Treat_As_Error;
819 Check_Unreferenced_Formals := True;
822 Check_Unreferenced_Formals := False;
825 Warn_On_Unrecognized_Pragma := True;
828 Warn_On_Unrecognized_Pragma := False;
831 Warn_On_Hiding := True;
834 Warn_On_Hiding := False;
837 Implementation_Unit_Warnings := True;
840 Implementation_Unit_Warnings := False;
843 Warn_On_Obsolescent_Feature := True;
846 Warn_On_Obsolescent_Feature := False;
849 Warn_On_Constant := True;
852 Warn_On_Constant := False;
855 Elab_Warnings := True;
858 Elab_Warnings := False;
861 Warn_On_Modified_Unread := True;
864 Warn_On_Modified_Unread := False;
867 Warning_Mode := Normal;
870 Address_Clause_Overlay_Warnings := True;
873 Address_Clause_Overlay_Warnings := False;
876 Ineffective_Inline_Warnings := True;
879 Ineffective_Inline_Warnings := False;
882 Warn_On_Redundant_Constructs := True;
885 Warn_On_Redundant_Constructs := False;
888 Warning_Mode := Suppress;
891 Check_Unreferenced := True;
893 Check_Unreferenced_Formals := True;
896 Check_Unreferenced := False;
897 Check_Withs := False;
898 Check_Unreferenced_Formals := False;
901 Warn_On_No_Value_Assigned := True;
904 Warn_On_No_Value_Assigned := False;
907 Warn_On_Export_Import := True;
910 Warn_On_Export_Import := False;
913 Warn_On_Ada_2005_Compatibility := True;
916 Warn_On_Ada_2005_Compatibility := False;
919 Warn_On_Unchecked_Conversion := True;
922 Warn_On_Unchecked_Conversion := False;
924 -- Allow and ignore 'w' so that the old
925 -- format (e.g. -gnatwuwl) will work.
935 Storing (First_Stored + 1) := C;
936 Store_Compilation_Switch
937 (Storing (Storing'First .. First_Stored + 1));
945 -- Processing for W switch
954 for J in WC_Encoding_Method loop
955 if Switch_Chars (Ptr) = WC_Encoding_Letters (J) then
956 Wide_Character_Encoding_Method := J;
959 elsif J = WC_Encoding_Method'Last then
964 Upper_Half_Encoding :=
965 Wide_Character_Encoding_Method in
966 WC_Upper_Half_Encoding_Method;
970 -- Processing for x switch
974 Xref_Active := False;
976 -- Processing for X switch
980 Extensions_Allowed := True;
981 Ada_Version := Ada_Version_Type'Last;
982 Ada_Version_Explicit := Ada_Version;
984 -- Processing for y switch
990 Set_Default_Style_Check_Options;
993 Store_Switch := False;
994 Storing (First_Stored) := 'y';
998 Last_Stored : Integer;
1001 Set_Style_Check_Options
1002 (Switch_Chars (Ptr .. Max), OK, Ptr);
1008 Ptr := First_Char + 1;
1010 while Ptr <= Max loop
1011 Last_Stored := First_Stored + 1;
1012 Storing (Last_Stored) := Switch_Chars (Ptr);
1014 if Switch_Chars (Ptr) = 'M' then
1018 or else Switch_Chars (Ptr) not in '0' .. '9';
1019 Last_Stored := Last_Stored + 1;
1020 Storing (Last_Stored) := Switch_Chars (Ptr);
1027 Store_Compilation_Switch
1028 (Storing (Storing'First .. Last_Stored));
1033 -- Processing for z switch
1038 -- Allowed for compiler only if this is the only
1039 -- -z switch, we do not allow multiple occurrences
1041 if Distribution_Stub_Mode = No_Stubs then
1042 case Switch_Chars (Ptr) is
1044 Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
1047 Distribution_Stub_Mode := Generate_Caller_Stub_Body;
1057 -- Processing for Z switch
1062 ("-gnatZ is no longer supported: consider using --RTS=zcx");
1064 -- Processing for 83 switch
1073 if Switch_Chars (Ptr) /= '3' then
1077 Ada_Version := Ada_83;
1078 Ada_Version_Explicit := Ada_Version;
1081 -- Processing for 95 switch
1090 if Switch_Chars (Ptr) /= '5' then
1094 Ada_Version := Ada_95;
1095 Ada_Version_Explicit := Ada_Version;
1098 -- Processing for 05 switch
1107 if Switch_Chars (Ptr) /= '5' then
1111 Ada_Version := Ada_05;
1112 Ada_Version_Explicit := Ada_Version;
1115 -- Ignore extra switch character
1120 -- Anything else is an error (illegal switch character)
1127 if Store_Switch then
1128 Storing (First_Stored .. First_Stored + Ptr - First_Char - 1) :=
1129 Switch_Chars (First_Char .. Ptr - 1);
1130 Store_Compilation_Switch
1131 (Storing (Storing'First .. First_Stored + Ptr - First_Char - 1));
1134 First_Switch := False;
1139 Osint.Fail ("invalid switch: ", (1 => C));
1141 when Bad_Switch_Value =>
1142 Osint.Fail ("numeric value out of range for switch: ", (1 => C));
1144 when Missing_Switch_Value =>
1145 Osint.Fail ("missing numeric value for switch: ", (1 => C));
1147 end Scan_Front_End_Switches;