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)
136 Osint.Fail ("--RTS cannot be specified multiple times");
139 -- Valid --RTS switch
141 Opt.No_Stdinc := True;
142 Opt.RTS_Switch := True;
146 (Switch_Chars (Ptr + 4 .. Max), Include);
150 (Switch_Chars (Ptr + 4 .. Max), Objects);
152 if RTS_Src_Path_Name /= null
153 and then RTS_Lib_Path_Name /= null
155 -- Store the -fRTS switch (Note: Store_Compilation_Switch
156 -- changes -fRTS back into --RTS for the actual output).
158 Store_Compilation_Switch (Switch_Chars);
160 elsif RTS_Src_Path_Name = null
161 and then RTS_Lib_Path_Name = null
163 Osint.Fail ("RTS path not valid: missing " &
164 "adainclude and adalib directories");
166 elsif RTS_Src_Path_Name = null then
167 Osint.Fail ("RTS path not valid: missing " &
168 "adainclude directory");
170 elsif RTS_Lib_Path_Name = null then
171 Osint.Fail ("RTS path not valid: missing " &
176 -- There are no other switches not starting with -gnat
179 Bad_Switch (Switch_Chars);
182 -- Case of switch starting with -gnat
187 -- Loop to scan through switches given in switch string
189 while Ptr <= Max loop
191 Store_Switch := True;
193 C := Switch_Chars (Ptr);
199 Assertions_Enabled := True;
200 Debug_Pragmas_Enabled := True;
202 -- Processing for A switch
206 Config_File := False;
208 -- Processing for b switch
212 Brief_Output := True;
214 -- Processing for B switch
218 Assume_No_Invalid_Values := True;
220 -- Processing for c switch
223 if not First_Switch then
225 ("-gnatc must be first if combined with other switches");
229 Operating_Mode := Check_Semantics;
235 -- Processing for d switch
238 Store_Switch := False;
241 -- Note: for the debug switch, the remaining characters in this
242 -- switch field must all be debug flags, since all valid switch
243 -- characters are also valid debug characters.
245 -- Loop to scan out debug flags
249 C := Switch_Chars (Ptr);
250 exit when C = ASCII.NUL or else C = '/' or else C = '-';
252 if C in '1' .. '9' or else
253 C in 'a' .. 'z' or else
257 Set_Dotted_Debug_Flag (C);
258 Store_Compilation_Switch ("-gnatd." & C);
261 Store_Compilation_Switch ("-gnatd" & C);
268 Bad_Switch ("-gnatd." & Switch_Chars (Ptr .. Max));
270 Bad_Switch ("-gnatd" & Switch_Chars (Ptr .. Max));
276 -- Processing for D switch
281 -- Scan optional integer line limit value
283 if Ptr <= Max and then Switch_Chars (Ptr) in '0' .. '9' then
284 Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'D');
285 Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
288 -- Note: -gnatD also sets -gnatx (to turn off cross-reference
289 -- generation in the ali file) since otherwise this generation
290 -- gets confused by the "wrong" Sloc values put in the tree.
292 Debug_Generated_Code := True;
293 Xref_Active := False;
294 Set_Debug_Flag ('g');
296 -- -gnate? (extended switches)
301 -- The -gnate? switches are all double character switches
302 -- so we must always have a character after the e.
305 Bad_Switch ("-gnate");
308 case Switch_Chars (Ptr) is
311 Store_Switch := False;
312 Enable_Switch_Storing;
315 -- -gnatec (configuration pragmas)
318 Store_Switch := False;
321 -- There may be an equal sign between -gnatec and
322 -- the path name of the config file.
324 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
329 Bad_Switch ("-gnatec");
333 Config_File_Name : constant String_Access :=
335 (Switch_Chars (Ptr .. Max));
338 if Config_File_Names = null then
340 new String_List'(1 => Config_File_Name);
344 New_Names : constant String_List_Access :=
347 Config_File_Names'Length + 1);
350 for Index in Config_File_Names'Range loop
352 Config_File_Names (Index);
353 Config_File_Names (Index) := null;
356 New_Names (New_Names'Last) := Config_File_Name;
357 Free (Config_File_Names);
358 Config_File_Names := New_Names;
365 -- -gnateD switch (preprocessing symbol definition)
368 Store_Switch := False;
372 Bad_Switch ("-gnateD");
375 Add_Symbol_Definition (Switch_Chars (Ptr .. Max));
379 Store_Compilation_Switch
380 ("-gnateD" & Switch_Chars (Ptr .. Max));
383 -- -gnatef (full source path for brief error messages)
386 Store_Switch := False;
388 Full_Path_Name_For_Brief_Errors := True;
391 -- -gnateG (save preprocessor output)
395 Bad_Switch (Switch_Chars);
398 Generate_Processed_File := True;
401 -- -gnateI (index of unit in multi-unit source)
405 Scan_Pos (Switch_Chars, Max, Ptr, Multiple_Unit_Index, C);
407 -- -gnatem (mapping file)
410 Store_Switch := False;
413 -- There may be an equal sign between -gnatem and
414 -- the path name of the mapping file.
416 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
421 Bad_Switch ("-gnatem");
425 new String'(Switch_Chars (Ptr .. Max));
428 -- -gnatep (preprocessing data file)
431 Store_Switch := False;
434 -- There may be an equal sign between -gnatep and
435 -- the path name of the mapping file.
437 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
442 Bad_Switch ("-gnatep");
445 Preprocessing_Data_File :=
446 new String'(Switch_Chars (Ptr .. Max));
448 -- Store the switch, normalizing to -gnatep=
450 Store_Compilation_Switch
451 ("-gnatep=" & Preprocessing_Data_File.all);
456 Store_Switch := False;
457 Disable_Switch_Storing;
460 -- All other -gnate? switches are unassigned
463 Bad_Switch ("-gnate" & Switch_Chars (Ptr .. Max));
466 -- -gnatE (dynamic elaboration checks)
470 Dynamic_Elaboration_Checks := True;
472 -- -gnatf (full error messages)
476 All_Errors_Mode := True;
478 -- Processing for F switch
482 External_Name_Exp_Casing := Uppercase;
483 External_Name_Imp_Casing := Uppercase;
485 -- Processing for g switch
490 Identifier_Character_Set := 'n';
491 System_Extend_Unit := Empty;
492 Warning_Mode := Treat_As_Error;
494 -- Set Ada 2005 mode explicitly. We don't want to rely on the
495 -- implicit setting here, since for example, we want
496 -- Preelaborate_05 treated as Preelaborate
498 Ada_Version := Ada_05;
499 Ada_Version_Explicit := Ada_Version;
501 -- Set default warnings for -gnatg
503 Check_Unreferenced := True;
504 Check_Unreferenced_Formals := True;
506 Constant_Condition_Warnings := True;
507 Implementation_Unit_Warnings := True;
508 Ineffective_Inline_Warnings := True;
509 Warn_On_Assertion_Failure := True;
510 Warn_On_Assumed_Low_Bound := True;
511 Warn_On_Bad_Fixed_Value := True;
512 Warn_On_Constant := True;
513 Warn_On_Export_Import := True;
514 Warn_On_Modified_Unread := True;
515 Warn_On_No_Value_Assigned := True;
516 Warn_On_Non_Local_Exception := False;
517 Warn_On_Obsolescent_Feature := True;
518 Warn_On_Redundant_Constructs := True;
519 Warn_On_Object_Renames_Function := True;
520 Warn_On_Unchecked_Conversion := True;
521 Warn_On_Unrecognized_Pragma := True;
523 Set_GNAT_Style_Check_Options;
525 -- Processing for G switch
529 Print_Generated_Code := True;
531 -- Scan optional integer line limit value
533 if Ptr <= Max and then Switch_Chars (Ptr) in '0' .. '9' then
534 Scan_Nat (Switch_Chars, Max, Ptr, Sprint_Line_Limit, 'G');
535 Sprint_Line_Limit := Nat'Max (Sprint_Line_Limit, 40);
538 -- Processing for h switch
542 Usage_Requested := True;
544 -- Processing for H switch
550 -- Processing for i switch
554 Bad_Switch ("-gnati");
558 C := Switch_Chars (Ptr);
568 Identifier_Character_Set := C;
572 Bad_Switch ("-gnati" & Switch_Chars (Ptr .. Max));
575 -- Processing for I switch
579 Ignore_Rep_Clauses := True;
581 -- Processing for j switch
586 -- There may be an equal sign between -gnatj and the value
588 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
592 Scan_Nat (Switch_Chars, Max, Ptr, Error_Msg_Line_Length, C);
594 -- Processing for k switch
599 (Switch_Chars, Max, Ptr, Maximum_File_Name_Length, C);
601 -- Processing for l switch
607 -- There may be an equal sign between -gnatl and a file name
609 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
611 Osint.Fail ("file name for -gnatl= is null");
613 Opt.Full_List_File_Name :=
614 new String'(Switch_Chars (Ptr + 1 .. Max));
619 -- Processing for L switch
623 Dump_Source_Text := True;
625 -- Processing for m switch
630 -- There may be an equal sign between -gnatm and the value
632 if Ptr <= Max and then Switch_Chars (Ptr) = '=' then
636 Scan_Nat (Switch_Chars, Max, Ptr, Maximum_Errors, C);
638 -- Processing for n switch
642 Inline_Active := True;
644 -- Processing for N switch
648 Inline_Active := True;
649 Front_End_Inlining := True;
651 -- Processing for o switch
655 Suppress_Options (Overflow_Check) := False;
656 Opt.Enable_Overflow_Checks := True;
658 -- Processing for O switch
661 Store_Switch := False;
663 Output_File_Name_Present := True;
665 -- Processing for p switch
670 -- Set all specific options as well as All_Checks in the
671 -- Suppress_Options array, excluding Elaboration_Check, since
672 -- this is treated specially because we do not want -gnatp to
673 -- disable static elaboration processing.
675 for J in Suppress_Options'Range loop
676 if J /= Elaboration_Check then
677 Suppress_Options (J) := True;
681 Validity_Checks_On := False;
682 Opt.Suppress_Checks := True;
683 Opt.Enable_Overflow_Checks := False;
685 -- Processing for P switch
689 Polling_Required := True;
691 -- Processing for q switch
695 Try_Semantics := True;
697 -- Processing for Q switch
701 Force_ALI_Tree_File := True;
702 Try_Semantics := True;
704 -- Processing for r switch
708 Treat_Restrictions_As_Warnings := True;
710 -- Processing for R switch
713 Back_Annotate_Rep_Info := True;
714 List_Representation_Info := 1;
717 while Ptr <= Max loop
718 C := Switch_Chars (Ptr);
720 if C in '1' .. '3' then
721 List_Representation_Info :=
722 Character'Pos (C) - Character'Pos ('0');
724 elsif Switch_Chars (Ptr) = 's' then
725 List_Representation_Info_To_File := True;
727 elsif Switch_Chars (Ptr) = 'm' then
728 List_Representation_Info_Mechanisms := True;
731 Bad_Switch ("-gnatR" & Switch_Chars (Ptr .. Max));
737 -- Processing for s switch
740 if not First_Switch then
742 ("-gnats must be first if combined with other switches");
746 Operating_Mode := Check_Syntax;
748 -- Processing for S switch
751 Print_Standard := True;
754 -- Processing for t switch
760 if Operating_Mode = Check_Semantics then
764 Back_Annotate_Rep_Info := True;
766 -- Processing for T switch
770 Scan_Pos (Switch_Chars, Max, Ptr, Table_Factor, C);
772 -- Processing for u switch
778 -- Processing for U switch
782 Unique_Error_Tag := True;
784 -- Processing for v switch
788 Verbose_Mode := True;
790 -- Processing for V switch
793 Store_Switch := False;
797 Bad_Switch ("-gnatV");
804 Set_Validity_Check_Options
805 (Switch_Chars (Ptr .. Max), OK, Ptr);
808 Bad_Switch ("-gnatV" & Switch_Chars (Ptr .. Max));
811 for Index in First_Char + 1 .. Max loop
812 Store_Compilation_Switch
813 ("-gnatV" & Switch_Chars (Index));
820 -- Processing for w switch
823 Store_Switch := False;
827 Bad_Switch ("-gnatw");
830 while Ptr <= Max loop
831 C := Switch_Chars (Ptr);
833 -- Case of dot switch
835 if C = '.' and then Ptr < Max then
837 C := Switch_Chars (Ptr);
839 if Set_Dot_Warning_Switch (C) then
840 Store_Compilation_Switch ("-gnatw." & C);
842 Bad_Switch ("-gnatw." & Switch_Chars (Ptr .. Max));
845 -- Normal case, no dot
848 if Set_Warning_Switch (C) then
849 Store_Compilation_Switch ("-gnatw" & C);
851 Bad_Switch ("-gnatw" & Switch_Chars (Ptr .. Max));
860 -- Processing for W switch
866 Bad_Switch ("-gnatW");
870 Wide_Character_Encoding_Method :=
871 Get_WC_Encoding_Method (Switch_Chars (Ptr));
873 when Constraint_Error =>
874 Bad_Switch ("-gnatW" & Switch_Chars (Ptr .. Max));
877 Wide_Character_Encoding_Method_Specified := True;
879 Upper_Half_Encoding :=
880 Wide_Character_Encoding_Method in
881 WC_Upper_Half_Encoding_Method;
885 -- Processing for x switch
889 Xref_Active := False;
891 -- Processing for X switch
895 Extensions_Allowed := True;
897 -- Processing for y switch
903 Set_Default_Style_Check_Options;
906 Store_Switch := False;
912 Set_Style_Check_Options
913 (Switch_Chars (Ptr .. Max), OK, Ptr);
917 ("bad -gnaty switch (" &
918 Style_Msg_Buf (1 .. Style_Msg_Len) & ')');
921 Ptr := First_Char + 1;
922 while Ptr <= Max loop
923 if Switch_Chars (Ptr) = 'M' then
928 or else Switch_Chars (Ptr) not in '0' .. '9';
931 Store_Compilation_Switch
932 ("-gnaty" & Switch_Chars (First_Char .. Ptr - 1));
935 Store_Compilation_Switch
936 ("-gnaty" & Switch_Chars (Ptr));
943 -- Processing for z switch
948 -- Allowed for compiler only if this is the only
949 -- -z switch, we do not allow multiple occurrences
951 if Distribution_Stub_Mode = No_Stubs then
952 case Switch_Chars (Ptr) is
954 Distribution_Stub_Mode := Generate_Receiver_Stub_Body;
957 Distribution_Stub_Mode := Generate_Caller_Stub_Body;
960 Bad_Switch ("-gnatz" & Switch_Chars (Ptr .. Max));
966 -- Processing for Z switch
971 ("-gnatZ is no longer supported: consider using --RTS=zcx");
973 -- Processing for 83 switch
977 Bad_Switch ("-gnat8");
982 if Switch_Chars (Ptr) /= '3' then
983 Bad_Switch ("-gnat8" & Switch_Chars (Ptr .. Max));
986 Ada_Version := Ada_83;
987 Ada_Version_Explicit := Ada_Version;
990 -- Processing for 95 switch
994 Bad_Switch ("-gnat9");
999 if Switch_Chars (Ptr) /= '5' then
1000 Bad_Switch ("-gnat9" & Switch_Chars (Ptr .. Max));
1003 Ada_Version := Ada_95;
1004 Ada_Version_Explicit := Ada_Version;
1007 -- Processing for 05 switch
1011 Bad_Switch ("-gnat0");
1016 if Switch_Chars (Ptr) /= '5' then
1017 Bad_Switch ("-gnat0" & Switch_Chars (Ptr .. Max));
1020 Ada_Version := Ada_05;
1021 Ada_Version_Explicit := Ada_Version;
1024 -- Ignore extra switch character
1029 -- Anything else is an error (illegal switch character)
1032 Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max));
1035 if Store_Switch then
1036 Store_Compilation_Switch
1037 ("-gnat" & Switch_Chars (First_Char .. Ptr - 1));
1040 First_Switch := False;
1043 end Scan_Front_End_Switches;