1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2008, 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 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Debug; use Debug;
28 with Osint; use Osint;
30 with Prepcomp; use Prepcomp;
31 with Validsw; use Validsw;
32 with Sem_Warn; use Sem_Warn;
33 with Stylesw; use Stylesw;
35 with System.OS_Lib; use System.OS_Lib;
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 First_Switch : Boolean := True;
50 -- False for all but first switch
52 Max : constant Natural := Switch_Chars'Last;
57 Store_Switch : Boolean;
58 -- For -gnatxx switches, the normal processing, signalled by this flag
59 -- being set to True, is to store the switch on exit from the case
60 -- statement, the switch stored is -gnat followed by the characters
61 -- from First_Char to Ptr-1. For cases like -gnaty, where the switch
62 -- is stored in separate pieces, this flag is set to False, and the
63 -- appropriate calls to Store_Compilation_Switch are made from within
66 First_Char : Positive;
67 -- Marks start of switch to be stored
70 Ptr := Switch_Chars'First;
72 -- Skip past the initial character (must be the switch character)
80 -- Handle switches that do not start with -gnat
83 or else Switch_Chars (Ptr .. Ptr + 3) /= "gnat"
85 -- There are two front-end switches that do not start with -gnat:
88 if Switch_Chars (Ptr) = 'I' then
90 -- Set flag Search_Directory_Present if switch is "-I" only:
91 -- the directory will be the next argument.
94 Search_Directory_Present := True;
100 -- Find out whether this is a -I- or regular -Ixxx switch
102 -- Note: -I switches are not recorded in the ALI file, since the
103 -- meaning of the program depends on the source files compiled,
104 -- not where they came from.
106 if Ptr = Max and then Switch_Chars (Ptr) = '-' then
107 Look_In_Primary_Dir := False;
109 Add_Src_Search_Dir (Switch_Chars (Ptr .. Max));
112 -- Processing of the --RTS switch. --RTS may have been modified by
113 -- gcc into -fRTS (for GCC targets).
116 and then (Switch_Chars (Ptr .. Ptr + 3) = "fRTS"
118 Switch_Chars (Ptr .. Ptr + 3) = "-RTS")
123 or else Switch_Chars (Ptr + 3) /= '='
125 Osint.Fail ("missing path for --RTS");
127 -- Check that this is the first time --RTS is specified or if
128 -- it is not the first time, the same path has been specified.
130 if RTS_Specified = null then
131 RTS_Specified := new String'(Switch_Chars (Ptr + 4 .. Max));
134 RTS_Specified.all /= Switch_Chars (Ptr + 4 .. Max)
137 ("--RTS cannot be specified multiple times");
140 -- Valid --RTS switch
142 Opt.No_Stdinc := True;
143 Opt.RTS_Switch := True;
147 (Switch_Chars (Ptr + 4 .. Max), Include);
151 (Switch_Chars (Ptr + 4 .. Max), Objects);
153 if RTS_Src_Path_Name /= null
154 and then RTS_Lib_Path_Name /= null
156 -- Store the -fRTS switch (Note: Store_Compilation_Switch
157 -- changes -fRTS back into --RTS for the actual output).
159 Store_Compilation_Switch (Switch_Chars);
161 elsif RTS_Src_Path_Name = null
162 and then RTS_Lib_Path_Name = null
164 Osint.Fail ("RTS path not valid: missing " &
165 "adainclude and adalib directories");
167 elsif RTS_Src_Path_Name = null then
168 Osint.Fail ("RTS path not valid: missing " &
169 "adainclude directory");
171 elsif RTS_Lib_Path_Name = null then
172 Osint.Fail ("RTS path not valid: missing " &
177 -- There are no other switches not starting with -gnat
180 Bad_Switch (Switch_Chars);
183 -- Case of switch starting with -gnat
188 -- Loop to scan through switches given in switch string
190 while Ptr <= Max loop
192 Store_Switch := True;
194 C := Switch_Chars (Ptr);
200 Assertions_Enabled := True;
201 Debug_Pragmas_Enabled := True;
203 -- Processing for A switch
207 Config_File := False;
209 -- Processing for b switch
213 Brief_Output := True;
215 -- Processing for B switch
219 Assume_No_Invalid_Values := True;
221 -- Processing for c switch
224 if not First_Switch then
226 ("-gnatc must be first if combined with other switches");
230 Operating_Mode := Check_Semantics;
236 -- Processing for d switch
239 Store_Switch := False;
242 -- Note: for the debug switch, the remaining characters in this
243 -- switch field must all be debug flags, since all valid switch
244 -- characters are also valid debug characters.
246 -- Loop to scan out debug flags
250 C := Switch_Chars (Ptr);
251 exit when C = ASCII.NUL or else C = '/' or else C = '-';
253 if C in '1' .. '9' or else
254 C in 'a' .. 'z' or else
258 Set_Dotted_Debug_Flag (C);
259 Store_Compilation_Switch ("-gnatd." & C);
262 Store_Compilation_Switch ("-gnatd" & C);
269 Bad_Switch ("-gnatd." & Switch_Chars (Ptr .. Max));
271 Bad_Switch ("-gnatd" & Switch_Chars (Ptr .. Max));
277 -- Processing for D switch
282 -- Note: -gnatD also sets -gnatx (to turn off cross-reference
283 -- generation in the ali file) since otherwise this generation
284 -- gets confused by the "wrong" Sloc values put in the tree.
286 Debug_Generated_Code := True;
287 Xref_Active := False;
288 Set_Debug_Flag ('g');
290 -- -gnate? (extended switches)
295 -- The -gnate? switches are all double character switches
296 -- so we must always have a character after the e.
299 Bad_Switch ("-gnate");
302 case Switch_Chars (Ptr) is
304 -- -gnatec (configuration pragmas)
307 Store_Switch := False;
310 -- There may be an equal sign between -gnatec and
311 -- the path name of the config file.
313 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
318 Bad_Switch ("-gnatec");
322 Config_File_Name : constant String_Access :=
324 (Switch_Chars (Ptr .. Max));
327 if Config_File_Names = null then
329 new String_List'(1 => Config_File_Name);
333 New_Names : constant String_List_Access :=
336 Config_File_Names'Length + 1);
339 for Index in Config_File_Names'Range loop
341 Config_File_Names (Index);
342 Config_File_Names (Index) := null;
345 New_Names (New_Names'Last) := Config_File_Name;
346 Free (Config_File_Names);
347 Config_File_Names := New_Names;
354 -- -gnateD switch (preprocessing symbol definition)
357 Store_Switch := False;
361 Bad_Switch ("-gnateD");
364 Add_Symbol_Definition (Switch_Chars (Ptr .. Max));
368 Store_Compilation_Switch
369 ("-gnateD" & Switch_Chars (Ptr .. Max));
372 -- -gnatef (full source path for brief error messages)
375 Store_Switch := False;
377 Full_Path_Name_For_Brief_Errors := True;
380 -- -gnateG (save preprocessor output)
384 Bad_Switch (Switch_Chars);
387 Generate_Processed_File := True;
390 -- -gnateI (index of unit in multi-unit source)
394 Scan_Pos (Switch_Chars, Max, Ptr, Multiple_Unit_Index, C);
396 -- -gnatem (mapping file)
399 Store_Switch := False;
402 -- There may be an equal sign between -gnatem and
403 -- the path name of the mapping file.
405 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
410 Bad_Switch ("-gnatem");
414 new String'(Switch_Chars (Ptr .. Max));
417 -- -gnatep (preprocessing data file)
420 Store_Switch := False;
423 -- There may be an equal sign between -gnatep and
424 -- the path name of the mapping file.
426 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
431 Bad_Switch ("-gnatep");
434 Preprocessing_Data_File :=
435 new String'(Switch_Chars (Ptr .. Max));
437 -- Store the switch, normalizing to -gnatep=
439 Store_Compilation_Switch
440 ("-gnatep=" & Preprocessing_Data_File.all);
445 Store_Switch := False;
446 Disable_Switch_Storing;
449 -- All other -gnate? switches are unassigned
452 Bad_Switch ("-gnate" & Switch_Chars (Ptr .. Max));
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 Ada 2005 mode explicitly. We don't want to rely on the
484 -- implicit setting here, since for example, we want
485 -- Preelaborate_05 treated as Preelaborate
487 Ada_Version := Ada_05;
488 Ada_Version_Explicit := Ada_Version;
490 -- Set default warnings for -gnatg
492 Check_Unreferenced := True;
493 Check_Unreferenced_Formals := True;
495 Constant_Condition_Warnings := True;
496 Implementation_Unit_Warnings := True;
497 Ineffective_Inline_Warnings := True;
498 Warn_On_Assertion_Failure := True;
499 Warn_On_Assumed_Low_Bound := True;
500 Warn_On_Bad_Fixed_Value := True;
501 Warn_On_Constant := True;
502 Warn_On_Export_Import := True;
503 Warn_On_Modified_Unread := True;
504 Warn_On_No_Value_Assigned := True;
505 Warn_On_Non_Local_Exception := False;
506 Warn_On_Obsolescent_Feature := True;
507 Warn_On_Redundant_Constructs := True;
508 Warn_On_Object_Renames_Function := True;
509 Warn_On_Unchecked_Conversion := True;
510 Warn_On_Unrecognized_Pragma := True;
512 Set_GNAT_Style_Check_Options;
514 -- Processing for G switch
518 Print_Generated_Code := True;
520 -- Processing for h switch
524 Usage_Requested := True;
526 -- Processing for H switch
532 -- Processing for i switch
536 Bad_Switch ("-gnati");
540 C := Switch_Chars (Ptr);
550 Identifier_Character_Set := C;
554 Bad_Switch ("-gnati" & Switch_Chars (Ptr .. Max));
557 -- Processing for I switch
561 Ignore_Rep_Clauses := True;
563 -- Processing for j switch
568 -- There may be an equal sign between -gnatj and the value
570 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
574 Scan_Nat (Switch_Chars, Max, Ptr, Error_Msg_Line_Length, C);
576 -- Processing for k switch
581 (Switch_Chars, Max, Ptr, Maximum_File_Name_Length, C);
583 -- Processing for l switch
589 -- There may be an equal sign between -gnatl and a file name
591 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
593 Osint.Fail ("file name for -gnatl= is null");
595 Opt.Full_List_File_Name :=
596 new String'(Switch_Chars (Ptr + 1 .. Max));
601 -- Processing for L switch
605 Dump_Source_Text := True;
607 -- Processing for m switch
612 -- There may be an equal sign between -gnatm and the value
614 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
618 Scan_Nat (Switch_Chars, Max, Ptr, Maximum_Errors, C);
620 -- Processing for n switch
624 Inline_Active := True;
626 -- Processing for N switch
630 Inline_Active := True;
631 Front_End_Inlining := True;
633 -- Processing for o switch
637 Suppress_Options (Overflow_Check) := False;
638 Opt.Enable_Overflow_Checks := True;
640 -- Processing for O switch
643 Store_Switch := False;
645 Output_File_Name_Present := True;
647 -- Processing for p switch
652 -- Set all specific options as well as All_Checks in the
653 -- Suppress_Options array, excluding Elaboration_Check, since
654 -- this is treated specially because we do not want -gnatp to
655 -- disable static elaboration processing.
657 for J in Suppress_Options'Range loop
658 if J /= Elaboration_Check then
659 Suppress_Options (J) := True;
663 Validity_Checks_On := False;
664 Opt.Suppress_Checks := True;
665 Opt.Enable_Overflow_Checks := False;
667 -- Processing for P switch
671 Polling_Required := True;
673 -- Processing for q switch
677 Try_Semantics := True;
679 -- Processing for Q switch
683 Force_ALI_Tree_File := True;
684 Try_Semantics := True;
686 -- Processing for r switch
690 Treat_Restrictions_As_Warnings := True;
692 -- Processing for R switch
695 Back_Annotate_Rep_Info := True;
696 List_Representation_Info := 1;
699 while Ptr <= Max loop
700 C := Switch_Chars (Ptr);
702 if C in '1' .. '3' then
703 List_Representation_Info :=
704 Character'Pos (C) - Character'Pos ('0');
706 elsif Switch_Chars (Ptr) = 's' then
707 List_Representation_Info_To_File := True;
709 elsif Switch_Chars (Ptr) = 'm' then
710 List_Representation_Info_Mechanisms := True;
713 Bad_Switch ("-gnatR" & Switch_Chars (Ptr .. Max));
719 -- Processing for s switch
722 if not First_Switch then
724 ("-gnats must be first if combined with other switches");
728 Operating_Mode := Check_Syntax;
730 -- Processing for S switch
733 Print_Standard := True;
736 -- Processing for t switch
742 if Operating_Mode = Check_Semantics then
746 Back_Annotate_Rep_Info := True;
748 -- Processing for T switch
752 Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor, C);
754 -- Processing for u switch
760 -- Processing for U switch
764 Unique_Error_Tag := True;
766 -- Processing for v switch
770 Verbose_Mode := True;
772 -- Processing for V switch
775 Store_Switch := False;
779 Bad_Switch ("-gnatV");
786 Set_Validity_Check_Options
787 (Switch_Chars (Ptr .. Max), OK, Ptr);
790 Bad_Switch ("-gnatV" & Switch_Chars (Ptr .. Max));
793 for Index in First_Char + 1 .. Max loop
794 Store_Compilation_Switch
795 ("-gnatV" & Switch_Chars (Index));
802 -- Processing for w switch
805 Store_Switch := False;
809 Bad_Switch ("-gnatw");
812 while Ptr <= Max loop
813 C := Switch_Chars (Ptr);
815 -- Case of dot switch
817 if C = '.' and then Ptr < Max then
819 C := Switch_Chars (Ptr);
821 if Set_Dot_Warning_Switch (C) then
822 Store_Compilation_Switch ("-gnatw." & C);
824 Bad_Switch ("-gnatw." & Switch_Chars (Ptr .. Max));
827 -- Normal case, no dot
830 if Set_Warning_Switch (C) then
831 Store_Compilation_Switch ("-gnatw" & C);
833 Bad_Switch ("-gnatw" & Switch_Chars (Ptr .. Max));
842 -- Processing for W switch
848 Bad_Switch ("-gnatW");
852 Wide_Character_Encoding_Method :=
853 Get_WC_Encoding_Method (Switch_Chars (Ptr));
855 when Constraint_Error =>
856 Bad_Switch ("-gnatW" & Switch_Chars (Ptr .. Max));
859 Wide_Character_Encoding_Method_Specified := True;
861 Upper_Half_Encoding :=
862 Wide_Character_Encoding_Method in
863 WC_Upper_Half_Encoding_Method;
867 -- Processing for x switch
871 Xref_Active := False;
873 -- Processing for X switch
877 Extensions_Allowed := True;
879 -- Processing for y switch
885 Set_Default_Style_Check_Options;
888 Store_Switch := False;
894 Set_Style_Check_Options
895 (Switch_Chars (Ptr .. Max), OK, Ptr);
899 ("bad -gnaty switch (" &
900 Style_Msg_Buf (1 .. Style_Msg_Len) & ')');
903 Ptr := First_Char + 1;
904 while Ptr <= Max loop
905 if Switch_Chars (Ptr) = 'M' then
910 or else Switch_Chars (Ptr) not in '0' .. '9';
913 Store_Compilation_Switch
914 ("-gnaty" & Switch_Chars (First_Char .. Ptr - 1));
917 Store_Compilation_Switch
918 ("-gnaty" & Switch_Chars (Ptr));
925 -- Processing for z switch
930 -- Allowed for compiler only if this is the only
931 -- -z switch, we do not allow multiple occurrences
933 if Distribution_Stub_Mode = No_Stubs then
934 case Switch_Chars (Ptr) is
936 Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
939 Distribution_Stub_Mode := Generate_Caller_Stub_Body;
942 Bad_Switch ("-gnatz" & Switch_Chars (Ptr .. Max));
948 -- Processing for Z switch
953 ("-gnatZ is no longer supported: consider using --RTS=zcx");
955 -- Processing for 83 switch
959 Bad_Switch ("-gnat8");
964 if Switch_Chars (Ptr) /= '3' then
965 Bad_Switch ("-gnat8" & Switch_Chars (Ptr .. Max));
968 Ada_Version := Ada_83;
969 Ada_Version_Explicit := Ada_Version;
972 -- Processing for 95 switch
976 Bad_Switch ("-gnat9");
981 if Switch_Chars (Ptr) /= '5' then
982 Bad_Switch ("-gnat9" & Switch_Chars (Ptr .. Max));
985 Ada_Version := Ada_95;
986 Ada_Version_Explicit := Ada_Version;
989 -- Processing for 05 switch
993 Bad_Switch ("-gnat0");
998 if Switch_Chars (Ptr) /= '5' then
999 Bad_Switch ("-gnat0" & Switch_Chars (Ptr .. Max));
1002 Ada_Version := Ada_05;
1003 Ada_Version_Explicit := Ada_Version;
1006 -- Ignore extra switch character
1011 -- Anything else is an error (illegal switch character)
1014 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
1017 if Store_Switch then
1018 Store_Compilation_Switch
1019 ("-gnat" & Switch_Chars (First_Char .. Ptr - 1));
1022 First_Switch := False;
1025 end Scan_Front_End_Switches;