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
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 -- -gnatem (mapping file)
388 Store_Switch := False;
391 -- There may be an equal sign between -gnatem and
392 -- the path name of the mapping file.
394 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
403 new String'(Switch_Chars (Ptr .. Max));
406 -- -gnatep (preprocessing data file)
409 Store_Switch := False;
412 -- There may be an equal sign between -gnatep and
413 -- the path name of the mapping file.
415 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
423 Preprocessing_Data_File :=
424 new String'(Switch_Chars (Ptr .. Max));
427 -- Because we may store a longer switch (we normalize
428 -- to -gnatep=), use a local variable.
432 (1 .. Preprocessing_Data_File'Length + 8);
435 To_Store (1 .. 8) := "-gnatep=";
436 To_Store (9 .. Preprocessing_Data_File'Length + 8) :=
437 Preprocessing_Data_File.all;
438 Store_Compilation_Switch (To_Store);
443 -- All other -gnate? switches are unassigned
449 -- -gnatE (dynamic elaboration checks)
453 Dynamic_Elaboration_Checks := True;
455 -- -gnatf (full error messages)
459 All_Errors_Mode := True;
461 -- Processing for F switch
465 External_Name_Exp_Casing := Uppercase;
466 External_Name_Imp_Casing := Uppercase;
468 -- Processing for g switch
473 Identifier_Character_Set := 'n';
474 System_Extend_Unit := Empty;
475 Warning_Mode := Treat_As_Error;
477 -- Set default warnings (basically -gnatwa)
479 Check_Unreferenced := True;
480 Check_Unreferenced_Formals := True;
482 Constant_Condition_Warnings := True;
483 Implementation_Unit_Warnings := True;
484 Ineffective_Inline_Warnings := True;
485 Warn_On_Constant := True;
486 Warn_On_Export_Import := True;
487 Warn_On_Modified_Unread := True;
488 Warn_On_No_Value_Assigned := True;
489 Warn_On_Obsolescent_Feature := True;
490 Warn_On_Redundant_Constructs := True;
491 Warn_On_Unchecked_Conversion := True;
492 Warn_On_Unrecognized_Pragma := True;
494 Set_Default_Style_Check_Options;
496 -- Processing for G switch
500 Print_Generated_Code := True;
502 -- Processing for h switch
506 Usage_Requested := True;
508 -- Processing for H switch
514 -- Processing for i switch
522 C := Switch_Chars (Ptr);
532 Identifier_Character_Set := C;
539 -- Processing for k switch
543 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_File_Name_Length);
545 -- Processing for l switch
551 -- Processing for L switch
555 Zero_Cost_Exceptions_Set := True;
556 Zero_Cost_Exceptions_Val := False;
558 -- Processing for m switch
562 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Errors);
564 -- Processing for n switch
568 Inline_Active := True;
570 -- Processing for N switch
574 Inline_Active := True;
575 Front_End_Inlining := True;
577 -- Processing for o switch
581 Suppress_Options (Overflow_Check) := False;
582 Opt.Enable_Overflow_Checks := True;
584 -- Processing for O switch
587 Store_Switch := False;
589 Output_File_Name_Present := True;
591 -- Processing for p switch
595 Suppress_Options := (others => True);
596 Validity_Checks_On := False;
597 Opt.Suppress_Checks := True;
598 Opt.Enable_Overflow_Checks := False;
600 -- Processing for P switch
604 Polling_Required := True;
606 -- Processing for q switch
610 Try_Semantics := True;
612 -- Processing for q switch
616 Force_ALI_Tree_File := True;
617 Try_Semantics := True;
619 -- Processing for R switch
623 Back_Annotate_Rep_Info := True;
624 List_Representation_Info := 1;
626 while Ptr <= Max loop
627 C := Switch_Chars (Ptr);
629 if C in '1' .. '3' then
630 List_Representation_Info :=
631 Character'Pos (C) - Character'Pos ('0');
633 elsif Switch_Chars (Ptr) = 's' then
634 List_Representation_Info_To_File := True;
636 elsif Switch_Chars (Ptr) = 'm' then
637 List_Representation_Info_Mechanisms := True;
646 -- Processing for s switch
649 if not First_Switch then
651 ("-gnats must be first if combined with other switches");
655 Operating_Mode := Check_Syntax;
657 -- Processing for S switch
660 Print_Standard := True;
663 -- Processing for t switch
669 if Operating_Mode = Check_Semantics then
673 Back_Annotate_Rep_Info := True;
675 -- Processing for T switch
679 Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor);
681 -- Processing for u switch
687 -- Processing for U switch
691 Unique_Error_Tag := True;
693 -- Processing for v switch
697 Verbose_Mode := True;
699 -- Processing for V switch
702 Store_Switch := False;
703 Storing (First_Stored) := 'V';
714 Set_Validity_Check_Options
715 (Switch_Chars (Ptr .. Max), OK, Ptr);
721 for Index in First_Char + 1 .. Max loop
722 Storing (First_Stored + 1) :=
723 Switch_Chars (Index);
724 Store_Compilation_Switch
725 (Storing (Storing'First .. First_Stored + 1));
732 -- Processing for w switch
735 Store_Switch := False;
736 Storing (First_Stored) := 'w';
743 while Ptr <= Max loop
744 C := Switch_Chars (Ptr);
748 Check_Unreferenced := True;
749 Check_Unreferenced_Formals := True;
751 Constant_Condition_Warnings := True;
752 Implementation_Unit_Warnings := True;
753 Ineffective_Inline_Warnings := True;
754 Warn_On_Constant := True;
755 Warn_On_Export_Import := True;
756 Warn_On_Modified_Unread := True;
757 Warn_On_No_Value_Assigned := True;
758 Warn_On_Obsolescent_Feature := True;
759 Warn_On_Redundant_Constructs := True;
760 Warn_On_Unchecked_Conversion := True;
761 Warn_On_Unrecognized_Pragma := True;
764 Check_Unreferenced := False;
765 Check_Unreferenced_Formals := False;
766 Check_Withs := False;
767 Constant_Condition_Warnings := False;
768 Elab_Warnings := False;
769 Implementation_Unit_Warnings := False;
770 Ineffective_Inline_Warnings := False;
771 Warn_On_Constant := False;
772 Warn_On_Dereference := False;
773 Warn_On_Export_Import := False;
774 Warn_On_Hiding := False;
775 Warn_On_Modified_Unread := False;
776 Warn_On_No_Value_Assigned := False;
777 Warn_On_Obsolescent_Feature := False;
778 Warn_On_Redundant_Constructs := False;
779 Warn_On_Unchecked_Conversion := False;
780 Warn_On_Unrecognized_Pragma := False;
783 Constant_Condition_Warnings := True;
786 Constant_Condition_Warnings := False;
789 Warn_On_Dereference := True;
792 Warn_On_Dereference := False;
795 Warning_Mode := Treat_As_Error;
798 Check_Unreferenced_Formals := True;
801 Check_Unreferenced_Formals := False;
804 Warn_On_Unrecognized_Pragma := True;
807 Warn_On_Unrecognized_Pragma := False;
810 Warn_On_Hiding := True;
813 Warn_On_Hiding := False;
816 Implementation_Unit_Warnings := True;
819 Implementation_Unit_Warnings := False;
822 Warn_On_Obsolescent_Feature := True;
825 Warn_On_Obsolescent_Feature := False;
828 Warn_On_Constant := True;
831 Warn_On_Constant := False;
834 Elab_Warnings := True;
837 Elab_Warnings := False;
840 Warn_On_Modified_Unread := True;
843 Warn_On_Modified_Unread := False;
846 Warning_Mode := Normal;
849 Address_Clause_Overlay_Warnings := True;
852 Address_Clause_Overlay_Warnings := False;
855 Ineffective_Inline_Warnings := True;
858 Ineffective_Inline_Warnings := False;
861 Warn_On_Redundant_Constructs := True;
864 Warn_On_Redundant_Constructs := False;
867 Warning_Mode := Suppress;
870 Check_Unreferenced := True;
872 Check_Unreferenced_Formals := True;
875 Check_Unreferenced := False;
876 Check_Withs := False;
877 Check_Unreferenced_Formals := False;
880 Warn_On_No_Value_Assigned := True;
883 Warn_On_No_Value_Assigned := False;
886 Warn_On_Export_Import := True;
889 Warn_On_Export_Import := False;
892 Warn_On_Unchecked_Conversion := True;
895 Warn_On_Unchecked_Conversion := False;
897 -- Allow and ignore 'w' so that the old
898 -- format (e.g. -gnatwuwl) will work.
908 Storing (First_Stored + 1) := C;
909 Store_Compilation_Switch
910 (Storing (Storing'First .. First_Stored + 1));
918 -- Processing for W switch
927 for J in WC_Encoding_Method loop
928 if Switch_Chars (Ptr) = WC_Encoding_Letters (J) then
929 Wide_Character_Encoding_Method := J;
932 elsif J = WC_Encoding_Method'Last then
937 Upper_Half_Encoding :=
938 Wide_Character_Encoding_Method in
939 WC_Upper_Half_Encoding_Method;
943 -- Processing for x switch
947 Xref_Active := False;
949 -- Processing for X switch
953 Extensions_Allowed := True;
955 -- Processing for y switch
961 Set_Default_Style_Check_Options;
964 Store_Switch := False;
965 Storing (First_Stored) := 'y';
969 Last_Stored : Integer;
972 Set_Style_Check_Options
973 (Switch_Chars (Ptr .. Max), OK, Ptr);
979 Ptr := First_Char + 1;
981 while Ptr <= Max loop
982 Last_Stored := First_Stored + 1;
983 Storing (Last_Stored) := Switch_Chars (Ptr);
985 if Switch_Chars (Ptr) = 'M' then
989 or else Switch_Chars (Ptr) not in '0' .. '9';
990 Last_Stored := Last_Stored + 1;
991 Storing (Last_Stored) := Switch_Chars (Ptr);
998 Store_Compilation_Switch
999 (Storing (Storing'First .. Last_Stored));
1004 -- Processing for z switch
1009 -- Allowed for compiler only if this is the only
1010 -- -z switch, we do not allow multiple occurrences
1012 if Distribution_Stub_Mode = No_Stubs then
1013 case Switch_Chars (Ptr) is
1015 Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
1018 Distribution_Stub_Mode := Generate_Caller_Stub_Body;
1028 -- Processing for Z switch
1032 Zero_Cost_Exceptions_Set := True;
1033 Zero_Cost_Exceptions_Val := True;
1035 -- Processing for 83 switch
1045 if Switch_Chars (Ptr) /= '3' then
1053 -- Ignore extra switch character
1058 -- Anything else is an error (illegal switch character)
1065 if Store_Switch then
1066 Storing (First_Stored .. First_Stored + Ptr - First_Char - 1) :=
1067 Switch_Chars (First_Char .. Ptr - 1);
1068 Store_Compilation_Switch
1069 (Storing (Storing'First .. First_Stored + Ptr - First_Char - 1));
1072 First_Switch := False;
1077 Osint.Fail ("invalid switch: ", (1 => C));
1079 when Bad_Switch_Value =>
1080 Osint.Fail ("numeric value out of range for switch: ", (1 => C));
1082 when Missing_Switch_Value =>
1083 Osint.Fail ("missing numeric value for switch: ", (1 => C));
1085 end Scan_Front_End_Switches;